0g-chain/cli_test/cli_test.go

1392 lines
44 KiB
Go
Raw Normal View History

//go:build cli_test
2019-06-25 12:01:02 +00:00
// +build cli_test
package clitest
import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"testing"
Update cosmos-sdk to v0.47.7 (#1811) * Update cometbft, cosmos, ethermint, and ibc-go * Replace github.com/tendermint/tendermint by github.com/cometbft/cometbft * Replace github.com/tendermint/tm-db by github.com/cometbft/cometbft-db * Replace gogo/protobuf with cosmos/gogoproto & simapp replacement * Replace cosmos-sdk/simapp/helpers with cosmos-sdk/testutil/sims * Remove no longer used simulations * Replace ibchost with ibcexported See https://github.com/cosmos/ibc-go/blob/v7.2.2/docs/migrations/v6-to-v7.md#ibc-module-constants * Add new consensus params keeper * Add consensus keeper to blockers * Fix keeper and module issues in app.go * Add IsSendEnabledCoins and update SetParams interface changes * Fix protobuf build for cosmos 47 (#1800) * fix cp errors by using -f; fix lint by only linting our proto dir; and use proofs.proto directly from ics23 for ibc-go v7 * run proto-all; commit updated third party deps and swagger changes * regenerate proto files * use correct gocosmos build plugin for buf * re-gen all protobuf files to update paths for new gocosmos plugin * update protoc and buf to latest versions * fix staking keeper issues in app.go * update tally handler for gov changes * chain id fix and flag fixes * update deps for cometbft 47.7 upgrade * remove all module legacy queriers * update stakingKeeper to pointer * Replace ModuleCdc from govv1beta1 to govcodec * remove simulations * abci.LastCommitInfo → abci.CommitInfo * Remove unused code in keys.go * simapp.MakeTestEncodingConfig -> moduletestutil.MakeTestEncodingConfi * Fix chain id issues in tests * Fix remaining unit test issues * Update changelog for upgrade * Fix e2e tests using updated kvtool * Update protonet to v47 compatible genesis * Bump cometbft-db to v0.9.1-kava.1 * Update kvtool * Remove extra changelog * Fix merged rocksdb issues * go mod cleanup * Bump cometbft-db to v9 and go to 1.21 * Bump rocksdb version to v8.10.0 * Update kvtool to latest version * Update gin to v1.9.0 * Use ibctm.ModuleName in app_test * Fallback to genesis chain id instead of client toml * Remove all simulations * Fix cdp migrations issue with v47 * Update dependencies to correct tags --------- Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
2024-02-06 22:54:10 +00:00
"github.com/cometbft/cometbft/crypto/ed25519"
tmtypes "github.com/cometbft/cometbft/types"
2019-06-25 12:01:02 +00:00
"github.com/stretchr/testify/require"
2019-09-12 16:19:13 +00:00
2020-04-27 17:16:18 +00:00
"github.com/cosmos/cosmos-sdk/client/flags"
2019-06-25 12:01:02 +00:00
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/gov"
2019-09-12 16:19:13 +00:00
"github.com/cosmos/cosmos-sdk/x/mint"
2019-06-25 12:01:02 +00:00
)
2020-04-28 14:27:12 +00:00
func TestKvCLIKeysAddMultisig(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
// key names order does not matter
f.KeysAdd("msig1", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", keyBar, keyBaz))
2020-04-28 14:27:12 +00:00
ke1Address1 := f.KeysShow("msig1").Address
f.KeysDelete("msig1")
2019-06-25 12:01:02 +00:00
f.KeysAdd("msig2", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", keyBaz, keyBar))
2020-04-28 14:27:12 +00:00
require.Equal(t, ke1Address1, f.KeysShow("msig2").Address)
f.KeysDelete("msig2")
2019-06-25 12:01:02 +00:00
f.KeysAdd("msig3", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", keyBar, keyBaz),
"--nosort")
f.KeysAdd("msig4", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", keyBaz, keyBar),
"--nosort")
require.NotEqual(t, f.KeysShow("msig3").Address, f.KeysShow("msig4").Address)
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
2020-04-28 14:27:12 +00:00
func TestKvCLIKeysAddRecover(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
exitSuccess, _, _ := f.KeysAddRecover("empty-mnemonic", "")
require.False(t, exitSuccess)
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
require.True(t, exitSuccess)
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
// test old bip44 coin type
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
require.True(t, exitSuccess)
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
2024-08-02 11:32:08 +00:00
func TestZgChainCLIKeysAddRecoverHDPath(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
2019-06-25 12:01:02 +00:00
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
2019-06-25 12:01:02 +00:00
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
2019-06-25 12:01:02 +00:00
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
// test old bip44 coin type
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
2019-09-12 16:19:13 +00:00
exitSuccess, _, _ := f.KeysAddRecover("test-recover-fail", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path --hd-path 44'/459'/0'/0/0")
require.False(t, exitSuccess)
// test -hd-path flag
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH6", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/0'/0/0")
require.True(t, exitSuccess)
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH7", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/2'/0/17")
require.True(t, exitSuccess)
2024-08-02 11:32:08 +00:00
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
2020-04-28 14:27:12 +00:00
func TestKvCLIMinimumFees(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server with minimum fees
2019-06-25 12:01:02 +00:00
minGasPrice, _ := sdk.NewDecFromStr("0.000006")
fees := fmt.Sprintf(
"--minimum-gas-prices=%s,%s",
sdk.NewDecCoinFromDec(feeDenom, minGasPrice),
sdk.NewDecCoinFromDec(fee2Denom, minGasPrice),
)
proc := f.GDStart(fees)
defer proc.Stop(false)
barAddr := f.KeyAddress(keyBar)
// Send a transaction that will get rejected
2019-09-12 16:19:13 +00:00
success, stdOut, _ := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(fee2Denom, 10), "-y")
require.Contains(t, stdOut, "insufficient fees")
require.True(f.T, success)
2019-06-25 12:01:02 +00:00
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure tx w/ correct fees pass
txFees := fmt.Sprintf("--fees=%s", sdk.NewInt64Coin(feeDenom, 2))
success, _, _ = f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(fee2Denom, 10), txFees, "-y")
require.True(f.T, success)
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure tx w/ improper fees fails
txFees = fmt.Sprintf("--fees=%s", sdk.NewInt64Coin(feeDenom, 1))
2019-09-12 16:19:13 +00:00
success, stdOut, _ = f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(fooDenom, 10), txFees, "-y")
require.Contains(t, stdOut, "insufficient fees")
require.True(f.T, success)
2019-06-25 12:01:02 +00:00
// Cleanup testing directories
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLIGasPrices(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server with minimum fees
2019-06-25 12:01:02 +00:00
minGasPrice, _ := sdk.NewDecFromStr("0.000006")
proc := f.GDStart(fmt.Sprintf("--minimum-gas-prices=%s", sdk.NewDecCoinFromDec(feeDenom, minGasPrice)))
defer proc.Stop(false)
barAddr := f.KeyAddress(keyBar)
// insufficient gas prices (tx fails)
badGasPrice, _ := sdk.NewDecFromStr("0.000003")
2019-09-12 16:19:13 +00:00
success, stdOut, _ := f.TxSend(
2019-06-25 12:01:02 +00:00
keyFoo, barAddr, sdk.NewInt64Coin(fooDenom, 50),
fmt.Sprintf("--gas-prices=%s", sdk.NewDecCoinFromDec(feeDenom, badGasPrice)), "-y")
2019-09-12 16:19:13 +00:00
require.Contains(t, stdOut, "insufficient fees")
require.True(t, success)
2019-06-25 12:01:02 +00:00
// wait for a block confirmation
tests.WaitForNextNBlocksTM(1, f.Port)
// sufficient gas prices (tx passes)
success, _, _ = f.TxSend(
keyFoo, barAddr, sdk.NewInt64Coin(fooDenom, 50),
fmt.Sprintf("--gas-prices=%s", sdk.NewDecCoinFromDec(feeDenom, minGasPrice)), "-y")
require.True(t, success)
// wait for a block confirmation
tests.WaitForNextNBlocksTM(1, f.Port)
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLIFeesDeduction(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server with minimum fees
2019-06-25 12:01:02 +00:00
minGasPrice, _ := sdk.NewDecFromStr("0.000006")
proc := f.GDStart(fmt.Sprintf("--minimum-gas-prices=%s", sdk.NewDecCoinFromDec(feeDenom, minGasPrice)))
defer proc.Stop(false)
// Save key addresses for later use
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
fooAmt := fooAcc.GetCoins().AmountOf(fooDenom)
// test simulation
success, _, _ := f.TxSend(
keyFoo, barAddr, sdk.NewInt64Coin(fooDenom, 1000),
fmt.Sprintf("--fees=%s", sdk.NewInt64Coin(feeDenom, 2)), "--dry-run")
require.True(t, success)
// Wait for a block
tests.WaitForNextNBlocksTM(1, f.Port)
// ensure state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, fooAmt.Int64(), fooAcc.GetCoins().AmountOf(fooDenom).Int64())
// insufficient funds (coins + fees) tx fails
2019-09-12 16:19:13 +00:00
largeCoins := sdk.TokensFromConsensusPower(10000000)
success, stdOut, _ := f.TxSend(
2019-06-25 12:01:02 +00:00
keyFoo, barAddr, sdk.NewCoin(fooDenom, largeCoins),
fmt.Sprintf("--fees=%s", sdk.NewInt64Coin(feeDenom, 2)), "-y")
2019-09-12 16:19:13 +00:00
require.Contains(t, stdOut, "insufficient account funds")
require.True(t, success)
2019-06-25 12:01:02 +00:00
// Wait for a block
tests.WaitForNextNBlocksTM(1, f.Port)
// ensure state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, fooAmt.Int64(), fooAcc.GetCoins().AmountOf(fooDenom).Int64())
// test success (transfer = coins + fees)
success, _, _ = f.TxSend(
keyFoo, barAddr, sdk.NewInt64Coin(fooDenom, 500),
fmt.Sprintf("--fees=%s", sdk.NewInt64Coin(feeDenom, 2)), "-y")
require.True(t, success)
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLISend(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
// Save key addresses for later use
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
2019-09-12 16:19:13 +00:00
startTokens := sdk.TokensFromConsensusPower(50)
2019-06-25 12:01:02 +00:00
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
2019-09-12 16:19:13 +00:00
sendTokens := sdk.TokensFromConsensusPower(10)
2020-04-28 14:27:12 +00:00
2019-06-25 12:01:02 +00:00
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
barAcc := f.QueryAccount(barAddr)
require.Equal(t, sendTokens, barAcc.GetCoins().AmountOf(denom))
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
// Test --dry-run
2020-04-28 18:04:30 +00:00
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--dry-run")
2019-06-25 12:01:02 +00:00
require.True(t, success)
2019-09-12 16:19:13 +00:00
// Test --generate-only
success, stdout, stderr := f.TxSend(
fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only=true",
)
require.Empty(t, stderr)
require.True(t, success)
2020-04-27 17:16:18 +00:00
msg := f.unmarshalStdTx(f.T, stdout)
2019-09-12 16:19:13 +00:00
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)
2019-06-25 12:01:02 +00:00
// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
// test autosequencing
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
barAcc = f.QueryAccount(barAddr)
require.Equal(t, sendTokens.MulRaw(2), barAcc.GetCoins().AmountOf(denom))
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(sendTokens.MulRaw(2)), fooAcc.GetCoins().AmountOf(denom))
// test memo
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--memo='testmemo'", "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
barAcc = f.QueryAccount(barAddr)
require.Equal(t, sendTokens.MulRaw(3), barAcc.GetCoins().AmountOf(denom))
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(sendTokens.MulRaw(3)), fooAcc.GetCoins().AmountOf(denom))
f.Cleanup()
}
func TestKvCLISendMultiplePerBlock(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
// Save key addresses for later use
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
startTokens := fooAcc.GetCoins().AmountOf(fooDenom)
sendTokens := sdk.TokensFromConsensusPower(1)
numTxsToSend := 30
for i := 0; i < numTxsToSend; i++ {
seq := fooAcc.GetSequence() + uint64(i)
f.TxSend(keyFoo, barAddr, sdk.NewCoin(fooDenom, sendTokens), "-y", fmt.Sprintf("--sequence=%d", seq), "--broadcast-mode=sync")
}
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
totalSent := sendTokens.MulRaw(int64(numTxsToSend))
barAcc := f.QueryAccount(barAddr)
require.Equal(t, totalSent, barAcc.GetCoins().AmountOf(fooDenom))
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(totalSent), fooAcc.GetCoins().AmountOf(fooDenom))
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLIGasAuto(t *testing.T) {
2019-10-15 16:42:51 +00:00
// https://github.com/cosmos/cosmos-sdk/pull/5179
t.Skip()
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
2019-09-12 16:19:13 +00:00
startTokens := sdk.TokensFromConsensusPower(50)
2019-06-25 12:01:02 +00:00
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test failure with auto gas disabled and very little gas set by hand
2019-09-12 16:19:13 +00:00
sendTokens := sdk.TokensFromConsensusPower(10)
success, stdOut, _ := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=10", "-y")
require.Contains(t, stdOut, "out of gas in location")
require.True(t, success)
2019-06-25 12:01:02 +00:00
// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test failure with negative gas
success, _, _ = f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=-100", "-y")
require.False(t, success)
// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test failure with 0 gas
2019-09-12 16:19:13 +00:00
success, stdOut, _ = f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=0", "-y")
require.Contains(t, stdOut, "out of gas in location")
require.True(t, success)
2019-06-25 12:01:02 +00:00
// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Enable auto gas
success, stdout, stderr := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=auto", "-y")
require.NotEmpty(t, stderr)
require.True(t, success)
sendResp := sdk.TxResponse{}
2020-04-28 14:27:12 +00:00
err := f.cdc.UnmarshalJSON([]byte(stdout), &sendResp)
2019-06-25 12:01:02 +00:00
require.Nil(t, err)
require.True(t, sendResp.GasWanted >= sendResp.GasUsed)
tests.WaitForNextNBlocksTM(1, f.Port)
// Check state has changed accordingly
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLICreateValidator(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
barAddr := f.KeyAddress(keyBar)
barVal := sdk.ValAddress(barAddr)
2020-04-28 14:27:12 +00:00
consPubKey := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, ed25519.GenPrivKey().PubKey())
2019-06-25 12:01:02 +00:00
2019-09-12 16:19:13 +00:00
sendTokens := sdk.TokensFromConsensusPower(10)
2019-06-25 12:01:02 +00:00
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
barAcc := f.QueryAccount(barAddr)
require.Equal(t, sendTokens, barAcc.GetCoins().AmountOf(denom))
// Generate a create validator transaction and ensure correctness
success, stdout, stderr := f.TxStakingCreateValidator(barAddr.String(), consPubKey, sdk.NewInt64Coin(denom, 2), "--generate-only")
require.True(f.T, success)
require.Empty(f.T, stderr)
2020-04-28 14:27:12 +00:00
2020-04-27 17:16:18 +00:00
msg := f.unmarshalStdTx(f.T, stdout)
2019-06-25 12:01:02 +00:00
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
// Test --dry-run
2019-09-12 16:19:13 +00:00
newValTokens := sdk.TokensFromConsensusPower(2)
2020-04-28 14:27:12 +00:00
success, _, _ = f.TxStakingCreateValidator(barAddr.String(), consPubKey, sdk.NewCoin(denom, newValTokens), "--dry-run")
2019-06-25 12:01:02 +00:00
require.True(t, success)
// Create the validator
f.TxStakingCreateValidator(keyBar, consPubKey, sdk.NewCoin(denom, newValTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure funds were deducted properly
barAcc = f.QueryAccount(barAddr)
require.Equal(t, sendTokens.Sub(newValTokens), barAcc.GetCoins().AmountOf(denom))
// Ensure that validator state is as expected
validator := f.QueryStakingValidator(barVal)
require.Equal(t, validator.OperatorAddress, barVal)
require.True(sdk.IntEq(t, newValTokens, validator.Tokens))
// Query delegations to the validator
validatorDelegations := f.QueryStakingDelegationsTo(barVal)
require.Len(t, validatorDelegations, 1)
require.NotZero(t, validatorDelegations[0].Shares)
// unbond a single share
2019-09-12 16:19:13 +00:00
unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(1))
2019-06-25 12:01:02 +00:00
success = f.TxStakingUnbond(keyBar, unbondAmt.String(), barVal, "-y")
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure bonded staking is correct
remainingTokens := newValTokens.Sub(unbondAmt.Amount)
validator = f.QueryStakingValidator(barVal)
require.Equal(t, remainingTokens, validator.Tokens)
// Get unbonding delegations from the validator
validatorUbds := f.QueryStakingUnbondingDelegationsFrom(barVal)
require.Len(t, validatorUbds, 1)
require.Len(t, validatorUbds[0].Entries, 1)
require.Equal(t, remainingTokens.String(), validatorUbds[0].Entries[0].Balance.String())
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLIQueryRewards(t *testing.T) {
2019-09-12 16:19:13 +00:00
t.Parallel()
f := InitFixtures(t)
genesisState := f.GenesisState()
2020-04-28 14:27:12 +00:00
inflationMin := sdk.MustNewDecFromStr("1.0")
2019-09-12 16:19:13 +00:00
var mintData mint.GenesisState
2020-04-28 14:27:12 +00:00
f.cdc.UnmarshalJSON(genesisState[mint.ModuleName], &mintData)
2019-09-12 16:19:13 +00:00
mintData.Minter.Inflation = inflationMin
mintData.Params.InflationMin = inflationMin
2020-04-28 14:27:12 +00:00
mintData.Params.InflationMax = sdk.MustNewDecFromStr("1.0")
mintDataBz, err := f.cdc.MarshalJSON(mintData)
2019-09-12 16:19:13 +00:00
require.NoError(t, err)
genesisState[mint.ModuleName] = mintDataBz
2020-04-28 14:10:02 +00:00
genFile := filepath.Join(f.KvdHome, "config", "genesis.json")
2019-09-12 16:19:13 +00:00
genDoc, err := tmtypes.GenesisDocFromFile(genFile)
require.NoError(t, err)
2020-04-28 14:27:12 +00:00
genDoc.AppState, err = f.cdc.MarshalJSON(genesisState)
2019-09-12 16:19:13 +00:00
require.NoError(t, genDoc.SaveAs(genFile))
2020-04-28 14:10:02 +00:00
// start kvd server
2019-09-12 16:19:13 +00:00
proc := f.GDStart()
defer proc.Stop(false)
fooAddr := f.KeyAddress(keyFoo)
rewards := f.QueryRewards(fooAddr)
require.Equal(t, 1, len(rewards.Rewards))
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLIQuerySupply(t *testing.T) {
2019-09-12 16:19:13 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-09-12 16:19:13 +00:00
proc := f.GDStart()
defer proc.Stop(false)
totalSupply := f.QueryTotalSupply()
totalSupplyOf := f.QueryTotalSupplyOf(fooDenom)
require.Equal(t, totalCoins, totalSupply)
require.True(sdk.IntEq(t, totalCoins.AmountOf(fooDenom), totalSupplyOf))
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLISubmitProposal(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
f.QueryGovParamDeposit()
f.QueryGovParamVoting()
f.QueryGovParamTallying()
fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
2019-09-12 16:19:13 +00:00
startTokens := sdk.TokensFromConsensusPower(50)
2019-06-25 12:01:02 +00:00
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom))
proposalsQuery := f.QueryGovProposals()
require.Empty(t, proposalsQuery)
// Test submit generate only for submit proposal
2019-09-12 16:19:13 +00:00
proposalTokens := sdk.TokensFromConsensusPower(5)
2019-06-25 12:01:02 +00:00
success, stdout, stderr := f.TxGovSubmitProposal(
fooAddr.String(), "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens), "--generate-only", "-y")
require.True(t, success)
require.Empty(t, stderr)
2020-04-27 17:16:18 +00:00
msg := f.unmarshalStdTx(t, stdout)
2019-06-25 12:01:02 +00:00
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
// Test --dry-run
success, _, _ = f.TxGovSubmitProposal(keyFoo, "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens), "--dry-run")
require.True(t, success)
// Create the proposal
f.TxGovSubmitProposal(keyFoo, "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
2020-04-28 14:27:12 +00:00
// Ensure transaction events can be queried
searchResult := f.QueryTxs(1, 50, "message.action=submit_proposal", fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, searchResult.Txs, 1)
2019-06-25 12:01:02 +00:00
// Ensure deposit was deducted
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(proposalTokens), fooAcc.GetCoins().AmountOf(denom))
// Ensure propsal is directly queryable
proposal1 := f.QueryGovProposal(1)
require.Equal(t, uint64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusDepositPeriod, proposal1.Status)
// Ensure query proposals returns properly
proposalsQuery = f.QueryGovProposals()
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
// Query the deposits on the proposal
deposit := f.QueryGovDeposit(1, fooAddr)
require.Equal(t, proposalTokens, deposit.Amount.AmountOf(denom))
// Test deposit generate only
2019-09-12 16:19:13 +00:00
depositTokens := sdk.TokensFromConsensusPower(10)
2019-06-25 12:01:02 +00:00
success, stdout, stderr = f.TxGovDeposit(1, fooAddr.String(), sdk.NewCoin(denom, depositTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
2020-04-27 17:16:18 +00:00
msg = f.unmarshalStdTx(t, stdout)
2019-06-25 12:01:02 +00:00
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
// Run the deposit transaction
f.TxGovDeposit(1, keyFoo, sdk.NewCoin(denom, depositTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// test query deposit
deposits := f.QueryGovDeposits(1)
require.Len(t, deposits, 1)
require.Equal(t, proposalTokens.Add(depositTokens), deposits[0].Amount.AmountOf(denom))
// Ensure querying the deposit returns the proper amount
deposit = f.QueryGovDeposit(1, fooAddr)
require.Equal(t, proposalTokens.Add(depositTokens), deposit.Amount.AmountOf(denom))
2020-04-28 14:27:12 +00:00
// Ensure events are set on the transaction
searchResult = f.QueryTxs(1, 50, "message.action=deposit", fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, searchResult.Txs, 1)
2019-06-25 12:01:02 +00:00
// Ensure account has expected amount of funds
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(proposalTokens.Add(depositTokens)), fooAcc.GetCoins().AmountOf(denom))
// Fetch the proposal and ensure it is now in the voting period
proposal1 = f.QueryGovProposal(1)
require.Equal(t, uint64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusVotingPeriod, proposal1.Status)
// Test vote generate only
success, stdout, stderr = f.TxGovVote(1, gov.OptionYes, fooAddr.String(), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
2020-04-27 17:16:18 +00:00
msg = f.unmarshalStdTx(t, stdout)
2019-06-25 12:01:02 +00:00
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
// Vote on the proposal
f.TxGovVote(1, gov.OptionYes, keyFoo, "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// Query the vote
vote := f.QueryGovVote(1, fooAddr)
require.Equal(t, uint64(1), vote.ProposalID)
require.Equal(t, gov.OptionYes, vote.Option)
// Query the votes
votes := f.QueryGovVotes(1)
require.Len(t, votes, 1)
require.Equal(t, uint64(1), votes[0].ProposalID)
require.Equal(t, gov.OptionYes, votes[0].Option)
2020-04-28 14:27:12 +00:00
// Ensure events are applied to voting transaction properly
searchResult = f.QueryTxs(1, 50, "message.action=vote", fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, searchResult.Txs, 1)
2019-06-25 12:01:02 +00:00
// Ensure no proposals in deposit period
proposalsQuery = f.QueryGovProposals("--status=DepositPeriod")
require.Empty(t, proposalsQuery)
// Ensure the proposal returns as in the voting period
proposalsQuery = f.QueryGovProposals("--status=VotingPeriod")
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
// submit a second test proposal
f.TxGovSubmitProposal(keyFoo, "Text", "Apples", "test", sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// Test limit on proposals query
2020-04-28 14:27:12 +00:00
proposalsQuery = f.QueryGovProposals("--limit=2")
require.Len(t, proposalsQuery, 2)
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
2019-06-25 12:01:02 +00:00
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLISubmitParamChangeProposal(t *testing.T) {
2019-09-12 16:19:13 +00:00
t.Parallel()
f := InitFixtures(t)
proc := f.GDStart()
defer proc.Stop(false)
fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom))
// write proposal to file
proposalTokens := sdk.TokensFromConsensusPower(5)
proposal := fmt.Sprintf(`{
"title": "Param Change",
"description": "Update max validators",
"changes": [
{
"subspace": "staking",
"key": "MaxValidators",
"value": 105
}
],
2020-04-30 13:13:23 +00:00
"deposit": [
{
"denom": "%s",
"amount": "%s"
}
]
2019-09-12 16:19:13 +00:00
}
2020-04-30 13:13:23 +00:00
`, sdk.DefaultBondDenom, proposalTokens.String())
2019-09-12 16:19:13 +00:00
proposalFile := WriteToNewTempFile(t, proposal)
// create the param change proposal
f.TxGovSubmitParamChangeProposal(keyFoo, proposalFile.Name(), sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
2020-04-28 14:27:12 +00:00
// ensure transaction events can be queried
txsPage := f.QueryTxs(1, 50, "message.action=submit_proposal", fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, txsPage.Txs, 1)
// ensure deposit was deducted
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(proposalTokens).String(), fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom).String())
// ensure proposal is directly queryable
proposal1 := f.QueryGovProposal(1)
require.Equal(t, uint64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusDepositPeriod, proposal1.Status)
// ensure correct query proposals result
proposalsQuery := f.QueryGovProposals()
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
// ensure the correct deposit amount on the proposal
deposit := f.QueryGovDeposit(1, fooAddr)
require.Equal(t, proposalTokens, deposit.Amount.AmountOf(denom))
// Cleanup testing directories
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLISubmitCommunityPoolSpendProposal(t *testing.T) {
2019-09-12 16:19:13 +00:00
t.Parallel()
f := InitFixtures(t)
// create some inflation
genesisState := f.GenesisState()
2020-04-28 14:27:12 +00:00
inflationMin := sdk.MustNewDecFromStr("1.0")
2019-09-12 16:19:13 +00:00
var mintData mint.GenesisState
2020-04-28 14:27:12 +00:00
f.cdc.UnmarshalJSON(genesisState[mint.ModuleName], &mintData)
2019-09-12 16:19:13 +00:00
mintData.Minter.Inflation = inflationMin
mintData.Params.InflationMin = inflationMin
2020-04-28 14:27:12 +00:00
mintData.Params.InflationMax = sdk.MustNewDecFromStr("1.0")
mintDataBz, err := f.cdc.MarshalJSON(mintData)
2019-09-12 16:19:13 +00:00
require.NoError(t, err)
genesisState[mint.ModuleName] = mintDataBz
2020-04-28 14:10:02 +00:00
genFile := filepath.Join(f.KvdHome, "config", "genesis.json")
2019-09-12 16:19:13 +00:00
genDoc, err := tmtypes.GenesisDocFromFile(genFile)
require.NoError(t, err)
2020-04-28 14:27:12 +00:00
genDoc.AppState, err = f.cdc.MarshalJSON(genesisState)
2019-09-12 16:19:13 +00:00
require.NoError(t, genDoc.SaveAs(genFile))
proc := f.GDStart()
defer proc.Stop(false)
fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom))
tests.WaitForNextNBlocksTM(3, f.Port)
// write proposal to file
proposalTokens := sdk.TokensFromConsensusPower(5)
proposal := fmt.Sprintf(`{
"title": "Community Pool Spend",
"description": "Spend from community pool",
"recipient": "%s",
2020-04-30 13:13:23 +00:00
"amount": [
{
"denom": "%s",
"amount": "1"
}
],
"deposit": [
{
"denom": "%s",
"amount": "%s"
}
]
2019-09-12 16:19:13 +00:00
}
2020-04-30 13:13:23 +00:00
`, fooAddr, sdk.DefaultBondDenom, sdk.DefaultBondDenom, proposalTokens.String())
2019-09-12 16:19:13 +00:00
proposalFile := WriteToNewTempFile(t, proposal)
// create the param change proposal
f.TxGovSubmitCommunityPoolSpendProposal(keyFoo, proposalFile.Name(), sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
2020-04-28 14:27:12 +00:00
// ensure transaction events can be queried
txsPage := f.QueryTxs(1, 50, "message.action=submit_proposal", fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, txsPage.Txs, 1)
// ensure deposit was deducted
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(proposalTokens).String(), fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom).String())
// ensure proposal is directly queryable
proposal1 := f.QueryGovProposal(1)
require.Equal(t, uint64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusDepositPeriod, proposal1.Status)
// ensure correct query proposals result
proposalsQuery := f.QueryGovProposals()
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
// ensure the correct deposit amount on the proposal
deposit := f.QueryGovDeposit(1, fooAddr)
require.Equal(t, proposalTokens, deposit.Amount.AmountOf(denom))
// Cleanup testing directories
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLIQueryTxPagination(t *testing.T) {
Update cosmos-sdk to v0.47.7 (#1811) * Update cometbft, cosmos, ethermint, and ibc-go * Replace github.com/tendermint/tendermint by github.com/cometbft/cometbft * Replace github.com/tendermint/tm-db by github.com/cometbft/cometbft-db * Replace gogo/protobuf with cosmos/gogoproto & simapp replacement * Replace cosmos-sdk/simapp/helpers with cosmos-sdk/testutil/sims * Remove no longer used simulations * Replace ibchost with ibcexported See https://github.com/cosmos/ibc-go/blob/v7.2.2/docs/migrations/v6-to-v7.md#ibc-module-constants * Add new consensus params keeper * Add consensus keeper to blockers * Fix keeper and module issues in app.go * Add IsSendEnabledCoins and update SetParams interface changes * Fix protobuf build for cosmos 47 (#1800) * fix cp errors by using -f; fix lint by only linting our proto dir; and use proofs.proto directly from ics23 for ibc-go v7 * run proto-all; commit updated third party deps and swagger changes * regenerate proto files * use correct gocosmos build plugin for buf * re-gen all protobuf files to update paths for new gocosmos plugin * update protoc and buf to latest versions * fix staking keeper issues in app.go * update tally handler for gov changes * chain id fix and flag fixes * update deps for cometbft 47.7 upgrade * remove all module legacy queriers * update stakingKeeper to pointer * Replace ModuleCdc from govv1beta1 to govcodec * remove simulations * abci.LastCommitInfo → abci.CommitInfo * Remove unused code in keys.go * simapp.MakeTestEncodingConfig -> moduletestutil.MakeTestEncodingConfi * Fix chain id issues in tests * Fix remaining unit test issues * Update changelog for upgrade * Fix e2e tests using updated kvtool * Update protonet to v47 compatible genesis * Bump cometbft-db to v0.9.1-kava.1 * Update kvtool * Remove extra changelog * Fix merged rocksdb issues * go mod cleanup * Bump cometbft-db to v9 and go to 1.21 * Bump rocksdb version to v8.10.0 * Update kvtool to latest version * Update gin to v1.9.0 * Use ibctm.ModuleName in app_test * Fallback to genesis chain id instead of client toml * Remove all simulations * Fix cdp migrations issue with v47 * Update dependencies to correct tags --------- Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
2024-02-06 22:54:10 +00:00
// Skip until https://github.com/cometbft/cometbft/issues/4432 has been
2020-04-28 14:27:12 +00:00
// resolved and included in a release.
t.SkipNow()
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
accFoo := f.QueryAccount(fooAddr)
seq := accFoo.GetSequence()
for i := 1; i <= 30; i++ {
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(fooDenom, int64(i)), fmt.Sprintf("--sequence=%d", seq), "-y")
require.True(t, success)
seq++
}
// perPage = 15, 2 pages
2020-04-28 14:27:12 +00:00
txsPage1 := f.QueryTxs(1, 15, fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, txsPage1.Txs, 15)
require.Equal(t, txsPage1.Count, 15)
2020-04-28 14:27:12 +00:00
txsPage2 := f.QueryTxs(2, 15, fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, txsPage2.Txs, 15)
require.NotEqual(t, txsPage1.Txs, txsPage2.Txs)
2019-06-25 12:01:02 +00:00
// perPage = 16, 2 pages
2020-04-28 14:27:12 +00:00
txsPage1 = f.QueryTxs(1, 16, fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, txsPage1.Txs, 16)
2020-04-28 14:27:12 +00:00
txsPage2 = f.QueryTxs(2, 16, fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, txsPage2.Txs, 14)
require.NotEqual(t, txsPage1.Txs, txsPage2.Txs)
2019-06-25 12:01:02 +00:00
// perPage = 50
2020-04-28 14:27:12 +00:00
txsPageFull := f.QueryTxs(1, 50, fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
require.Len(t, txsPageFull.Txs, 30)
2020-04-28 14:27:12 +00:00
expected := txsPageFull.Txs
got := append(txsPage1.Txs, txsPage2.Txs...)
require.Equal(t, expected, got)
2019-06-25 12:01:02 +00:00
// perPage = 0
2020-04-28 14:27:12 +00:00
f.QueryTxsInvalid(errors.New("ERROR: page must greater than 0"), 0, 50, fmt.Sprintf("message.sender=%s", fooAddr))
2019-06-25 12:01:02 +00:00
// limit = 0
2020-04-28 14:27:12 +00:00
f.QueryTxsInvalid(errors.New("ERROR: limit must greater than 0"), 1, 0, fmt.Sprintf("message.sender=%s", fooAddr))
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
2020-04-28 14:27:12 +00:00
func TestKvCLIValidateSignatures(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
// generate sendTx with default gas
success, stdout, stderr := f.TxSend(fooAddr.String(), barAddr, sdk.NewInt64Coin(denom, 10), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
// write unsigned tx to file
unsignedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(unsignedTxFile.Name())
// validate we can successfully sign
2020-04-28 14:27:12 +00:00
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name())
2019-06-25 12:01:02 +00:00
require.True(t, success)
2020-04-27 17:16:18 +00:00
stdTx := f.unmarshalStdTx(t, stdout)
2019-06-25 12:01:02 +00:00
require.Equal(t, len(stdTx.Msgs), 1)
require.Equal(t, 1, len(stdTx.GetSignatures()))
require.Equal(t, fooAddr.String(), stdTx.GetSigners()[0].String())
// write signed tx to file
signedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(signedTxFile.Name())
// validate signatures
success, _, _ = f.TxSign(keyFoo, signedTxFile.Name(), "--validate-signatures")
require.True(t, success)
// modify the transaction
stdTx.Memo = "MODIFIED-ORIGINAL-TX-BAD"
2020-04-27 17:16:18 +00:00
bz := f.marshalStdTx(t, stdTx)
2019-06-25 12:01:02 +00:00
modSignedTxFile := WriteToNewTempFile(t, string(bz))
defer os.Remove(modSignedTxFile.Name())
// validate signature validation failure due to different transaction sig bytes
success, _, _ = f.TxSign(keyFoo, modSignedTxFile.Name(), "--validate-signatures")
require.False(t, success)
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLISendGenerateSignAndBroadcast(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
// Test generate sendTx with default gas
2019-09-12 16:19:13 +00:00
sendTokens := sdk.TokensFromConsensusPower(10)
2019-06-25 12:01:02 +00:00
success, stdout, stderr := f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
2020-04-27 17:16:18 +00:00
msg := f.unmarshalStdTx(t, stdout)
require.Equal(t, msg.Fee.Gas, uint64(flags.DefaultGasLimit))
2019-06-25 12:01:02 +00:00
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
// Test generate sendTx with --gas=$amount
success, stdout, stderr = f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--gas=100", "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
2020-04-27 17:16:18 +00:00
msg = f.unmarshalStdTx(t, stdout)
2019-06-25 12:01:02 +00:00
require.Equal(t, msg.Fee.Gas, uint64(100))
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
// Test generate sendTx, estimate gas
2019-09-12 16:19:13 +00:00
success, stdout, stderr = f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only")
2019-06-25 12:01:02 +00:00
require.True(t, success)
2019-09-12 16:19:13 +00:00
require.Empty(t, stderr)
2020-04-27 17:16:18 +00:00
msg = f.unmarshalStdTx(t, stdout)
2019-06-25 12:01:02 +00:00
require.True(t, msg.Fee.Gas > 0)
require.Equal(t, len(msg.Msgs), 1)
// Write the output to disk
unsignedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(unsignedTxFile.Name())
// Test sign --validate-signatures
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name(), "--validate-signatures")
require.False(t, success)
require.Equal(t, fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n\n", fooAddr.String()), stdout)
// Test sign
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name())
require.True(t, success)
2020-04-27 17:16:18 +00:00
msg = f.unmarshalStdTx(t, stdout)
2019-06-25 12:01:02 +00:00
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 1, len(msg.GetSignatures()))
require.Equal(t, fooAddr.String(), msg.GetSigners()[0].String())
// Write the output to disk
signedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(signedTxFile.Name())
// Test sign --validate-signatures
success, stdout, _ = f.TxSign(keyFoo, signedTxFile.Name(), "--validate-signatures")
require.True(t, success)
require.Equal(t, fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n 0: %v\t\t\t[OK]\n\n", fooAddr.String(),
fooAddr.String()), stdout)
// Ensure foo has right amount of funds
fooAcc := f.QueryAccount(fooAddr)
2019-09-12 16:19:13 +00:00
startTokens := sdk.TokensFromConsensusPower(50)
2019-06-25 12:01:02 +00:00
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test broadcast
success, stdout, _ = f.TxBroadcast(signedTxFile.Name())
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account state
barAcc := f.QueryAccount(barAddr)
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, sendTokens, barAcc.GetCoins().AmountOf(denom))
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvCLIMultisignInsufficientCosigners(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server with minimum fees
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
fooBarBazAddr := f.KeyAddress(keyFooBarBaz)
barAddr := f.KeyAddress(keyBar)
// Send some tokens from one account to the other
success, _, _ := f.TxSend(keyFoo, fooBarBazAddr, sdk.NewInt64Coin(denom, 10), "-y")
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)
// Test generate sendTx with multisig
success, stdout, _ := f.TxSend(fooBarBazAddr.String(), barAddr, sdk.NewInt64Coin(denom, 5), "--generate-only")
require.True(t, success)
// Write the output to disk
unsignedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(unsignedTxFile.Name())
// Sign with foo's key
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
require.True(t, success)
// Write the output to disk
fooSignatureFile := WriteToNewTempFile(t, stdout)
defer os.Remove(fooSignatureFile.Name())
// Multisign, not enough signatures
success, stdout, _ = f.TxMultisign(unsignedTxFile.Name(), keyFooBarBaz, []string{fooSignatureFile.Name()})
require.True(t, success)
// Write the output to disk
signedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(signedTxFile.Name())
// Validate the multisignature
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures")
require.False(t, success)
// Broadcast the transaction
2019-09-12 16:19:13 +00:00
success, stdOut, _ := f.TxBroadcast(signedTxFile.Name())
require.Contains(t, stdOut, "signature verification failed")
require.True(t, success)
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
2020-04-28 14:27:12 +00:00
func TestKvCLIEncode(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
// Build a testing transaction and write it to disk
barAddr := f.KeyAddress(keyBar)
keyAddr := f.KeyAddress(keyFoo)
2019-09-12 16:19:13 +00:00
sendTokens := sdk.TokensFromConsensusPower(10)
2019-06-25 12:01:02 +00:00
success, stdout, stderr := f.TxSend(keyAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only", "--memo", "deadbeef")
require.True(t, success)
require.Empty(t, stderr)
// Write it to disk
jsonTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(jsonTxFile.Name())
// Run the encode command, and trim the extras from the stdout capture
success, base64Encoded, _ := f.TxEncode(jsonTxFile.Name())
require.True(t, success)
trimmedBase64 := strings.Trim(base64Encoded, "\"\n")
// Decode the base64
decodedBytes, err := base64.StdEncoding.DecodeString(trimmedBase64)
require.Nil(t, err)
// Check that the transaction decodes as epxceted
var decodedTx auth.StdTx
2020-04-28 18:04:30 +00:00
require.Nil(t, f.cdc.UnmarshalBinaryLengthPrefixed(decodedBytes, &decodedTx))
2019-06-25 12:01:02 +00:00
require.Equal(t, "deadbeef", decodedTx.Memo)
}
2020-04-28 14:27:12 +00:00
func TestKvCLIMultisignSortSignatures(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server with minimum fees
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
fooBarBazAddr := f.KeyAddress(keyFooBarBaz)
barAddr := f.KeyAddress(keyBar)
// Send some tokens from one account to the other
success, _, _ := f.TxSend(keyFoo, fooBarBazAddr, sdk.NewInt64Coin(denom, 10), "-y")
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
fooBarBazAcc := f.QueryAccount(fooBarBazAddr)
require.Equal(t, int64(10), fooBarBazAcc.GetCoins().AmountOf(denom).Int64())
// Test generate sendTx with multisig
success, stdout, _ := f.TxSend(fooBarBazAddr.String(), barAddr, sdk.NewInt64Coin(denom, 5), "--generate-only")
require.True(t, success)
// Write the output to disk
unsignedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(unsignedTxFile.Name())
// Sign with foo's key
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String())
require.True(t, success)
// Write the output to disk
fooSignatureFile := WriteToNewTempFile(t, stdout)
defer os.Remove(fooSignatureFile.Name())
// Sign with baz's key
success, stdout, _ = f.TxSign(keyBaz, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String())
require.True(t, success)
// Write the output to disk
bazSignatureFile := WriteToNewTempFile(t, stdout)
defer os.Remove(bazSignatureFile.Name())
// Multisign, keys in different order
success, stdout, _ = f.TxMultisign(unsignedTxFile.Name(), keyFooBarBaz, []string{
bazSignatureFile.Name(), fooSignatureFile.Name(),
})
2019-06-25 12:01:02 +00:00
require.True(t, success)
// Write the output to disk
signedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(signedTxFile.Name())
// Validate the multisignature
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures")
require.True(t, success)
// Broadcast the transaction
success, _, _ = f.TxBroadcast(signedTxFile.Name())
require.True(t, success)
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
2020-04-28 14:27:12 +00:00
func TestKvCLIMultisign(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server with minimum fees
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
fooBarBazAddr := f.KeyAddress(keyFooBarBaz)
bazAddr := f.KeyAddress(keyBaz)
// Send some tokens from one account to the other
success, _, _ := f.TxSend(keyFoo, fooBarBazAddr, sdk.NewInt64Coin(denom, 10), "-y")
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
fooBarBazAcc := f.QueryAccount(fooBarBazAddr)
require.Equal(t, int64(10), fooBarBazAcc.GetCoins().AmountOf(denom).Int64())
// Test generate sendTx with multisig
success, stdout, stderr := f.TxSend(fooBarBazAddr.String(), bazAddr, sdk.NewInt64Coin(denom, 10), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
// Write the output to disk
unsignedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(unsignedTxFile.Name())
// Sign with foo's key
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
require.True(t, success)
// Write the output to disk
fooSignatureFile := WriteToNewTempFile(t, stdout)
defer os.Remove(fooSignatureFile.Name())
// Sign with bar's key
success, stdout, _ = f.TxSign(keyBar, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
require.True(t, success)
// Write the output to disk
barSignatureFile := WriteToNewTempFile(t, stdout)
defer os.Remove(barSignatureFile.Name())
// Multisign
2020-04-28 14:27:12 +00:00
// Does not work in offline mode
success, stdout, _ = f.TxMultisign(unsignedTxFile.Name(), keyFooBarBaz, []string{
fooSignatureFile.Name(), barSignatureFile.Name(),
}, "--offline")
2020-04-28 14:27:12 +00:00
require.Contains(t, "couldn't verify signature", stdout)
require.False(t, success)
// Success multisign
2019-06-25 12:01:02 +00:00
success, stdout, _ = f.TxMultisign(unsignedTxFile.Name(), keyFooBarBaz, []string{
fooSignatureFile.Name(), barSignatureFile.Name(),
})
2019-06-25 12:01:02 +00:00
require.True(t, success)
// Write the output to disk
signedTxFile := WriteToNewTempFile(t, stdout)
defer os.Remove(signedTxFile.Name())
// Validate the multisignature
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures", "-y")
require.True(t, success)
// Broadcast the transaction
success, _, _ = f.TxBroadcast(signedTxFile.Name())
require.True(t, success)
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
2020-04-28 14:27:12 +00:00
func TestKvCLIConfig(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := InitFixtures(t)
node := fmt.Sprintf("%s:%s", f.RPCAddr, f.Port)
// Set available configuration options
f.CLIConfig("broadcast-mode", "block")
f.CLIConfig("node", node)
f.CLIConfig("output", "text")
f.CLIConfig("trust-node", "true")
f.CLIConfig("chain-id", f.ChainID)
f.CLIConfig("trace", "false")
f.CLIConfig("indent", "true")
2020-04-28 14:27:12 +00:00
f.CLIConfig("keyring-backend", "test")
2019-06-25 12:01:02 +00:00
2020-04-28 14:10:02 +00:00
config, err := ioutil.ReadFile(path.Join(f.KvcliHome, "config", "config.toml"))
2019-06-25 12:01:02 +00:00
require.NoError(t, err)
expectedConfig := fmt.Sprintf(`broadcast-mode = "block"
chain-id = "%s"
indent = true
2020-04-28 14:27:12 +00:00
keyring-backend = "test"
2019-06-25 12:01:02 +00:00
node = "%s"
output = "text"
trace = false
trust-node = true
`, f.ChainID, node)
require.Equal(t, expectedConfig, string(config))
f.Cleanup()
}
2020-04-28 14:27:12 +00:00
func TestKvdCollectGentxs(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
2019-09-12 16:19:13 +00:00
var customMaxBytes, customMaxGas int64 = 99999999, 1234567
2019-06-25 12:01:02 +00:00
f := NewFixtures(t)
// Initialise temporary directories
gentxDir, err := ioutil.TempDir("", "")
gentxDoc := filepath.Join(gentxDir, "gentx.json")
require.NoError(t, err)
// Reset testing path
f.UnsafeResetAll()
// Initialize keys
f.KeysAdd(keyFoo)
// Configure json output
f.CLIConfig("output", "json")
// Run init
2020-04-28 14:27:12 +00:00
f.KvInit(keyFoo)
2019-06-25 12:01:02 +00:00
2019-09-12 16:19:13 +00:00
// Customise genesis.json
genFile := f.GenesisFile()
genDoc, err := tmtypes.GenesisDocFromFile(genFile)
require.NoError(t, err)
genDoc.ConsensusParams.Block.MaxBytes = customMaxBytes
genDoc.ConsensusParams.Block.MaxGas = customMaxGas
genDoc.SaveAs(genFile)
2019-06-25 12:01:02 +00:00
// Add account to genesis.json
f.AddGenesisAccount(f.KeyAddress(keyFoo), startCoins)
// Write gentx file
f.GenTx(keyFoo, fmt.Sprintf("--output-document=%s", gentxDoc))
// Collect gentxs from a custom directory
f.CollectGenTxs(fmt.Sprintf("--gentx-dir=%s", gentxDir))
2019-09-12 16:19:13 +00:00
genDoc, err = tmtypes.GenesisDocFromFile(genFile)
require.NoError(t, err)
require.Equal(t, genDoc.ConsensusParams.Block.MaxBytes, customMaxBytes)
require.Equal(t, genDoc.ConsensusParams.Block.MaxGas, customMaxGas)
2019-06-25 12:01:02 +00:00
f.Cleanup(gentxDir)
}
2020-04-28 14:27:12 +00:00
func TestKvdAddGenesisAccount(t *testing.T) {
2019-06-25 12:01:02 +00:00
t.Parallel()
f := NewFixtures(t)
// Reset testing path
f.UnsafeResetAll()
// Initialize keys
f.KeysDelete(keyFoo)
f.KeysDelete(keyBar)
f.KeysDelete(keyBaz)
f.KeysAdd(keyFoo)
f.KeysAdd(keyBar)
f.KeysAdd(keyBaz)
// Configure json output
f.CLIConfig("output", "json")
// Run init
2020-04-28 14:27:12 +00:00
f.KvInit(keyFoo)
2019-06-25 12:01:02 +00:00
// Add account to genesis.json
bazCoins := sdk.Coins{
sdk.NewInt64Coin("acoin", 1000000),
sdk.NewInt64Coin("bcoin", 1000000),
}
f.AddGenesisAccount(f.KeyAddress(keyFoo), startCoins)
f.AddGenesisAccount(f.KeyAddress(keyBar), bazCoins)
genesisState := f.GenesisState()
2019-09-12 16:19:13 +00:00
2020-04-28 14:27:12 +00:00
authGenState := auth.GetGenesisStateFromAppState(f.cdc, genesisState)
2019-09-13 20:52:10 +00:00
accounts := authGenState.Accounts
require.Equal(t, accounts[0].GetAddress(), f.KeyAddress(keyFoo))
require.Equal(t, accounts[1].GetAddress(), f.KeyAddress(keyBar))
require.True(t, accounts[0].GetCoins().IsEqual(startCoins))
require.True(t, accounts[1].GetCoins().IsEqual(bazCoins))
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
func TestSlashingGetParams(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
params := f.QuerySlashingParams()
require.Equal(t, int64(100), params.SignedBlocksWindow)
require.Equal(t, sdk.NewDecWithPrec(5, 1), params.MinSignedPerWindow)
sinfo := f.QuerySigningInfo(f.GDTendermint("show-validator"))
require.Equal(t, int64(0), sinfo.StartHeight)
require.False(t, sinfo.Tombstoned)
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}
func TestValidateGenesis(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
2020-04-28 14:10:02 +00:00
// start kvd server
2019-06-25 12:01:02 +00:00
proc := f.GDStart()
defer proc.Stop(false)
f.ValidateGenesis()
2019-09-12 16:19:13 +00:00
// Cleanup testing directories
f.Cleanup()
2019-06-25 12:01:02 +00:00
}