Merge PR #3400: power reduction for Tendermint

* add uncompiled power functionality

* fix some compile errors

* Power -> TendermintPower

* tests rename GetTendermintPower

* test fix

* working

* fix delegation tests

* fix slash tests

* staking/keeper tests passing

* docs reversion

* debuggin workin

* x/staking test pass

* fix gov tests

* fix x/slashing tests

* working distribution test fixes

* fix distribution tests

* lint

* fix lcd tests

* fix gov test

* lint

* CLI fixes, rm stakingTypes

* typos

* working cli fixes

* cli test fix

* cli tests fixed

* testnet creation modification

* typo

* pending

* Sanitize Dec.Roundint64 (#3475)

* merge fixes

* @cwgoes comments

* fix tests

* change power reduction to 10^-6

* option to turn off minting for LCD tests
This commit is contained in:
frog power 4000
2019-02-05 21:30:48 -08:00
committed by GitHub
parent df94f522f9
commit 52f2ec71a9
56 changed files with 1159 additions and 955 deletions
+2 -4
View File
@@ -23,14 +23,12 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
var (
// bonded tokens given to genesis validators/accounts
freeFermionVal = int64(100)
freeFermionsAcc = sdk.NewInt(150)
bondDenom = stakingTypes.DefaultBondDenom
freeFermionsAcc = staking.TokensFromTendermintPower(150)
bondDenom = staking.DefaultBondDenom
)
// State to Unmarshal
+4 -5
View File
@@ -15,7 +15,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
var (
@@ -104,7 +103,7 @@ func TestGaiaAppGenState(t *testing.T) {
func makeMsg(name string, pk crypto.PubKey) auth.StdTx {
desc := staking.NewDescription(name, "", "", "")
comm := stakingTypes.CommissionMsg{}
comm := staking.CommissionMsg{}
msg := staking.NewMsgCreateValidator(sdk.ValAddress(pk.Address()), pk, sdk.NewInt64Coin(bondDenom,
50), desc, comm)
return auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, nil, "")
@@ -131,7 +130,7 @@ func TestGaiaGenesisValidation(t *testing.T) {
// require bonded + jailed validator fails validation
genesisState = makeGenesisState(t, genTxs)
val1 := stakingTypes.NewValidator(addr1, pk1, stakingTypes.Description{Moniker: "test #2"})
val1 := staking.NewValidator(addr1, pk1, staking.NewDescription("test #2", "", "", ""))
val1.Jailed = true
val1.Status = sdk.Bonded
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val1)
@@ -141,7 +140,7 @@ func TestGaiaGenesisValidation(t *testing.T) {
// require duplicate validator fails validation
val1.Jailed = false
genesisState = makeGenesisState(t, genTxs)
val2 := stakingTypes.NewValidator(addr1, pk1, stakingTypes.Description{Moniker: "test #3"})
val2 := staking.NewValidator(addr1, pk1, staking.NewDescription("test #3", "", "", ""))
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val1)
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val2)
err = GaiaValidateGenesisState(genesisState)
@@ -152,7 +151,7 @@ func TestNewDefaultGenesisAccount(t *testing.T) {
addr := secp256k1.GenPrivKeySecp256k1([]byte("")).PubKey().Address()
acc := NewDefaultGenesisAccount(sdk.AccAddress(addr))
require.Equal(t, sdk.NewInt(1000), acc.Coins.AmountOf("footoken"))
require.Equal(t, sdk.NewInt(150), acc.Coins.AmountOf(bondDenom))
require.Equal(t, staking.TokensFromTendermintPower(150), acc.Coins.AmountOf(bondDenom))
}
func TestGenesisStateSanitize(t *testing.T) {
+4 -5
View File
@@ -34,7 +34,6 @@ import (
slashingsim "github.com/cosmos/cosmos-sdk/x/slashing/simulation"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingsim "github.com/cosmos/cosmos-sdk/x/staking/simulation"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
var (
@@ -98,7 +97,7 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
// randomly generate some genesis accounts
for i, acc := range accs {
coins := sdk.Coins{sdk.NewCoin(stakingTypes.DefaultBondDenom, sdk.NewInt(amount))}
coins := sdk.Coins{sdk.NewCoin(staking.DefaultBondDenom, sdk.NewInt(amount))}
bacc := auth.NewBaseAccountWithAddress(acc.Address)
bacc.SetCoins(coins)
@@ -155,7 +154,7 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
govGenesis := gov.GenesisState{
StartingProposalID: uint64(r.Intn(100)),
DepositParams: gov.DepositParams{
MinDeposit: sdk.Coins{sdk.NewInt64Coin(stakingTypes.DefaultBondDenom, int64(r.Intn(1e3)))},
MinDeposit: sdk.Coins{sdk.NewInt64Coin(staking.DefaultBondDenom, int64(r.Intn(1e3)))},
MaxDepositPeriod: vp,
},
VotingParams: gov.VotingParams{
@@ -174,7 +173,7 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
Params: staking.Params{
UnbondingTime: time.Duration(randIntBetween(r, 60, 60*60*24*3*2)) * time.Second,
MaxValidators: uint16(r.Intn(250)),
BondDenom: stakingTypes.DefaultBondDenom,
BondDenom: staking.DefaultBondDenom,
},
}
fmt.Printf("Selected randomly generated staking parameters:\n\t%+v\n", stakingGenesis)
@@ -195,7 +194,7 @@ func appStateRandomizedFn(r *rand.Rand, accs []simulation.Account, genesisTimest
Minter: mint.InitialMinter(
sdk.NewDecWithPrec(int64(r.Intn(99)), 2)),
Params: mint.NewParams(
stakingTypes.DefaultBondDenom,
staking.DefaultBondDenom,
sdk.NewDecWithPrec(int64(r.Intn(99)), 2),
sdk.NewDecWithPrec(20, 2),
sdk.NewDecWithPrec(7, 2),
+63 -65
View File
@@ -20,7 +20,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
func TestGaiaCLIKeysAddMultisig(t *testing.T) {
@@ -167,8 +166,9 @@ func TestGaiaCLIFeesDeduction(t *testing.T) {
require.Equal(t, fooAmt.Int64(), fooAcc.GetCoins().AmountOf(fooDenom).Int64())
// insufficient funds (coins + fees) tx fails
largeCoins := staking.TokensFromTendermintPower(10000000)
success, _, _ = f.TxSend(
keyFoo, barAddr, sdk.NewInt64Coin(fooDenom, 10000000),
keyFoo, barAddr, sdk.NewCoin(fooDenom, largeCoins),
fmt.Sprintf("--fees=%s", sdk.NewInt64Coin(feeDenom, 2)))
require.False(t, success)
@@ -201,45 +201,47 @@ func TestGaiaCLISend(t *testing.T) {
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(denom).Int64())
startTokens := staking.TokensFromTendermintPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Send some tokens from one account to the other
f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10))
sendTokens := staking.TokensFromTendermintPower(10)
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens))
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
barAcc := f.QueryAccount(barAddr)
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, sendTokens, barAcc.GetCoins().AmountOf(denom))
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
// Test --dry-run
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--dry-run")
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--dry-run")
require.True(t, success)
// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
// test autosequencing
f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10))
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens))
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
barAcc = f.QueryAccount(barAddr)
require.Equal(t, int64(20), barAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, sendTokens.MulRaw(2), barAcc.GetCoins().AmountOf(denom))
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(30), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens.Sub(sendTokens.MulRaw(2)), fooAcc.GetCoins().AmountOf(denom))
// test memo
f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--memo='testmemo'")
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--memo='testmemo'")
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure account balances match expected
barAcc = f.QueryAccount(barAddr)
require.Equal(t, int64(30), barAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, sendTokens.MulRaw(3), barAcc.GetCoins().AmountOf(denom))
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(20), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens.Sub(sendTokens.MulRaw(3)), fooAcc.GetCoins().AmountOf(denom))
f.Cleanup()
}
@@ -256,34 +258,36 @@ func TestGaiaCLIGasAuto(t *testing.T) {
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(denom).Int64())
startTokens := staking.TokensFromTendermintPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test failure with auto gas disabled and very little gas set by hand
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--gas=10")
sendTokens := staking.TokensFromTendermintPower(10)
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=10")
require.False(t, success)
// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test failure with negative gas
success, _, _ = f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--gas=-100")
success, _, _ = f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=-100")
require.False(t, success)
// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test failure with 0 gas
success, _, _ = f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--gas=0")
success, _, _ = f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=0")
require.False(t, success)
// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Enable auto gas
success, stdout, stderr := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--gas=auto")
success, stdout, stderr := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=auto")
require.NotEmpty(t, stderr)
require.True(t, success)
cdc := app.MakeCodec()
@@ -295,7 +299,7 @@ func TestGaiaCLIGasAuto(t *testing.T) {
// Check state has changed accordingly
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
f.Cleanup()
}
@@ -308,23 +312,17 @@ func TestGaiaCLICreateValidator(t *testing.T) {
proc := f.GDStart()
defer proc.Stop(false)
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
barVal := sdk.ValAddress(barAddr)
consPubKey := sdk.MustBech32ifyConsPub(ed25519.GenPrivKey().PubKey())
f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10))
sendTokens := staking.TokensFromTendermintPower(10)
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens))
tests.WaitForNextNBlocksTM(1, f.Port)
barAcc := f.QueryAccount(barAddr)
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf(denom).Int64())
fooAcc := f.QueryAccount(fooAddr)
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(denom).Int64())
defaultParams := staking.DefaultParams()
initialPool := staking.InitialPool()
initialPool.BondedTokens = initialPool.BondedTokens.Add(sdk.NewInt(101)) // Delegate tx on GaiaAppGenState
require.Equal(t, sendTokens, barAcc.GetCoins().AmountOf(denom))
// Generate a create validator transaction and ensure correctness
success, stdout, stderr := f.TxStakingCreateValidator(keyBar, consPubKey, sdk.NewInt64Coin(denom, 2), "--generate-only")
@@ -337,21 +335,22 @@ func TestGaiaCLICreateValidator(t *testing.T) {
require.Equal(t, 0, len(msg.GetSignatures()))
// Test --dry-run
success, _, _ = f.TxStakingCreateValidator(keyBar, consPubKey, sdk.NewInt64Coin(denom, 2), "--dry-run")
newValTokens := staking.TokensFromTendermintPower(2)
success, _, _ = f.TxStakingCreateValidator(keyBar, consPubKey, sdk.NewCoin(denom, newValTokens), "--dry-run")
require.True(t, success)
// Create the validator
f.TxStakingCreateValidator(keyBar, consPubKey, sdk.NewInt64Coin(denom, 2))
f.TxStakingCreateValidator(keyBar, consPubKey, sdk.NewCoin(denom, newValTokens))
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure funds were deducted properly
barAcc = f.QueryAccount(barAddr)
require.Equal(t, int64(8), barAcc.GetCoins().AmountOf(denom).Int64())
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.OperatorAddr, barVal)
require.True(sdk.IntEq(t, sdk.NewInt(2), validator.Tokens))
require.True(sdk.IntEq(t, newValTokens, validator.Tokens))
// Query delegations to the validator
validatorDelegations := f.QueryStakingDelegationsTo(barVal)
@@ -359,27 +358,21 @@ func TestGaiaCLICreateValidator(t *testing.T) {
require.NotZero(t, validatorDelegations[0].Shares)
// unbond a single share
success = f.TxStakingUnbond(keyBar, "1", barVal)
unbondTokens := staking.TokensFromTendermintPower(1)
success = f.TxStakingUnbond(keyBar, unbondTokens.String(), barVal)
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure bonded staking is correct
remainingTokens := newValTokens.Sub(unbondTokens)
validator = f.QueryStakingValidator(barVal)
require.Equal(t, "1", validator.Tokens.String())
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, "1", validatorUbds[0].Entries[0].Balance.Amount.String())
// Query staking parameters
params := f.QueryStakingParameters()
require.True(t, defaultParams.Equal(params))
// Query staking pool
pool := f.QueryStakingPool()
require.Equal(t, initialPool.BondedTokens, pool.BondedTokens)
require.Equal(t, remainingTokens.String(), validatorUbds[0].Entries[0].Balance.Amount.String())
f.Cleanup()
}
@@ -399,14 +392,16 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(stakingTypes.DefaultBondDenom).Int64())
startTokens := staking.TokensFromTendermintPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(staking.DefaultBondDenom))
proposalsQuery := f.QueryGovProposals()
require.Empty(t, proposalsQuery)
// Test submit generate only for submit proposal
proposalTokens := staking.TokensFromTendermintPower(5)
success, stdout, stderr := f.TxGovSubmitProposal(
keyFoo, "Text", "Test", "test", sdk.NewInt64Coin(denom, 5), "--generate-only")
keyFoo, "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg := unmarshalStdTx(t, stdout)
@@ -415,11 +410,11 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, 0, len(msg.GetSignatures()))
// Test --dry-run
success, _, _ = f.TxGovSubmitProposal(keyFoo, "Text", "Test", "test", sdk.NewInt64Coin(denom, 5), "--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.NewInt64Coin(denom, 5))
f.TxGovSubmitProposal(keyFoo, "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens))
tests.WaitForNextNBlocksTM(1, f.Port)
// Ensure transaction tags can be queried
@@ -428,7 +423,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
// Ensure deposit was deducted
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(45), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, startTokens.Sub(proposalTokens), fooAcc.GetCoins().AmountOf(denom))
// Ensure propsal is directly queryable
proposal1 := f.QueryGovProposal(1)
@@ -441,10 +436,11 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
// Query the deposits on the proposal
deposit := f.QueryGovDeposit(1, fooAddr)
require.Equal(t, int64(5), deposit.Amount.AmountOf(denom).Int64())
require.Equal(t, proposalTokens, deposit.Amount.AmountOf(denom))
// Test deposit generate only
success, stdout, stderr = f.TxGovDeposit(1, keyFoo, sdk.NewInt64Coin(denom, 10), "--generate-only")
depositTokens := staking.TokensFromTendermintPower(10)
success, stdout, stderr = f.TxGovDeposit(1, keyFoo, sdk.NewCoin(denom, depositTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg = unmarshalStdTx(t, stdout)
@@ -453,17 +449,17 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, 0, len(msg.GetSignatures()))
// Run the deposit transaction
f.TxGovDeposit(1, keyFoo, sdk.NewInt64Coin(denom, 10))
f.TxGovDeposit(1, keyFoo, sdk.NewCoin(denom, depositTokens))
tests.WaitForNextNBlocksTM(1, f.Port)
// test query deposit
deposits := f.QueryGovDeposits(1)
require.Len(t, deposits, 1)
require.Equal(t, int64(15), deposits[0].Amount.AmountOf(denom).Int64())
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, int64(15), deposit.Amount.AmountOf(denom).Int64())
require.Equal(t, proposalTokens.Add(depositTokens), deposit.Amount.AmountOf(denom))
// Ensure tags are set on the transaction
txs = f.QueryTxs(1, 50, "action:deposit", fmt.Sprintf("depositor:%s", fooAddr))
@@ -471,7 +467,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
// Ensure account has expected amount of funds
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf(denom).Int64())
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)
@@ -515,7 +511,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, uint64(1), proposalsQuery[0].GetProposalID())
// submit a second test proposal
f.TxGovSubmitProposal(keyFoo, "Text", "Apples", "test", sdk.NewInt64Coin(denom, 5))
f.TxGovSubmitProposal(keyFoo, "Text", "Apples", "test", sdk.NewCoin(denom, proposalTokens))
tests.WaitForNextNBlocksTM(1, f.Port)
// Test limit on proposals query
@@ -635,7 +631,8 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
barAddr := f.KeyAddress(keyBar)
// Test generate sendTx with default gas
success, stdout, stderr := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--generate-only")
sendTokens := staking.TokensFromTendermintPower(10)
success, stdout, stderr := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg := unmarshalStdTx(t, stdout)
@@ -644,7 +641,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
require.Equal(t, 0, len(msg.GetSignatures()))
// Test generate sendTx with --gas=$amount
success, stdout, stderr = f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--gas=100", "--generate-only")
success, stdout, stderr = f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=100", "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
msg = unmarshalStdTx(t, stdout)
@@ -653,7 +650,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
require.Equal(t, 0, len(msg.GetSignatures()))
// Test generate sendTx, estimate gas
success, stdout, stderr = f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--gas=auto", "--generate-only")
success, stdout, stderr = f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=auto", "--generate-only")
require.True(t, success)
require.NotEmpty(t, stderr)
msg = unmarshalStdTx(t, stdout)
@@ -689,7 +686,8 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
// Ensure foo has right amount of funds
fooAcc := f.QueryAccount(fooAddr)
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(denom).Int64())
startTokens := staking.TokensFromTendermintPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test broadcast
success, stdout, _ = f.TxBroadcast(signedTxFile.Name())
@@ -706,8 +704,8 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
// Ensure account state
barAcc := f.QueryAccount(barAddr)
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(denom).Int64())
require.Equal(t, sendTokens, barAcc.GetCoins().AmountOf(denom))
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
f.Cleanup()
}
+4 -4
View File
@@ -38,10 +38,10 @@ const (
)
var startCoins = sdk.Coins{
sdk.NewInt64Coin(feeDenom, 1000000),
sdk.NewInt64Coin(fee2Denom, 1000000),
sdk.NewInt64Coin(fooDenom, 1000),
sdk.NewInt64Coin(denom, 150),
sdk.NewCoin(feeDenom, staking.TokensFromTendermintPower(1000000)),
sdk.NewCoin(fee2Denom, staking.TokensFromTendermintPower(1000000)),
sdk.NewCoin(fooDenom, staking.TokensFromTendermintPower(1000)),
sdk.NewCoin(denom, staking.TokensFromTendermintPower(150)),
}
//___________________________________________________________________________________
+4 -3
View File
@@ -26,12 +26,13 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
const (
defaultAmount = "100" + stakingTypes.DefaultBondDenom
var (
defaultTokens = staking.TokensFromTendermintPower(100)
defaultAmount = defaultTokens.String() + staking.DefaultBondDenom
defaultCommissionRate = "0.1"
defaultCommissionMaxRate = "0.2"
defaultCommissionMaxChangeRate = "0.01"
+6 -3
View File
@@ -188,18 +188,21 @@ func initTestnet(config *tmconfig.Config, cdc *codec.Codec) error {
return err
}
accTokens := staking.TokensFromTendermintPower(1000)
accStakingTokens := staking.TokensFromTendermintPower(500)
accs = append(accs, app.GenesisAccount{
Address: addr,
Coins: sdk.Coins{
sdk.NewInt64Coin(fmt.Sprintf("%stoken", nodeDirName), 1000),
sdk.NewInt64Coin(stakingtypes.DefaultBondDenom, 500),
sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), accTokens),
sdk.NewCoin(stakingtypes.DefaultBondDenom, accStakingTokens),
},
})
valTokens := staking.TokensFromTendermintPower(100)
msg := staking.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewInt64Coin(stakingtypes.DefaultBondDenom, 100),
sdk.NewCoin(stakingtypes.DefaultBondDenom, valTokens),
staking.NewDescription(nodeDirName, "", "", ""),
staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
)