Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: power reduction for Tendermint #3400

Merged
merged 38 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4ea3477
add uncompiled power functionality
rigelrozanski Jan 25, 2019
3b0f7c6
fix some compile errors
rigelrozanski Jan 25, 2019
1bd2fbf
Merge remote-tracking branch 'origin/develop' into rigel/tmint-power-…
rigelrozanski Jan 29, 2019
874f065
Power -> TendermintPower
rigelrozanski Jan 29, 2019
af5a1e3
tests rename GetTendermintPower
rigelrozanski Jan 29, 2019
5ec0826
test fix
rigelrozanski Jan 30, 2019
b792be6
working
rigelrozanski Jan 30, 2019
bce1ff0
fix delegation tests
rigelrozanski Jan 30, 2019
5fb7d78
fix slash tests
rigelrozanski Jan 30, 2019
31c2b8e
staking/keeper tests passing
rigelrozanski Jan 30, 2019
753e71b
docs reversion
rigelrozanski Jan 30, 2019
0a71ae3
debuggin workin
rigelrozanski Jan 30, 2019
500ae2d
x/staking test pass
rigelrozanski Jan 31, 2019
93a9d66
fix gov tests
rigelrozanski Jan 31, 2019
2f5ae44
fix x/slashing tests
rigelrozanski Jan 31, 2019
328b7bf
working distribution test fixes
rigelrozanski Jan 31, 2019
7958a14
fix distribution tests
rigelrozanski Jan 31, 2019
f7c7a1d
lint
rigelrozanski Jan 31, 2019
836e963
fix lcd tests
rigelrozanski Feb 1, 2019
bba4591
fix gov test
rigelrozanski Feb 1, 2019
079b4ad
lint
rigelrozanski Feb 1, 2019
ffff826
CLI fixes, rm stakingTypes
rigelrozanski Feb 1, 2019
1ab4597
typos
rigelrozanski Feb 1, 2019
6ac2afd
working cli fixes
rigelrozanski Feb 1, 2019
9f42196
Merge remote-tracking branch 'origin/develop' into rigel/tmint-power-…
rigelrozanski Feb 1, 2019
239f145
cli test fix
rigelrozanski Feb 1, 2019
8dcf0d7
cli tests fixed
rigelrozanski Feb 1, 2019
49c1a3c
testnet creation modification
rigelrozanski Feb 1, 2019
b1db0f4
typo
rigelrozanski Feb 1, 2019
d2cc658
pending
rigelrozanski Feb 1, 2019
b2241ef
Sanitize Dec.Roundint64 (#3475)
rigelrozanski Feb 2, 2019
7df1018
Merge remote-tracking branch 'origin/develop' into rigel/tmint-power-…
rigelrozanski Feb 6, 2019
cefba46
merge fixes
rigelrozanski Feb 6, 2019
5e95340
@cwgoes comments
rigelrozanski Feb 6, 2019
a952a41
fix tests
rigelrozanski Feb 6, 2019
a984da1
change power reduction to 10^-6
rigelrozanski Feb 6, 2019
450cad0
option to turn off minting for LCD tests
rigelrozanski Feb 6, 2019
f8c1ffc
Merge branch 'develop' into rigel/tmint-power-reduce
cwgoes Feb 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix lcd tests
  • Loading branch information
rigelrozanski committed Feb 1, 2019
commit 836e9633ea9465be8ef905512b3798697234362b
104 changes: 59 additions & 45 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

const (
Expand All @@ -41,7 +40,7 @@ const (
altPw = "12345678901"
)

var fees = sdk.Coins{sdk.NewInt64Coin(stakingTypes.DefaultBondDenom, 5)}
var fees = sdk.Coins{sdk.NewInt64Coin(staking.DefaultBondDenom, 5)}

func init() {
mintkey.BcryptSecurityParameter = 1
Expand Down Expand Up @@ -176,14 +175,14 @@ func TestCoinSend(t *testing.T) {
coins := acc.GetCoins()
expectedBalance := initialBalance[0].Minus(fees[0])

require.Equal(t, stakingTypes.DefaultBondDenom, coins[0].Denom)
require.Equal(t, staking.DefaultBondDenom, coins[0].Denom)
require.Equal(t, expectedBalance.Amount.SubRaw(1), coins[0].Amount)
expectedBalance = coins[0]

// query receiver
acc2 := getAccount(t, port, receiveAddr)
coins2 := acc2.GetCoins()
require.Equal(t, stakingTypes.DefaultBondDenom, coins2[0].Denom)
require.Equal(t, staking.DefaultBondDenom, coins2[0].Denom)
require.Equal(t, int64(1), coins2[0].Amount.Int64())

// test failure with too little gas
Expand Down Expand Up @@ -217,7 +216,7 @@ func TestCoinSend(t *testing.T) {
require.NotZero(t, gasEstResp.GasEstimate)

acc = getAccount(t, port, addr)
require.Equal(t, expectedBalance.Amount, acc.GetCoins().AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount, acc.GetCoins().AmountOf(staking.DefaultBondDenom))

// run successful tx
gas := fmt.Sprintf("%d", gasEstResp.GasEstimate)
Expand All @@ -233,7 +232,7 @@ func TestCoinSend(t *testing.T) {

acc = getAccount(t, port, addr)
expectedBalance = expectedBalance.Minus(fees[0])
require.Equal(t, expectedBalance.Amount.SubRaw(1), acc.GetCoins().AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.SubRaw(1), acc.GetCoins().AmountOf(staking.DefaultBondDenom))
}

func TestCoinSendAccAuto(t *testing.T) {
Expand All @@ -253,7 +252,7 @@ func TestCoinSendAccAuto(t *testing.T) {
coins := acc.GetCoins()
expectedBalance := initialBalance[0].Minus(fees[0])

require.Equal(t, stakingTypes.DefaultBondDenom, coins[0].Denom)
require.Equal(t, staking.DefaultBondDenom, coins[0].Denom)
require.Equal(t, expectedBalance.Amount.SubRaw(1), coins[0].Amount)
}

Expand Down Expand Up @@ -409,7 +408,10 @@ func TestPoolParamsQuery(t *testing.T) {
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(freeFermions) // freeFermionsAcc = 50 on GaiaAppGenState

require.Equal(t, initialPool.BondedTokens, pool.BondedTokens)
require.Equal(t, initialPool.NotBondedTokens, pool.NotBondedTokens)

//TODO include this test once REST for distribution is online, need to include distirbution tokens from inflation
// for this equality to make sense
//require.Equal(t, initialPool.NotBondedTokens, pool.NotBondedTokens)
}

func TestValidatorsQuery(t *testing.T) {
Expand Down Expand Up @@ -451,14 +453,16 @@ func TestBonding(t *testing.T) {
require.Equal(t, 2, len(valPubKeys))
require.Equal(t, 2, len(operAddrs))

amt := sdk.NewDec(60)
amt := staking.TokensFromTendermintPower(60)
amtDec := sdk.NewDecFromInt(amt)
validator := getValidator(t, port, operAddrs[0])

acc := getAccount(t, port, addr)
initialBalance := acc.GetCoins()

// create bond TX
resultTx := doDelegate(t, port, name1, pw, addr, operAddrs[0], 60, fees)
delTokens := staking.TokensFromTendermintPower(60)
resultTx := doDelegate(t, port, name1, pw, addr, operAddrs[0], delTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

require.Equal(t, uint32(0), resultTx.CheckTx.Code)
Expand All @@ -476,16 +480,16 @@ func TestBonding(t *testing.T) {
acc = getAccount(t, port, addr)
coins := acc.GetCoins()
expectedBalance := initialBalance[0].Minus(fees[0])
require.Equal(t, expectedBalance.Amount.SubRaw(60), coins.AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(delTokens), coins.AmountOf(staking.DefaultBondDenom))
expectedBalance = coins[0]

// query delegation
bond := getDelegation(t, port, addr, operAddrs[0])
require.Equal(t, amt, bond.Shares)
require.Equal(t, amtDec, bond.Shares)

delegatorDels := getDelegatorDelegations(t, port, addr)
require.Len(t, delegatorDels, 1)
require.Equal(t, amt, delegatorDels[0].Shares)
require.Equal(t, amtDec, delegatorDels[0].Shares)

// query all delegations to validator
bonds := getValidatorDelegations(t, port, operAddrs[0])
Expand All @@ -494,13 +498,14 @@ func TestBonding(t *testing.T) {
bondedValidators := getDelegatorValidators(t, port, addr)
require.Len(t, bondedValidators, 1)
require.Equal(t, operAddrs[0], bondedValidators[0].OperatorAddr)
require.Equal(t, validator.DelegatorShares.Add(amt).String(), bondedValidators[0].DelegatorShares.String())
require.Equal(t, validator.DelegatorShares.Add(amtDec).String(), bondedValidators[0].DelegatorShares.String())

bondedValidator := getDelegatorValidator(t, port, addr, operAddrs[0])
require.Equal(t, operAddrs[0], bondedValidator.OperatorAddr)

// testing unbonding
resultTx = doUndelegate(t, port, name1, pw, addr, operAddrs[0], 30, fees)
unbondingTokens := staking.TokensFromTendermintPower(30)
resultTx = doUndelegate(t, port, name1, pw, addr, operAddrs[0], unbondingTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

require.Equal(t, uint32(0), resultTx.CheckTx.Code)
Expand All @@ -511,8 +516,8 @@ func TestBonding(t *testing.T) {
coins = acc.GetCoins()
expectedBalance = expectedBalance.Minus(fees[0])
require.True(t,
expectedBalance.Amount.LT(coins.AmountOf(stakingTypes.DefaultBondDenom)) ||
expectedBalance.Amount.Equal(coins.AmountOf(stakingTypes.DefaultBondDenom)),
expectedBalance.Amount.LT(coins.AmountOf(staking.DefaultBondDenom)) ||
expectedBalance.Amount.Equal(coins.AmountOf(staking.DefaultBondDenom)),
"should get tokens back from automatic withdrawal after an unbonding delegation",
)
expectedBalance = coins[0]
Expand All @@ -527,10 +532,11 @@ func TestBonding(t *testing.T) {

ubd := getUnbondingDelegation(t, port, addr, operAddrs[0])
require.Len(t, ubd.Entries, 1)
require.Equal(t, int64(30), ubd.Entries[0].Balance.Amount.Int64())
require.Equal(t, delTokens.DivRaw(2), ubd.Entries[0].Balance.Amount)

// test redelegation
resultTx = doBeginRedelegation(t, port, name1, pw, addr, operAddrs[0], operAddrs[1], 30, fees)
rdTokens := staking.TokensFromTendermintPower(30)
resultTx = doBeginRedelegation(t, port, name1, pw, addr, operAddrs[0], operAddrs[1], rdTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

require.Equal(t, uint32(0), resultTx.CheckTx.Code)
Expand All @@ -540,8 +546,8 @@ func TestBonding(t *testing.T) {
acc = getAccount(t, port, addr)
expectedBalance = expectedBalance.Minus(fees[0])
require.True(t,
expectedBalance.Amount.LT(coins.AmountOf(stakingTypes.DefaultBondDenom)) ||
expectedBalance.Amount.Equal(coins.AmountOf(stakingTypes.DefaultBondDenom)),
expectedBalance.Amount.LT(coins.AmountOf(staking.DefaultBondDenom)) ||
expectedBalance.Amount.Equal(coins.AmountOf(staking.DefaultBondDenom)),
"should get tokens back from automatic withdrawal after an unbonding delegation",
)

Expand All @@ -555,34 +561,35 @@ func TestBonding(t *testing.T) {
require.Equal(t, resultTx.Height, txs[0].Height)

// query delegations, unbondings and redelegations from validator and delegator
rdShares := sdk.NewDecFromInt(rdTokens)
delegatorDels = getDelegatorDelegations(t, port, addr)
require.Len(t, delegatorDels, 1)
require.Equal(t, "30.000000000000000000", delegatorDels[0].GetShares().String())
require.Equal(t, rdShares, delegatorDels[0].GetShares())

redelegation := getRedelegations(t, port, addr, operAddrs[0], operAddrs[1])
require.Len(t, redelegation, 1)
require.Len(t, redelegation[0].Entries, 1)
require.Equal(t, "30", redelegation[0].Entries[0].Balance.Amount.String())
require.Equal(t, rdTokens, redelegation[0].Entries[0].Balance.Amount)

delegatorUbds := getDelegatorUnbondingDelegations(t, port, addr)
require.Len(t, delegatorUbds, 1)
require.Len(t, delegatorUbds[0].Entries, 1)
require.Equal(t, "30", delegatorUbds[0].Entries[0].Balance.Amount.String())
require.Equal(t, rdTokens, delegatorUbds[0].Entries[0].Balance.Amount)

delegatorReds := getRedelegations(t, port, addr, nil, nil)
require.Len(t, delegatorReds, 1)
require.Len(t, delegatorReds[0].Entries, 1)
require.Equal(t, "30", delegatorReds[0].Entries[0].Balance.Amount.String())
require.Equal(t, rdTokens, delegatorReds[0].Entries[0].Balance.Amount)

validatorUbds := getValidatorUnbondingDelegations(t, port, operAddrs[0])
require.Len(t, validatorUbds, 1)
require.Len(t, validatorUbds[0].Entries, 1)
require.Equal(t, "30", validatorUbds[0].Entries[0].Balance.Amount.String())
require.Equal(t, rdTokens, validatorUbds[0].Entries[0].Balance.Amount)

validatorReds := getRedelegations(t, port, nil, operAddrs[0], nil)
require.Len(t, validatorReds, 1)
require.Len(t, validatorReds[0].Entries, 1)
require.Equal(t, "30", validatorReds[0].Entries[0].Balance.Amount.String())
require.Equal(t, rdTokens, validatorReds[0].Entries[0].Balance.Amount)

// TODO Undonding status not currently implemented
// require.Equal(t, sdk.Unbonding, bondedValidators[0].Status)
Expand Down Expand Up @@ -610,7 +617,8 @@ func TestSubmitProposal(t *testing.T) {
initialBalance := acc.GetCoins()

// create SubmitProposal TX
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, 5, fees)
proposalTokens := staking.TokensFromTendermintPower(5)
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

// check if tx was committed
Expand All @@ -623,7 +631,7 @@ func TestSubmitProposal(t *testing.T) {
// verify balance
acc = getAccount(t, port, addr)
expectedBalance := initialBalance[0].Minus(fees[0])
require.Equal(t, expectedBalance.Amount.SubRaw(5), acc.GetCoins().AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), acc.GetCoins().AmountOf(staking.DefaultBondDenom))

// query proposal
proposal := getProposal(t, port, proposalID)
Expand All @@ -643,7 +651,8 @@ func TestDeposit(t *testing.T) {
initialBalance := acc.GetCoins()

// create SubmitProposal TX
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, 5, fees)
proposalTokens := staking.TokensFromTendermintPower(5)
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

// check if tx was committed
Expand All @@ -657,34 +666,36 @@ func TestDeposit(t *testing.T) {
acc = getAccount(t, port, addr)
coins := acc.GetCoins()
expectedBalance := initialBalance[0].Minus(fees[0])
require.Equal(t, expectedBalance.Amount.SubRaw(5), coins.AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), coins.AmountOf(staking.DefaultBondDenom))
expectedBalance = coins[0]

// query proposal
proposal := getProposal(t, port, proposalID)
require.Equal(t, "Test", proposal.GetTitle())

// create SubmitProposal TX
resultTx = doDeposit(t, port, seed, name1, pw, addr, proposalID, 5, fees)
depositTokens := staking.TokensFromTendermintPower(5)
resultTx = doDeposit(t, port, seed, name1, pw, addr, proposalID, depositTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

// verify balance after deposit and fee
acc = getAccount(t, port, addr)
expectedBalance = expectedBalance.Minus(fees[0])
require.Equal(t, expectedBalance.Amount.SubRaw(5), acc.GetCoins().AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(depositTokens), acc.GetCoins().AmountOf(staking.DefaultBondDenom))

// query tx
txs := getTransactions(t, port, fmt.Sprintf("action=deposit&depositor=%s", addr))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

// query proposal
totalCoins := sdk.Coins{sdk.NewCoin(staking.DefaultBondDenom, staking.TokensFromTendermintPower(10))}
proposal = getProposal(t, port, proposalID)
require.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{sdk.NewInt64Coin(stakingTypes.DefaultBondDenom, 10)}))
require.True(t, proposal.GetTotalDeposit().IsEqual(totalCoins))

// query deposit
deposit := getDeposit(t, port, proposalID, addr)
require.True(t, deposit.Amount.IsEqual(sdk.Coins{sdk.NewInt64Coin(stakingTypes.DefaultBondDenom, 10)}))
require.True(t, deposit.Amount.IsEqual(totalCoins))
}

func TestVote(t *testing.T) {
Expand All @@ -696,7 +707,8 @@ func TestVote(t *testing.T) {
initialBalance := acc.GetCoins()

// create SubmitProposal TX
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, 10, fees)
proposalTokens := staking.TokensFromTendermintPower(10)
resultTx := doSubmitProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

// check if tx was committed
Expand All @@ -710,7 +722,7 @@ func TestVote(t *testing.T) {
acc = getAccount(t, port, addr)
coins := acc.GetCoins()
expectedBalance := initialBalance[0].Minus(fees[0])
require.Equal(t, expectedBalance.Amount.SubRaw(10), coins.AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), coins.AmountOf(staking.DefaultBondDenom))
expectedBalance = coins[0]

// query proposal
Expand All @@ -726,7 +738,7 @@ func TestVote(t *testing.T) {
acc = getAccount(t, port, addr)
coins = acc.GetCoins()
expectedBalance = expectedBalance.Minus(fees[0])
require.Equal(t, expectedBalance.Amount, coins.AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount, coins.AmountOf(staking.DefaultBondDenom))
expectedBalance = coins[0]

// query tx
Expand All @@ -742,18 +754,19 @@ func TestVote(t *testing.T) {
require.Equal(t, sdk.ZeroDec(), tally.Yes, "tally should be 0 as the address is not bonded")

// create bond TX
resultTx = doDelegate(t, port, name1, pw, addr, operAddrs[0], 60, fees)
delTokens := staking.TokensFromTendermintPower(60)
resultTx = doDelegate(t, port, name1, pw, addr, operAddrs[0], delTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

// verify balance
acc = getAccount(t, port, addr)
coins = acc.GetCoins()
expectedBalance = expectedBalance.Minus(fees[0])
require.Equal(t, expectedBalance.Amount.SubRaw(60), coins.AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(delTokens), coins.AmountOf(staking.DefaultBondDenom))
expectedBalance = coins[0]

tally = getTally(t, port, proposalID)
require.Equal(t, sdk.NewDec(60), tally.Yes, "tally should be equal to the amount delegated")
require.Equal(t, sdk.NewDecFromInt(delTokens), tally.Yes, "tally should be equal to the amount delegated")

// change vote option
resultTx = doVote(t, port, seed, name1, pw, addr, proposalID, "No", fees)
Expand All @@ -762,11 +775,11 @@ func TestVote(t *testing.T) {
// verify balance
acc = getAccount(t, port, addr)
expectedBalance = expectedBalance.Minus(fees[0])
require.Equal(t, expectedBalance.Amount, acc.GetCoins().AmountOf(stakingTypes.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount, acc.GetCoins().AmountOf(staking.DefaultBondDenom))

tally = getTally(t, port, proposalID)
require.Equal(t, sdk.ZeroDec(), tally.Yes, "tally should be 0 the user changed the option")
require.Equal(t, sdk.NewDec(60), tally.No, "tally should be equal to the amount delegated")
require.Equal(t, sdk.NewDecFromInt(delTokens), tally.No, "tally should be equal to the amount delegated")
}

func TestUnjail(t *testing.T) {
Expand All @@ -791,7 +804,7 @@ func TestProposalsQuery(t *testing.T) {
defer cleanup()

depositParam := getDepositParam(t, port)
halfMinDeposit := depositParam.MinDeposit.AmountOf(stakingTypes.DefaultBondDenom).Int64() / 2
halfMinDeposit := depositParam.MinDeposit.AmountOf(staking.DefaultBondDenom).DivRaw(2)
getVotingParam(t, port)
getTallyingParam(t, port)

Expand Down Expand Up @@ -838,7 +851,8 @@ func TestProposalsQuery(t *testing.T) {
require.Equal(t, deposit, deposits[0])

// increasing the amount of the deposit should update the existing one
resultTx = doDeposit(t, port, seeds[0], names[0], passwords[0], addrs[0], proposalID1, 1, fees)
depositTokens := staking.TokensFromTendermintPower(1)
resultTx = doDeposit(t, port, seeds[0], names[0], passwords[0], addrs[0], proposalID1, depositTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

deposits = getDeposits(t, port, proposalID1)
Expand Down
Loading