No need to create a fake slice of signatures nor skip account no./sequence check

This commit is contained in:
Alessio Treglia 2018-08-31 17:47:20 +02:00
parent 1ed76565f2
commit d84885ca49
No known key found for this signature in database
GPG Key ID: E8A48AE5311D765A
3 changed files with 12 additions and 17 deletions

View File

@ -159,6 +159,8 @@ func (ctx CLIContext) WithUseLedger(useLedger bool) CLIContext {
// WithCertifier - return a copy of the context with an updated Certifier
func (ctx CLIContext) WithCertifier(certifier tmlite.Certifier) CLIContext {
ctx.Certifier = certifier
return ctx
}
// WithGasAdjustment returns a copy of the context with an updated GasAdjustment flag.
func (ctx CLIContext) WithGasAdjustment(adjustment float64) CLIContext {

View File

@ -68,9 +68,6 @@ func NewAnteHandler(am AccountMapper, fck FeeCollectionKeeper) sdk.AnteHandler {
sigs := stdTx.GetSignatures() // When simulating, this would just be a 0-length slice.
signerAddrs := stdTx.GetSigners()
msgs := tx.GetMsgs()
if simulate {
sigs = make([]StdSignature, len(signerAddrs))
}
// charge gas for the memo
newCtx.GasMeter().ConsumeGas(memoCostPerByte*sdk.Gas(len(stdTx.GetMemo())), "memo")
@ -160,20 +157,16 @@ func processSig(
accnum := acc.GetAccountNumber()
seq := acc.GetSequence()
// Perform checks that wouldn't pass successfully in simulation, i.e. sig
// would be empty as simulated transactions come with no signatures whatsoever.
if !simulate {
// Check account number.
if accnum != sig.AccountNumber {
return nil, sdk.ErrInvalidSequence(
fmt.Sprintf("Invalid account number. Got %d, expected %d", sig.AccountNumber, accnum)).Result()
}
// Check account number.
if accnum != sig.AccountNumber {
return nil, sdk.ErrInvalidSequence(
fmt.Sprintf("Invalid account number. Got %d, expected %d", sig.AccountNumber, accnum)).Result()
}
// Check sequence number.
if seq != sig.Sequence {
return nil, sdk.ErrInvalidSequence(
fmt.Sprintf("Invalid sequence. Got %d, expected %d", sig.Sequence, seq)).Result()
}
// Check sequence number.
if seq != sig.Sequence {
return nil, sdk.ErrInvalidSequence(
fmt.Sprintf("Invalid sequence. Got %d, expected %d", sig.Sequence, seq)).Result()
}
err := acc.SetSequence(seq + 1)
if err != nil {

View File

@ -123,7 +123,7 @@ func TestMsgSendWithAccounts(t *testing.T) {
msgs: []sdk.Msg{sendMsg1, sendMsg2},
accNums: []int64{0},
accSeqs: []int64{0},
expSimPass: true,
expSimPass: false,
expPass: false,
privKeys: []crypto.PrivKey{priv1},
},