cosmos-sdk/x/auth/stdtx_test.go
Dev Ojha cb86efa054 Merge PR #2376: auth: Don't recalculate mempool fees for every msg signer, misc. cleanup
This PR begins improving the godocs for the auth module, and begins cleaning
up the Ante handler.

Additionally we previously calculated if the fee was sufficient for the tx
on every single signer. This is now refactored to be more efficient, and have
a better logical flow. No changelog entry as this is new to this release.
2018-09-27 02:34:01 +08:00

54 lines
1.3 KiB
Go

package auth
import (
"fmt"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
)
var (
priv = ed25519.GenPrivKey()
addr = sdk.AccAddress(priv.PubKey().Address())
)
func TestStdTx(t *testing.T) {
msgs := []sdk.Msg{sdk.NewTestMsg(addr)}
fee := newStdFee()
sigs := []StdSignature{}
tx := NewStdTx(msgs, fee, sigs, "")
require.Equal(t, msgs, tx.GetMsgs())
require.Equal(t, sigs, tx.GetSignatures())
feePayer := tx.GetSigners()[0]
require.Equal(t, addr, feePayer)
}
func TestStdSignBytes(t *testing.T) {
type args struct {
chainID string
accnum int64
sequence int64
fee StdFee
msgs []sdk.Msg
memo string
}
defaultFee := newStdFee()
tests := []struct {
args args
want string
}{
{
args{"1234", 3, 6, defaultFee, []sdk.Msg{sdk.NewTestMsg(addr)}, "memo"},
fmt.Sprintf("{\"account_number\":\"3\",\"chain_id\":\"1234\",\"fee\":{\"amount\":[{\"amount\":\"150\",\"denom\":\"atom\"}],\"gas\":\"5000\"},\"memo\":\"memo\",\"msgs\":[[\"%s\"]],\"sequence\":\"6\"}", addr),
},
}
for i, tc := range tests {
got := string(StdSignBytes(tc.args.chainID, tc.args.accnum, tc.args.sequence, tc.args.fee, tc.args.msgs, tc.args.memo))
require.Equal(t, tc.want, got, "Got unexpected result on test case i: %d", i)
}
}