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

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>
This commit is contained in:
mergify[bot] 2024-09-13 14:50:40 +02:00 committed by GitHub
parent 18dd4cde21
commit ff7faf57d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 10 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)