* Start system tests * Go mod tidy * Add system tests (#1411) * Add tests * Add test-system to CI * Fix path * Remove store artifact steps * Add small fixes * Add stake/unstake tests * Add unsafe-reset-all extention + system test * Replace ustake with stake * Add more tests + fix bug in cli * Fix comments and add multi contract system test * Updates and fixes to system tests (#1449) * Updates * Minor cleanup * Make tests pass --------- Co-authored-by: Alexander Peters <alpe@users.noreply.github.com> * Fix Makefile to return exit code for system tests (#1450) * Abort on error results --------- Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
55 lines
1.7 KiB
Go
55 lines
1.7 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, "100000000stake"},
|
|
)
|
|
|
|
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(99989999), cli.QueryBalance(account1Addr, "stake"))
|
|
|
|
rsp = cli.CustomQuery("q", "staking", "delegation", account1Addr, valAddr)
|
|
assert.Equal(t, "10000", gjson.Get(rsp, "balance.amount").String())
|
|
assert.Equal(t, "stake", gjson.Get(rsp, "balance.denom").String())
|
|
|
|
// 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, "balance.amount").String())
|
|
assert.Equal(t, "stake", gjson.Get(rsp, "balance.denom").String())
|
|
|
|
rsp = cli.CustomQuery("q", "staking", "unbonding-delegation", account1Addr, valAddr)
|
|
assert.Equal(t, "5000", gjson.Get(rsp, "entries.#.balance").Array()[0].String())
|
|
}
|