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: module inter-dependency cleanup #3621

Merged
merged 8 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ BREAKING CHANGES
* [gaiad init] [\#2602](https://github.com/cosmos/cosmos-sdk/issues/2602) New genesis workflow

* SDK
* [simulation] [\#2665](https://github.com/cosmos/cosmos-sdk/issues/2665) only argument to simulation.Invariant is now app
* [simulation] [\#2665](https://github.com/cosmos/cosmos-sdk/issues/2665) only argument to sdk.Invariant is now app

* Tendermint
* Upgrade to version 0.26.0
Expand Down
2 changes: 2 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BREAKING CHANGES
* Gaia

* SDK
* \#3621 staking.GenesisState.Bonds -> Delegations

* Tendermint

Expand All @@ -34,6 +35,7 @@ IMPROVEMENTS
* Gaia

* SDK
* \#3621 remove many inter-module dependancies
* [\#3601] JSON-stringify the ABCI log response which includes the log and message
index.
* [\#3604] Improve SDK funds related error messages and allow for unicode in
Expand Down
70 changes: 35 additions & 35 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
altPw = "12345678901"
)

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

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

require.Equal(t, staking.DefaultBondDenom, coins[0].Denom)
require.Equal(t, sdk.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, staking.DefaultBondDenom, coins2[0].Denom)
require.Equal(t, sdk.DefaultBondDenom, coins2[0].Denom)
require.Equal(t, int64(1), coins2[0].Amount.Int64())

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

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

// run successful tx
gas := fmt.Sprintf("%d", gasEstResp.GasEstimate)
Expand All @@ -301,7 +301,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(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.SubRaw(1), acc.GetCoins().AmountOf(sdk.DefaultBondDenom))
}

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

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

Expand Down Expand Up @@ -520,11 +520,11 @@ func TestPoolParamsQuery(t *testing.T) {
pool := getStakingPool(t, port)

initialPool := staking.InitialPool()
tokens := staking.TokensFromTendermintPower(100)
freeFermions := staking.TokensFromTendermintPower(50)
tokens := sdk.TokensFromTendermintPower(100)
freeTokens := sdk.TokensFromTendermintPower(50)
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(tokens)
initialPool.BondedTokens = initialPool.BondedTokens.Add(tokens) // Delegate tx on GaiaAppGenState
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(freeFermions) // freeFermionsAcc = 50 on GaiaAppGenState
initialPool.BondedTokens = initialPool.BondedTokens.Add(tokens) // Delegate tx on GaiaAppGenState
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(freeTokens) // freeTokensPerAcc = 50 on GaiaAppGenState

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

Expand Down Expand Up @@ -575,15 +575,15 @@ func TestBonding(t *testing.T) {
require.Equal(t, 2, len(valPubKeys))
require.Equal(t, 2, len(operAddrs))

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

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

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

Expand All @@ -601,7 +601,7 @@ func TestBonding(t *testing.T) {
acc = getAccount(t, port, addr)
coins := acc.GetCoins()
expectedBalance := initialBalance[0].Minus(fees[0])
require.Equal(t, expectedBalance.Amount.Sub(delTokens), coins.AmountOf(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(delTokens), coins.AmountOf(sdk.DefaultBondDenom))
expectedBalance = coins[0]

// query delegation
Expand All @@ -625,7 +625,7 @@ func TestBonding(t *testing.T) {
require.Equal(t, operAddrs[0], bondedValidator.OperatorAddr)

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

Expand All @@ -636,8 +636,8 @@ func TestBonding(t *testing.T) {
coins = acc.GetCoins()
expectedBalance = expectedBalance.Minus(fees[0])
require.True(t,
expectedBalance.Amount.LT(coins.AmountOf(staking.DefaultBondDenom)) ||
expectedBalance.Amount.Equal(coins.AmountOf(staking.DefaultBondDenom)),
expectedBalance.Amount.LT(coins.AmountOf(sdk.DefaultBondDenom)) ||
expectedBalance.Amount.Equal(coins.AmountOf(sdk.DefaultBondDenom)),
"should get tokens back from automatic withdrawal after an unbonding delegation",
)
expectedBalance = coins[0]
Expand All @@ -655,7 +655,7 @@ func TestBonding(t *testing.T) {
require.Equal(t, delTokens.DivRaw(2), ubd.Entries[0].Balance)

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

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

Expand Down Expand Up @@ -735,7 +735,7 @@ func TestSubmitProposal(t *testing.T) {
initialBalance := acc.GetCoins()

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

Expand All @@ -748,7 +748,7 @@ func TestSubmitProposal(t *testing.T) {
// verify balance
acc = getAccount(t, port, addr)
expectedBalance := initialBalance[0].Minus(fees[0])
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), acc.GetCoins().AmountOf(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), acc.GetCoins().AmountOf(sdk.DefaultBondDenom))

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

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

Expand All @@ -784,30 +784,30 @@ func TestDeposit(t *testing.T) {
acc = getAccount(t, port, addr)
coins := acc.GetCoins()
expectedBalance := initialBalance[0].Minus(fees[0])
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), coins.AmountOf(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), coins.AmountOf(sdk.DefaultBondDenom))
expectedBalance = coins[0]

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

// create SubmitProposal TX
depositTokens := staking.TokensFromTendermintPower(5)
depositTokens := sdk.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.Sub(depositTokens), acc.GetCoins().AmountOf(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(depositTokens), acc.GetCoins().AmountOf(sdk.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))}
totalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromTendermintPower(10))}
proposal = getProposal(t, port, proposalID)
require.True(t, proposal.GetTotalDeposit().IsEqual(totalCoins))

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

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

Expand All @@ -841,7 +841,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.Sub(proposalTokens), coins.AmountOf(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), coins.AmountOf(sdk.DefaultBondDenom))
expectedBalance = coins[0]

// query proposal
Expand All @@ -857,7 +857,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(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount, coins.AmountOf(sdk.DefaultBondDenom))
expectedBalance = coins[0]

// query tx
Expand All @@ -873,15 +873,15 @@ 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 := staking.TokensFromTendermintPower(60)
delTokens := sdk.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.Sub(delTokens), coins.AmountOf(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount.Sub(delTokens), coins.AmountOf(sdk.DefaultBondDenom))
expectedBalance = coins[0]

tally = getTally(t, port, proposalID)
Expand All @@ -894,7 +894,7 @@ 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(staking.DefaultBondDenom))
require.Equal(t, expectedBalance.Amount, acc.GetCoins().AmountOf(sdk.DefaultBondDenom))

tally = getTally(t, port, proposalID)
require.Equal(t, sdk.ZeroInt(), tally.Yes, "tally should be 0 the user changed the option")
Expand Down Expand Up @@ -927,7 +927,7 @@ func TestProposalsQuery(t *testing.T) {
defer cleanup()

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

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

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

Expand Down Expand Up @@ -1085,7 +1085,7 @@ func TestDistributionFlow(t *testing.T) {
require.Equal(t, valDistInfo.OperatorAddress.String(), sdk.AccAddress(valAddr).String())

// Delegate some coins
delTokens := staking.TokensFromTendermintPower(60)
delTokens := sdk.TokensFromTendermintPower(60)
resultTx := doDelegate(t, port, name1, pw, addr, valAddr, delTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)
require.Equal(t, uint32(0), resultTx.Code)
Expand Down
22 changes: 11 additions & 11 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
pubKey = ed25519.GenPrivKey().PubKey()
power = 1
}
startTokens := staking.TokensFromTendermintPower(power)
startTokens := sdk.TokensFromTendermintPower(power)

msg := staking.NewMsgCreateValidator(
sdk.ValAddress(operAddr),
pubKey,
sdk.NewCoin(staking.DefaultBondDenom, startTokens),
sdk.NewCoin(sdk.DefaultBondDenom, startTokens),
staking.NewDescription(fmt.Sprintf("validator-%d", i+1), "", "", ""),
staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
sdk.OneInt(),
Expand All @@ -255,8 +255,8 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
valOperAddrs = append(valOperAddrs, sdk.ValAddress(operAddr))

accAuth := auth.NewBaseAccountWithAddress(sdk.AccAddress(operAddr))
accTokens := staking.TokensFromTendermintPower(150)
accAuth.Coins = sdk.Coins{sdk.NewCoin(staking.DefaultBondDenom, accTokens)}
accTokens := sdk.TokensFromTendermintPower(150)
accAuth.Coins = sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, accTokens)}
accs = append(accs, gapp.NewGenesisAccount(&accAuth))
}

Expand All @@ -270,8 +270,8 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
// add some tokens to init accounts
for _, addr := range initAddrs {
accAuth := auth.NewBaseAccountWithAddress(addr)
accTokens := staking.TokensFromTendermintPower(100)
accAuth.Coins = sdk.Coins{sdk.NewCoin(staking.DefaultBondDenom, accTokens)}
accTokens := sdk.TokensFromTendermintPower(100)
accAuth.Coins = sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, accTokens)}
acc := gapp.NewGenesisAccount(&accAuth)
genesisState.Accounts = append(genesisState.Accounts, acc)
genesisState.StakingData.Pool.NotBondedTokens = genesisState.StakingData.Pool.NotBondedTokens.Add(accTokens)
Expand Down Expand Up @@ -707,7 +707,7 @@ func doTransferWithGas(
)

sr := rest.SendReq{
Amount: sdk.Coins{sdk.NewInt64Coin(staking.DefaultBondDenom, 1)},
Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 1)},
BaseReq: baseReq,
}

Expand Down Expand Up @@ -740,7 +740,7 @@ func doTransferWithGasAccAuto(
)

sr := rest.SendReq{
Amount: sdk.Coins{sdk.NewInt64Coin(staking.DefaultBondDenom, 1)},
Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 1)},
BaseReq: baseReq,
}

Expand Down Expand Up @@ -773,7 +773,7 @@ func doDelegate(t *testing.T, port, name, password string,
BaseReq: baseReq,
DelegatorAddr: delAddr,
ValidatorAddr: valAddr,
Delegation: sdk.NewCoin(staking.DefaultBondDenom, amount),
Delegation: sdk.NewCoin(sdk.DefaultBondDenom, amount),
}
req, err := cdc.MarshalJSON(msg)
require.NoError(t, err)
Expand Down Expand Up @@ -1079,7 +1079,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
Description: "test",
ProposalType: "Text",
Proposer: proposerAddr,
InitialDeposit: sdk.Coins{sdk.NewCoin(staking.DefaultBondDenom, amount)},
InitialDeposit: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, amount)},
BaseReq: baseReq,
}

Expand Down Expand Up @@ -1173,7 +1173,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk

dr := rest.DepositReq{
Depositor: proposerAddr,
Amount: sdk.Coins{sdk.NewCoin(staking.DefaultBondDenom, amount)},
Amount: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, amount)},
BaseReq: baseReq,
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (app *GaiaApp) initFromGenesisState(ctx sdk.Context, genesisState GenesisSt
// initialize module-specific stores
auth.InitGenesis(ctx, app.accountKeeper, app.feeCollectionKeeper, genesisState.AuthData)
bank.InitGenesis(ctx, app.bankKeeper, genesisState.BankData)
slashing.InitGenesis(ctx, app.slashingKeeper, genesisState.SlashingData, genesisState.StakingData)
slashing.InitGenesis(ctx, app.slashingKeeper, genesisState.SlashingData, genesisState.StakingData.Validators.ToSDKValidators())
gov.InitGenesis(ctx, app.govKeeper, genesisState.GovData)
mint.InitGenesis(ctx, app.mintKeeper, genesisState.MintData)

Expand Down
Loading