From 18ff17064298352e0e5f668a408d77045df214ac Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Thu, 12 Sep 2024 15:38:55 +0200 Subject: [PATCH 1/2] Make staking test more stable --- tests/systemtests/cli.go | 11 +++++++++++ tests/systemtests/staking_test.go | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/systemtests/cli.go b/tests/systemtests/cli.go index 871d810ea4a..fcc6bb518c0 100644 --- a/tests/systemtests/cli.go +++ b/tests/systemtests/cli.go @@ -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) diff --git a/tests/systemtests/staking_test.go b/tests/systemtests/staking_test.go index f197bff1a0a..5f8f911191b 100644 --- a/tests/systemtests/staking_test.go +++ b/tests/systemtests/staking_test.go @@ -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")) @@ -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) From 73ff13ca3a7bb29daa32885cd5c2e94ae7935764 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Thu, 12 Sep 2024 15:56:37 +0200 Subject: [PATCH 2/2] Minor update --- tests/systemtests/account_test.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/systemtests/account_test.go b/tests/systemtests/account_test.go index 42580862e60..5f3ee7e340a 100644 --- a/tests/systemtests/account_test.go +++ b/tests/systemtests/account_test.go @@ -33,10 +33,8 @@ 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) { @@ -44,10 +42,8 @@ func TestAccountCreation(t *testing.T) { } _ = 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)