clean some code
This commit is contained in:
parent
863dc1484e
commit
0a5f64b64f
|
@ -116,23 +116,23 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress {
|
||||||
return addresses
|
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) {
|
func AddTestAddrsFromPubKeys(app *SimApp, ctx sdk.Context, pubKeys []crypto.PubKey, accAmt sdk.Int) {
|
||||||
initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
|
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)
|
setTotalSupply(app, ctx, accAmt, len(pubKeys))
|
||||||
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply...)))
|
|
||||||
|
|
||||||
// fill all the addresses with some coins, set the loose pool tokens simultaneously
|
// fill all the addresses with some coins, set the loose pool tokens simultaneously
|
||||||
for _, pubKey := range pubKeys {
|
for _, pubKey := range pubKeys {
|
||||||
acc := app.AccountKeeper.NewAccountWithAddress(ctx, sdk.AccAddress(pubKey.Address()))
|
saveAccount(app, ctx, sdk.AccAddress(pubKey.Address()), initCoins)
|
||||||
app.AccountKeeper.SetAccount(ctx, acc)
|
|
||||||
|
|
||||||
_, err := app.BankKeeper.AddCoins(ctx, sdk.AccAddress(pubKey.Address()), initCoins)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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
|
// 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)
|
testAddrs := strategy(accNum)
|
||||||
|
|
||||||
initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
|
initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
|
||||||
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(len(testAddrs)))))
|
setTotalSupply(app, ctx, accAmt, accNum)
|
||||||
prevSupply := app.SupplyKeeper.GetSupply(ctx)
|
|
||||||
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply...)))
|
|
||||||
|
|
||||||
// fill all the addresses with some coins, set the loose pool tokens simultaneously
|
// fill all the addresses with some coins, set the loose pool tokens simultaneously
|
||||||
for _, addr := range testAddrs {
|
for _, addr := range testAddrs {
|
||||||
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
|
saveAccount(app, ctx, addr, initCoins)
|
||||||
app.AccountKeeper.SetAccount(ctx, acc)
|
|
||||||
|
|
||||||
_, err := app.BankKeeper.AddCoins(ctx, addr, initCoins)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return testAddrs
|
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.
|
// ConvertAddrsToValAddrs converts the provided addresses to ValAddress.
|
||||||
func ConvertAddrsToValAddrs(addrs []sdk.AccAddress) []sdk.ValAddress {
|
func ConvertAddrsToValAddrs(addrs []sdk.AccAddress) []sdk.ValAddress {
|
||||||
valAddrs := make([]sdk.ValAddress, len(addrs))
|
valAddrs := make([]sdk.ValAddress, len(addrs))
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
package keeper
|
|
Loading…
Reference in New Issue