Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(systemtest): Add cli.RunAndWait for common operations #21689

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions tests/systemtests/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,17 @@ func TestAccountCreation(t *testing.T) {
rsp := cli.CustomQuery("q", "auth", "account", account1Addr)
assert.Equal(t, account1Addr, gjson.Get(rsp, "account.value.address").String(), rsp)

rsp1 := cli.Run("tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from="+account1Addr, "--fees=1stake")
txResult, found := cli.AwaitTxCommitted(rsp1)
require.True(t, found)
RequireTxSuccess(t, txResult)
rsp1 := cli.RunAndWait("tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from="+account1Addr, "--fees=1stake")
RequireTxSuccess(t, rsp1)

// query account2
assertNotFound := func(t assert.TestingT, err error, msgAndArgs ...interface{}) (ok bool) {
return strings.Contains(err.Error(), "not found: key not found")
}
_ = cli.WithRunErrorMatcher(assertNotFound).CustomQuery("q", "auth", "account", account2Addr)

rsp3 := cli.Run("tx", "bank", "send", account2Addr, account1Addr, "1000stake", "--from="+account2Addr, "--fees=1stake")
txResult, found = cli.AwaitTxCommitted(rsp3)
require.True(t, found)
RequireTxSuccess(t, txResult)
rsp3 := cli.RunAndWait("tx", "bank", "send", account2Addr, account1Addr, "1000stake", "--from="+account2Addr, "--fees=1stake")
RequireTxSuccess(t, rsp3)

// query account2 to make sure its created
rsp4 := cli.CustomQuery("q", "auth", "account", account2Addr)
Expand Down
11 changes: 11 additions & 0 deletions tests/systemtests/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,18 @@ func (c CLIWrapper) Run(args ...string) string {
return rsp
}

// RunAndWait runs a cli command and waits for the server result when the TX is executed
// It returns the result of the transaction.
func (c CLIWrapper) RunAndWait(args ...string) string {
rsp := c.Run(args...)
RequireTxSuccess(c.t, rsp)
txResult, found := c.AwaitTxCommitted(rsp)
require.True(c.t, found)
return txResult
}

// AwaitTxCommitted wait for tx committed on chain
// returns the server execution result and true when found within 3 blocks.
func (c CLIWrapper) AwaitTxCommitted(submitResp string, timeout ...time.Duration) (string, bool) {
c.t.Helper()
RequireTxSuccess(c.t, submitResp)
Expand Down
4 changes: 2 additions & 2 deletions tests/systemtests/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestStakeUnstake(t *testing.T) {
valAddr := gjson.Get(rsp, "validators.#.operator_address").Array()[0].String()

// stake tokens
rsp = cli.Run("tx", "staking", "delegate", valAddr, "10000stake", "--from="+account1Addr, "--fees=1stake")
rsp = cli.RunAndWait("tx", "staking", "delegate", valAddr, "10000stake", "--from="+account1Addr, "--fees=1stake")
RequireTxSuccess(t, rsp)

t.Log(cli.QueryBalance(account1Addr, "stake"))
Expand All @@ -42,7 +42,7 @@ func TestStakeUnstake(t *testing.T) {
assert.Equal(t, "stake", gjson.Get(rsp, "delegation_response.balance.denom").String(), rsp)

// unstake tokens
rsp = cli.Run("tx", "staking", "unbond", valAddr, "5000stake", "--from="+account1Addr, "--fees=1stake")
rsp = cli.RunAndWait("tx", "staking", "unbond", valAddr, "5000stake", "--from="+account1Addr, "--fees=1stake")
RequireTxSuccess(t, rsp)

rsp = cli.CustomQuery("q", "staking", "delegation", account1Addr, valAddr)
Expand Down
Loading