clean some code

This commit is contained in:
Jonathan Gimeno 2020-03-03 11:05:20 +01:00
parent 863dc1484e
commit 0a5f64b64f
2 changed files with 24 additions and 22 deletions

View File

@ -116,23 +116,23 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress {
return addresses
}
// AddTestAddrsFromPubKeys adds the addresses into the SimApp providing only the public keys.
func AddTestAddrsFromPubKeys(app *SimApp, ctx sdk.Context, pubKeys []crypto.PubKey, accAmt sdk.Int) {
initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(len(pubKeys)))))
prevSupply := app.SupplyKeeper.GetSupply(ctx)
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply...)))
setTotalSupply(app, ctx, accAmt, len(pubKeys))
// fill all the addresses with some coins, set the loose pool tokens simultaneously
for _, pubKey := range pubKeys {
acc := app.AccountKeeper.NewAccountWithAddress(ctx, sdk.AccAddress(pubKey.Address()))
app.AccountKeeper.SetAccount(ctx, acc)
_, err := app.BankKeeper.AddCoins(ctx, sdk.AccAddress(pubKey.Address()), initCoins)
if err != nil {
panic(err)
}
saveAccount(app, ctx, sdk.AccAddress(pubKey.Address()), initCoins)
}
return
}
// setTotalSupply provides the total supply based on accAmt * totalAccounts.
func setTotalSupply(app *SimApp, ctx sdk.Context, accAmt sdk.Int, totalAccounts int) {
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(totalAccounts))))
prevSupply := app.SupplyKeeper.GetSupply(ctx)
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply...)))
}
// AddTestAddrs constructs and returns accNum amount of accounts with an
@ -151,23 +151,26 @@ func addTestAddrs(app *SimApp, ctx sdk.Context, accNum int, accAmt sdk.Int, stra
testAddrs := strategy(accNum)
initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(len(testAddrs)))))
prevSupply := app.SupplyKeeper.GetSupply(ctx)
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply...)))
setTotalSupply(app, ctx, accAmt, accNum)
// fill all the addresses with some coins, set the loose pool tokens simultaneously
for _, addr := range testAddrs {
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
app.AccountKeeper.SetAccount(ctx, acc)
_, err := app.BankKeeper.AddCoins(ctx, addr, initCoins)
if err != nil {
panic(err)
}
saveAccount(app, ctx, addr, initCoins)
}
return testAddrs
}
// saveAccount saves the provided account into the simapp with balance based on initCoins.
func saveAccount(app *SimApp, ctx sdk.Context, addr sdk.AccAddress, initCoins sdk.Coins) {
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
app.AccountKeeper.SetAccount(ctx, acc)
_, err := app.BankKeeper.AddCoins(ctx, addr, initCoins)
if err != nil {
panic(err)
}
}
// ConvertAddrsToValAddrs converts the provided addresses to ValAddress.
func ConvertAddrsToValAddrs(addrs []sdk.AccAddress) []sdk.ValAddress {
valAddrs := make([]sdk.ValAddress, len(addrs))

View File

@ -1 +0,0 @@
package keeper