Skip to content

Commit

Permalink
Merge pull request #769 from axone-protocol/feat/predicate-iterate
Browse files Browse the repository at this point in the history
Feat/predicate iterate
  • Loading branch information
ccamel authored Oct 7, 2024
2 parents 4ec2178 + f7dbb4c commit 274bf3b
Show file tree
Hide file tree
Showing 25 changed files with 1,158 additions and 194 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ mock: ## Generate all the mocks (for tests)
@mockgen -destination x/logic/testutil/gas_mocks.go -package testutil cosmossdk.io/store/types GasMeter
@mockgen -destination x/logic/testutil/fs_mocks.go -package testutil io/fs FS
@mockgen -destination x/logic/testutil/read_file_fs_mocks.go -package testutil io/fs ReadFileFS
@mockgen -source "$$(go list -f '{{.Dir}}' github.com/cosmos/cosmos-sdk/codec/types)/interface_registry.go" \
-package testutil \
-destination x/logic/testutil/interface_registry_mocks.go

## Release:
.PHONY: release-assets
Expand Down
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,12 @@ func New(

app.LogicKeeper = *logicmodulekeeper.NewKeeper(
appCodec,
app.interfaceRegistry,
keys[logicmoduletypes.StoreKey],
keys[logicmoduletypes.MemStoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper,
authkeeper.NewQueryServer(app.AccountKeeper),
app.BankKeeper,
app.provideFS,
)
Expand Down
4 changes: 2 additions & 2 deletions docs/predicate/bank_balances_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ sidebar_position: 1
The signature is as follows:

```text
bank_balances(?Account, ?Balances)
bank_balances(?Address, ?Balances)
```

where:

- Account represents the account address \(in Bech32 format\).
- Address represents the account address \(in Bech32 format\).
- Balances represents the balances of the account as a list of pairs of coin denomination and amount.

## Examples
Expand Down
4 changes: 2 additions & 2 deletions docs/predicate/bank_locked_balances_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ sidebar_position: 2
The signature is as follows:

```text
bank_locked_balances(?Account, ?Balances)
bank_locked_balances(?Address, ?Balances)
```

where:

- Account represents the account address \(in Bech32 format\).
- Address represents the account address \(in Bech32 format\).
- Balances represents the locked balances of the account as a list of pairs of coin denomination and amount.

## Examples
Expand Down
4 changes: 2 additions & 2 deletions docs/predicate/bank_spendable_balances_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ sidebar_position: 3
The signature is as follows:

```text
bank_spendable_balances(?Account, ?Balances)
bank_spendable_balances(?Address, ?Balances)
```

where:

- Account represents the account address \(in Bech32 format\).
- Address represents the account address \(in Bech32 format\).
- Balances represents the spendable balances of the account as a list of pairs of coin denomination and amount.

## Examples
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ replace (
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0

// Use cutom fork of prolog interpreter
github.com/ichiban/prolog => github.com/axone-protocol/prolog v1.0.1-0.20240924120526-53584b2b5c0b
github.com/ichiban/prolog => github.com/axone-protocol/prolog v1.0.1-0.20240930131208-a7e37dcfde82

// replace broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ github.com/aws/aws-sdk-go v1.44.224/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/axone-protocol/prolog v1.0.1-0.20240924120526-53584b2b5c0b h1:s4U2NJBSdjZHRVOQuS2USITMFZO+Y3DuQBZagP527Q4=
github.com/axone-protocol/prolog v1.0.1-0.20240924120526-53584b2b5c0b/go.mod h1:lbZPekEi6qr5WX29GgEmhZlTxUkeWeiJ8cZZRq8qjAE=
github.com/axone-protocol/prolog v1.0.1-0.20240930131208-a7e37dcfde82 h1:Q9L+P3plaPoLLRUyLPYMk/HogUDoOVucInvsweOFYs0=
github.com/axone-protocol/prolog v1.0.1-0.20240930131208-a7e37dcfde82/go.mod h1:lbZPekEi6qr5WX29GgEmhZlTxUkeWeiJ8cZZRq8qjAE=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down
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
9 changes: 5 additions & 4 deletions x/logic/keeper/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ type writerStringer interface {
}

func (k Keeper) enhanceContext(ctx context.Context) context.Context {
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx = sdkCtx.WithValue(types.AuthKeeperContextKey, k.authKeeper)
sdkCtx = sdkCtx.WithValue(types.BankKeeperContextKey, k.bankKeeper)
return sdkCtx
return sdk.UnwrapSDKContext(ctx).
WithValue(types.InterfaceRegistryContextKey, k.interfaceRegistry).
WithValue(types.AuthKeeperContextKey, k.authKeeper).
WithValue(types.AuthQueryServiceContextKey, k.authQueryService).
WithValue(types.BankKeeperContextKey, k.bankKeeper)
}

func (k Keeper) execute(
Expand Down
40 changes: 20 additions & 20 deletions x/logic/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/axone-protocol/axoned/v10/x/logic/fs"
Expand All @@ -15,25 +16,22 @@ import (

type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
cdc codec.BinaryCodec
interfaceRegistry cdctypes.InterfaceRegistry
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
// the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account.
authority sdk.AccAddress

authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
fsProvider fs.Provider
authKeeper types.AccountKeeper
authQueryService types.AuthQueryService
bankKeeper types.BankKeeper
fsProvider fs.Provider
}
)

func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,
authority sdk.AccAddress,
authKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
func NewKeeper(cdc codec.BinaryCodec, interfaceRegistry cdctypes.InterfaceRegistry, storeKey, memKey storetypes.StoreKey,
authority sdk.AccAddress, authKeeper types.AccountKeeper, authQueryService types.AuthQueryService, bankKeeper types.BankKeeper,
fsProvider fs.Provider,
) *Keeper {
// ensure gov module account is set and is not nil
Expand All @@ -42,13 +40,15 @@ func NewKeeper(
}

return &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
authority: authority,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
fsProvider: fsProvider,
cdc: cdc,
interfaceRegistry: interfaceRegistry,
storeKey: storeKey,
memKey: memKey,
authority: authority,
authKeeper: authKeeper,
authQueryService: authQueryService,
bankKeeper: bankKeeper,
fsProvider: fsProvider,
}
}

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 274bf3b

Please sign in to comment.