Skip to content

Commit

Permalink
test(logic): update tests following refactor of balance-related predi…
Browse files Browse the repository at this point in the history
…cates
  • Loading branch information
ccamel committed Oct 4, 2024
1 parent 8a01b10 commit 315ec2a
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 36 deletions.
20 changes: 11 additions & 9 deletions x/logic/keeper/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ func TestFeatures(t *testing.T) {
}

type testCase struct {
ctx sdktestutil.TestContext
accountKeeper *logictestutil.MockAccountKeeper
bankKeeper *logictestutil.MockBankKeeper
wasmKeeper *logictestutil.MockWasmKeeper
params types.Params
request types.QueryServiceAskRequest
got *types.QueryServiceAskResponse
ctx sdktestutil.TestContext
accountKeeper *logictestutil.MockAccountKeeper
authQueryService *logictestutil.MockAuthQueryService
bankKeeper *logictestutil.MockBankKeeper
wasmKeeper *logictestutil.MockWasmKeeper
params types.Params
request types.QueryServiceAskRequest
got *types.QueryServiceAskResponse
}

type SmartContractConfiguration struct {
Expand Down Expand Up @@ -291,18 +292,19 @@ func newQueryClient(ctx context.Context) (types.QueryServiceClient, error) {
encCfg := moduletestutil.MakeTestEncodingConfig(logic.AppModuleBasic{})
logicKeeper := keeper.NewKeeper(
encCfg.Codec,
encCfg.InterfaceRegistry,
key,
key,
authtypes.NewModuleAddress(govtypes.ModuleName),
tc.accountKeeper,
tc.authQueryService,
tc.bankKeeper,
func(ctx context.Context) fs.FS {
vfs := composite.NewFS()
vfs.Mount(wasm.Scheme, wasm.NewFS(ctx, tc.wasmKeeper))

return vfs
},
)
})

if err := logicKeeper.SetParams(tc.ctx.Ctx, tc.params); err != nil {
return nil, err
Expand Down
18 changes: 4 additions & 14 deletions x/logic/keeper/grpc_query_ask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/axone-protocol/axoned/v10/x/logic"
Expand Down Expand Up @@ -153,11 +151,6 @@ func TestGRPCAsk(t *testing.T) {
maxGas: 1000,
expectedError: "out of gas: logic <ReadPerByte> (1018/1000): limit exceeded",
},
{
query: "bank_balances(X, Y).",
maxGas: 3000,
expectedError: "out of gas: logic <panic: {ValuePerByte}> (3093/3000): limit exceeded",
},
{
query: "block_height(X).",
maxGas: 3000,
Expand Down Expand Up @@ -398,25 +391,22 @@ func TestGRPCAsk(t *testing.T) {
// gomock initializations
ctrl := gomock.NewController(t)
accountKeeper := logictestutil.NewMockAccountKeeper(ctrl)
authQueryService := logictestutil.NewMockAuthQueryService(ctrl)
bankKeeper := logictestutil.NewMockBankKeeper(ctrl)
fsProvider := logictestutil.NewMockFS(ctrl)

bankKeeper.EXPECT().GetAccountsBalances(gomock.Any()).Do(func(ctx gocontext.Context) []bankypes.Balance {
sdk.UnwrapSDKContext(ctx).GasMeter().ConsumeGas(2000, "ValuePerByte")
return nil
}).AnyTimes()

logicKeeper := keeper.NewKeeper(
encCfg.Codec,
encCfg.InterfaceRegistry,
key,
key,
authtypes.NewModuleAddress(govtypes.ModuleName),
accountKeeper,
authQueryService,
bankKeeper,
func(_ gocontext.Context) fs.FS {
return fsProvider
},
)
})
maxResultCount := sdkmath.NewUint(tc.maxResultCount)
maxSize := sdkmath.NewUint(tc.maxSize)
params := types.DefaultParams()
Expand Down
6 changes: 4 additions & 2 deletions x/logic/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,22 @@ func TestGRPCParams(t *testing.T) {
// gomock initializations
ctrl := gomock.NewController(t)
accountKeeper := logictestutil.NewMockAccountKeeper(ctrl)
authQueryService := logictestutil.NewMockAuthQueryService(ctrl)
bankKeeper := logictestutil.NewMockBankKeeper(ctrl)
fsProvider := logictestutil.NewMockFS(ctrl)

logicKeeper := keeper.NewKeeper(
encCfg.Codec,
encCfg.InterfaceRegistry,
key,
key,
authtypes.NewModuleAddress(govtypes.ModuleName),
accountKeeper,
authQueryService,
bankKeeper,
func(_ gocontext.Context) fs.FS {
return fsProvider
},
)
})

Convey("and given params to the keeper", func() {
err := logicKeeper.SetParams(testCtx.Ctx, tc.params)
Expand Down
6 changes: 4 additions & 2 deletions x/logic/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ func TestUpdateParams(t *testing.T) {
// gomock initializations
ctrl := gomock.NewController(t)
accountKeeper := logictestutil.NewMockAccountKeeper(ctrl)
authQueryService := logictestutil.NewMockAuthQueryService(ctrl)
bankKeeper := logictestutil.NewMockBankKeeper(ctrl)
fsProvider := logictestutil.NewMockFS(ctrl)

logicKeeper := keeper.NewKeeper(
encCfg.Codec,
encCfg.InterfaceRegistry,
key,
key,
authtypes.NewModuleAddress(govtypes.ModuleName),
accountKeeper,
authQueryService,
bankKeeper,
func(_ gocontext.Context) fs.FS {
return fsProvider
},
)
})

msgServer := keeper.NewMsgServerImpl(*logicKeeper)

Expand Down
Loading

0 comments on commit 315ec2a

Please sign in to comment.