Skip to content

Commit

Permalink
test: e2e/staking to system tests (#21882)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano committed Sep 25, 2024
1 parent 71f1807 commit c971f75
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 147 deletions.
20 changes: 0 additions & 20 deletions tests/e2e/staking/cli_test.go

This file was deleted.

122 changes: 0 additions & 122 deletions tests/e2e/staking/suite.go

This file was deleted.

2 changes: 1 addition & 1 deletion tests/systemtests/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ go test -mod=readonly -tags='system_test' -v ./... --run TestQueryTotalSupply -
## Part 4: Set state via TX

Complexer workflows and tests require modifying state on a running chain. This works only with builtin logic and operations.
If we want to burn some our new tokens, we need to submit a bank burn message to do this.
If we want to burn some of our new tokens, we need to submit a bank burn message to do this.
The CLI wrapper works similar to the query. Just pass the parameters. It uses the `node0` key as *default*:

```go
Expand Down
17 changes: 13 additions & 4 deletions tests/systemtests/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func TestStakeUnstake(t *testing.T) {
// Scenario:
// delegate tokens to validator
// check validator has been updated
// undelegate some tokens

sut.ResetChain(t)
Expand All @@ -29,24 +30,32 @@ func TestStakeUnstake(t *testing.T) {
// query validator address to delegate tokens
rsp := cli.CustomQuery("q", "staking", "validators")
valAddr := gjson.Get(rsp, "validators.#.operator_address").Array()[0].String()
valPk := gjson.Get(rsp, "validators.#.consensus_pubkey.value").Array()[0].String()

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

t.Log(cli.QueryBalance(account1Addr, "stake"))
assert.Equal(t, int64(9989999), cli.QueryBalance(account1Addr, "stake"))
assert.Equal(t, int64(8999999), cli.QueryBalance(account1Addr, "stake"))

// check validator has been updated
rsp = cli.CustomQuery("q", "block-results", gjson.Get(rsp, "height").String())
validatorUpdates := gjson.Get(rsp, "validator_updates").Array()
assert.NotEmpty(t, validatorUpdates)
vpk := gjson.Get(validatorUpdates[0].String(), "pub_key_bytes").String()
assert.Equal(t, vpk, valPk)

rsp = cli.CustomQuery("q", "staking", "delegation", account1Addr, valAddr)
assert.Equal(t, "10000", gjson.Get(rsp, "delegation_response.balance.amount").String(), rsp)
assert.Equal(t, "1000000", gjson.Get(rsp, "delegation_response.balance.amount").String(), rsp)
assert.Equal(t, "stake", gjson.Get(rsp, "delegation_response.balance.denom").String(), rsp)

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

rsp = cli.CustomQuery("q", "staking", "delegation", account1Addr, valAddr)
assert.Equal(t, "5000", gjson.Get(rsp, "delegation_response.balance.amount").String(), rsp)
assert.Equal(t, "995000", gjson.Get(rsp, "delegation_response.balance.amount").String(), rsp)
assert.Equal(t, "stake", gjson.Get(rsp, "delegation_response.balance.denom").String(), rsp)

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

0 comments on commit c971f75

Please sign in to comment.