Files
wasmd/tests/system/staking_test.go
Alexander Peters cd7837680b Add system tests for chain upgrade (#1643)
* Start chain upgrade tests

* Fix stakeunstake test

* Make test pass

* Better stop chain

* Test chain upgrade

* Set upgrade handler order

* Fix app for chain upgrade

* Minor cleanup

* Check contract state

* Updates

* Gov constitution migration will be handled by the sdk

* Deactivate upgrade test

* Helper

* Better upgrade structure an minor updates

(cherry picked from commit 32a01da4563b52df6167929f3535d111ad18a1b7)

* Updates

* Gci formatting

* Updates

* Testnet commit timeout

* Update

* Store artifacts on system test failure

* Better circleci setup

* Artifact path

* x

* Fix upgrade

* Generic upgrade handler

* Fix imports

* Update tests/system/cli.go

Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>

---------

Co-authored-by: Pino' Surace <pino.surace@live.it>
Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
2023-10-13 14:16:31 +02:00

55 lines
1.8 KiB
Go

//go:build system_test
package system
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tidwall/gjson"
)
func TestStakeUnstake(t *testing.T) {
// Scenario:
// delegate tokens to validator
// undelegate some tokens
sut.ResetChain(t)
cli := NewWasmdCLI(t, sut, verbose)
// add genesis account with some tokens
account1Addr := cli.AddKey("account1")
sut.ModifyGenesisCLI(t,
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"},
)
sut.StartChain(t)
// query validator address to delegate tokens
rsp := cli.CustomQuery("q", "staking", "validators")
valAddr := gjson.Get(rsp, "validators.#.operator_address").Array()[0].String()
// stake tokens
rsp = cli.CustomCommand("tx", "staking", "delegate", valAddr, "10000stake", "--from="+account1Addr, "--fees=1stake")
RequireTxSuccess(t, rsp)
t.Log(cli.QueryBalance(account1Addr, "stake"))
assert.Equal(t, int64(9989999), cli.QueryBalance(account1Addr, "stake"))
rsp = cli.CustomQuery("q", "staking", "delegation", account1Addr, valAddr)
assert.Equal(t, "10000", 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.CustomCommand("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, "stake", gjson.Get(rsp, "delegation_response.balance.denom").String(), rsp)
rsp = cli.CustomQuery("q", "staking", "unbonding-delegation", account1Addr, valAddr)
assert.Equal(t, "5000", gjson.Get(rsp, "unbond.entries.#.balance").Array()[0].String(), rsp)
}