fix conflicts from development

This commit is contained in:
Federico Kunze 2020-04-30 17:12:22 -04:00
commit 511e1e07ac
No known key found for this signature in database
GPG Key ID: 655F93A970080A30
7 changed files with 364 additions and 371 deletions

View File

@ -150,7 +150,10 @@ test:
test-rest:
rest_test/./run_all_tests_from_make.sh
test-cli:
# Run cli integration tests
# `-p 4` to use 4 cores, `-tags cli_test` to tell go not to ignore the cli package
# These tests use the `kvd` or `kvcli` binaries in the build dir, or in `$BUILDDIR` if that env var is set.
test-cli: build
@go test ./cli_test -tags cli_test -v -p 4
# Kick start lots of sims on an AWS cluster.

View File

@ -1,14 +0,0 @@
# CLI Integration tests
Run the full suite:
```bash
make build
go test -v -p 4 ./cli_test -tags cli_test
```
`-v` for verbose, `-p 4` to use 4 cores, `-tags cli_test` a build tag (specified in `cli_test.go`) to tell go not to ignore the package
> NOTE: While the full suite runs in parallel, some of the tests can take up to a minute to complete
> NOTE: The tests will use the `kvd` or `kvcli` binaries in the build dir. Or in `$BUILDDIR` if that env var is set.

View File

@ -12,33 +12,33 @@ import (
"path/filepath"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"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"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/kava-labs/kava/app"
)
func TestGaiaCLIKeysAddMultisig(t *testing.T) {
func TestKvCLIKeysAddMultisig(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// key names order does not matter
f.KeysAdd("msig1", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", keyBar, keyBaz))
ke1Address1 := f.KeysShow("msig1").Address
f.KeysDelete("msig1")
f.KeysAdd("msig2", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", keyBaz, keyBar))
require.Equal(t, f.KeysShow("msig1").Address, f.KeysShow("msig2").Address)
require.Equal(t, ke1Address1, f.KeysShow("msig2").Address)
f.KeysDelete("msig2")
f.KeysAdd("msig3", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", keyBar, keyBaz),
@ -52,7 +52,7 @@ func TestGaiaCLIKeysAddMultisig(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIKeysAddRecover(t *testing.T) {
func TestKvCLIKeysAddRecover(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
@ -72,7 +72,7 @@ func TestGaiaCLIKeysAddRecover(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIKeysAddRecoverHDPath(t *testing.T) {
func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
@ -96,11 +96,11 @@ func TestGaiaCLIKeysAddRecoverHDPath(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIMinimumFees(t *testing.T) {
func TestKvCLIMinimumFees(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server with minimum fees
// start kvd server with minimum fees
minGasPrice, _ := sdk.NewDecFromStr("0.000006")
fees := fmt.Sprintf(
"--minimum-gas-prices=%s,%s",
@ -134,11 +134,11 @@ func TestGaiaCLIMinimumFees(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIGasPrices(t *testing.T) {
func TestKvCLIGasPrices(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server with minimum fees
// start kvd server with minimum fees
minGasPrice, _ := sdk.NewDecFromStr("0.000006")
proc := f.GDStart(fmt.Sprintf("--minimum-gas-prices=%s", sdk.NewDecCoinFromDec(feeDenom, minGasPrice)))
defer proc.Stop(false)
@ -168,11 +168,11 @@ func TestGaiaCLIGasPrices(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIFeesDeduction(t *testing.T) {
func TestKvCLIFeesDeduction(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server with minimum fees
// start kvd server with minimum fees
minGasPrice, _ := sdk.NewDecFromStr("0.000006")
proc := f.GDStart(fmt.Sprintf("--minimum-gas-prices=%s", sdk.NewDecCoinFromDec(feeDenom, minGasPrice)))
defer proc.Stop(false)
@ -221,11 +221,11 @@ func TestGaiaCLIFeesDeduction(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLISend(t *testing.T) {
func TestKvCLISend(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
@ -237,8 +237,8 @@ func TestGaiaCLISend(t *testing.T) {
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Send some tokens from one account to the other
sendTokens := sdk.TokensFromConsensusPower(10)
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
@ -258,7 +258,7 @@ func TestGaiaCLISend(t *testing.T) {
)
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
msg := f.unmarshalStdTx(f.T, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)
@ -290,48 +290,13 @@ func TestGaiaCLISend(t *testing.T) {
f.Cleanup()
}
// Note: this was removed from gaia due to update in sdk PR#4062 but is now working
func TestGaiaCLIConfirmTx(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad 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 := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// send some tokens from one account to the other
sendTokens := sdk.TokensFromConsensusPower(10)
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))
// send some tokens from one account to the other (cancelling confirmation)
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "-n")
tests.WaitForNextNBlocksTM(1, f.Port)
// ensure account balances match expected
barAcc = f.QueryAccount(barAddr)
require.Equal(t, sendTokens, barAcc.GetCoins().AmountOf(denom))
}
func TestGaiaCLIGasAuto(t *testing.T) {
func TestKvCLIGasAuto(t *testing.T) {
// https://github.com/cosmos/cosmos-sdk/pull/5179
t.Skip()
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
@ -373,9 +338,8 @@ func TestGaiaCLIGasAuto(t *testing.T) {
success, stdout, stderr := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=auto", "-y")
require.NotEmpty(t, stderr)
require.True(t, success)
cdc := app.MakeCodec()
sendResp := sdk.TxResponse{}
err := cdc.UnmarshalJSON([]byte(stdout), &sendResp)
err := f.cdc.UnmarshalJSON([]byte(stdout), &sendResp)
require.Nil(t, err)
require.True(t, sendResp.GasWanted >= sendResp.GasUsed)
tests.WaitForNextNBlocksTM(1, f.Port)
@ -387,18 +351,18 @@ func TestGaiaCLIGasAuto(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLICreateValidator(t *testing.T) {
func TestKvCLICreateValidator(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
barAddr := f.KeyAddress(keyBar)
barVal := sdk.ValAddress(barAddr)
consPubKey := sdk.MustBech32ifyConsPub(ed25519.GenPrivKey().PubKey())
consPubKey := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, ed25519.GenPrivKey().PubKey())
sendTokens := sdk.TokensFromConsensusPower(10)
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "-y")
@ -409,17 +373,17 @@ func TestGaiaCLICreateValidator(t *testing.T) {
// 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)
msg := unmarshalStdTx(f.T, stdout)
msg := f.unmarshalStdTx(f.T, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
// Test --dry-run
newValTokens := sdk.TokensFromConsensusPower(2)
success, _, _ = f.TxStakingCreateValidator(keyBar, consPubKey, sdk.NewCoin(denom, newValTokens), "--dry-run")
success, _, _ = f.TxStakingCreateValidator(barAddr.String(), consPubKey, sdk.NewCoin(denom, newValTokens), "--dry-run")
require.True(t, success)
// Create the validator
@ -460,29 +424,28 @@ func TestGaiaCLICreateValidator(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIQueryRewards(t *testing.T) {
func TestKvCLIQueryRewards(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
cdc := app.MakeCodec()
genesisState := f.GenesisState()
inflationMin := sdk.MustNewDecFromStr("10000.0")
inflationMin := sdk.MustNewDecFromStr("1.0")
var mintData mint.GenesisState
cdc.UnmarshalJSON(genesisState[mint.ModuleName], &mintData)
f.cdc.UnmarshalJSON(genesisState[mint.ModuleName], &mintData)
mintData.Minter.Inflation = inflationMin
mintData.Params.InflationMin = inflationMin
mintData.Params.InflationMax = sdk.MustNewDecFromStr("15000.0")
mintDataBz, err := cdc.MarshalJSON(mintData)
mintData.Params.InflationMax = sdk.MustNewDecFromStr("1.0")
mintDataBz, err := f.cdc.MarshalJSON(mintData)
require.NoError(t, err)
genesisState[mint.ModuleName] = mintDataBz
genFile := filepath.Join(f.GaiadHome, "config", "genesis.json")
genFile := filepath.Join(f.KvdHome, "config", "genesis.json")
genDoc, err := tmtypes.GenesisDocFromFile(genFile)
require.NoError(t, err)
genDoc.AppState, err = cdc.MarshalJSON(genesisState)
genDoc.AppState, err = f.cdc.MarshalJSON(genesisState)
require.NoError(t, genDoc.SaveAs(genFile))
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
@ -493,11 +456,11 @@ func TestGaiaCLIQueryRewards(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIQuerySupply(t *testing.T) {
func TestKvCLIQuerySupply(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
@ -510,11 +473,11 @@ func TestGaiaCLIQuerySupply(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLISubmitProposal(t *testing.T) {
func TestKvCLISubmitProposal(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
@ -537,7 +500,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
fooAddr.String(), "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens), "--generate-only", "-y")
require.True(t, success)
require.Empty(t, stderr)
msg := unmarshalStdTx(t, stdout)
msg := f.unmarshalStdTx(t, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
@ -550,8 +513,8 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
f.TxGovSubmitProposal(keyFoo, "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure transaction tags can be queried
searchResult := f.QueryTxs(1, 50, "message.action:submit_proposal", fmt.Sprintf("message.sender:%s", fooAddr))
// Ensure transaction events can be queried
searchResult := f.QueryTxs(1, 50, "message.action=submit_proposal", fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, searchResult.Txs, 1)
// Ensure deposit was deducted
@ -576,7 +539,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
success, stdout, stderr = f.TxGovDeposit(1, fooAddr.String(), sdk.NewCoin(denom, depositTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg = unmarshalStdTx(t, stdout)
msg = f.unmarshalStdTx(t, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
@ -594,8 +557,8 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
deposit = f.QueryGovDeposit(1, fooAddr)
require.Equal(t, proposalTokens.Add(depositTokens), deposit.Amount.AmountOf(denom))
// Ensure tags are set on the transaction
searchResult = f.QueryTxs(1, 50, "message.action:deposit", fmt.Sprintf("message.sender:%s", fooAddr))
// Ensure events are set on the transaction
searchResult = f.QueryTxs(1, 50, "message.action=deposit", fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, searchResult.Txs, 1)
// Ensure account has expected amount of funds
@ -611,7 +574,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
success, stdout, stderr = f.TxGovVote(1, gov.OptionYes, fooAddr.String(), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg = unmarshalStdTx(t, stdout)
msg = f.unmarshalStdTx(t, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
@ -631,8 +594,8 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, uint64(1), votes[0].ProposalID)
require.Equal(t, gov.OptionYes, votes[0].Option)
// Ensure tags are applied to voting transaction properly
searchResult = f.QueryTxs(1, 50, "message.action:vote", fmt.Sprintf("message.sender:%s", fooAddr))
// Ensure events are applied to voting transaction properly
searchResult = f.QueryTxs(1, 50, "message.action=vote", fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, searchResult.Txs, 1)
// Ensure no proposals in deposit period
@ -648,13 +611,14 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
tests.WaitForNextNBlocksTM(1, f.Port)
// Test limit on proposals query
proposalsQuery = f.QueryGovProposals("--limit=1")
require.Equal(t, uint64(2), proposalsQuery[0].ProposalID)
proposalsQuery = f.QueryGovProposals("--limit=2")
require.Len(t, proposalsQuery, 2)
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
f.Cleanup()
}
func TestGaiaCLISubmitParamChangeProposal(t *testing.T) {
func TestKvCLISubmitParamChangeProposal(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
@ -680,12 +644,12 @@ func TestGaiaCLISubmitParamChangeProposal(t *testing.T) {
],
"deposit": [
{
"denom": "stake",
"denom": "%s",
"amount": "%s"
}
]
}
`, proposalTokens.String())
`, sdk.DefaultBondDenom, proposalTokens.String())
proposalFile := WriteToNewTempFile(t, proposal)
@ -693,8 +657,8 @@ func TestGaiaCLISubmitParamChangeProposal(t *testing.T) {
f.TxGovSubmitParamChangeProposal(keyFoo, proposalFile.Name(), sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// ensure transaction tags can be queried
txsPage := f.QueryTxs(1, 50, "message.action:submit_proposal", fmt.Sprintf("message.sender:%s", fooAddr))
// ensure transaction events can be queried
txsPage := f.QueryTxs(1, 50, "message.action=submit_proposal", fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage.Txs, 1)
// ensure deposit was deducted
@ -718,27 +682,26 @@ func TestGaiaCLISubmitParamChangeProposal(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLISubmitCommunityPoolSpendProposal(t *testing.T) {
func TestKvCLISubmitCommunityPoolSpendProposal(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// create some inflation
cdc := app.MakeCodec()
genesisState := f.GenesisState()
inflationMin := sdk.MustNewDecFromStr("10000.0")
inflationMin := sdk.MustNewDecFromStr("1.0")
var mintData mint.GenesisState
cdc.UnmarshalJSON(genesisState[mint.ModuleName], &mintData)
f.cdc.UnmarshalJSON(genesisState[mint.ModuleName], &mintData)
mintData.Minter.Inflation = inflationMin
mintData.Params.InflationMin = inflationMin
mintData.Params.InflationMax = sdk.MustNewDecFromStr("15000.0")
mintDataBz, err := cdc.MarshalJSON(mintData)
mintData.Params.InflationMax = sdk.MustNewDecFromStr("1.0")
mintDataBz, err := f.cdc.MarshalJSON(mintData)
require.NoError(t, err)
genesisState[mint.ModuleName] = mintDataBz
genFile := filepath.Join(f.GaiadHome, "config", "genesis.json")
genFile := filepath.Join(f.KvdHome, "config", "genesis.json")
genDoc, err := tmtypes.GenesisDocFromFile(genFile)
require.NoError(t, err)
genDoc.AppState, err = cdc.MarshalJSON(genesisState)
genDoc.AppState, err = f.cdc.MarshalJSON(genesisState)
require.NoError(t, genDoc.SaveAs(genFile))
proc := f.GDStart()
@ -777,8 +740,8 @@ func TestGaiaCLISubmitCommunityPoolSpendProposal(t *testing.T) {
f.TxGovSubmitCommunityPoolSpendProposal(keyFoo, proposalFile.Name(), sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
// ensure transaction tags can be queried
txsPage := f.QueryTxs(1, 50, "message.action:submit_proposal", fmt.Sprintf("message.sender:%s", fooAddr))
// ensure transaction events can be queried
txsPage := f.QueryTxs(1, 50, "message.action=submit_proposal", fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage.Txs, 1)
// ensure deposit was deducted
@ -802,11 +765,15 @@ func TestGaiaCLISubmitCommunityPoolSpendProposal(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIQueryTxPagination(t *testing.T) {
func TestKvCLIQueryTxPagination(t *testing.T) {
// Skip until https://github.com/tendermint/tendermint/issues/4432 has been
// resolved and included in a release.
t.SkipNow()
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
@ -823,40 +790,44 @@ func TestGaiaCLIQueryTxPagination(t *testing.T) {
}
// perPage = 15, 2 pages
txsPage1 := f.QueryTxs(1, 15, fmt.Sprintf("message.sender:%s", fooAddr))
txsPage1 := f.QueryTxs(1, 15, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage1.Txs, 15)
require.Equal(t, txsPage1.Count, 15)
txsPage2 := f.QueryTxs(2, 15, fmt.Sprintf("message.sender:%s", fooAddr))
txsPage2 := f.QueryTxs(2, 15, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage2.Txs, 15)
require.NotEqual(t, txsPage1.Txs, txsPage2.Txs)
// perPage = 16, 2 pages
txsPage1 = f.QueryTxs(1, 16, fmt.Sprintf("message.sender:%s", fooAddr))
txsPage1 = f.QueryTxs(1, 16, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage1.Txs, 16)
txsPage2 = f.QueryTxs(2, 16, fmt.Sprintf("message.sender:%s", fooAddr))
txsPage2 = f.QueryTxs(2, 16, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage2.Txs, 14)
require.NotEqual(t, txsPage1.Txs, txsPage2.Txs)
// perPage = 50
txsPageFull := f.QueryTxs(1, 50, fmt.Sprintf("message.sender:%s", fooAddr))
txsPageFull := f.QueryTxs(1, 50, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPageFull.Txs, 30)
require.Equal(t, txsPageFull.Txs, append(txsPage1.Txs, txsPage2.Txs...))
expected := txsPageFull.Txs
got := append(txsPage1.Txs, txsPage2.Txs...)
require.Equal(t, expected, got)
// perPage = 0
f.QueryTxsInvalid(errors.New("ERROR: page must greater than 0"), 0, 50, fmt.Sprintf("message.sender:%s", fooAddr))
f.QueryTxsInvalid(errors.New("ERROR: page must greater than 0"), 0, 50, fmt.Sprintf("message.sender=%s", fooAddr))
// limit = 0
f.QueryTxsInvalid(errors.New("ERROR: limit must greater than 0"), 1, 0, fmt.Sprintf("message.sender:%s", fooAddr))
f.QueryTxsInvalid(errors.New("ERROR: limit must greater than 0"), 1, 0, fmt.Sprintf("message.sender=%s", fooAddr))
// Cleanup testing directories
f.Cleanup()
}
func TestGaiaCLIValidateSignatures(t *testing.T) {
func TestKvCLIValidateSignatures(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
@ -873,10 +844,9 @@ func TestGaiaCLIValidateSignatures(t *testing.T) {
defer os.Remove(unsignedTxFile.Name())
// validate we can successfully sign
success, stdout, stderr = f.TxSign(keyFoo, unsignedTxFile.Name())
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name())
require.True(t, success)
require.Empty(t, stderr)
stdTx := unmarshalStdTx(t, stdout)
stdTx := f.unmarshalStdTx(t, stdout)
require.Equal(t, len(stdTx.Msgs), 1)
require.Equal(t, 1, len(stdTx.GetSignatures()))
require.Equal(t, fooAddr.String(), stdTx.GetSigners()[0].String())
@ -891,7 +861,7 @@ func TestGaiaCLIValidateSignatures(t *testing.T) {
// modify the transaction
stdTx.Memo = "MODIFIED-ORIGINAL-TX-BAD"
bz := marshalStdTx(t, stdTx)
bz := f.marshalStdTx(t, stdTx)
modSignedTxFile := WriteToNewTempFile(t, string(bz))
defer os.Remove(modSignedTxFile.Name())
@ -902,11 +872,11 @@ func TestGaiaCLIValidateSignatures(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
func TestKvCLISendGenerateSignAndBroadcast(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
@ -918,8 +888,8 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
success, stdout, stderr := f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg := unmarshalStdTx(t, stdout)
require.Equal(t, msg.Fee.Gas, uint64(client.DefaultGasLimit))
msg := f.unmarshalStdTx(t, stdout)
require.Equal(t, msg.Fee.Gas, uint64(flags.DefaultGasLimit))
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
@ -927,7 +897,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
success, stdout, stderr = f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--gas=100", "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg = unmarshalStdTx(t, stdout)
msg = f.unmarshalStdTx(t, stdout)
require.Equal(t, msg.Fee.Gas, uint64(100))
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 0, len(msg.GetSignatures()))
@ -936,7 +906,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
success, stdout, stderr = f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg = unmarshalStdTx(t, stdout)
msg = f.unmarshalStdTx(t, stdout)
require.True(t, msg.Fee.Gas > 0)
require.Equal(t, len(msg.Msgs), 1)
@ -952,7 +922,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
// Test sign
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name())
require.True(t, success)
msg = unmarshalStdTx(t, stdout)
msg = f.unmarshalStdTx(t, stdout)
require.Equal(t, len(msg.Msgs), 1)
require.Equal(t, 1, len(msg.GetSignatures()))
require.Equal(t, fooAddr.String(), msg.GetSigners()[0].String())
@ -986,11 +956,11 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIMultisignInsufficientCosigners(t *testing.T) {
func TestKvCLIMultisignInsufficientCosigners(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server with minimum fees
// start kvd server with minimum fees
proc := f.GDStart()
defer proc.Stop(false)
@ -1039,16 +1009,14 @@ func TestGaiaCLIMultisignInsufficientCosigners(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIEncode(t *testing.T) {
func TestKvCLIEncode(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
cdc := app.MakeCodec()
// Build a testing transaction and write it to disk
barAddr := f.KeyAddress(keyBar)
keyAddr := f.KeyAddress(keyFoo)
@ -1073,15 +1041,15 @@ func TestGaiaCLIEncode(t *testing.T) {
// Check that the transaction decodes as epxceted
var decodedTx auth.StdTx
require.Nil(t, cdc.UnmarshalBinaryLengthPrefixed(decodedBytes, &decodedTx))
require.Nil(t, f.cdc.UnmarshalBinaryLengthPrefixed(decodedBytes, &decodedTx))
require.Equal(t, "deadbeef", decodedTx.Memo)
}
func TestGaiaCLIMultisignSortSignatures(t *testing.T) {
func TestKvCLIMultisignSortSignatures(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server with minimum fees
// start kvd server with minimum fees
proc := f.GDStart()
defer proc.Stop(false)
@ -1142,11 +1110,11 @@ func TestGaiaCLIMultisignSortSignatures(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIMultisign(t *testing.T) {
func TestKvCLIMultisign(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server with minimum fees
// start kvd server with minimum fees
proc := f.GDStart()
defer proc.Stop(false)
@ -1188,6 +1156,14 @@ func TestGaiaCLIMultisign(t *testing.T) {
defer os.Remove(barSignatureFile.Name())
// Multisign
// Does not work in offline mode
success, stdout, _ = f.TxMultisign(unsignedTxFile.Name(), keyFooBarBaz, []string{
fooSignatureFile.Name(), barSignatureFile.Name()}, "--offline")
require.Contains(t, "couldn't verify signature", stdout)
require.False(t, success)
// Success multisign
success, stdout, _ = f.TxMultisign(unsignedTxFile.Name(), keyFooBarBaz, []string{
fooSignatureFile.Name(), barSignatureFile.Name()})
require.True(t, success)
@ -1208,7 +1184,7 @@ func TestGaiaCLIMultisign(t *testing.T) {
f.Cleanup()
}
func TestGaiaCLIConfig(t *testing.T) {
func TestKvCLIConfig(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
node := fmt.Sprintf("%s:%s", f.RPCAddr, f.Port)
@ -1221,12 +1197,14 @@ func TestGaiaCLIConfig(t *testing.T) {
f.CLIConfig("chain-id", f.ChainID)
f.CLIConfig("trace", "false")
f.CLIConfig("indent", "true")
f.CLIConfig("keyring-backend", "test")
config, err := ioutil.ReadFile(path.Join(f.GaiacliHome, "config", "config.toml"))
config, err := ioutil.ReadFile(path.Join(f.KvcliHome, "config", "config.toml"))
require.NoError(t, err)
expectedConfig := fmt.Sprintf(`broadcast-mode = "block"
chain-id = "%s"
indent = true
keyring-backend = "test"
node = "%s"
output = "text"
trace = false
@ -1237,7 +1215,7 @@ trust-node = true
f.Cleanup()
}
func TestGaiadCollectGentxs(t *testing.T) {
func TestKvdCollectGentxs(t *testing.T) {
t.Parallel()
var customMaxBytes, customMaxGas int64 = 99999999, 1234567
f := NewFixtures(t)
@ -1257,7 +1235,7 @@ func TestGaiadCollectGentxs(t *testing.T) {
f.CLIConfig("output", "json")
// Run init
f.GDInit(keyFoo)
f.KvInit(keyFoo)
// Customise genesis.json
@ -1285,7 +1263,7 @@ func TestGaiadCollectGentxs(t *testing.T) {
f.Cleanup(gentxDir)
}
func TestGaiadAddGenesisAccount(t *testing.T) {
func TestKvdAddGenesisAccount(t *testing.T) {
t.Parallel()
f := NewFixtures(t)
@ -1304,7 +1282,7 @@ func TestGaiadAddGenesisAccount(t *testing.T) {
f.CLIConfig("output", "json")
// Run init
f.GDInit(keyFoo)
f.KvInit(keyFoo)
// Add account to genesis.json
bazCoins := sdk.Coins{
@ -1316,9 +1294,7 @@ func TestGaiadAddGenesisAccount(t *testing.T) {
f.AddGenesisAccount(f.KeyAddress(keyBar), bazCoins)
genesisState := f.GenesisState()
cdc := app.MakeCodec()
authGenState := auth.GetGenesisStateFromAppState(cdc, genesisState)
authGenState := auth.GetGenesisStateFromAppState(f.cdc, genesisState)
accounts := authGenState.Accounts
require.Equal(t, accounts[0].GetAddress(), f.KeyAddress(keyFoo))
@ -1334,12 +1310,11 @@ func TestSlashingGetParams(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)
params := f.QuerySlashingParams()
require.Equal(t, time.Duration(120000000000), params.MaxEvidenceAge)
require.Equal(t, int64(100), params.SignedBlocksWindow)
require.Equal(t, sdk.NewDecWithPrec(5, 1), params.MinSignedPerWindow)
@ -1355,7 +1330,7 @@ func TestValidateGenesis(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
// start gaiad server
// start kvd server
proc := f.GDStart()
defer proc.Stop(false)

View File

@ -66,7 +66,7 @@ func init() {
// set the address prefixes
config := sdk.GetConfig()
app.SetBech32AddressPrefixes(config)
config.Seal()
// config.Seal()
}
//___________________________________________________________________________________
@ -76,15 +76,17 @@ func init() {
type Fixtures struct {
BuildDir string
RootDir string
GaiadBinary string
GaiacliBinary string
KvdBinary string
KvcliBinary string
ChainID string
RPCAddr string
Port string
GaiadHome string
GaiacliHome string
KvdHome string
KvcliHome string
P2PAddr string
T *testing.T
cdc *codec.Codec
}
// NewFixtures creates a new instance of Fixtures with many vars set
@ -104,26 +106,29 @@ func NewFixtures(t *testing.T) *Fixtures {
require.NoError(t, err)
}
cdc := app.MakeCodec()
return &Fixtures{
T: t,
BuildDir: buildDir,
RootDir: tmpDir,
GaiadBinary: filepath.Join(buildDir, "kvd"),
GaiacliBinary: filepath.Join(buildDir, "kvcli"),
GaiadHome: filepath.Join(tmpDir, ".kvd"),
GaiacliHome: filepath.Join(tmpDir, ".kvcli"),
KvdBinary: filepath.Join(buildDir, "kvd"),
KvcliBinary: filepath.Join(buildDir, "kvcli"),
KvdHome: filepath.Join(tmpDir, ".kvd"),
KvcliHome: filepath.Join(tmpDir, ".kvcli"),
RPCAddr: servAddr,
P2PAddr: p2pAddr,
Port: port,
cdc: cdc,
}
}
// GenesisFile returns the path of the genesis file
func (f Fixtures) GenesisFile() string {
return filepath.Join(f.GaiadHome, "config", "genesis.json")
return filepath.Join(f.KvdHome, "config", "genesis.json")
}
// GenesisFile returns the application's genesis state
// GenesisState returns the application's genesis state
func (f Fixtures) GenesisState() simapp.GenesisState {
cdc := codec.New()
genDoc, err := tmtypes.GenesisDocFromFile(f.GenesisFile())
@ -142,6 +147,8 @@ func InitFixtures(t *testing.T) (f *Fixtures) {
// reset test state
f.UnsafeResetAll()
f.CLIConfig("keyring-backend", "test")
// ensure keystore has foo and bar keys
f.KeysDelete(keyFoo)
f.KeysDelete(keyBar)
@ -157,8 +164,8 @@ func InitFixtures(t *testing.T) (f *Fixtures) {
// ensure that CLI output is in JSON format
f.CLIConfig("output", "json")
// NOTE: GDInit sets the ChainID
f.GDInit(keyFoo)
// NOTE: KvInit sets the ChainID
f.KvInit(keyFoo)
f.CLIConfig("chain-id", f.ChainID)
f.CLIConfig("broadcast-mode", "block")
@ -189,24 +196,24 @@ func (f *Fixtures) Cleanup(dirs ...string) {
// Flags returns the flags necessary for making most CLI calls
func (f *Fixtures) Flags() string {
return fmt.Sprintf("--home=%s --node=%s", f.GaiacliHome, f.RPCAddr)
return fmt.Sprintf("--home=%s --node=%s", f.KvcliHome, f.RPCAddr)
}
//___________________________________________________________________________________
// gaiad
// kavad
// UnsafeResetAll is gaiad unsafe-reset-all
// UnsafeResetAll is kavad unsafe-reset-all
func (f *Fixtures) UnsafeResetAll(flags ...string) {
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.GaiadBinary, f.GaiadHome)
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
executeWrite(f.T, addFlags(cmd, flags))
err := os.RemoveAll(filepath.Join(f.GaiadHome, "config", "gentx"))
err := os.RemoveAll(filepath.Join(f.KvdHome, "config", "gentx"))
require.NoError(f.T, err)
}
// GDInit is gaiad init
// NOTE: GDInit sets the ChainID for the Fixtures instance
func (f *Fixtures) GDInit(moniker string, flags ...string) {
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.GaiadBinary, f.GaiadHome, moniker)
// KvInit is kavad init
// NOTE: KvInit sets the ChainID for the Fixtures instance
func (f *Fixtures) KvInit(moniker string, flags ...string) {
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
_, stderr := tests.ExecuteT(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
var chainID string
@ -221,78 +228,83 @@ func (f *Fixtures) GDInit(moniker string, flags ...string) {
f.ChainID = chainID
}
// AddGenesisAccount is gaiad add-genesis-account
// AddGenesisAccount is kavad add-genesis-account
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s", f.GaiadBinary, address, coins, f.GaiadHome)
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.KvdBinary, address, coins, f.KvdHome)
executeWriteCheckErr(f.T, addFlags(cmd, flags))
}
// GenTx is gaiad gentx
// GenTx is kavad gentx
func (f *Fixtures) GenTx(name string, flags ...string) {
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s", f.GaiadBinary, name, f.GaiadHome, f.GaiacliHome)
executeWriteCheckErr(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s --keyring-backend=test", f.KvdBinary, name, f.KvdHome, f.KvcliHome)
executeWriteCheckErr(f.T, addFlags(cmd, flags))
}
// CollectGenTxs is gaiad collect-gentxs
// CollectGenTxs is kavad collect-gentxs
func (f *Fixtures) CollectGenTxs(flags ...string) {
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.GaiadBinary, f.GaiadHome)
executeWriteCheckErr(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
executeWriteCheckErr(f.T, addFlags(cmd, flags))
}
// GDStart runs gaiad start with the appropriate flags and returns a process
// GDStart runs kavad start with the appropriate flags and returns a process
func (f *Fixtures) GDStart(flags ...string) *tests.Process {
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v", f.GaiadBinary, f.GaiadHome, f.RPCAddr, f.P2PAddr)
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v", f.KvdBinary, f.KvdHome, f.RPCAddr, f.P2PAddr)
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
tests.WaitForTMStart(f.Port)
tests.WaitForNextNBlocksTM(1, f.Port)
return proc
}
// GDTendermint returns the results of gaiad tendermint [query]
// GDTendermint returns the results of kavad tendermint [query]
func (f *Fixtures) GDTendermint(query string) string {
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.GaiadBinary, query, f.GaiadHome)
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
require.Empty(f.T, stderr)
require.True(f.T, success)
return strings.TrimSpace(stdout)
}
// ValidateGenesis runs gaiad validate-genesis
// ValidateGenesis runs kavad validate-genesis
func (f *Fixtures) ValidateGenesis() {
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.GaiadBinary, f.GaiadHome)
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
executeWriteCheckErr(f.T, cmd)
}
//___________________________________________________________________________________
// gaiacli keys
// kvcli keys
// KeysDelete is gaiacli keys delete
// KeysDelete is kvcli keys delete
func (f *Fixtures) KeysDelete(name string, flags ...string) {
cmd := fmt.Sprintf("%s keys delete --home=%s %s", f.GaiacliBinary, f.GaiacliHome, name)
cmd := fmt.Sprintf("%s keys delete --keyring-backend=test --home=%s %s", f.KvcliBinary,
f.KvcliHome, name)
executeWrite(f.T, addFlags(cmd, append(append(flags, "-y"), "-f")))
}
// KeysAdd is gaiacli keys add
// KeysAdd is kvcli keys add
func (f *Fixtures) KeysAdd(name string, flags ...string) {
cmd := fmt.Sprintf("%s keys add --home=%s %s", f.GaiacliBinary, f.GaiacliHome, name)
executeWriteCheckErr(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
cmd := fmt.Sprintf("%s keys add --keyring-backend=test --home=%s %s", f.KvcliBinary,
f.KvcliHome, name)
executeWriteCheckErr(f.T, addFlags(cmd, flags))
}
// KeysAddRecover prepares gaiacli keys add --recover
// KeysAddRecover prepares kvcli keys add --recover
func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (exitSuccess bool, stdout, stderr string) {
cmd := fmt.Sprintf("%s keys add --home=%s --recover %s", f.GaiacliBinary, f.GaiacliHome, name)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass, mnemonic)
cmd := fmt.Sprintf("%s keys add --keyring-backend=test --home=%s --recover %s",
f.KvcliBinary, f.KvcliHome, name)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), mnemonic)
}
// KeysAddRecoverHDPath prepares gaiacli keys add --recover --account --index
// KeysAddRecoverHDPath prepares kvcli keys add --recover --account --index
func (f *Fixtures) KeysAddRecoverHDPath(name, mnemonic string, account uint32, index uint32, flags ...string) {
cmd := fmt.Sprintf("%s keys add --home=%s --recover %s --account %d --index %d", f.GaiacliBinary, f.GaiacliHome, name, account, index)
executeWriteCheckErr(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass, mnemonic)
cmd := fmt.Sprintf("%s keys add --keyring-backend=test --home=%s --recover %s --account %d"+
" --index %d", f.KvcliBinary, f.KvcliHome, name, account, index)
executeWriteCheckErr(f.T, addFlags(cmd, flags), mnemonic)
}
// KeysShow is gaiacli keys show
// KeysShow is kvcli keys show
func (f *Fixtures) KeysShow(name string, flags ...string) keys.KeyOutput {
cmd := fmt.Sprintf("%s keys show --home=%s %s", f.GaiacliBinary, f.GaiacliHome, name)
cmd := fmt.Sprintf("%s keys show --keyring-backend=test --home=%s %s", f.KvcliBinary,
f.KvcliHome, name)
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var ko keys.KeyOutput
err := clientkeys.UnmarshalJSON([]byte(out), &ko)
@ -309,88 +321,101 @@ func (f *Fixtures) KeyAddress(name string) sdk.AccAddress {
}
//___________________________________________________________________________________
// gaiacli config
// kvcli config
// CLIConfig is gaiacli config
// CLIConfig is kvcli config
func (f *Fixtures) CLIConfig(key, value string, flags ...string) {
cmd := fmt.Sprintf("%s config --home=%s %s %s", f.GaiacliBinary, f.GaiacliHome, key, value)
cmd := fmt.Sprintf("%s config --home=%s %s %s", f.KvcliBinary, f.KvcliHome, key, value)
executeWriteCheckErr(f.T, addFlags(cmd, flags))
}
//___________________________________________________________________________________
// gaiacli tx send/sign/broadcast
// kvcli tx send/sign/broadcast
// TxSend is gaiacli tx send
// Status is kvcli status
func (f *Fixtures) Status(flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s status %s", f.KvcliBinary, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxSend is kvcli tx send
func (f *Fixtures) TxSend(from string, to sdk.AccAddress, amount sdk.Coin, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx send %s %s %s %v", f.GaiacliBinary, from, to, amount, f.Flags())
cmd := fmt.Sprintf("%s tx send --keyring-backend=test %s %s %s %v", f.KvcliBinary, from,
to, amount, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxSign is gaiacli tx sign
// TxSign is kvcli tx sign
func (f *Fixtures) TxSign(signer, fileName string, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx sign %v --from=%s %v", f.GaiacliBinary, f.Flags(), signer, fileName)
cmd := fmt.Sprintf("%s tx sign %v --keyring-backend=test --from=%s %v", f.KvcliBinary,
f.Flags(), signer, fileName)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxBroadcast is gaiacli tx broadcast
// TxBroadcast is kvcli tx broadcast
func (f *Fixtures) TxBroadcast(fileName string, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx broadcast %v %v", f.GaiacliBinary, f.Flags(), fileName)
cmd := fmt.Sprintf("%s tx broadcast %v %v", f.KvcliBinary, f.Flags(), fileName)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxEncode is gaiacli tx encode
// TxEncode is kvcli tx encode
func (f *Fixtures) TxEncode(fileName string, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx encode %v %v", f.GaiacliBinary, f.Flags(), fileName)
cmd := fmt.Sprintf("%s tx encode %v %v", f.KvcliBinary, f.Flags(), fileName)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxMultisign is gaiacli tx multisign
// TxMultisign is kvcli tx multisign
func (f *Fixtures) TxMultisign(fileName, name string, signaturesFiles []string,
flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx multisign %v %s %s %s", f.GaiacliBinary, f.Flags(),
cmd := fmt.Sprintf("%s tx multisign --keyring-backend=test %v %s %s %s", f.KvcliBinary, f.Flags(),
fileName, name, strings.Join(signaturesFiles, " "),
)
return executeWriteRetStdStreams(f.T, cmd)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags))
}
//___________________________________________________________________________________
// gaiacli tx staking
// kvcli tx staking
// TxStakingCreateValidator is gaiacli tx staking create-validator
// TxStakingCreateValidator is kvcli tx staking create-validator
func (f *Fixtures) TxStakingCreateValidator(from, consPubKey string, amount sdk.Coin, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx staking create-validator %v --from=%s --pubkey=%s", f.GaiacliBinary, f.Flags(), from, consPubKey)
cmd := fmt.Sprintf("%s tx staking create-validator %v --keyring-backend=test --from=%s"+
" --pubkey=%s", f.KvcliBinary, f.Flags(), from, consPubKey)
cmd += fmt.Sprintf(" --amount=%v --moniker=%v --commission-rate=%v", amount, from, "0.05")
cmd += fmt.Sprintf(" --commission-max-rate=%v --commission-max-change-rate=%v", "0.20", "0.10")
cmd += fmt.Sprintf(" --min-self-delegation=%v", "1")
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxStakingUnbond is gaiacli tx staking unbond
// TxStakingUnbond is kvcli tx staking unbond
func (f *Fixtures) TxStakingUnbond(from, shares string, validator sdk.ValAddress, flags ...string) bool {
cmd := fmt.Sprintf("%s tx staking unbond %s %v --from=%s %v", f.GaiacliBinary, validator, shares, from, f.Flags())
cmd := fmt.Sprintf("%s tx staking unbond --keyring-backend=test %s %v --from=%s %v",
f.KvcliBinary, validator, shares, from, f.Flags())
return executeWrite(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
//___________________________________________________________________________________
// gaiacli tx gov
// kvcli tx gov
// TxGovSubmitProposal is gaiacli tx gov submit-proposal
// TxGovSubmitProposal is kvcli tx gov submit-proposal
func (f *Fixtures) TxGovSubmitProposal(from, typ, title, description string, deposit sdk.Coin, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx gov submit-proposal %v --from=%s --type=%s", f.GaiacliBinary, f.Flags(), from, typ)
cmd := fmt.Sprintf("%s tx gov submit-proposal %v --keyring-backend=test --from=%s --type=%s",
f.KvcliBinary, f.Flags(), from, typ)
cmd += fmt.Sprintf(" --title=%s --description=%s --deposit=%s", title, description, deposit)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxGovDeposit is gaiacli tx gov deposit
// TxGovDeposit is kvcli tx gov deposit
func (f *Fixtures) TxGovDeposit(proposalID int, from string, amount sdk.Coin, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx gov deposit %d %s --from=%s %v", f.GaiacliBinary, proposalID, amount, from, f.Flags())
cmd := fmt.Sprintf("%s tx gov deposit %d %s --keyring-backend=test --from=%s %v",
f.KvcliBinary, proposalID, amount, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxGovVote is gaiacli tx gov vote
// TxGovVote is kvcli tx gov vote
func (f *Fixtures) TxGovVote(proposalID int, option gov.VoteOption, from string, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx gov vote %d %s --from=%s %v", f.GaiacliBinary, proposalID, option, from, f.Flags())
cmd := fmt.Sprintf("%s tx gov vote %d %s --keyring-backend=test --from=%s %v",
f.KvcliBinary, proposalID, option, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
@ -401,8 +426,8 @@ func (f *Fixtures) TxGovSubmitParamChangeProposal(
) (bool, string, string) {
cmd := fmt.Sprintf(
"%s tx gov submit-proposal param-change %s --from=%s %v",
f.GaiacliBinary, proposalPath, from, f.Flags(),
"%s tx gov submit-proposal param-change %s --keyring-backend=test --from=%s %v",
f.KvcliBinary, proposalPath, from, f.Flags(),
)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
@ -415,19 +440,19 @@ func (f *Fixtures) TxGovSubmitCommunityPoolSpendProposal(
) (bool, string, string) {
cmd := fmt.Sprintf(
"%s tx gov submit-proposal community-pool-spend %s --from=%s %v",
f.GaiacliBinary, proposalPath, from, f.Flags(),
"%s tx gov submit-proposal community-pool-spend %s --keyring-backend=test --from=%s %v",
f.KvcliBinary, proposalPath, from, f.Flags(),
)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
//___________________________________________________________________________________
// gaiacli query account
// kvcli query account
// QueryAccount is gaiacli query account
// QueryAccount is kvcli query account
func (f *Fixtures) QueryAccount(address sdk.AccAddress, flags ...string) auth.BaseAccount {
cmd := fmt.Sprintf("%s query account %s %v", f.GaiacliBinary, address, f.Flags())
cmd := fmt.Sprintf("%s query account %s %v", f.KvcliBinary, address, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var initRes map[string]json.RawMessage
err := json.Unmarshal([]byte(out), &initRes)
@ -442,186 +467,186 @@ func (f *Fixtures) QueryAccount(address sdk.AccAddress, flags ...string) auth.Ba
}
//___________________________________________________________________________________
// gaiacli query txs
// kvcli query txs
// QueryTxs is gaiacli query txs
func (f *Fixtures) QueryTxs(page, limit int, tags ...string) *sdk.SearchTxsResult {
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --tags='%s' %v", f.GaiacliBinary, page, limit, queryTags(tags), f.Flags())
// QueryTxs is kvcli query txs
func (f *Fixtures) QueryTxs(page, limit int, events ...string) *sdk.SearchTxsResult {
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --events='%s' %v", f.KvcliBinary, page, limit, queryEvents(events), f.Flags())
out, _ := tests.ExecuteT(f.T, cmd, "")
var result sdk.SearchTxsResult
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &result)
err := f.cdc.UnmarshalJSON([]byte(out), &result)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return &result
}
// QueryTxsInvalid query txs with wrong parameters and compare expected error
func (f *Fixtures) QueryTxsInvalid(expectedErr error, page, limit int, tags ...string) {
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --tags='%s' %v", f.GaiacliBinary, page, limit, queryTags(tags), f.Flags())
func (f *Fixtures) QueryTxsInvalid(expectedErr error, page, limit int, events ...string) {
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --events='%s' %v", f.KvcliBinary, page, limit, queryEvents(events), f.Flags())
_, err := tests.ExecuteT(f.T, cmd, "")
require.EqualError(f.T, expectedErr, err)
}
//___________________________________________________________________________________
// gaiacli query staking
// kvcli query staking
// QueryStakingValidator is gaiacli query staking validator
// QueryStakingValidator is kvcli query staking validator
func (f *Fixtures) QueryStakingValidator(valAddr sdk.ValAddress, flags ...string) staking.Validator {
cmd := fmt.Sprintf("%s query staking validator %s %v", f.GaiacliBinary, valAddr, f.Flags())
cmd := fmt.Sprintf("%s query staking validator %s %v", f.KvcliBinary, valAddr, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var validator staking.Validator
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &validator)
err := f.cdc.UnmarshalJSON([]byte(out), &validator)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return validator
}
// QueryStakingUnbondingDelegationsFrom is gaiacli query staking unbonding-delegations-from
// QueryStakingUnbondingDelegationsFrom is kvcli query staking unbonding-delegations-from
func (f *Fixtures) QueryStakingUnbondingDelegationsFrom(valAddr sdk.ValAddress, flags ...string) []staking.UnbondingDelegation {
cmd := fmt.Sprintf("%s query staking unbonding-delegations-from %s %v", f.GaiacliBinary, valAddr, f.Flags())
cmd := fmt.Sprintf("%s query staking unbonding-delegations-from %s %v", f.KvcliBinary, valAddr, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var ubds []staking.UnbondingDelegation
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &ubds)
err := f.cdc.UnmarshalJSON([]byte(out), &ubds)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return ubds
}
// QueryStakingDelegationsTo is gaiacli query staking delegations-to
// QueryStakingDelegationsTo is kvcli query staking delegations-to
func (f *Fixtures) QueryStakingDelegationsTo(valAddr sdk.ValAddress, flags ...string) []staking.Delegation {
cmd := fmt.Sprintf("%s query staking delegations-to %s %v", f.GaiacliBinary, valAddr, f.Flags())
cmd := fmt.Sprintf("%s query staking delegations-to %s %v", f.KvcliBinary, valAddr, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var delegations []staking.Delegation
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &delegations)
err := f.cdc.UnmarshalJSON([]byte(out), &delegations)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return delegations
}
// QueryStakingPool is gaiacli query staking pool
// QueryStakingPool is kvcli query staking pool
func (f *Fixtures) QueryStakingPool(flags ...string) staking.Pool {
cmd := fmt.Sprintf("%s query staking pool %v", f.GaiacliBinary, f.Flags())
cmd := fmt.Sprintf("%s query staking pool %v", f.KvcliBinary, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var pool staking.Pool
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &pool)
err := f.cdc.UnmarshalJSON([]byte(out), &pool)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return pool
}
// QueryStakingParameters is gaiacli query staking parameters
// QueryStakingParameters is kvcli query staking parameters
func (f *Fixtures) QueryStakingParameters(flags ...string) staking.Params {
cmd := fmt.Sprintf("%s query staking params %v", f.GaiacliBinary, f.Flags())
cmd := fmt.Sprintf("%s query staking params %v", f.KvcliBinary, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var params staking.Params
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &params)
err := f.cdc.UnmarshalJSON([]byte(out), &params)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return params
}
//___________________________________________________________________________________
// gaiacli query gov
// kvcli query gov
// QueryGovParamDeposit is gaiacli query gov param deposit
// QueryGovParamDeposit is kvcli query gov param deposit
func (f *Fixtures) QueryGovParamDeposit() gov.DepositParams {
cmd := fmt.Sprintf("%s query gov param deposit %s", f.GaiacliBinary, f.Flags())
cmd := fmt.Sprintf("%s query gov param deposit %s", f.KvcliBinary, f.Flags())
out, _ := tests.ExecuteT(f.T, cmd, "")
var depositParam gov.DepositParams
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &depositParam)
err := f.cdc.UnmarshalJSON([]byte(out), &depositParam)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return depositParam
}
// QueryGovParamVoting is gaiacli query gov param voting
// QueryGovParamVoting is kvcli query gov param voting
func (f *Fixtures) QueryGovParamVoting() gov.VotingParams {
cmd := fmt.Sprintf("%s query gov param voting %s", f.GaiacliBinary, f.Flags())
cmd := fmt.Sprintf("%s query gov param voting %s", f.KvcliBinary, f.Flags())
out, _ := tests.ExecuteT(f.T, cmd, "")
var votingParam gov.VotingParams
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &votingParam)
err := f.cdc.UnmarshalJSON([]byte(out), &votingParam)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return votingParam
}
// QueryGovParamTallying is gaiacli query gov param tallying
// QueryGovParamTallying is kvcli query gov param tallying
func (f *Fixtures) QueryGovParamTallying() gov.TallyParams {
cmd := fmt.Sprintf("%s query gov param tallying %s", f.GaiacliBinary, f.Flags())
cmd := fmt.Sprintf("%s query gov param tallying %s", f.KvcliBinary, f.Flags())
out, _ := tests.ExecuteT(f.T, cmd, "")
var tallyingParam gov.TallyParams
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &tallyingParam)
err := f.cdc.UnmarshalJSON([]byte(out), &tallyingParam)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return tallyingParam
}
// QueryGovProposals is gaiacli query gov proposals
// QueryGovProposals is kvcli query gov proposals
func (f *Fixtures) QueryGovProposals(flags ...string) gov.Proposals {
cmd := fmt.Sprintf("%s query gov proposals %v", f.GaiacliBinary, f.Flags())
cmd := fmt.Sprintf("%s query gov proposals %v", f.KvcliBinary, f.Flags())
stdout, stderr := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
if strings.Contains(stderr, "no matching proposals found") {
return gov.Proposals{}
}
require.Empty(f.T, stderr)
var out gov.Proposals
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(stdout), &out)
err := f.cdc.UnmarshalJSON([]byte(stdout), &out)
require.NoError(f.T, err)
return out
}
// QueryGovProposal is gaiacli query gov proposal
// QueryGovProposal is kvcli query gov proposal
func (f *Fixtures) QueryGovProposal(proposalID int, flags ...string) gov.Proposal {
cmd := fmt.Sprintf("%s query gov proposal %d %v", f.GaiacliBinary, proposalID, f.Flags())
cmd := fmt.Sprintf("%s query gov proposal %d %v", f.KvcliBinary, proposalID, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var proposal gov.Proposal
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &proposal)
err := f.cdc.UnmarshalJSON([]byte(out), &proposal)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return proposal
}
// QueryGovVote is gaiacli query gov vote
// QueryGovVote is kvcli query gov vote
func (f *Fixtures) QueryGovVote(proposalID int, voter sdk.AccAddress, flags ...string) gov.Vote {
cmd := fmt.Sprintf("%s query gov vote %d %s %v", f.GaiacliBinary, proposalID, voter, f.Flags())
cmd := fmt.Sprintf("%s query gov vote %d %s %v", f.KvcliBinary, proposalID, voter, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var vote gov.Vote
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &vote)
err := f.cdc.UnmarshalJSON([]byte(out), &vote)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return vote
}
// QueryGovVotes is gaiacli query gov votes
// QueryGovVotes is kvcli query gov votes
func (f *Fixtures) QueryGovVotes(proposalID int, flags ...string) []gov.Vote {
cmd := fmt.Sprintf("%s query gov votes %d %v", f.GaiacliBinary, proposalID, f.Flags())
cmd := fmt.Sprintf("%s query gov votes %d %v", f.KvcliBinary, proposalID, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var votes []gov.Vote
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &votes)
err := f.cdc.UnmarshalJSON([]byte(out), &votes)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return votes
}
// QueryGovDeposit is gaiacli query gov deposit
// QueryGovDeposit is kvcli query gov deposit
func (f *Fixtures) QueryGovDeposit(proposalID int, depositor sdk.AccAddress, flags ...string) gov.Deposit {
cmd := fmt.Sprintf("%s query gov deposit %d %s %v", f.GaiacliBinary, proposalID, depositor, f.Flags())
cmd := fmt.Sprintf("%s query gov deposit %d %s %v", f.KvcliBinary, proposalID, depositor, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var deposit gov.Deposit
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &deposit)
err := f.cdc.UnmarshalJSON([]byte(out), &deposit)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return deposit
}
// QueryGovDeposits is gaiacli query gov deposits
// QueryGovDeposits is kvcli query gov deposits
func (f *Fixtures) QueryGovDeposits(propsalID int, flags ...string) []gov.Deposit {
cmd := fmt.Sprintf("%s query gov deposits %d %v", f.GaiacliBinary, propsalID, f.Flags())
cmd := fmt.Sprintf("%s query gov deposits %d %v", f.KvcliBinary, propsalID, f.Flags())
out, _ := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
var deposits []gov.Deposit
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &deposits)
err := f.cdc.UnmarshalJSON([]byte(out), &deposits)
require.NoError(f.T, err, "out %v\n, err %v", out, err)
return deposits
}
@ -631,24 +656,24 @@ func (f *Fixtures) QueryGovDeposits(propsalID int, flags ...string) []gov.Deposi
// QuerySigningInfo returns the signing info for a validator
func (f *Fixtures) QuerySigningInfo(val string) slashing.ValidatorSigningInfo {
cmd := fmt.Sprintf("%s query slashing signing-info %s %s", f.GaiacliBinary, val, f.Flags())
cmd := fmt.Sprintf("%s query slashing signing-info %s %s", f.KvcliBinary, val, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
var sinfo slashing.ValidatorSigningInfo
err := cdc.UnmarshalJSON([]byte(res), &sinfo)
err := f.cdc.UnmarshalJSON([]byte(res), &sinfo)
require.NoError(f.T, err)
return sinfo
}
// QuerySlashingParams is gaiacli query slashing params
// QuerySlashingParams is kvcli query slashing params
func (f *Fixtures) QuerySlashingParams() slashing.Params {
cmd := fmt.Sprintf("%s query slashing params %s", f.GaiacliBinary, f.Flags())
cmd := fmt.Sprintf("%s query slashing params %s", f.KvcliBinary, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
var params slashing.Params
err := cdc.UnmarshalJSON([]byte(res), &params)
err := f.cdc.UnmarshalJSON([]byte(res), &params)
require.NoError(f.T, err)
return params
}
@ -658,12 +683,12 @@ func (f *Fixtures) QuerySlashingParams() slashing.Params {
// QueryRewards returns the rewards of a delegator
func (f *Fixtures) QueryRewards(delAddr sdk.AccAddress, flags ...string) distribution.QueryDelegatorTotalRewardsResponse {
cmd := fmt.Sprintf("%s query distribution rewards %s %s", f.GaiacliBinary, delAddr, f.Flags())
cmd := fmt.Sprintf("%s query distribution rewards %s %s", f.KvcliBinary, delAddr, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
var rewards distribution.QueryDelegatorTotalRewardsResponse
err := cdc.UnmarshalJSON([]byte(res), &rewards)
err := f.cdc.UnmarshalJSON([]byte(res), &rewards)
require.NoError(f.T, err)
return rewards
}
@ -673,23 +698,23 @@ func (f *Fixtures) QueryRewards(delAddr sdk.AccAddress, flags ...string) distrib
// QueryTotalSupply returns the total supply of coins
func (f *Fixtures) QueryTotalSupply(flags ...string) (totalSupply sdk.Coins) {
cmd := fmt.Sprintf("%s query supply total %s", f.GaiacliBinary, f.Flags())
cmd := fmt.Sprintf("%s query supply total %s", f.KvcliBinary, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(res), &totalSupply)
err := f.cdc.UnmarshalJSON([]byte(res), &totalSupply)
require.NoError(f.T, err)
return totalSupply
}
// QueryTotalSupplyOf returns the total supply of a given coin denom
func (f *Fixtures) QueryTotalSupplyOf(denom string, flags ...string) sdk.Int {
cmd := fmt.Sprintf("%s query supply total %s %s", f.GaiacliBinary, denom, f.Flags())
cmd := fmt.Sprintf("%s query supply total %s %s", f.KvcliBinary, denom, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
var supplyOf sdk.Int
err := cdc.UnmarshalJSON([]byte(res), &supplyOf)
err := f.cdc.UnmarshalJSON([]byte(res), &supplyOf)
require.NoError(f.T, err)
return supplyOf
}
@ -746,9 +771,9 @@ func addFlags(cmd string, flags []string) string {
return strings.TrimSpace(cmd)
}
func queryTags(tags []string) (out string) {
for _, tag := range tags {
out += tag + "&"
func queryEvents(events []string) (out string) {
for _, event := range events {
out += event + "&"
}
return strings.TrimSuffix(out, "&")
}
@ -762,15 +787,15 @@ func WriteToNewTempFile(t *testing.T, s string) *os.File {
return fp
}
func marshalStdTx(t *testing.T, stdTx auth.StdTx) []byte {
cdc := app.MakeCodec()
bz, err := cdc.MarshalBinaryBare(stdTx)
//nolint:deadcode,unused
func (f *Fixtures) marshalStdTx(t *testing.T, stdTx auth.StdTx) []byte {
bz, err := f.cdc.MarshalBinaryBare(stdTx)
require.NoError(t, err)
return bz
}
func unmarshalStdTx(t *testing.T, s string) (stdTx auth.StdTx) {
cdc := app.MakeCodec()
require.Nil(t, cdc.UnmarshalJSON([]byte(s), &stdTx))
//nolint:deadcode,unused
func (f *Fixtures) unmarshalStdTx(t *testing.T, s string) (stdTx auth.StdTx) {
require.Nil(t, f.cdc.UnmarshalJSON([]byte(s), &stdTx))
return
}

View File

@ -11,8 +11,7 @@ import (
"github.com/tendermint/tendermint/libs/cli"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
@ -22,6 +21,7 @@ import (
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/genutil"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
)
const (
@ -170,6 +170,7 @@ func AddGenesisAccountCmd(
}
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)")
cmd.Flags().String(flagClientHome, defaultClientHome, "client's home directory")
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
cmd.Flags().Uint64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")

View File

@ -111,13 +111,12 @@ func SimulateMsgPlaceBid(ak auth.AccountKeeper, keeper keeper.Keeper) simulation
bidder.PrivKey,
)
_, result, err := app.Deliver(tx)
_, _, err = app.Deliver(tx)
if err != nil {
// to aid debugging, add the stack trace to the comment field of the returned opMsg
return simulation.NewOperationMsg(msg, false, fmt.Sprintf("%+v", err)), nil, err
}
// to aid debugging, add the result log to the comment field
return simulation.NewOperationMsg(msg, true, result.Log), nil, nil
return simulation.NewOperationMsg(msg, true, ""), nil, nil
}
}

View File

@ -7,7 +7,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/simulation"
appparams "github.com/kava-labs/kava/app/params"
@ -134,7 +133,7 @@ func SimulateMsgCdp(ak types.AccountKeeper, k keeper.Keeper, pfk types.Pricefeed
// a cdp already exists, deposit to it, draw debt from it, or repay debt to it
// close 25% of the time
if canClose(acc, existingCDP, debtParam.Denom) && shouldClose(r) {
if canClose(spendableCoins, existingCDP, debtParam.Denom) && shouldClose(r) {
repaymentAmount := spendableCoins.AmountOf(debtParam.Denom)
msg := types.NewMsgRepayDebt(acc.GetAddress(), randCollateralParam.Denom, sdk.NewCoin(debtParam.Denom, repaymentAmount))
@ -157,7 +156,7 @@ func SimulateMsgCdp(ak types.AccountKeeper, k keeper.Keeper, pfk types.Pricefeed
}
// deposit 25% of the time
if hasCoins(acc, randCollateralParam.Denom) && shouldDeposit(r) {
if hasCoins(spendableCoins, randCollateralParam.Denom) && shouldDeposit(r) {
randDepositAmount := sdk.NewInt(int64(simulation.RandIntBetween(r, 1, int(spendableCoins.AmountOf(randCollateralParam.Denom).Int64()))))
msg := types.NewMsgDeposit(acc.GetAddress(), acc.GetAddress(), sdk.NewCoin(randCollateralParam.Denom, randDepositAmount))
@ -224,16 +223,21 @@ func SimulateMsgCdp(ak types.AccountKeeper, k keeper.Keeper, pfk types.Pricefeed
}
// repay debt 25% of the time
if hasCoins(acc, debtParam.Denom) {
if hasCoins(spendableCoins, debtParam.Denom) {
debt := existingCDP.Principal.Amount
maxRepay := spendableCoins.AmountOf(debtParam.Denom)
payableDebt := debt.Sub(debtParam.DebtFloor)
if maxRepay.GT(payableDebt) {
maxRepay = payableDebt
if payableDebt.IsZero() {
return simulation.NewOperationMsgBasic(types.ModuleName, "no-operation", "cannot make partial repayment, cdp at debt floor", false, nil), nil, nil
}
randRepayAmount := sdk.NewInt(int64(simulation.RandIntBetween(r, 1, int(maxRepay.Int64()))))
if debt.Equal(debtParam.DebtFloor) && spendableCoins.AmountOf(debtParam.Denom).GTE(debt) {
randRepayAmount = debt
maxRepay := sdk.MinInt(
spendableCoins.AmountOf(debtParam.Denom),
payableDebt,
)
var randRepayAmount sdk.Int
if maxRepay.Equal(sdk.OneInt()) {
randRepayAmount = sdk.OneInt()
} else {
randRepayAmount = sdk.NewInt(int64(simulation.RandIntBetween(r, 1, int(maxRepay.Int64()))))
}
msg := types.NewMsgRepayDebt(acc.GetAddress(), randCollateralParam.Denom, sdk.NewCoin(debtParam.Denom, randRepayAmount))
@ -272,8 +276,8 @@ func shouldDeposit(r *rand.Rand) bool {
return value > threshold
}
func hasCoins(acc authexported.Account, denom string) bool {
return acc.GetCoins().AmountOf(denom).IsPositive()
func hasCoins(spendableCoins sdk.Coins, denom string) bool {
return spendableCoins.AmountOf(denom).IsPositive()
}
func shouldClose(r *rand.Rand) bool {
@ -282,7 +286,7 @@ func shouldClose(r *rand.Rand) bool {
return value > threshold
}
func canClose(acc authexported.Account, c types.CDP, denom string) bool {
func canClose(spendableCoins sdk.Coins, c types.CDP, denom string) bool {
repaymentAmount := c.Principal.Add(c.AccumulatedFees).Amount
return acc.GetCoins().AmountOf(denom).GTE(repaymentAmount)
return spendableCoins.AmountOf(denom).GTE(repaymentAmount)
}