-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make osmoutils store + module account tests not import osmosis (#3775) (
#3789) * Satisfy store_helper code * Make osmoutils tests not integrated (cherry picked from commit 793bb50) Co-authored-by: Dev Ojha <[email protected]>
- Loading branch information
1 parent
7dd1747
commit 502435e
Showing
4 changed files
with
132 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package noapptest | ||
|
||
// NOTE: This file is pulled from the SDK: | ||
// https://github.com/cosmos/cosmos-sdk/blob/2eb51447494163bc9beef1b2cc8aa91c3691b2a7/types/module/testutil/codec.go#L23 | ||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/std" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/cosmos/cosmos-sdk/x/auth/tx" | ||
) | ||
|
||
// TestEncodingConfig defines an encoding configuration that is used for testing | ||
// purposes. Note, MakeTestEncodingConfig takes a series of AppModuleBasic types | ||
// which should only contain the relevant module being tested and any potential | ||
// dependencies. | ||
type TestEncodingConfig struct { | ||
InterfaceRegistry types.InterfaceRegistry | ||
Codec codec.Codec | ||
TxConfig client.TxConfig | ||
Amino *codec.LegacyAmino | ||
} | ||
|
||
func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig { | ||
cdc := codec.NewLegacyAmino() | ||
interfaceRegistry := types.NewInterfaceRegistry() | ||
codec := codec.NewProtoCodec(interfaceRegistry) | ||
|
||
encCfg := TestEncodingConfig{ | ||
InterfaceRegistry: interfaceRegistry, | ||
Codec: codec, | ||
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes), | ||
Amino: cdc, | ||
} | ||
|
||
mb := module.NewBasicManager(modules...) | ||
|
||
std.RegisterLegacyAminoCodec(encCfg.Amino) | ||
std.RegisterInterfaces(encCfg.InterfaceRegistry) | ||
mb.RegisterLegacyAminoCodec(encCfg.Amino) | ||
mb.RegisterInterfaces(encCfg.InterfaceRegistry) | ||
|
||
return encCfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package noapptest | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/store" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
||
dbm "github.com/tendermint/tm-db" | ||
) | ||
|
||
func CtxWithStoreKeys(keys []sdk.StoreKey, header tmproto.Header, isCheckTx bool) sdk.Context { | ||
db := dbm.NewMemDB() | ||
logger := log.NewNopLogger() | ||
cms := store.NewCommitMultiStore(db, logger) | ||
for _, key := range keys { | ||
cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, nil) | ||
} | ||
err := cms.LoadLatestVersion() | ||
if err != nil { | ||
panic(err) | ||
} | ||
return sdk.NewContext(cms, header, isCheckTx, logger) | ||
} | ||
|
||
func DefaultCtxWithStoreKeys(storeKeys []sdk.StoreKey) sdk.Context { | ||
header := tmproto.Header{Height: 1, ChainID: "osmoutils-test-1", Time: time.Now().UTC()} | ||
deliverTx := false | ||
return CtxWithStoreKeys(storeKeys, header, deliverTx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters