Skip to content

Commit 18a2266

Browse files
move test helper for more accesibility
1 parent b2e3fcb commit 18a2266

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

app/ante/ante_test.go

+1-33
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import (
44
"testing"
55
"time"
66

7-
"github.com/cosmos/cosmos-sdk/codec"
87
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
98
"github.com/cosmos/cosmos-sdk/simapp/helpers"
109
sdk "github.com/cosmos/cosmos-sdk/types"
11-
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
1210
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
1311
"github.com/stretchr/testify/require"
1412
abci "github.com/tendermint/tendermint/abci/types"
@@ -47,7 +45,7 @@ func TestAppAnteHandler(t *testing.T) {
4745
tApp = tApp.InitializeFromGenesisStatesWithTimeAndChainID(
4846
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
4947
chainID,
50-
NewFundedGenStateWithSameCoins(
48+
app.NewFundedGenStateWithSameCoins(
5149
tApp.AppCodec(),
5250
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
5351
testAddresses,
@@ -128,36 +126,6 @@ func TestAppAnteHandler(t *testing.T) {
128126
}
129127
}
130128

131-
// NewFundedGenStateWithSameCoins creates a (auth and bank) genesis state populated with accounts from the given addresses and balance.
132-
func NewFundedGenStateWithSameCoins(cdc codec.JSONCodec, balance sdk.Coins, addresses []sdk.AccAddress) app.GenesisState {
133-
balances := make([]banktypes.Balance, len(addresses))
134-
for i, addr := range addresses {
135-
balances[i] = banktypes.Balance{
136-
Address: addr.String(),
137-
Coins: balance,
138-
}
139-
}
140-
141-
bankGenesis := banktypes.NewGenesisState(
142-
banktypes.DefaultParams(),
143-
balances,
144-
nil,
145-
[]banktypes.Metadata{}, // Metadata is not used in the antehandler to it is left out here
146-
)
147-
148-
accounts := make(authtypes.GenesisAccounts, len(addresses))
149-
for i := range addresses {
150-
accounts[i] = authtypes.NewBaseAccount(addresses[i], nil, 0, 0)
151-
}
152-
153-
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), accounts)
154-
155-
return app.GenesisState{
156-
authtypes.ModuleName: cdc.MustMarshalJSON(authGenesis),
157-
banktypes.ModuleName: cdc.MustMarshalJSON(bankGenesis),
158-
}
159-
}
160-
161129
// TODO Test pricefeed oracles and bep3 deputy txs can always get into the mempool.
162130

163131
// func newPricefeedGenStateMulti(cdc codec.JSONCodec, oracles []sdk.AccAddress) app.GenesisState {

app/test_common.go

+26-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
1414
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
1515
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
16+
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
1617
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
1718
distkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
1819
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
@@ -160,16 +161,34 @@ func GeneratePrivKeyAddressPairs(n int) (keys []cryptotypes.PrivKey, addrs []sdk
160161
return
161162
}
162163

163-
// Create a new auth genesis state from some addresses and coins. The state is returned marshalled into a map.
164-
func NewAuthGenState(cdc codec.JSONCodec, addresses []sdk.AccAddress, coins []sdk.Coins) GenesisState {
165-
// Create GenAccounts
166-
accounts := authtypes.GenesisAccounts{}
164+
// NewFundedGenStateWithSameCoins creates a (auth and bank) genesis state populated with accounts from the given addresses and balance.
165+
func NewFundedGenStateWithSameCoins(cdc codec.JSONCodec, balance sdk.Coins, addresses []sdk.AccAddress) GenesisState {
166+
balances := make([]banktypes.Balance, len(addresses))
167+
for i, addr := range addresses {
168+
balances[i] = banktypes.Balance{
169+
Address: addr.String(),
170+
Coins: balance,
171+
}
172+
}
173+
174+
bankGenesis := banktypes.NewGenesisState(
175+
banktypes.DefaultParams(),
176+
balances,
177+
nil,
178+
[]banktypes.Metadata{}, // Metadata is not widely used in the sdk or kava
179+
)
180+
181+
accounts := make(authtypes.GenesisAccounts, len(addresses))
167182
for i := range addresses {
168-
accounts = append(accounts, authtypes.NewBaseAccount(addresses[i], nil, 0, 0))
183+
accounts[i] = authtypes.NewBaseAccount(addresses[i], nil, 0, 0)
169184
}
170-
// Create the auth genesis state
185+
171186
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), accounts)
172-
return GenesisState{authtypes.ModuleName: cdc.MustMarshalJSON(authGenesis)}
187+
188+
return GenesisState{
189+
authtypes.ModuleName: cdc.MustMarshalJSON(authGenesis),
190+
banktypes.ModuleName: cdc.MustMarshalJSON(bankGenesis),
191+
}
173192
}
174193

175194
// TODO move auth builder to a new package

0 commit comments

Comments
 (0)