fixes from review

This commit is contained in:
Ethan Buchman 2018-03-17 21:53:27 +01:00
parent a908a01fe2
commit 7c3213fa00
5 changed files with 49 additions and 31 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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

View File

@ -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}

View File

@ -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") })
}