Merge PR #41: Staking ValidatorPowerRank to use "Potential Consensus Power"

This commit is contained in:
frog power 4000 2019-06-11 22:29:48 +02:00 committed by Alexander Bezobchuk
parent 0710669c8e
commit 4eb067906b
7 changed files with 49 additions and 48 deletions

View File

@ -0,0 +1 @@
#3985 ValidatorPowerRank uses potential consensus power

View File

@ -187,7 +187,7 @@ func TestGaiaCLIFeesDeduction(t *testing.T) {
require.Equal(t, fooAmt.Int64(), fooAcc.GetCoins().AmountOf(fooDenom).Int64())
// insufficient funds (coins + fees) tx fails
largeCoins := sdk.TokensFromTendermintPower(10000000)
largeCoins := sdk.TokensFromConsensusPower(10000000)
success, _, _ = f.TxSend(
keyFoo, barAddr, sdk.NewCoin(fooDenom, largeCoins),
fmt.Sprintf("--fees=%s", sdk.NewInt64Coin(feeDenom, 2)), "-y")
@ -222,11 +222,11 @@ func TestGaiaCLISend(t *testing.T) {
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Send some tokens from one account to the other
sendTokens := sdk.TokensFromTendermintPower(10)
sendTokens := sdk.TokensFromConsensusPower(10)
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
@ -291,11 +291,11 @@ func TestGaiaCLIConfirmTx(t *testing.T) {
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// send some tokens from one account to the other
sendTokens := sdk.TokensFromTendermintPower(10)
sendTokens := sdk.TokensFromConsensusPower(10)
f.txSendWithConfirm(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "Y")
tests.WaitForNextNBlocksTM(1, f.Port)
@ -327,11 +327,11 @@ func TestGaiaCLIGasAuto(t *testing.T) {
barAddr := f.KeyAddress(keyBar)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test failure with auto gas disabled and very little gas set by hand
sendTokens := sdk.TokensFromTendermintPower(10)
sendTokens := sdk.TokensFromConsensusPower(10)
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--gas=10", "-y")
require.False(t, success)
@ -386,7 +386,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
consPubKey := sdk.MustBech32ifyConsPub(ed25519.GenPrivKey().PubKey())
sendTokens := sdk.TokensFromTendermintPower(10)
sendTokens := sdk.TokensFromConsensusPower(10)
f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)
@ -404,7 +404,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
require.Equal(t, 0, len(msg.GetSignatures()))
// Test --dry-run
newValTokens := sdk.TokensFromTendermintPower(2)
newValTokens := sdk.TokensFromConsensusPower(2)
success, _, _ = f.TxStakingCreateValidator(keyBar, consPubKey, sdk.NewCoin(denom, newValTokens), "--dry-run")
require.True(t, success)
@ -427,7 +427,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
require.NotZero(t, validatorDelegations[0].Shares)
// unbond a single share
unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromTendermintPower(1))
unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(1))
success = f.TxStakingUnbond(keyBar, unbondAmt.String(), barVal, "-y")
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)
@ -494,14 +494,14 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom))
proposalsQuery := f.QueryGovProposals()
require.Empty(t, proposalsQuery)
// Test submit generate only for submit proposal
proposalTokens := sdk.TokensFromTendermintPower(5)
proposalTokens := sdk.TokensFromConsensusPower(5)
success, stdout, stderr := f.TxGovSubmitProposal(
fooAddr.String(), "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens), "--generate-only", "-y")
require.True(t, success)
@ -541,7 +541,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, proposalTokens, deposit.Amount.AmountOf(denom))
// Test deposit generate only
depositTokens := sdk.TokensFromTendermintPower(10)
depositTokens := sdk.TokensFromConsensusPower(10)
success, stdout, stderr = f.TxGovDeposit(1, fooAddr.String(), sdk.NewCoin(denom, depositTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
@ -632,11 +632,11 @@ func TestGaiaCLISubmitParamChangeProposal(t *testing.T) {
fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom))
// write proposal to file
proposalTokens := sdk.TokensFromTendermintPower(5)
proposalTokens := sdk.TokensFromConsensusPower(5)
proposal := fmt.Sprintf(`{
"title": "Param Change",
"description": "Update max validators",
@ -715,13 +715,13 @@ func TestGaiaCLISubmitCommunityPoolSpendProposal(t *testing.T) {
fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom))
tests.WaitForNextNBlocksTM(3, f.Port)
// write proposal to file
proposalTokens := sdk.TokensFromTendermintPower(5)
proposalTokens := sdk.TokensFromConsensusPower(5)
proposal := fmt.Sprintf(`{
"title": "Community Pool Spend",
"description": "Spend from community pool",
@ -886,7 +886,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
barAddr := f.KeyAddress(keyBar)
// Test generate sendTx with default gas
sendTokens := sdk.TokensFromTendermintPower(10)
sendTokens := sdk.TokensFromConsensusPower(10)
success, stdout, stderr := f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only")
require.True(t, success)
require.Empty(t, stderr)
@ -941,7 +941,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
// Ensure foo has right amount of funds
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
startTokens := sdk.TokensFromConsensusPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
// Test broadcast
@ -1024,7 +1024,7 @@ func TestGaiaCLIEncode(t *testing.T) {
barAddr := f.KeyAddress(keyBar)
keyAddr := f.KeyAddress(keyFoo)
sendTokens := sdk.TokensFromTendermintPower(10)
sendTokens := sdk.TokensFromConsensusPower(10)
success, stdout, stderr := f.TxSend(keyAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only", "--memo", "deadbeef")
require.True(t, success)
require.Empty(t, stderr)

View File

@ -46,14 +46,14 @@ const (
var (
startCoins = sdk.Coins{
sdk.NewCoin(feeDenom, sdk.TokensFromTendermintPower(1000000)),
sdk.NewCoin(fee2Denom, sdk.TokensFromTendermintPower(1000000)),
sdk.NewCoin(fooDenom, sdk.TokensFromTendermintPower(1000)),
sdk.NewCoin(denom, sdk.TokensFromTendermintPower(150)),
sdk.NewCoin(feeDenom, sdk.TokensFromConsensusPower(1000000)),
sdk.NewCoin(fee2Denom, sdk.TokensFromConsensusPower(1000000)),
sdk.NewCoin(fooDenom, sdk.TokensFromConsensusPower(1000)),
sdk.NewCoin(denom, sdk.TokensFromConsensusPower(150)),
}
vestingCoins = sdk.Coins{
sdk.NewCoin(feeDenom, sdk.TokensFromTendermintPower(500000)),
sdk.NewCoin(feeDenom, sdk.TokensFromConsensusPower(500000)),
}
)

View File

@ -190,8 +190,8 @@ func InitTestnet(config *tmconfig.Config, cdc *codec.Codec, mbm module.BasicMana
return err
}
accTokens := sdk.TokensFromTendermintPower(1000)
accStakingTokens := sdk.TokensFromTendermintPower(500)
accTokens := sdk.TokensFromConsensusPower(1000)
accStakingTokens := sdk.TokensFromConsensusPower(500)
accs = append(accs, genaccounts.GenesisAccount{
Address: addr,
Coins: sdk.Coins{
@ -200,7 +200,7 @@ func InitTestnet(config *tmconfig.Config, cdc *codec.Codec, mbm module.BasicMana
},
})
valTokens := sdk.TokensFromTendermintPower(100)
valTokens := sdk.TokensFromConsensusPower(100)
msg := staking.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.12
require (
github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c // indirect
github.com/cosmos/cosmos-sdk v0.28.2-0.20190610160148-8cc708b67cf8
github.com/cosmos/cosmos-sdk v0.28.2-0.20190606154315-d6cb24e849a3
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
github.com/google/gofuzz v1.0.0 // indirect
github.com/gorilla/mux v1.7.2 // indirect

View File

@ -157,7 +157,7 @@ func defaultGenesis(config *tmcfg.Config, nValidators int, initAddrs []sdk.AccAd
pubKey = ed25519.GenPrivKey().PubKey()
power = 1
}
startTokens := sdk.TokensFromTendermintPower(power)
startTokens := sdk.TokensFromConsensusPower(power)
msg := staking.NewMsgCreateValidator(
sdk.ValAddress(operAddr),
@ -182,7 +182,7 @@ func defaultGenesis(config *tmcfg.Config, nValidators int, initAddrs []sdk.AccAd
valOperAddrs = append(valOperAddrs, sdk.ValAddress(operAddr))
accAuth := auth.NewBaseAccountWithAddress(sdk.AccAddress(operAddr))
accTokens := sdk.TokensFromTendermintPower(150)
accTokens := sdk.TokensFromConsensusPower(150)
accAuth.Coins = sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, accTokens)}
accs = append(accs, genaccounts.NewGenesisAccount(&accAuth))
}
@ -206,7 +206,7 @@ func defaultGenesis(config *tmcfg.Config, nValidators int, initAddrs []sdk.AccAd
// add some tokens to init accounts
for _, addr := range initAddrs {
accAuth := auth.NewBaseAccountWithAddress(addr)
accTokens := sdk.TokensFromTendermintPower(100)
accTokens := sdk.TokensFromConsensusPower(100)
accAuth.Coins = sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, accTokens)}
acc := genaccounts.NewGenesisAccount(&accAuth)
accs = append(accs, acc)

View File

@ -398,8 +398,8 @@ func TestPoolParamsQuery(t *testing.T) {
pool := getStakingPool(t, port)
initialPool := staking.InitialPool()
tokens := sdk.TokensFromTendermintPower(100)
freeTokens := sdk.TokensFromTendermintPower(50)
tokens := sdk.TokensFromConsensusPower(100)
freeTokens := sdk.TokensFromConsensusPower(50)
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(tokens)
initialPool.BondedTokens = initialPool.BondedTokens.Add(tokens) // Delegate tx on GaiaAppGenState
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(freeTokens)
@ -457,7 +457,7 @@ func TestBonding(t *testing.T) {
require.Equal(t, 2, len(valPubKeys))
require.Equal(t, 2, len(operAddrs))
amt := sdk.TokensFromTendermintPower(60)
amt := sdk.TokensFromConsensusPower(60)
amtDec := amt.ToDec()
validator := getValidator(t, port, operAddrs[0])
@ -465,7 +465,7 @@ func TestBonding(t *testing.T) {
initialBalance := acc.GetCoins()
// create bond TX
delTokens := sdk.TokensFromTendermintPower(60)
delTokens := sdk.TokensFromConsensusPower(60)
resultTx := doDelegate(t, port, name1, pw, addr, operAddrs[0], delTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -507,7 +507,7 @@ func TestBonding(t *testing.T) {
require.Equal(t, operAddrs[0], bondedValidator.OperatorAddress)
// testing unbonding
unbondingTokens := sdk.TokensFromTendermintPower(30)
unbondingTokens := sdk.TokensFromConsensusPower(30)
resultTx = doUndelegate(t, port, name1, pw, addr, operAddrs[0], unbondingTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -537,7 +537,7 @@ func TestBonding(t *testing.T) {
require.Equal(t, delTokens.QuoRaw(2), ubd.Entries[0].Balance)
// test redelegation
rdTokens := sdk.TokensFromTendermintPower(30)
rdTokens := sdk.TokensFromConsensusPower(30)
resultTx = doBeginRedelegation(t, port, name1, pw, addr, operAddrs[0], operAddrs[1], rdTokens, fees)
require.Equal(t, uint32(0), resultTx.Code)
tests.WaitForHeight(resultTx.Height+1, port)
@ -622,7 +622,7 @@ func TestSubmitProposal(t *testing.T) {
initialBalance := acc.GetCoins()
// create SubmitProposal TX
proposalTokens := sdk.TokensFromTendermintPower(5)
proposalTokens := sdk.TokensFromConsensusPower(5)
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -661,7 +661,7 @@ func TestSubmitCommunityPoolSpendProposal(t *testing.T) {
initialBalance := acc.GetCoins()
// create proposal tx
proposalTokens := sdk.TokensFromTendermintPower(5)
proposalTokens := sdk.TokensFromConsensusPower(5)
resultTx := doSubmitCommunityPoolSpendProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -700,7 +700,7 @@ func TestSubmitParamChangeProposal(t *testing.T) {
initialBalance := acc.GetCoins()
// create proposal tx
proposalTokens := sdk.TokensFromTendermintPower(5)
proposalTokens := sdk.TokensFromConsensusPower(5)
resultTx := doSubmitParamChangeProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -739,7 +739,7 @@ func TestDeposit(t *testing.T) {
initialBalance := acc.GetCoins()
// create SubmitProposal TX
proposalTokens := sdk.TokensFromTendermintPower(5)
proposalTokens := sdk.TokensFromConsensusPower(5)
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -763,7 +763,7 @@ func TestDeposit(t *testing.T) {
require.Equal(t, "Test", proposal.GetTitle())
// create SubmitProposal TX
depositTokens := sdk.TokensFromTendermintPower(5)
depositTokens := sdk.TokensFromConsensusPower(5)
resultTx = doDeposit(t, port, seed, name1, pw, addr, proposalID, depositTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -778,7 +778,7 @@ func TestDeposit(t *testing.T) {
require.Equal(t, resultTx.Height, txResult.Txs[0].Height)
// query proposal
totalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromTendermintPower(10))}
totalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10))}
proposal = getProposal(t, port, proposalID)
require.True(t, proposal.TotalDeposit.IsEqual(totalCoins))
@ -800,7 +800,7 @@ func TestVote(t *testing.T) {
initialBalance := acc.GetCoins()
// create SubmitProposal TX
proposalTokens := sdk.TokensFromTendermintPower(10)
proposalTokens := sdk.TokensFromConsensusPower(10)
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -848,7 +848,7 @@ func TestVote(t *testing.T) {
require.Equal(t, sdk.ZeroInt(), tally.Yes, "tally should be 0 as the address is not bonded")
// create bond TX
delTokens := sdk.TokensFromTendermintPower(60)
delTokens := sdk.TokensFromConsensusPower(60)
resultTx = doDelegate(t, port, name1, pw, addr, operAddrs[0], delTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -961,7 +961,7 @@ func TestProposalsQuery(t *testing.T) {
require.Equal(t, deposit, deposits[0])
// increasing the amount of the deposit should update the existing one
depositTokens := sdk.TokensFromTendermintPower(1)
depositTokens := sdk.TokensFromConsensusPower(1)
resultTx = doDeposit(t, port, seeds[0], names[0], passwords[0], addrs[0], proposalID1, depositTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
@ -1076,7 +1076,7 @@ func TestDistributionFlow(t *testing.T) {
require.Equal(t, valDistInfo.OperatorAddress.String(), sdk.AccAddress(valAddr).String())
// Delegate some coins
delTokens := sdk.TokensFromTendermintPower(60)
delTokens := sdk.TokensFromConsensusPower(60)
resultTx := doDelegate(t, port, name1, pw, addr, valAddr, delTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
require.Equal(t, uint32(0), resultTx.Code)