mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-23 23:05:18 +00:00
rename test helper func
This commit is contained in:
parent
83969f3702
commit
2152bb4ed2
@ -44,7 +44,6 @@ import (
|
||||
// So TestApp.InitializeFromGenesisStates() will call InitGenesis with the default genesis state.
|
||||
// and TestApp.InitializeFromGenesisStates(authState, cdpState) will do the same but overwrite the auth and cdp sections of the default genesis state
|
||||
// Creating the genesis states can be combersome, but helper methods can make it easier such as NewAuthGenStateFromAccounts below.
|
||||
//
|
||||
type TestApp struct {
|
||||
App
|
||||
}
|
||||
@ -71,19 +70,6 @@ func (tApp TestApp) GetCDPKeeper() cdp.Keeper { return tApp.cdpKee
|
||||
func (tApp TestApp) GetLiquidatorKeeper() liquidator.Keeper { return tApp.liquidatorKeeper }
|
||||
func (tApp TestApp) GetPriceFeedKeeper() pricefeed.Keeper { return tApp.pricefeedKeeper }
|
||||
|
||||
// Create a new auth genesis state from some addresses and coins. The state is returned marshalled into a map.
|
||||
// TODO make this not a TestApp method.
|
||||
func (tApp TestApp) NewAuthGenStateFromAccounts(addresses []sdk.AccAddress, coins []sdk.Coins) GenesisState {
|
||||
// Create GenAccounts
|
||||
accounts := authexported.GenesisAccounts{}
|
||||
for i := range addresses {
|
||||
accounts = append(accounts, auth.NewBaseAccount(addresses[i], coins[i], nil, 0, 0))
|
||||
}
|
||||
// Create the auth genesis state
|
||||
authGenesis := auth.NewGenesisState(auth.DefaultParams(), accounts)
|
||||
return GenesisState{auth.ModuleName: auth.ModuleCdc.MustMarshalJSON(authGenesis)}
|
||||
}
|
||||
|
||||
// This calls InitChain on the app using the default genesis state, overwitten with any passed in genesis states
|
||||
func (tApp TestApp) InitializeFromGenesisStates(genesisStates ...GenesisState) TestApp {
|
||||
// Create a default genesis state and overwrite with provided values
|
||||
@ -115,6 +101,18 @@ func (tApp TestApp) CheckBalance(t *testing.T, ctx sdk.Context, owner sdk.AccAdd
|
||||
require.Equal(t, expectedCoins, actualCoins)
|
||||
}
|
||||
|
||||
// Create a new auth genesis state from some addresses and coins. The state is returned marshalled into a map.
|
||||
func NewAuthGenState(addresses []sdk.AccAddress, coins []sdk.Coins) GenesisState {
|
||||
// Create GenAccounts
|
||||
accounts := authexported.GenesisAccounts{}
|
||||
for i := range addresses {
|
||||
accounts = append(accounts, auth.NewBaseAccount(addresses[i], coins[i], nil, 0, 0))
|
||||
}
|
||||
// Create the auth genesis state
|
||||
authGenesis := auth.NewGenesisState(auth.DefaultParams(), accounts)
|
||||
return GenesisState{auth.ModuleName: auth.ModuleCdc.MustMarshalJSON(authGenesis)}
|
||||
}
|
||||
|
||||
// GeneratePrivKeyAddressPairsFromRand generates (deterministically) a total of n private keys and addresses.
|
||||
// TODO only generate secp256 keys?
|
||||
func GeneratePrivKeyAddressPairs(n int) (keys []crypto.PrivKey, addrs []sdk.AccAddress) {
|
||||
|
@ -17,7 +17,7 @@ func TestKeeper_EndBlocker(t *testing.T) {
|
||||
seller := addrs[0]
|
||||
|
||||
tApp := app.NewTestApp()
|
||||
authGenState := tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100))})
|
||||
authGenState := app.NewAuthGenState(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100))})
|
||||
tApp.InitializeFromGenesisStates(authGenState)
|
||||
|
||||
ctx := tApp.NewContext(true, abci.Header{})
|
||||
|
@ -19,7 +19,7 @@ func TestKeeper_ForwardAuction(t *testing.T) {
|
||||
buyer := addrs[1]
|
||||
|
||||
tApp := app.NewTestApp()
|
||||
authGenState := tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100)), cs(c("token1", 100), c("token2", 100))})
|
||||
authGenState := app.NewAuthGenState(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100)), cs(c("token1", 100), c("token2", 100))})
|
||||
tApp.InitializeFromGenesisStates(authGenState)
|
||||
|
||||
ctx := tApp.NewContext(false, abci.Header{})
|
||||
@ -52,7 +52,7 @@ func TestKeeper_ReverseAuction(t *testing.T) {
|
||||
buyer := addrs[1]
|
||||
|
||||
tApp := app.NewTestApp()
|
||||
authGenState := tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100)), cs(c("token1", 100), c("token2", 100))})
|
||||
authGenState := app.NewAuthGenState(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100)), cs(c("token1", 100), c("token2", 100))})
|
||||
tApp.InitializeFromGenesisStates(authGenState)
|
||||
|
||||
ctx := tApp.NewContext(false, abci.Header{})
|
||||
@ -86,7 +86,7 @@ func TestKeeper_ForwardReverseAuction(t *testing.T) {
|
||||
recipient := addrs[2]
|
||||
|
||||
tApp := app.NewTestApp()
|
||||
authGenState := tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100)), cs(c("token1", 100), c("token2", 100)), cs(c("token1", 100), c("token2", 100))})
|
||||
authGenState := app.NewAuthGenState(addrs, []sdk.Coins{cs(c("token1", 100), c("token2", 100)), cs(c("token1", 100), c("token2", 100)), cs(c("token1", 100), c("token2", 100))})
|
||||
tApp.InitializeFromGenesisStates(authGenState)
|
||||
|
||||
ctx := tApp.NewContext(false, abci.Header{})
|
||||
|
@ -20,7 +20,7 @@ func TestApp_CreateModifyDeleteCDP(t *testing.T) {
|
||||
testAddr := addrs[0]
|
||||
testPrivKey := privKeys[0]
|
||||
tApp.InitializeFromGenesisStates(
|
||||
tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("xrp", 100))}),
|
||||
app.NewAuthGenState(addrs, []sdk.Coins{cs(c("xrp", 100))}),
|
||||
)
|
||||
ctx := tApp.NewContext(false, abci.Header{})
|
||||
// check balance
|
||||
|
@ -35,7 +35,7 @@ func TestKeeper_AddSubtractGetCoins(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
// setup app with an account
|
||||
tApp := app.NewTestApp()
|
||||
authGenState := tApp.NewAuthGenStateFromAccounts([]sdk.AccAddress{normalAddr}, []sdk.Coins{cs(c("usdx", 100), c("kava", 100))})
|
||||
authGenState := app.NewAuthGenState([]sdk.AccAddress{normalAddr}, []sdk.Coins{cs(c("usdx", 100), c("kava", 100))})
|
||||
tApp.InitializeFromGenesisStates(authGenState)
|
||||
|
||||
// create a new context and setup the liquidator account
|
||||
|
@ -97,7 +97,7 @@ func TestKeeper_ModifyCDP(t *testing.T) {
|
||||
// setup keeper
|
||||
tApp := app.NewTestApp()
|
||||
// initialize cdp owner account with coins
|
||||
authGen := tApp.NewAuthGenStateFromAccounts([]sdk.AccAddress{ownerAddr}, []sdk.Coins{tc.priorState.OwnerCoins})
|
||||
authGen := app.NewAuthGenState([]sdk.AccAddress{ownerAddr}, []sdk.Coins{tc.priorState.OwnerCoins})
|
||||
tApp.InitializeFromGenesisStates(authGen)
|
||||
// create a context for db access
|
||||
ctx := tApp.NewContext(false, abci.Header{})
|
||||
@ -172,7 +172,7 @@ func TestKeeper_PartialSeizeCDP(t *testing.T) {
|
||||
testAddr := addrs[0]
|
||||
|
||||
tApp := app.NewTestApp()
|
||||
authGenState := tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c(collateral, 100))})
|
||||
authGenState := app.NewAuthGenState(addrs, []sdk.Coins{cs(c(collateral, 100))})
|
||||
tApp.InitializeFromGenesisStates(authGenState)
|
||||
|
||||
ctx := tApp.NewContext(false, abci.Header{})
|
||||
|
@ -19,7 +19,7 @@ func TestKeeper_SeizeAndStartCollateralAuction(t *testing.T) {
|
||||
|
||||
tApp := app.NewTestApp()
|
||||
tApp.InitializeFromGenesisStates(
|
||||
tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("btc", 100))}),
|
||||
app.NewAuthGenState(addrs, []sdk.Coins{cs(c("btc", 100))}),
|
||||
NewPFGenState("btc", sdk.MustNewDecFromStr("8000.00")),
|
||||
NewCDPGenState(),
|
||||
NewLiquidatorGenState(),
|
||||
@ -80,7 +80,7 @@ func TestKeeper_partialSeizeCDP(t *testing.T) {
|
||||
|
||||
tApp := app.NewTestApp()
|
||||
tApp.InitializeFromGenesisStates(
|
||||
tApp.NewAuthGenStateFromAccounts(addrs, []sdk.Coins{cs(c("btc", 100))}),
|
||||
app.NewAuthGenState(addrs, []sdk.Coins{cs(c("btc", 100))}),
|
||||
NewPFGenState("btc", sdk.MustNewDecFromStr("8000.00")),
|
||||
NewCDPGenState(),
|
||||
NewLiquidatorGenState(),
|
||||
|
Loading…
Reference in New Issue
Block a user