diff --git a/types/errors.go b/types/errors.go index 5c96d8c241..48e08b1164 100644 --- a/types/errors.go +++ b/types/errors.go @@ -52,7 +52,7 @@ func CodeToDefaultMsg(code CodeType) string { case CodeUnrecognizedAddress: return "Unrecognized address" case CodeInvalidPubKey: - return "Missing pubkey" + return "Invalid pubkey" default: return fmt.Sprintf("Unknown code %d", code) } diff --git a/types/tx_msg.go b/types/tx_msg.go index b41d9879a9..21bc330540 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -146,3 +146,32 @@ func (msg StdSignMsg) Bytes() []byte { // Application function variable used to unmarshal transaction bytes type TxDecoder func(txBytes []byte) (Tx, Error) + +//__________________________________________________________ + +var _ Msg = (*TestMsg)(nil) + +// msg type for testing +type TestMsg struct { + signers []Address +} + +func NewTestMsg(addrs ...Address) *TestMsg { + return &TestMsg{ + signers: addrs, + } +} + +func (msg *TestMsg) Type() string { return "TestMsg" } +func (msg *TestMsg) Get(key interface{}) (value interface{}) { return nil } +func (msg *TestMsg) GetSignBytes() []byte { + bz, err := json.Marshal(msg.signers) + if err != nil { + panic(err) + } + return bz +} +func (msg *TestMsg) ValidateBasic() Error { return nil } +func (msg *TestMsg) GetSigners() []Address { + return msg.signers +} diff --git a/x/auth/ante.go b/x/auth/ante.go index 2da0d92868..43b9bb8341 100644 --- a/x/auth/ante.go +++ b/x/auth/ante.go @@ -133,7 +133,9 @@ func processSig( return } -// deduct the fee from the account +// Deduct the fee from the account. +// We could use the CoinKeeper (in addition to the AccountMapper, +// because the CoinKeeper doesn't give us accounts), but it seems easier to do this. func deductFees(acc sdk.Account, fee sdk.StdFee) (sdk.Account, sdk.Result) { coins := acc.GetCoins() feeAmount := fee.Amount diff --git a/x/auth/ante_test.go b/x/auth/ante_test.go index ecd2226230..5bbb3d0b69 100644 --- a/x/auth/ante_test.go +++ b/x/auth/ante_test.go @@ -1,7 +1,6 @@ package auth import ( - "encoding/json" "testing" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,29 +10,8 @@ import ( crypto "github.com/tendermint/go-crypto" ) -// msg type for testing -type testMsg struct { - signers []sdk.Address -} - -func newTestMsg(addrs ...sdk.Address) *testMsg { - return &testMsg{ - signers: addrs, - } -} - -func (msg *testMsg) Type() string { return "testMsg" } -func (msg *testMsg) Get(key interface{}) (value interface{}) { return nil } -func (msg *testMsg) GetSignBytes() []byte { - bz, err := json.Marshal(msg.signers) - if err != nil { - panic(err) - } - return bz -} -func (msg *testMsg) ValidateBasic() sdk.Error { return nil } -func (msg *testMsg) GetSigners() []sdk.Address { - return msg.signers +func newTestMsg(addrs ...sdk.Address) *sdk.TestMsg { + return sdk.NewTestMsg(addrs...) } func newStdFee() sdk.StdFee { @@ -246,6 +224,10 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { var tx sdk.Tx msg := newTestMsg(addr1) fee := newStdFee() + fee2 := newStdFee() + fee2.Gas += 100 + fee3 := newStdFee() + fee3.Amount[0].Amount += 100 // test good tx and signBytes privs, seqs := []crypto.PrivKey{priv1}, []int64{0} @@ -253,6 +235,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { checkValidTx(t, anteHandler, ctx, tx) chainID := ctx.ChainID() + chainID2 := chainID + "somemorestuff" codeUnauth := sdk.CodeUnauthorized cases := []struct { @@ -262,9 +245,12 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { msg sdk.Msg code sdk.CodeType }{ - {"", []int64{1}, fee, msg, codeUnauth}, // test invalid chain_id - {chainID, []int64{2}, fee, msg, codeUnauth}, // test wrong seqs - {chainID, []int64{1}, fee, newTestMsg(addr2), codeUnauth}, // test wrong msg + {chainID2, []int64{1}, fee, msg, codeUnauth}, // test wrong chain_id + {chainID, []int64{2}, fee, msg, codeUnauth}, // test wrong seqs + {chainID, []int64{1, 2}, fee, msg, codeUnauth}, // test wrong seqs + {chainID, []int64{1}, fee, newTestMsg(addr2), codeUnauth}, // test wrong msg + {chainID, []int64{1}, fee2, newTestMsg(addr2), codeUnauth}, // test wrong fee + {chainID, []int64{1}, fee3, newTestMsg(addr2), codeUnauth}, // test wrong fee } privs, seqs = []crypto.PrivKey{priv1}, []int64{1} diff --git a/x/auth/baseaccount_test.go b/x/auth/baseaccount_test.go index 85adc8cdca..b2f5b54ae2 100644 --- a/x/auth/baseaccount_test.go +++ b/x/auth/baseaccount_test.go @@ -27,7 +27,7 @@ func TestBaseAccountAddressPubKey(t *testing.T) { assert.EqualValues(t, addr1, acc.GetAddress()) assert.EqualValues(t, crypto.PubKey{}, acc.GetPubKey()) - // cant override address + // can't override address err := acc.SetAddress(addr2) assert.NotNil(t, err) assert.EqualValues(t, addr1, acc.GetAddress()) @@ -37,7 +37,7 @@ func TestBaseAccountAddressPubKey(t *testing.T) { assert.Nil(t, err) assert.Equal(t, pub1, acc.GetPubKey()) - // cant override pubkey + // can't override pubkey err = acc.SetPubKey(pub2) assert.NotNil(t, err) assert.Equal(t, pub1, acc.GetPubKey()) @@ -111,6 +111,7 @@ func TestBaseAccountGetSet(t *testing.T) { _, _, addr := keyPubAddr() acc := NewBaseAccountWithAddress(addr) + // Get/Set are not yet defined - all values cause a panic. assert.Panics(t, func() { acc.Get("key") }) assert.Panics(t, func() { acc.Set("key", "value") }) }