Skip to content

Commit

Permalink
WIP: add few more testcases and start tests on grpc queries
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilkumarpilli committed Sep 10, 2024
1 parent f2b5903 commit 7c9611c
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions tests/systemtests/bank_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build system_test

package systemtests

import (
Expand Down Expand Up @@ -32,12 +30,12 @@ func TestBankSendTxCmd(t *testing.T) {
sut.StartChain(t)

// query accounts balances
balance := cli.QueryBalance(account1Addr, "stake")
assert.Equal(t, int64(initialAmount), balance)
balance = cli.QueryBalance(account2Addr, "stake")
assert.Equal(t, int64(initialAmount), balance)
balance1 := cli.QueryBalance(account1Addr, "stake")
assert.Equal(t, int64(initialAmount), balance1)
balance2 := cli.QueryBalance(account2Addr, "stake")
assert.Equal(t, int64(initialAmount), balance2)

bankSendCmdArgs := []string{"tx", "bank", "send", account1Addr, account2Addr, "1000stake", "--from=" + account1Addr}
bankSendCmdArgs := []string{"tx", "bank", "send", account1Addr, account2Addr, "1000stake"}

testCases := []struct {
name string
Expand Down Expand Up @@ -90,6 +88,26 @@ func TestBankSendTxCmd(t *testing.T) {
})
}

// test tx bank send with insufficient funds
insufficientCmdArgs := bankSendCmdArgs[0 : len(bankSendCmdArgs)-1]
insufficientCmdArgs = append(insufficientCmdArgs, initialBalance, "--fees=10stake")
rsp := cli.Run(insufficientCmdArgs...)
RequireTxFailure(t, rsp)
assert.Contains(t, rsp, sdkerrors.ErrInsufficientFunds.Error())

// test tx bank send with unauthorized signature
assertUnauthorizedErr := func(t assert.TestingT, gotErr error, gotOutputs ...interface{}) bool {
assert.Len(t, gotOutputs, 1)
code := gjson.Get(gotOutputs[0].(string), "code")
assert.True(t, code.Exists())
assert.Equal(t, int64(sdkerrors.ErrUnauthorized.ABCICode()), code.Int())
return false
}
invalidCli := cli
invalidCli.chainID = cli.chainID + "a" // set invalid chain-id
rsp = invalidCli.WithRunErrorMatcher(assertUnauthorizedErr).Run(bankSendCmdArgs...)
RequireTxFailure(t, rsp)

// test tx bank send generate only
assertGenOnlyOutput := func(t assert.TestingT, gotErr error, gotOutputs ...interface{}) bool {
assert.Len(t, gotOutputs, 1)
Expand Down Expand Up @@ -214,3 +232,21 @@ func TestBankMultiSendTxCmd(t *testing.T) {
})
}
}

func TestBankGRPCQueries(t *testing.T) {
// scenario: test bank grpc gateway queries
// given a running chain

sut.ResetChain(t)
cli := NewCLIWrapper(t, sut, verbose)
// add genesis account with some tokens
account1Addr := cli.AddKey("account1")
account2Addr := cli.AddKey("account2")
require.NotEqual(t, account1Addr, account2Addr)
sut.ModifyGenesisCLI(t,
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"},
)

sut.StartChain(t)

}

0 comments on commit 7c9611c

Please sign in to comment.