Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed May 10, 2023
1 parent 56e472b commit 6d3edc7
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 43 deletions.
4 changes: 2 additions & 2 deletions aclmapping/dex/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (suite *KeeperTestSuite) TestMsgPlaceOrder() {
}
for _, tc := range tests {
suite.Run(fmt.Sprintf("Test Case: %s", tc.name), func() {
goCtx := context.WithValue(suite.Ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(suite.App.GetKey(dextypes.MemStoreKey)))
goCtx := context.WithValue(suite.Ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(suite.App.GetMemKey(dextypes.MemStoreKey)))
suite.Ctx = suite.Ctx.WithContext(goCtx)

handlerCtx, cms := aclutils.CacheTxContext(suite.Ctx)
Expand Down Expand Up @@ -203,7 +203,7 @@ func (suite *KeeperTestSuite) TestMsgCancelOrder() {
}
for _, tc := range tests {
suite.Run(fmt.Sprintf("Test Case: %s", tc.name), func() {
goCtx := context.WithValue(suite.Ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(suite.App.GetKey(dextypes.MemStoreKey)))
goCtx := context.WithValue(suite.Ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(suite.App.GetMemKey(dextypes.MemStoreKey)))
suite.Ctx = suite.Ctx.WithContext(goCtx)

_, err := suite.msgServer.PlaceOrders(
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func New(
app.DexKeeper = *dexmodulekeeper.NewKeeper(
appCodec,
keys[dexmoduletypes.StoreKey],
keys[dexmoduletypes.MemStoreKey],
memKeys[dexmoduletypes.MemStoreKey],
app.GetSubspace(dexmoduletypes.ModuleName),
app.EpochKeeper,
app.BankKeeper,
Expand Down
4 changes: 2 additions & 2 deletions wasmbinding/test/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestWasmGetOrderSimulation(t *testing.T) {
require.NoError(t, err)

testWrapper.Ctx = testWrapper.Ctx.WithBlockHeight(11).WithBlockTime(time.Unix(3600, 0))
testWrapper.Ctx = testWrapper.Ctx.WithContext(context.WithValue(testWrapper.Ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testWrapper.App.GetKey(dextypes.MemStoreKey))))
testWrapper.Ctx = testWrapper.Ctx.WithContext(context.WithValue(testWrapper.Ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testWrapper.App.GetMemKey(dextypes.MemStoreKey))))
testWrapper.App.DexKeeper.AddRegisteredPair(
testWrapper.Ctx,
app.TestContract,
Expand All @@ -273,7 +273,7 @@ func TestWasmGetOrderSimulation(t *testing.T) {
}, app.TestContract)
testWrapper.App.OracleKeeper.SetBaseExchangeRate(testWrapper.Ctx, oracleutils.MicroAtomDenom, sdk.NewDec(12))
testWrapper.Ctx = testWrapper.Ctx.WithBlockHeight(14).WithBlockTime(time.Unix(3700, 0))
testWrapper.Ctx = testWrapper.Ctx.WithContext(context.WithValue(testWrapper.Ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testWrapper.App.GetKey(dextypes.MemStoreKey))))
testWrapper.Ctx = testWrapper.Ctx.WithContext(context.WithValue(testWrapper.Ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testWrapper.App.GetMemKey(dextypes.MemStoreKey))))

res, err := customQuerier(testWrapper.Ctx, rawQuery)
require.NoError(t, err)
Expand Down
5 changes: 2 additions & 3 deletions x/dex/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
keepertest "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/utils/datastructures"
dex "github.com/sei-protocol/sei-chain/x/dex/cache"
Expand Down Expand Up @@ -131,8 +130,8 @@ func TestClearCancellationForPair(t *testing.T) {
}

func TestSynchronization(t *testing.T) {
_, ctx := keepertest.DexKeeper(t)
stateOne := dex.NewMemState(sdk.NewKVStoreKey(types.MemStoreKey))
k, ctx := keepertest.DexKeeper(t)
stateOne := dex.NewMemState(k.GetMemStoreKey())
targetContract := types.ContractAddress(TEST_CONTRACT)
// no go context
require.NotPanics(t, func() { stateOne.SynchronizeAccess(ctx, targetContract) })
Expand Down
21 changes: 21 additions & 0 deletions x/dex/contract/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var DexWhitelistedKeys = []string{
types.NextOrderIDKey,
types.MatchResultKey,
keeper.ContractPrefixKey,
}

var DexMemWhitelistedKeys = []string{
types.MemOrderKey,
types.MemDepositKey,
types.MemCancelKey,
Expand All @@ -34,12 +37,14 @@ func GetWhitelistMap(contractAddr string) map[string][]string {
res := map[string][]string{}
res[storetypes.NewKVStoreKey(types.StoreKey).Name()] = GetDexWhitelistedPrefixes(contractAddr)
res[storetypes.NewKVStoreKey(wasmtypes.StoreKey).Name()] = GetWasmWhitelistedPrefixes(contractAddr)
res[storetypes.NewKVStoreKey(types.MemStoreKey).Name()] = GetDexMemWhitelistedPrefixes(contractAddr)
return res
}

func GetPerPairWhitelistMap(contractAddr string, pair types.Pair) map[string][]string {
res := map[string][]string{}
res[storetypes.NewKVStoreKey(types.StoreKey).Name()] = GetDexPerPairWhitelistedPrefixes(contractAddr, pair)
res[storetypes.NewKVStoreKey(types.MemStoreKey).Name()] = GetDexMemPerPairWhitelistedPrefixes(contractAddr, pair)
return res
}

Expand All @@ -51,6 +56,14 @@ func GetDexWhitelistedPrefixes(contractAddr string) []string {
})
}

func GetDexMemWhitelistedPrefixes(contractAddr string) []string {
return utils.Map(DexMemWhitelistedKeys, func(key string) string {
return string(append(
types.KeyPrefix(key), types.AddressKeyPrefix(contractAddr)...,
))
})
}

func GetWasmWhitelistedPrefixes(contractAddr string) []string {
addr, _ := sdk.AccAddressFromBech32(contractAddr)
return utils.Map(WasmWhitelistedKeys, func(key string) string {
Expand All @@ -67,3 +80,11 @@ func GetDexPerPairWhitelistedPrefixes(contractAddr string, pair types.Pair) []st
), types.PairPrefix(pair.PriceDenom, pair.AssetDenom)...))
})
}

func GetDexMemPerPairWhitelistedPrefixes(contractAddr string, pair types.Pair) []string {
return utils.Map(DexMemWhitelistedKeys, func(key string) string {
return string(append(append(
types.KeyPrefix(key), types.AddressKeyPrefix(contractAddr)...,
), types.PairPrefix(pair.PriceDenom, pair.AssetDenom)...))
})
}
2 changes: 1 addition & 1 deletion x/dex/keeper/abci/end_block_place_orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestGetPlaceSudoMsg(t *testing.T) {
func TestGetDepositSudoMsg(t *testing.T) {
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
testAccount, _ := sdk.AccAddressFromBech32("sei1yezq49upxhunjjhudql2fnj5dgvcwjj87pn2wx")
amounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(1000000)))
bankkeeper := testApp.BankKeeper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
func TestDepositRent(t *testing.T) {
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
dexkeeper := testApp.DexKeeper

Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/msgserver/msg_server_place_orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestPlaceOrderWithDeposit(t *testing.T) {
}
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
bankkeeper := testApp.BankKeeper
testAccount, _ := sdk.AccAddressFromBech32(TestCreator)
amounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(10)))
Expand Down
14 changes: 7 additions & 7 deletions x/dex/keeper/msgserver/msg_server_register_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRegisterContract(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -78,7 +78,7 @@ func TestRegisterContractCircularDependency(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -128,7 +128,7 @@ func TestRegisterContractDuplicateDependency(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -165,7 +165,7 @@ func TestRegisterContractNumIncomingPaths(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -224,7 +224,7 @@ func TestRegisterContractSetSiblings(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -341,7 +341,7 @@ func TestRegisterContractWithInvalidRentBalance(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -384,7 +384,7 @@ func TestRegisterContractInvalidRentBalance(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down
6 changes: 3 additions & 3 deletions x/dex/keeper/msgserver/msg_server_register_pairs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func TestRegisterPairs(t *testing.T) {
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -102,7 +102,7 @@ func TestRegisterPairs(t *testing.T) {
func TestRegisterPairsInvalidMsg(t *testing.T) {
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -205,7 +205,7 @@ func TestRegisterPairsInvalidMsg(t *testing.T) {
func TestInvalidRegisterPairCreator(t *testing.T) {
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func TestUnregisterContractSetSiblings(t *testing.T) {
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestUpdatePriceTickSize(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -86,7 +86,7 @@ func TestUpdatePriceTickSizeInvalidMsg(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -193,7 +193,7 @@ func TestInvalidUpdatePriceTickSizeCreator(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestUpdateQuantityTickSize(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -86,7 +86,7 @@ func TestUpdateQuantityTickSizeInvalidMsg(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down Expand Up @@ -193,7 +193,7 @@ func TestInvalidUpdateQuantityTickSizeCreator(t *testing.T) {
// Instantiate and get contract address
testApp := keepertest.TestApp()
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetKey(types.MemStoreKey))))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), dexutils.DexMemStateContextKey, dexcache.NewMemState(testApp.GetMemKey(types.MemStoreKey))))
wctx := sdk.WrapSDKContext(ctx)
keeper := testApp.DexKeeper

Expand Down
Loading

0 comments on commit 6d3edc7

Please sign in to comment.