Skip to content

Commit

Permalink
No need to create a fake slice of signatures nor skip account no./seq…
Browse files Browse the repository at this point in the history
…uence check
  • Loading branch information
alessio committed Aug 31, 2018
1 parent 1ed7656 commit d84885c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 2 additions & 0 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 9 additions & 16 deletions x/auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down

0 comments on commit d84885c

Please sign in to comment.