From b9780ff9aee90903781ee1e7e5e0f746c06447f9 Mon Sep 17 00:00:00 2001 From: Zach Ramsay Date: Tue, 20 Feb 2018 23:57:24 +0000 Subject: [PATCH] x/bank: boost test coverage --- x/bank/tx_test.go | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/x/bank/tx_test.go b/x/bank/tx_test.go index 4ce8b1fe9d..bf78c7f282 100644 --- a/x/bank/tx_test.go +++ b/x/bank/tx_test.go @@ -1,6 +1,7 @@ package bank import ( + //"fmt" "testing" "github.com/stretchr/testify/assert" @@ -10,6 +11,27 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +func TestSendMsgType(t *testing.T) { + // Construct a SendMsg + var msg = SendMsg{ + Inputs: []Input{ + { + Address: crypto.Address([]byte("input")), + Coins: sdk.Coins{{"atom", 10}}, + Sequence: 1, + }, + }, + Outputs: []Output{ + { + Address: crypto.Address([]byte("output")), + Coins: sdk.Coins{{"atom", 10}}, + }, + }, + } + + assert.Equal(t, msg.Type(), "bank") +} + func TestInputValidation(t *testing.T) { addr1 := crypto.Address([]byte{1, 2}) addr2 := crypto.Address([]byte{7, 8}) @@ -165,6 +187,60 @@ func TestSendMsgValidation(t *testing.T) { } } +func TestSendMsgString(t *testing.T) { + // Construct a SendMsg + var msg = SendMsg{ + Inputs: []Input{ + { + Address: crypto.Address([]byte("input")), + Coins: sdk.Coins{{"atom", 10}}, + Sequence: 1, + }, + }, + Outputs: []Output{ + { + Address: crypto.Address([]byte("output")), + Coins: sdk.Coins{{"atom", 10}}, + }, + }, + } + res := msg.String() + assert.Equal(t, res, "SendMsg{[Input{696E707574,10atom}]->[Output{364637353734373037353734,10atom}]}") +} + +// ---------------------------------------- +// IssueMsg Tests + +func TestIssueMsgString(t *testing.T) { + // Construct a IssueMsg + var msg = IssueMsg{ + Banker: crypto.Address([]byte("input")), + Outputs: []Output{ + { + Address: crypto.Address([]byte("loan-from-bank")), + Coins: sdk.Coins{{"atom", 10}}, + }, + }, + } + res := msg.String() + assert.Equal(t, res, "IssueMsg{696E707574#[Output{36433646363136453244363637323646364432443632363136453642,10atom}]}") +} + +func TestIssueMsgType(t *testing.T) { + // Construct an IssueMsg + var msg = IssueMsg{ + Banker: crypto.Address([]byte("input")), + Outputs: []Output{ + { + Address: crypto.Address([]byte("loan-from-bank")), + Coins: sdk.Coins{{"atom", 10}}, + }, + }, + } + + assert.Equal(t, msg.Type(), "bank") +} + /* // TODO where does this test belong ? func TestSendMsgSigners(t *testing.T) {