diff --git a/.gitignore b/.gitignore index 56dfc93a..f91d5cde 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ seda.env .env # coverage files -coverage.txt \ No newline at end of file +coverage.txt diff --git a/app/app.go b/app/app.go index 9e4a9c98..1ddaa2f0 100644 --- a/app/app.go +++ b/app/app.go @@ -612,9 +612,12 @@ func NewApp( appCodec, runtime.NewKVStoreService(keys[wasmstoragetypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), + app.AccountKeeper, + app.BankKeeper, contractKeeper, + app.WasmKeeper, ) - wasmStorageModule := wasmstorage.NewAppModule(appCodec, app.WasmStorageKeeper, app.AccountKeeper, app.BankKeeper) + wasmStorageModule := wasmstorage.NewAppModule(appCodec, app.WasmStorageKeeper) /* =================================================== */ /* TRANSFER STACK */ diff --git a/dockerfiles/Dockerfile.e2e b/dockerfiles/Dockerfile.e2e index 5f872383..e8ee2256 100644 --- a/dockerfiles/Dockerfile.e2e +++ b/dockerfiles/Dockerfile.e2e @@ -1,5 +1,3 @@ -# syntax=docker/dockerfile:1 - ARG GO_VERSION="1.21" ARG RUNNER_IMAGE="alpine:3.17" ARG SEDA_EXPONENT="18" @@ -18,7 +16,8 @@ RUN apk add --no-cache \ ca-certificates \ build-base \ linux-headers \ - git + git \ + binutils-gold # Download go dependencies WORKDIR /seda-chain diff --git a/go.mod b/go.mod index 14f98202..6d1c9080 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( cosmossdk.io/x/tx v0.13.2 cosmossdk.io/x/upgrade v0.1.1 github.com/CosmWasm/wasmd v0.50.0 + github.com/CosmWasm/wasmvm v1.5.0 github.com/aws/aws-sdk-go v1.44.224 github.com/cometbft/cometbft v0.38.6 github.com/cosmos/cosmos-db v1.0.2 @@ -41,12 +42,14 @@ require ( github.com/hashicorp/go-plugin v1.6.0 github.com/ory/dockertest/v3 v3.10.0 github.com/pkg/errors v0.9.1 + github.com/sedaprotocol/seda-wasm-vm/tallyvm v0.0.0-20240617203732-2649db4864d8 github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c github.com/spf13/cast v1.6.0 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 + go.uber.org/mock v0.4.0 google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c google.golang.org/grpc v1.63.2 google.golang.org/protobuf v1.33.0 @@ -64,7 +67,6 @@ require ( github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.2 // indirect github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect - github.com/CosmWasm/wasmvm v1.5.0 // indirect github.com/DataDog/datadog-go v4.8.3+incompatible // indirect github.com/DataDog/zstd v1.5.5 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect diff --git a/go.sum b/go.sum index d938de98..3bfc44e1 100644 --- a/go.sum +++ b/go.sum @@ -1009,6 +1009,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg= github.com/sedaprotocol/rosetta-seda v0.0.0-20240427181737-e1d7563b2529 h1:VbJcd022MkoohRyAfktHnN99Brt/4eJr01mdLqPhGaE= github.com/sedaprotocol/rosetta-seda v0.0.0-20240427181737-e1d7563b2529/go.mod h1:GdlDqGJN2g55PHiwYJs2bQMlL0rdlQQbauK4dcrOI6w= +github.com/sedaprotocol/seda-wasm-vm/tallyvm v0.0.0-20240617203732-2649db4864d8 h1:9Vw+DoN9MW+qPDQvW1B+X7t0ulOUmYM3HTv7Khvqvj0= +github.com/sedaprotocol/seda-wasm-vm/tallyvm v0.0.0-20240617203732-2649db4864d8/go.mod h1:AaX9uRy6qD2q+o1SapTRnGUe9HHZWTmBN2BVNAptq3U= github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c h1:PbSn7HpWeox6lqBu6Ba6YZS3On3euwn1BPz/egsnEgA= github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c/go.mod h1:DEIXHk41VUzOMVbZnIApssPXtZ+2zrETDP7kJjGc1RM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= diff --git a/proto/sedachain/wasm_storage/v1/wasm_storage.proto b/proto/sedachain/wasm_storage/v1/wasm_storage.proto index a1a70d2c..d70e3683 100644 --- a/proto/sedachain/wasm_storage/v1/wasm_storage.proto +++ b/proto/sedachain/wasm_storage/v1/wasm_storage.proto @@ -14,7 +14,7 @@ message Wasm { google.protobuf.Timestamp added_at = 4 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; // ExpirationHeight represents the block height at which the data request - // wasm will be pruned. The value of zero means no expiration. + // wasm will be pruned. The value of zero means no expiration. int64 expiration_height = 5; } diff --git a/scripts/deploy_contracts.sh b/scripts/deploy_contracts.sh index 8049c13a..e9ca5991 100755 --- a/scripts/deploy_contracts.sh +++ b/scripts/deploy_contracts.sh @@ -5,7 +5,7 @@ set -x CHAIN_ID=seda-1-local RPC_URL=http://127.0.0.1:26657 BIN=$(git rev-parse --show-toplevel)/build/sedad -ARTIFACTS_DIR=$(git rev-parse --show-toplevel)/testutil/testwasms # must contain proxy_contract.wasm, data_requests.wasm, and staking.wasm +CONTRACT_WASM=$(git rev-parse --show-toplevel)/testutil/testwasms/seda_contract.wasm VOTING_PERIOD=30 # seconds DEV_ACCOUNT=$($BIN keys show satoshi --keyring-backend test -a) # for sending wasm-storage txs VOTE_ACCOUNT=$($BIN keys show satoshi --keyring-backend test -a) # for sending vote txs @@ -13,8 +13,7 @@ VOTE_ACCOUNT=$($BIN keys show satoshi --keyring-backend test -a) # for sending v echo "Deploying proxy contract" -# Proxy Contracts -OUTPUT="$($BIN tx wasm store $ARTIFACTS_DIR/proxy_contract.wasm --node $RPC_URL --from $DEV_ACCOUNT --keyring-backend test --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)" +OUTPUT="$($BIN tx wasm store $CONTRACT_WASM --node $RPC_URL --from $DEV_ACCOUNT --keyring-backend test --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)" TXHASH=$(echo $OUTPUT | jq -r '.txhash') sleep 10 @@ -25,7 +24,8 @@ PROXY_CODE_ID=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="store_code") echo "Instantiating proxy contract on code id $PROXY_CODE_ID" OUTPUT=$($BIN tx wasm-storage submit-proposal instantiate-and-register-proxy-contract $PROXY_CODE_ID \ - '{"token":"aseda"}' 74657374696e67 \ + '{"token":"aseda", "owner": "'$DEV_ACCOUNT'" }' \ + 74657374696e67 \ --admin $DEV_ACCOUNT \ --label proxy$PROXY_CODE_ID \ --title 'Proxy Contract' --summary 'Instantiates and registers proxy contract' --deposit 10000000aseda \ @@ -47,65 +47,3 @@ sleep $VOTING_PERIOD PROXY_CONTRACT_ADDRESS=$($BIN query wasm-storage proxy-contract-registry --output json | jq -r '.address') echo "Deployed proxy contract to: $PROXY_CONTRACT_ADDRESS" - -# ----------------------- -# Data Requests -# ----------------------- - -echo "Deploying Data Request contract" - -OUTPUT="$($BIN tx wasm store $ARTIFACTS_DIR/data_requests.wasm --node $RPC_URL --from $DEV_ACCOUNT --keyring-backend test --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)" -TXHASH=$(echo $OUTPUT | jq -r '.txhash') -sleep 10 -OUTPUT="$($BIN query tx $TXHASH --node $RPC_URL --output json)" -DRs_CODE_ID=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value') - -echo "Instantiating data request contract on code id $DRs_CODE_ID" - -OUTPUT=$($BIN tx wasm instantiate $DRs_CODE_ID '{"token":"aseda", "proxy": "'$PROXY_CONTRACT_ADDRESS'" }' --no-admin --from $DEV_ACCOUNT --keyring-backend test --node $RPC_URL --label dr$DRs_CODE_ID --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID) -TXHASH=$(echo "$OUTPUT" | jq -r '.txhash') -sleep 10 -OUTPUT="$($BIN query tx $TXHASH --node $RPC_URL --output json)" -DRs_CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value') - -echo "Deployed data request contract to: $DRs_CONTRACT_ADDRESS" - -# ----------------------- -# Staking -# ----------------------- - -echo "Deploying staking contract" - -OUTPUT="$($BIN tx wasm store $ARTIFACTS_DIR/staking.wasm --node $RPC_URL --from $DEV_ACCOUNT --keyring-backend test --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)" -TXHASH=$(echo $OUTPUT | jq -r '.txhash') -sleep 10 -OUTPUT="$($BIN query tx $TXHASH --node $RPC_URL --output json)" -STAKING_CODE_ID=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value') - -echo "Instantiating staking contract on code id $STAKING_CODE_ID" - -OUTPUT=$($BIN tx wasm instantiate $STAKING_CODE_ID '{"token":"aseda", "proxy": "'$PROXY_CONTRACT_ADDRESS'" }' --no-admin --from $DEV_ACCOUNT --keyring-backend test --node $RPC_URL --label staking$staking_code_id --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID) -TXHASH=$(echo "$OUTPUT" | jq -r '.txhash') -sleep 10 -OUTPUT="$($BIN query tx $TXHASH --node $RPC_URL --output json)" -STAKING_CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value') - -echo "Deployed staking contract to: $STAKING_CONTRACT_ADDRESS" - -# ----------------------- -# Setting properties -# ----------------------- - -echo "Setting dr address on proxy.." -OUTPUT="$($BIN tx wasm execute $PROXY_CONTRACT_ADDRESS '{"set_data_requests":{"contract": "'$DRs_CONTRACT_ADDRESS'" }}' --from $DEV_ACCOUNT --keyring-backend test --node $RPC_URL --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)" -TXHASH=$(echo "$OUTPUT" | jq -r '.txhash') -sleep 10 -OUTPUT="$($BIN query tx $TXHASH --node $RPC_URL --output json)" -echo "$OUTPUT" - -echo "Setting staking address on proxy.." -OUTPUT="$($BIN tx wasm execute $PROXY_CONTRACT_ADDRESS '{"set_staking":{"contract": "'$STAKING_CONTRACT_ADDRESS'" }}' --from $DEV_ACCOUNT --keyring-backend test --node $RPC_URL --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)" -TXHASH=$(echo "$OUTPUT" | jq -r '.txhash') -sleep 10 -OUTPUT="$($BIN query tx $TXHASH --node $RPC_URL --output json)" -echo "$OUTPUT" diff --git a/scripts/local_setup.sh b/scripts/local_setup.sh index 3e4088b5..408d17da 100755 --- a/scripts/local_setup.sh +++ b/scripts/local_setup.sh @@ -58,4 +58,4 @@ $BIN gentx satoshi 10000000000000000seda --keyring-backend test $BIN collect-gentxs # start the chain -$BIN start || echo "Failed to start the chain" +$BIN start --log_level debug || echo "Failed to start the chain" diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh new file mode 100755 index 00000000..0c41d112 --- /dev/null +++ b/scripts/mockgen.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +mockgen_cmd="mockgen" + +if ! [ -x "$(command -v $mockgen_cmd)" ]; then + echo "Error: $mockgen_cmd is not installed." >&2 + exit 1 +fi + +# Generate mocks for the given package +$mockgen_cmd -source=$GOPATH/pkg/mod/github.com/\!cosm\!wasm/wasmd@v0.50.0/x/wasm/types/exported_keepers.go -package testutil -destination x/wasm-storage/keeper/testutil/wasm_keepers_mock.go +$mockgen_cmd -source=x/wasm-storage/types/expected_keepers.go -package testutil -destination x/wasm-storage/keeper/testutil/expected_keepers_mock.go diff --git a/testutil/testwasms/seda_contract.wasm b/testutil/testwasms/seda_contract.wasm new file mode 100644 index 00000000..326a0910 Binary files /dev/null and b/testutil/testwasms/seda_contract.wasm differ diff --git a/x/randomness/keeper/keeper.go b/x/randomness/keeper/keeper.go index 07818b89..b78b0ed6 100644 --- a/x/randomness/keeper/keeper.go +++ b/x/randomness/keeper/keeper.go @@ -37,7 +37,7 @@ func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService) *K return &Keeper{ Seed: collections.NewItem(sb, SeedPrefix, "seed", collections.StringValue), - ValidatorVRFPubKeys: collections.NewMap(sb, ValidatorVRFPrefix, "validator-vrf-pubkeys", collections.StringKey, codec.CollInterfaceValue[cryptotypes.PubKey](cdc)), + ValidatorVRFPubKeys: collections.NewMap(sb, ValidatorVRFPrefix, "validator_vrf_pubkeys", collections.StringKey, codec.CollInterfaceValue[cryptotypes.PubKey](cdc)), } } diff --git a/x/wasm-storage/genesis.go b/x/wasm-storage/genesis.go index a1ea9415..ef08935e 100644 --- a/x/wasm-storage/genesis.go +++ b/x/wasm-storage/genesis.go @@ -15,6 +15,9 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) { if err := k.Params.Set(ctx, data.Params); err != nil { panic(err) } + if err := k.ProxyContractRegistry.Set(ctx, data.ProxyContractRegistry); err != nil { + panic(err) + } for i := range data.Wasms { wasm := data.Wasms[i] @@ -29,15 +32,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) { } } } - if data.ProxyContractRegistry != "" { - proxyAddr, err := sdk.AccAddressFromBech32(data.ProxyContractRegistry) - if err != nil { - panic(err) - } - if err = k.ProxyContractRegistry.Set(ctx, proxyAddr.String()); err != nil { - panic(err) - } - } } // ExportGenesis extracts all data from store to genesis state. diff --git a/x/wasm-storage/keeper/abci.go b/x/wasm-storage/keeper/abci.go index dad04da8..6b8af077 100644 --- a/x/wasm-storage/keeper/abci.go +++ b/x/wasm-storage/keeper/abci.go @@ -1,18 +1,50 @@ package keeper import ( + "encoding/base64" + "encoding/hex" + "encoding/json" + "errors" + "fmt" + "sort" + "cosmossdk.io/collections" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sedaprotocol/seda-wasm-vm/tallyvm" ) +type Request struct { + DrBinaryID string `json:"dr_binary_id"` + DrInputs string `json:"dr_inputs"` + GasLimit string `json:"gas_limit"` + GasPrice string `json:"gas_price"` + Height uint64 `json:"height"` + ID string `json:"id"` + Memo string `json:"memo"` + PaybackAddress string `json:"payback_address"` + ReplicationFactor int64 `json:"replication_factor"` + Reveals map[string]RevealBody `json:"reveals"` + SedaPayload string `json:"seda_payload"` + TallyBinaryID string `json:"tally_binary_id"` + TallyInputs string `json:"tally_inputs"` + Version string `json:"version"` +} + +type RevealBody struct { + ExitCode uint8 `json:"exit_code"` + Reveal string `json:"reveal"` // base64-encoded string +} + func (k Keeper) EndBlock(ctx sdk.Context) error { err := k.ProcessExpiredWasms(ctx) if err != nil { return err } - // TODO: Add Tally VM - + err = k.ExecuteTally(ctx) + if err != nil { + return err + } return nil } @@ -32,3 +64,94 @@ func (k Keeper) ProcessExpiredWasms(ctx sdk.Context) error { } return nil } + +func (k Keeper) ExecuteTally(ctx sdk.Context) error { + // 1. Get contract address. + contractAddr, err := k.ProxyContractRegistry.Get(ctx) + if contractAddr == "" || errors.Is(err, collections.ErrNotFound) { + k.Logger(ctx).Debug("proxy contract address not registered") + return nil + } + if err != nil { + return err + } + + // 2. Fetch tally-ready DRs. + queryRes, err := k.wasmViewKeeper.QuerySmart(ctx, sdk.MustAccAddressFromBech32(contractAddr), []byte(`{"get_data_requests_by_status":{"status": "tallying"}}`)) + if err != nil { + return err + } + var tallyList []Request + err = json.Unmarshal(queryRes, &tallyList) + if err != nil { + return err + } + + // 3. Loop through the list to apply filter and execute tally. + for id, req := range tallyList { + tallyInputs, err := base64.StdEncoding.DecodeString(req.TallyInputs) + if err != nil { + return fmt.Errorf("failed to decode tally input: %w", err) + } + + // Sort reveals. + keys := make([]string, len(req.Reveals)) + i := 0 + for k := range req.Reveals { + keys[i] = k + i++ + } + sort.Strings(keys) + reveals := make([]RevealBody, len(req.Reveals)) + for i, k := range keys { + reveals[i] = req.Reveals[k] + } + + outliers, consensus, err := ApplyFilter(tallyInputs, reveals) + if err != nil { + return err + } + + tallyID, err := hex.DecodeString(req.TallyBinaryID) + if err != nil { + return fmt.Errorf("failed to decode tally ID to hex: %w", err) + } + tallyWasm, err := k.DataRequestWasm.Get(ctx, tallyID) + if err != nil { + return fmt.Errorf("failed to get tally wasm for DR ID %d: %w", id, err) + } + + args, err := tallyVMArg(tallyInputs, req.Reveals, outliers) + if err != nil { + return err + } + + result := tallyvm.ExecuteTallyVm(tallyWasm.Bytecode, args, map[string]string{ + "CONSENSUS": fmt.Sprintf("%v", consensus), + }) + fmt.Println(result) + } + + // 4. Post results. + // msg := []byte("{\"data_requests\": {}}") + // drContractAddr, err := k.wasmKeeper.Sudo(ctx, sdk.MustAccAddressFromBech32(proxyContractAddr), msg) + // fmt.Println("dr contract addy: " + string(drContractAddr)) + + return nil +} + +func tallyVMArg(inputArgs []byte, reveals map[string]RevealBody, outliers []bool) ([]string, error) { + arg := []string{string(inputArgs)} + r, err := json.Marshal(reveals) + if err != nil { + return nil, err + } + arg = append(arg, string(r)) + o, err := json.Marshal(outliers) + if err != nil { + return nil, err + } + arg = append(arg, string(o)) + + return arg, err +} diff --git a/x/wasm-storage/keeper/abci_test.go b/x/wasm-storage/keeper/abci_test.go new file mode 100644 index 00000000..99621b17 --- /dev/null +++ b/x/wasm-storage/keeper/abci_test.go @@ -0,0 +1,83 @@ +package keeper_test + +import ( + "testing" + "time" + + "cosmossdk.io/core/header" + storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/tx/signing" + "github.com/stretchr/testify/require" + gomock "go.uber.org/mock/gomock" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" + sdktestutil "github.com/cosmos/cosmos-sdk/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/gogoproto/proto" + + "github.com/sedaprotocol/seda-chain/app/params" + "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper" + "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper/testdata" + "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper/testutil" + "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" +) + +// Random tally wasms. +// var mockFetchResponse = []byte(`{"145438bc73d32082ff459e18d1a3db72c50cdaaf908bd90ac9616e265daf4a17":{"commits":{},"dr_binary_id":"fcc85f81d2604dca02fdd1330cc39dc1a6446b8abb16b4f068d8a1d1e2a48877","dr_inputs":"","gas_limit":"20","gas_price":"10","height":5389299128623366229,"id":"145438bc73d32082ff459e18d1a3db72c50cdaaf908bd90ac9616e265daf4a17","memo":"","payback_address":"","replication_factor":2,"reveals":{},"seda_payload":"","tally_binary_id":"3256cbd8d4e68865ebdf3636df7a433fec8999b30a6202a1eb4a9f92363d5550","tally_inputs":"AwMDAwM=","version":"1.0.0"},"573d63b1ea24330e31e18768953699c7ca031e44483cc228a9638010baa8bad0":{"commits":{},"dr_binary_id":"a88516c04de6305f973bf43d7d0112c831eb511a2366df682a335d2aa0dec20b","dr_inputs":"","gas_limit":"20","gas_price":"10","height":7096383960515817382,"id":"573d63b1ea24330e31e18768953699c7ca031e44483cc228a9638010baa8bad0","memo":"","payback_address":"","replication_factor":3,"reveals":{},"seda_payload":"","tally_binary_id":"5d0cef6880aade3af9d59e285bb59ab128327d3ae49f943e31e554ab99b4d21e","tally_inputs":"BgYGBgY=","version":"1.0.0"},"830a37e6d676d4e6ef4458e7d93fa4126caa38efa3df7cfc28c7b0d7997fbe8d":{"commits":{},"dr_binary_id":"a88516c04de6305f973bf43d7d0112c831eb511a2366df682a335d2aa0dec20b","dr_inputs":"","gas_limit":"20","gas_price":"10","height":5515264981634441762,"id":"830a37e6d676d4e6ef4458e7d93fa4126caa38efa3df7cfc28c7b0d7997fbe8d","memo":"","payback_address":"","replication_factor":3,"reveals":{},"seda_payload":"","tally_binary_id":"5d0cef6880aade3af9d59e285bb59ab128327d3ae49f943e31e554ab99b4d21e","tally_inputs":"AgICAgI=","version":"1.0.0"},"b413cf7eb89f35cc44292ed3c6bd7a02bb3fd118c105117ad8e1037e77dd8db8":{"commits":{},"dr_binary_id":"a88516c04de6305f973bf43d7d0112c831eb511a2366df682a335d2aa0dec20b","dr_inputs":"","gas_limit":"20","gas_price":"10","height":14844550059642515049,"id":"b413cf7eb89f35cc44292ed3c6bd7a02bb3fd118c105117ad8e1037e77dd8db8","memo":"","payback_address":"","replication_factor":3,"reveals":{},"seda_payload":"","tally_binary_id":"5d0cef6880aade3af9d59e285bb59ab128327d3ae49f943e31e554ab99b4d21e","tally_inputs":"AwMDAwM=","version":"1.0.0"},"facc77c8dfb3ff645dbc5fb8778ab276841a3e2b4a80c1df5dc28fa516d1816c":{"commits":{},"dr_binary_id":"fcc85f81d2604dca02fdd1330cc39dc1a6446b8abb16b4f068d8a1d1e2a48877","dr_inputs":"","gas_limit":"20","gas_price":"10","height":8215532109948458411,"id":"facc77c8dfb3ff645dbc5fb8778ab276841a3e2b4a80c1df5dc28fa516d1816c","memo":"","payback_address":"","replication_factor":2,"reveals":{},"seda_payload":"","tally_binary_id":"3256cbd8d4e68865ebdf3636df7a433fec8999b30a6202a1eb4a9f92363d5550","tally_inputs":"AwMDAwM=","version":"1.0.0"}}`) + +// All requests use sample tally wasm and filter type none. +var mockFetchResponse2 = []byte(`[{"commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"20","gas_price":"10","height":1661661742461173125,"id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e","memo":"","payback_address":"","replication_factor":3,"reveals":{"1b85dfb9420e6757630a0db2280fa1787ec8c1e419a6aca76dbbfe8ef6e17521":{"exit_code":0,"gas_used":"10","reveal":"Ng==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"1dae290cd880b79d21079d89aee3460cf8a7d445fb35cade70cf8aa96924441c":{"exit_code":0,"gas_used":"10","reveal":"LQ==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"421e735518ef77fc1209a9d3585cdf096669b52ea68549e2ce048d4919b4c8c0":{"exit_code":0,"gas_used":"10","reveal":"DQ==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"}},"seda_payload":"","tally_binary_id":"2f12d9175337bf340095ee955f8dff5c7baf4cadb0958e63ac4676a6a56fa71e","tally_inputs":"AAEBAQE=","version":"1.0.0"},{"commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"20","gas_price":"10","height":9859593541233596221,"id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f","memo":"","payback_address":"","replication_factor":1,"reveals":{"c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":{"exit_code":0,"gas_used":"10","reveal":"Yw==","salt":"f837455a930a66464f1c50586dc745a6b14ea807727c6069acac24c9558b6dbf"}},"seda_payload":"","tally_binary_id":"2f12d9175337bf340095ee955f8dff5c7baf4cadb0958e63ac4676a6a56fa71e","tally_inputs":"AAEBAQE=","version":"1.0.0"}]`) + +var drWasmByteArray = []byte("82a9dda829eb7f8ffe9fbe49e45d47d2dad9664fbb7adf72492e3c81ebd3e29134d9bc12212bf83c6840f10e8246b9db54a4859b7ccd0123d86e5872c1e5082") + +func TestExecuteTally(t *testing.T) { + interfaceRegistry, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + SigningOptions: signing.Options{ + AddressCodec: address.Bech32Codec{ + Bech32Prefix: params.Bech32PrefixAccPub, + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: params.Bech32PrefixValAddr, + }, + }, + }) + require.NoError(t, err) + cdc := codec.NewProtoCodec(interfaceRegistry) + + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + testCtx := sdktestutil.DefaultContextWithDB(t, storeKey, storetypes.NewTransientStoreKey("transient_test")) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) + + ctrl := gomock.NewController(t) + accKeeper := testutil.NewMockAccountKeeper(ctrl) + bankKeeper := testutil.NewMockBankKeeper(ctrl) + contractOpsKeeper := testutil.NewMockContractOpsKeeper(ctrl) + viewKeeper := testutil.NewMockViewKeeper(ctrl) + + k := keeper.NewKeeper( + cdc, + runtime.NewKVStoreService(storeKey), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + accKeeper, + bankKeeper, + contractOpsKeeper, + viewKeeper, + ) + + // Add random address to contract registry and mock contract query result. + err = k.ProxyContractRegistry.Set(ctx, "seda1ucv5709wlf9jn84ynyjzyzeavwvurmdyxat26l") + require.NoError(t, err) + viewKeeper.EXPECT().QuerySmart(gomock.Any(), gomock.Any(), gomock.Any()).Return(mockFetchResponse2, nil) + + tallyWasm := types.NewWasm(testdata.SampleTallyWasm(), types.WasmTypeDataRequest, ctx.BlockTime(), ctx.BlockHeight(), 100) + err = k.DataRequestWasm.Set(ctx, tallyWasm.Hash, tallyWasm) + require.NoError(t, err) + + err = k.ExecuteTally(ctx) + require.NoError(t, err) +} diff --git a/x/wasm-storage/keeper/common_test.go b/x/wasm-storage/keeper/common_test.go index 29bd2d1d..03505044 100644 --- a/x/wasm-storage/keeper/common_test.go +++ b/x/wasm-storage/keeper/common_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "testing" - "time" storetypes "cosmossdk.io/store/types" "github.com/stretchr/testify/suite" @@ -26,7 +25,6 @@ type KeeperTestSuite struct { suite.Suite ctx sdk.Context keeper *keeper.Keeper - blockTime time.Time //nolint:unused // unused cdc codec.Codec msgSrvr wasmstoragetypes.MsgServer queryClient wasmstoragetypes.QueryClient @@ -64,7 +62,7 @@ func setupKeeper(t *testing.T, authority string) (*keeper.Keeper, moduletestutil encCfg := moduletestutil.MakeTestEncodingConfig(wasmstorage.AppModuleBasic{}) wasmstoragetypes.RegisterInterfaces(encCfg.InterfaceRegistry) - wasmStorageKeeper := keeper.NewKeeper(encCfg.Codec, runtime.NewKVStoreService(key), authority, nil) + wasmStorageKeeper := keeper.NewKeeper(encCfg.Codec, runtime.NewKVStoreService(key), authority, nil, nil, nil, nil) return wasmStorageKeeper, encCfg, ctx } diff --git a/x/wasm-storage/keeper/filter.go b/x/wasm-storage/keeper/filter.go new file mode 100644 index 00000000..23300634 --- /dev/null +++ b/x/wasm-storage/keeper/filter.go @@ -0,0 +1,40 @@ +package keeper + +import ( + "errors" +) + +const ( + filterNone byte = 0x00 + filterMode byte = 0x01 + filterStdDev byte = 0x02 +) + +// ApplyFilter processes filter of the type specified in the first byte of +// tally inputs. It returns an outlier list, which is a boolean list where +// true at index i means that the reveal at index i is an outlier, consensus +// boolean, and error. +func ApplyFilter(tallyInputs []byte, reveals []RevealBody) ([]bool, bool, error) { + if len(tallyInputs) < 1 { + return nil, false, errors.New("tally inputs should be at least 1 byte") + } + + switch tallyInputs[0] { + case filterNone: + outliers := make([]bool, len(reveals)) + for i := range outliers { + outliers[i] = false + } + return outliers, true, nil + + case filterMode: + // TODO: Reactivate mode filter + return nil, false, errors.New("filter type mode is not implemented") + + case filterStdDev: + return nil, false, errors.New("filter type standard deviation is not implemented") + + default: + return nil, false, errors.New("filter type is invalid") + } +} diff --git a/x/wasm-storage/keeper/filter_test.go b/x/wasm-storage/keeper/filter_test.go new file mode 100644 index 00000000..7089b427 --- /dev/null +++ b/x/wasm-storage/keeper/filter_test.go @@ -0,0 +1,44 @@ +package keeper_test + +import ( + "testing" + + "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper" + "github.com/stretchr/testify/require" +) + +func TestOutliers_None(t *testing.T) { + tests := []struct { + name string + tallyInput []byte + want []bool + reveals []keeper.RevealBody + wantErr error + }{ + { + name: "None filter", + tallyInput: []byte{0, 26, 129, 196}, // filterProp{ Algo: 0} + want: []bool{false, false, false, false, false}, + reveals: []keeper.RevealBody{ + {}, + {}, + {}, + {}, + {}, + }, + wantErr: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, _, err := keeper.ApplyFilter(tt.tallyInput, tt.reveals) + if tt.wantErr != nil { + require.ErrorIs(t, err, tt.wantErr) + return + } + + require.NoError(t, err) + require.Equal(t, tt.want, got) + }) + } +} diff --git a/x/wasm-storage/keeper/keeper.go b/x/wasm-storage/keeper/keeper.go index 66195ebe..58b3932c 100644 --- a/x/wasm-storage/keeper/keeper.go +++ b/x/wasm-storage/keeper/keeper.go @@ -15,10 +15,16 @@ import ( ) type Keeper struct { - authority string - wasmKeeper wasmtypes.ContractOpsKeeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + wasmKeeper wasmtypes.ContractOpsKeeper + wasmViewKeeper wasmtypes.ViewKeeper + + // authority is the address capable of executing MsgUpdateParams + // or MsgStoreOverlayWasm. Typically, this should be the gov module + // address. + authority string - // state management Schema collections.Schema DataRequestWasm collections.Map[[]byte, types.Wasm] OverlayWasm collections.Map[[]byte, types.Wasm] @@ -27,18 +33,28 @@ type Keeper struct { Params collections.Item[types.Params] } -func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string, wk wasmtypes.ContractOpsKeeper) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string, ak types.AccountKeeper, bk types.BankKeeper, wk wasmtypes.ContractOpsKeeper, wvk wasmtypes.ViewKeeper) *Keeper { sb := collections.NewSchemaBuilder(storeService) - return &Keeper{ + k := Keeper{ authority: authority, + accountKeeper: ak, + bankKeeper: bk, wasmKeeper: wk, - DataRequestWasm: collections.NewMap(sb, types.DataRequestPrefix, "data-request-wasm", collections.BytesKey, codec.CollValue[types.Wasm](cdc)), - OverlayWasm: collections.NewMap(sb, types.OverlayPrefix, "overlay-wasm", collections.BytesKey, codec.CollValue[types.Wasm](cdc)), - WasmExpiration: collections.NewKeySet(sb, types.WasmExpPrefix, "wasm-expiration", collections.PairKeyCodec(collections.Int64Key, collections.BytesKey)), - ProxyContractRegistry: collections.NewItem(sb, types.ProxyContractRegistryPrefix, "proxy-contract-registry", collections.StringValue), + wasmViewKeeper: wvk, + DataRequestWasm: collections.NewMap(sb, types.DataRequestPrefix, "data_request_wasm", collections.BytesKey, codec.CollValue[types.Wasm](cdc)), + OverlayWasm: collections.NewMap(sb, types.OverlayPrefix, "overlay_wasm", collections.BytesKey, codec.CollValue[types.Wasm](cdc)), + WasmExpiration: collections.NewKeySet(sb, types.WasmExpPrefix, "wasm_expiration", collections.PairKeyCodec(collections.Int64Key, collections.BytesKey)), + ProxyContractRegistry: collections.NewItem(sb, types.ProxyContractRegistryPrefix, "proxy_contract_registry", collections.StringValue), Params: collections.NewItem(sb, types.ParamsPrefix, "params", codec.CollValue[types.Params](cdc)), } + + schema, err := sb.Build() + if err != nil { + panic(err) + } + k.Schema = schema + return &k } // GetAuthority returns the module's authority. diff --git a/x/wasm-storage/keeper/keeper_test.go b/x/wasm-storage/keeper/keeper_test.go index d8c25214..e52e8568 100644 --- a/x/wasm-storage/keeper/keeper_test.go +++ b/x/wasm-storage/keeper/keeper_test.go @@ -16,7 +16,7 @@ import ( func (s *KeeperTestSuite) TestSetDataRequestWasm() { s.SetupTest() - wasm, err := os.ReadFile("test_utils/hello-world.wasm") + wasm, err := os.ReadFile("testutil/hello-world.wasm") s.Require().NoError(err) compWasm, err := ioutils.GzipIt(wasm) s.Require().NoError(err) diff --git a/x/wasm-storage/keeper/msg_server_test.go b/x/wasm-storage/keeper/msg_server_test.go index aa0b9577..ff3baa93 100644 --- a/x/wasm-storage/keeper/msg_server_test.go +++ b/x/wasm-storage/keeper/msg_server_test.go @@ -17,12 +17,12 @@ import ( ) func (s *KeeperTestSuite) TestStoreDataRequestWasm() { - regWasm, err := os.ReadFile("test_utils/hello-world.wasm") + regWasm, err := os.ReadFile("testutil/hello-world.wasm") s.Require().NoError(err) regWasmZipped, err := ioutils.GzipIt(regWasm) s.Require().NoError(err) - oversizedWasm, err := os.ReadFile("test_utils/oversized.wasm") + oversizedWasm, err := os.ReadFile("testutil/oversized.wasm") s.Require().NoError(err) oversizedWasmZipped, err := ioutils.GzipIt(oversizedWasm) s.Require().NoError(err) @@ -107,12 +107,12 @@ func (s *KeeperTestSuite) TestStoreDataRequestWasm() { } func (s *KeeperTestSuite) TestStoreOverlayWasm() { - regWasm, err := os.ReadFile("test_utils/hello-world.wasm") + regWasm, err := os.ReadFile("testutil/hello-world.wasm") s.Require().NoError(err) regWasmZipped, err := ioutils.GzipIt(regWasm) s.Require().NoError(err) - oversizedWasm, err := os.ReadFile("test_utils/oversized.wasm") + oversizedWasm, err := os.ReadFile("testutil/oversized.wasm") s.Require().NoError(err) oversizedWasmZipped, err := ioutils.GzipIt(oversizedWasm) s.Require().NoError(err) @@ -153,7 +153,7 @@ func (s *KeeperTestSuite) TestStoreOverlayWasm() { { name: "invalid authority", input: types.MsgStoreOverlayWasm{ - Sender: "cosmos16wfryel63g7axeamw68630wglalcnk3l0zuadc", + Sender: "seda1ucv5709wlf9jn84ynyjzyzeavwvurmdyxat26l", Wasm: regWasmZipped, WasmType: types.WasmTypeRelayer, }, @@ -276,13 +276,13 @@ func (s *KeeperTestSuite) TestUpdateParams() { { name: "invalid authority", input: types.MsgUpdateParams{ - Authority: "cosmos16wfryel63g7axeamw68630wglalcnk3l0zuadc", + Authority: "seda1ucv5709wlf9jn84ynyjzyzeavwvurmdyxat26l", Params: types.Params{ MaxWasmSize: 1, // 1 MB WasmTTL: 1000, }, }, - expErrMsg: "invalid authority; expected " + authority + ", got cosmos16wfryel63g7axeamw68630wglalcnk3l0zuadc", + expErrMsg: "invalid authority; expected " + authority + ", got seda1ucv5709wlf9jn84ynyjzyzeavwvurmdyxat26l", }, { name: "invalid max wasm size", @@ -336,7 +336,7 @@ func (s *KeeperTestSuite) TestDRWasmPruning() { s.Require().Empty(dataRequestWasms) // Save 1 DR Wasm with default exp [params.WasmTTL] - drWasm1, err := os.ReadFile("test_utils/hello-world.wasm") + drWasm1, err := os.ReadFile("testutil/hello-world.wasm") s.Require().NoError(err) drWasmZipped1, err := ioutils.GzipIt(drWasm1) s.Require().NoError(err) @@ -353,7 +353,7 @@ func (s *KeeperTestSuite) TestDRWasmPruning() { params.WasmTTL = 2 * wasmTTL s.Require().NoError(s.keeper.Params.Set(s.ctx, params)) - drWasm2, err := os.ReadFile("test_utils/cowsay.wasm") + drWasm2, err := os.ReadFile("testutil/cowsay.wasm") s.Require().NoError(err) drWasmZipped2, err := ioutils.GzipIt(drWasm2) s.Require().NoError(err) diff --git a/x/wasm-storage/keeper/querier.go b/x/wasm-storage/keeper/querier.go index 19f9d5ff..2c5935eb 100644 --- a/x/wasm-storage/keeper/querier.go +++ b/x/wasm-storage/keeper/querier.go @@ -73,6 +73,6 @@ func (q Querier) ProxyContractRegistry(c context.Context, _ *types.QueryProxyCon return nil, err } return &types.QueryProxyContractRegistryResponse{ - Address: sdk.AccAddress(proxyAddress).String(), + Address: proxyAddress, }, nil } diff --git a/x/wasm-storage/keeper/querier_test.go b/x/wasm-storage/keeper/querier_test.go index 69268d38..89e574c5 100644 --- a/x/wasm-storage/keeper/querier_test.go +++ b/x/wasm-storage/keeper/querier_test.go @@ -12,7 +12,7 @@ import ( func (s *KeeperTestSuite) TestDataRequestWasm() { s.SetupTest() - wasm, err := os.ReadFile("test_utils/hello-world.wasm") + wasm, err := os.ReadFile("testutil/hello-world.wasm") s.Require().NoError(err) compWasm, err := ioutils.GzipIt(wasm) s.Require().NoError(err) @@ -33,7 +33,7 @@ func (s *KeeperTestSuite) TestDataRequestWasm() { func (s *KeeperTestSuite) TestOverlayWasm() { s.SetupTest() - wasm, err := os.ReadFile("test_utils/hello-world.wasm") + wasm, err := os.ReadFile("testutil/hello-world.wasm") s.Require().NoError(err) compWasm, err := ioutils.GzipIt(wasm) s.Require().NoError(err) @@ -54,7 +54,7 @@ func (s *KeeperTestSuite) TestOverlayWasm() { func (s *KeeperTestSuite) TestDataRequestWasms() { s.SetupTest() - wasm, err := os.ReadFile("test_utils/hello-world.wasm") + wasm, err := os.ReadFile("testutil/hello-world.wasm") s.Require().NoError(err) compWasm, err := ioutils.GzipIt(wasm) s.Require().NoError(err) @@ -67,7 +67,7 @@ func (s *KeeperTestSuite) TestDataRequestWasms() { storedWasm, err := s.msgSrvr.StoreDataRequestWasm(s.ctx, &input) s.Require().NoError(err) - wasm2, err := os.ReadFile("test_utils/cowsay.wasm") + wasm2, err := os.ReadFile("testutil/cowsay.wasm") s.Require().NoError(err) compWasm2, err := ioutils.GzipIt(wasm2) s.Require().NoError(err) @@ -89,7 +89,7 @@ func (s *KeeperTestSuite) TestDataRequestWasms() { func (s *KeeperTestSuite) TestOverlayWasms() { s.SetupTest() - wasm, err := os.ReadFile("test_utils/hello-world.wasm") + wasm, err := os.ReadFile("testutil/hello-world.wasm") s.Require().NoError(err) compWasm, err := ioutils.GzipIt(wasm) s.Require().NoError(err) @@ -102,7 +102,7 @@ func (s *KeeperTestSuite) TestOverlayWasms() { storedWasm, err := s.msgSrvr.StoreOverlayWasm(s.ctx, &input) s.Require().NoError(err) - wasm2, err := os.ReadFile("test_utils/cowsay.wasm") + wasm2, err := os.ReadFile("testutil/cowsay.wasm") s.Require().NoError(err) compWasm2, err := ioutils.GzipIt(wasm2) s.Require().NoError(err) diff --git a/x/wasm-storage/keeper/testdata/contracts.go b/x/wasm-storage/keeper/testdata/contracts.go new file mode 100644 index 00000000..e3bfc5f7 --- /dev/null +++ b/x/wasm-storage/keeper/testdata/contracts.go @@ -0,0 +1,21 @@ +package testdata + +import ( + _ "embed" +) + +var ( + //go:embed seda_contract.wasm + sedaContract []byte + + //go:embed sample_tally.wasm + sampleTallyWasm []byte +) + +func SedaContractWasm() []byte { + return sedaContract +} + +func SampleTallyWasm() []byte { + return sampleTallyWasm +} diff --git a/x/wasm-storage/keeper/testdata/data_requests.wasm b/x/wasm-storage/keeper/testdata/data_requests.wasm new file mode 100644 index 00000000..eb8dada3 Binary files /dev/null and b/x/wasm-storage/keeper/testdata/data_requests.wasm differ diff --git a/x/wasm-storage/keeper/testdata/sample_tally.wasm b/x/wasm-storage/keeper/testdata/sample_tally.wasm new file mode 100644 index 00000000..b0acedec Binary files /dev/null and b/x/wasm-storage/keeper/testdata/sample_tally.wasm differ diff --git a/x/wasm-storage/keeper/testdata/seda_contract.wasm b/x/wasm-storage/keeper/testdata/seda_contract.wasm new file mode 100644 index 00000000..5203b51b Binary files /dev/null and b/x/wasm-storage/keeper/testdata/seda_contract.wasm differ diff --git a/x/wasm-storage/keeper/test_utils/cowsay.wasm b/x/wasm-storage/keeper/testutil/cowsay.wasm similarity index 100% rename from x/wasm-storage/keeper/test_utils/cowsay.wasm rename to x/wasm-storage/keeper/testutil/cowsay.wasm diff --git a/x/wasm-storage/keeper/testutil/debug.wasm b/x/wasm-storage/keeper/testutil/debug.wasm new file mode 100644 index 00000000..7b568969 Binary files /dev/null and b/x/wasm-storage/keeper/testutil/debug.wasm differ diff --git a/x/wasm-storage/keeper/testutil/expected_keepers_mock.go b/x/wasm-storage/keeper/testutil/expected_keepers_mock.go new file mode 100644 index 00000000..c4c6a6b5 --- /dev/null +++ b/x/wasm-storage/keeper/testutil/expected_keepers_mock.go @@ -0,0 +1,92 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/wasm-storage/types/expected_keepers.go +// +// Generated by this command: +// +// mockgen -source=x/wasm-storage/types/expected_keepers.go -package testutil -destination x/wasm-storage/keeper/testutil/expected_keepers_mock.go +// + +// Package testutil is a generated GoMock package. +package testutil + +import ( + context "context" + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/types" + gomock "go.uber.org/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// SpendableCoins mocks base method. +func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// SpendableCoins indicates an expected call of SpendableCoins. +func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) +} diff --git a/x/wasm-storage/keeper/test_utils/hello-world.wasm b/x/wasm-storage/keeper/testutil/hello-world.wasm similarity index 100% rename from x/wasm-storage/keeper/test_utils/hello-world.wasm rename to x/wasm-storage/keeper/testutil/hello-world.wasm diff --git a/x/wasm-storage/keeper/test_utils/oversized.wasm b/x/wasm-storage/keeper/testutil/oversized.wasm similarity index 100% rename from x/wasm-storage/keeper/test_utils/oversized.wasm rename to x/wasm-storage/keeper/testutil/oversized.wasm diff --git a/x/wasm-storage/keeper/testutil/wasm_keepers_mock.go b/x/wasm-storage/keeper/testutil/wasm_keepers_mock.go new file mode 100644 index 00000000..f93c27a3 --- /dev/null +++ b/x/wasm-storage/keeper/testutil/wasm_keepers_mock.go @@ -0,0 +1,570 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: /Users/hykim/go/pkg/mod/github.com/!cosm!wasm/wasmd@v0.50.0/x/wasm/types/exported_keepers.go +// +// Generated by this command: +// +// mockgen -source=/Users/hykim/go/pkg/mod/github.com/!cosm!wasm/wasmd@v0.50.0/x/wasm/types/exported_keepers.go -package testutil -destination x/wasm-storage/keeper/testutil/wasm_keepers_mock.go +// + +// Package testutil is a generated GoMock package. +package testutil + +import ( + context "context" + reflect "reflect" + + types "github.com/CosmWasm/wasmd/x/wasm/types" + types0 "github.com/CosmWasm/wasmvm/types" + types1 "github.com/cosmos/cosmos-sdk/types" + types2 "github.com/cosmos/ibc-go/modules/capability/types" + exported "github.com/cosmos/ibc-go/v8/modules/core/exported" + gomock "go.uber.org/mock/gomock" +) + +// MockViewKeeper is a mock of ViewKeeper interface. +type MockViewKeeper struct { + ctrl *gomock.Controller + recorder *MockViewKeeperMockRecorder +} + +// MockViewKeeperMockRecorder is the mock recorder for MockViewKeeper. +type MockViewKeeperMockRecorder struct { + mock *MockViewKeeper +} + +// NewMockViewKeeper creates a new mock instance. +func NewMockViewKeeper(ctrl *gomock.Controller) *MockViewKeeper { + mock := &MockViewKeeper{ctrl: ctrl} + mock.recorder = &MockViewKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockViewKeeper) EXPECT() *MockViewKeeperMockRecorder { + return m.recorder +} + +// GetByteCode mocks base method. +func (m *MockViewKeeper) GetByteCode(ctx context.Context, codeID uint64) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByteCode", ctx, codeID) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetByteCode indicates an expected call of GetByteCode. +func (mr *MockViewKeeperMockRecorder) GetByteCode(ctx, codeID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByteCode", reflect.TypeOf((*MockViewKeeper)(nil).GetByteCode), ctx, codeID) +} + +// GetCodeInfo mocks base method. +func (m *MockViewKeeper) GetCodeInfo(ctx context.Context, codeID uint64) *types.CodeInfo { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCodeInfo", ctx, codeID) + ret0, _ := ret[0].(*types.CodeInfo) + return ret0 +} + +// GetCodeInfo indicates an expected call of GetCodeInfo. +func (mr *MockViewKeeperMockRecorder) GetCodeInfo(ctx, codeID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCodeInfo", reflect.TypeOf((*MockViewKeeper)(nil).GetCodeInfo), ctx, codeID) +} + +// GetContractHistory mocks base method. +func (m *MockViewKeeper) GetContractHistory(ctx context.Context, contractAddr types1.AccAddress) []types.ContractCodeHistoryEntry { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetContractHistory", ctx, contractAddr) + ret0, _ := ret[0].([]types.ContractCodeHistoryEntry) + return ret0 +} + +// GetContractHistory indicates an expected call of GetContractHistory. +func (mr *MockViewKeeperMockRecorder) GetContractHistory(ctx, contractAddr any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetContractHistory", reflect.TypeOf((*MockViewKeeper)(nil).GetContractHistory), ctx, contractAddr) +} + +// GetContractInfo mocks base method. +func (m *MockViewKeeper) GetContractInfo(ctx context.Context, contractAddress types1.AccAddress) *types.ContractInfo { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetContractInfo", ctx, contractAddress) + ret0, _ := ret[0].(*types.ContractInfo) + return ret0 +} + +// GetContractInfo indicates an expected call of GetContractInfo. +func (mr *MockViewKeeperMockRecorder) GetContractInfo(ctx, contractAddress any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetContractInfo", reflect.TypeOf((*MockViewKeeper)(nil).GetContractInfo), ctx, contractAddress) +} + +// GetParams mocks base method. +func (m *MockViewKeeper) GetParams(ctx context.Context) types.Params { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetParams", ctx) + ret0, _ := ret[0].(types.Params) + return ret0 +} + +// GetParams indicates an expected call of GetParams. +func (mr *MockViewKeeperMockRecorder) GetParams(ctx any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParams", reflect.TypeOf((*MockViewKeeper)(nil).GetParams), ctx) +} + +// HasContractInfo mocks base method. +func (m *MockViewKeeper) HasContractInfo(ctx context.Context, contractAddress types1.AccAddress) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasContractInfo", ctx, contractAddress) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasContractInfo indicates an expected call of HasContractInfo. +func (mr *MockViewKeeperMockRecorder) HasContractInfo(ctx, contractAddress any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasContractInfo", reflect.TypeOf((*MockViewKeeper)(nil).HasContractInfo), ctx, contractAddress) +} + +// IsPinnedCode mocks base method. +func (m *MockViewKeeper) IsPinnedCode(ctx context.Context, codeID uint64) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsPinnedCode", ctx, codeID) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsPinnedCode indicates an expected call of IsPinnedCode. +func (mr *MockViewKeeperMockRecorder) IsPinnedCode(ctx, codeID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsPinnedCode", reflect.TypeOf((*MockViewKeeper)(nil).IsPinnedCode), ctx, codeID) +} + +// IterateCodeInfos mocks base method. +func (m *MockViewKeeper) IterateCodeInfos(ctx context.Context, cb func(uint64, types.CodeInfo) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateCodeInfos", ctx, cb) +} + +// IterateCodeInfos indicates an expected call of IterateCodeInfos. +func (mr *MockViewKeeperMockRecorder) IterateCodeInfos(ctx, cb any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateCodeInfos", reflect.TypeOf((*MockViewKeeper)(nil).IterateCodeInfos), ctx, cb) +} + +// IterateContractInfo mocks base method. +func (m *MockViewKeeper) IterateContractInfo(ctx context.Context, cb func(types1.AccAddress, types.ContractInfo) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateContractInfo", ctx, cb) +} + +// IterateContractInfo indicates an expected call of IterateContractInfo. +func (mr *MockViewKeeperMockRecorder) IterateContractInfo(ctx, cb any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateContractInfo", reflect.TypeOf((*MockViewKeeper)(nil).IterateContractInfo), ctx, cb) +} + +// IterateContractState mocks base method. +func (m *MockViewKeeper) IterateContractState(ctx context.Context, contractAddress types1.AccAddress, cb func([]byte, []byte) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateContractState", ctx, contractAddress, cb) +} + +// IterateContractState indicates an expected call of IterateContractState. +func (mr *MockViewKeeperMockRecorder) IterateContractState(ctx, contractAddress, cb any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateContractState", reflect.TypeOf((*MockViewKeeper)(nil).IterateContractState), ctx, contractAddress, cb) +} + +// IterateContractsByCode mocks base method. +func (m *MockViewKeeper) IterateContractsByCode(ctx context.Context, codeID uint64, cb func(types1.AccAddress) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateContractsByCode", ctx, codeID, cb) +} + +// IterateContractsByCode indicates an expected call of IterateContractsByCode. +func (mr *MockViewKeeperMockRecorder) IterateContractsByCode(ctx, codeID, cb any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateContractsByCode", reflect.TypeOf((*MockViewKeeper)(nil).IterateContractsByCode), ctx, codeID, cb) +} + +// IterateContractsByCreator mocks base method. +func (m *MockViewKeeper) IterateContractsByCreator(ctx context.Context, creator types1.AccAddress, cb func(types1.AccAddress) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateContractsByCreator", ctx, creator, cb) +} + +// IterateContractsByCreator indicates an expected call of IterateContractsByCreator. +func (mr *MockViewKeeperMockRecorder) IterateContractsByCreator(ctx, creator, cb any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateContractsByCreator", reflect.TypeOf((*MockViewKeeper)(nil).IterateContractsByCreator), ctx, creator, cb) +} + +// QueryRaw mocks base method. +func (m *MockViewKeeper) QueryRaw(ctx context.Context, contractAddress types1.AccAddress, key []byte) []byte { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryRaw", ctx, contractAddress, key) + ret0, _ := ret[0].([]byte) + return ret0 +} + +// QueryRaw indicates an expected call of QueryRaw. +func (mr *MockViewKeeperMockRecorder) QueryRaw(ctx, contractAddress, key any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRaw", reflect.TypeOf((*MockViewKeeper)(nil).QueryRaw), ctx, contractAddress, key) +} + +// QuerySmart mocks base method. +func (m *MockViewKeeper) QuerySmart(ctx context.Context, contractAddr types1.AccAddress, req []byte) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QuerySmart", ctx, contractAddr, req) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QuerySmart indicates an expected call of QuerySmart. +func (mr *MockViewKeeperMockRecorder) QuerySmart(ctx, contractAddr, req any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QuerySmart", reflect.TypeOf((*MockViewKeeper)(nil).QuerySmart), ctx, contractAddr, req) +} + +// MockContractOpsKeeper is a mock of ContractOpsKeeper interface. +type MockContractOpsKeeper struct { + ctrl *gomock.Controller + recorder *MockContractOpsKeeperMockRecorder +} + +// MockContractOpsKeeperMockRecorder is the mock recorder for MockContractOpsKeeper. +type MockContractOpsKeeperMockRecorder struct { + mock *MockContractOpsKeeper +} + +// NewMockContractOpsKeeper creates a new mock instance. +func NewMockContractOpsKeeper(ctrl *gomock.Controller) *MockContractOpsKeeper { + mock := &MockContractOpsKeeper{ctrl: ctrl} + mock.recorder = &MockContractOpsKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockContractOpsKeeper) EXPECT() *MockContractOpsKeeperMockRecorder { + return m.recorder +} + +// ClearContractAdmin mocks base method. +func (m *MockContractOpsKeeper) ClearContractAdmin(ctx types1.Context, contractAddress, caller types1.AccAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ClearContractAdmin", ctx, contractAddress, caller) + ret0, _ := ret[0].(error) + return ret0 +} + +// ClearContractAdmin indicates an expected call of ClearContractAdmin. +func (mr *MockContractOpsKeeperMockRecorder) ClearContractAdmin(ctx, contractAddress, caller any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearContractAdmin", reflect.TypeOf((*MockContractOpsKeeper)(nil).ClearContractAdmin), ctx, contractAddress, caller) +} + +// Create mocks base method. +func (m *MockContractOpsKeeper) Create(ctx types1.Context, creator types1.AccAddress, wasmCode []byte, instantiateAccess *types.AccessConfig) (uint64, []byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", ctx, creator, wasmCode, instantiateAccess) + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].([]byte) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Create indicates an expected call of Create. +func (mr *MockContractOpsKeeperMockRecorder) Create(ctx, creator, wasmCode, instantiateAccess any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockContractOpsKeeper)(nil).Create), ctx, creator, wasmCode, instantiateAccess) +} + +// Execute mocks base method. +func (m *MockContractOpsKeeper) Execute(ctx types1.Context, contractAddress, caller types1.AccAddress, msg []byte, coins types1.Coins) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Execute", ctx, contractAddress, caller, msg, coins) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Execute indicates an expected call of Execute. +func (mr *MockContractOpsKeeperMockRecorder) Execute(ctx, contractAddress, caller, msg, coins any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockContractOpsKeeper)(nil).Execute), ctx, contractAddress, caller, msg, coins) +} + +// Instantiate mocks base method. +func (m *MockContractOpsKeeper) Instantiate(ctx types1.Context, codeID uint64, creator, admin types1.AccAddress, initMsg []byte, label string, deposit types1.Coins) (types1.AccAddress, []byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Instantiate", ctx, codeID, creator, admin, initMsg, label, deposit) + ret0, _ := ret[0].(types1.AccAddress) + ret1, _ := ret[1].([]byte) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Instantiate indicates an expected call of Instantiate. +func (mr *MockContractOpsKeeperMockRecorder) Instantiate(ctx, codeID, creator, admin, initMsg, label, deposit any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Instantiate", reflect.TypeOf((*MockContractOpsKeeper)(nil).Instantiate), ctx, codeID, creator, admin, initMsg, label, deposit) +} + +// Instantiate2 mocks base method. +func (m *MockContractOpsKeeper) Instantiate2(ctx types1.Context, codeID uint64, creator, admin types1.AccAddress, initMsg []byte, label string, deposit types1.Coins, salt []byte, fixMsg bool) (types1.AccAddress, []byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Instantiate2", ctx, codeID, creator, admin, initMsg, label, deposit, salt, fixMsg) + ret0, _ := ret[0].(types1.AccAddress) + ret1, _ := ret[1].([]byte) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Instantiate2 indicates an expected call of Instantiate2. +func (mr *MockContractOpsKeeperMockRecorder) Instantiate2(ctx, codeID, creator, admin, initMsg, label, deposit, salt, fixMsg any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Instantiate2", reflect.TypeOf((*MockContractOpsKeeper)(nil).Instantiate2), ctx, codeID, creator, admin, initMsg, label, deposit, salt, fixMsg) +} + +// Migrate mocks base method. +func (m *MockContractOpsKeeper) Migrate(ctx types1.Context, contractAddress, caller types1.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Migrate", ctx, contractAddress, caller, newCodeID, msg) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Migrate indicates an expected call of Migrate. +func (mr *MockContractOpsKeeperMockRecorder) Migrate(ctx, contractAddress, caller, newCodeID, msg any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Migrate", reflect.TypeOf((*MockContractOpsKeeper)(nil).Migrate), ctx, contractAddress, caller, newCodeID, msg) +} + +// PinCode mocks base method. +func (m *MockContractOpsKeeper) PinCode(ctx types1.Context, codeID uint64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PinCode", ctx, codeID) + ret0, _ := ret[0].(error) + return ret0 +} + +// PinCode indicates an expected call of PinCode. +func (mr *MockContractOpsKeeperMockRecorder) PinCode(ctx, codeID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PinCode", reflect.TypeOf((*MockContractOpsKeeper)(nil).PinCode), ctx, codeID) +} + +// SetAccessConfig mocks base method. +func (m *MockContractOpsKeeper) SetAccessConfig(ctx types1.Context, codeID uint64, caller types1.AccAddress, newConfig types.AccessConfig) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetAccessConfig", ctx, codeID, caller, newConfig) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetAccessConfig indicates an expected call of SetAccessConfig. +func (mr *MockContractOpsKeeperMockRecorder) SetAccessConfig(ctx, codeID, caller, newConfig any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccessConfig", reflect.TypeOf((*MockContractOpsKeeper)(nil).SetAccessConfig), ctx, codeID, caller, newConfig) +} + +// SetContractInfoExtension mocks base method. +func (m *MockContractOpsKeeper) SetContractInfoExtension(ctx types1.Context, contract types1.AccAddress, extra types.ContractInfoExtension) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetContractInfoExtension", ctx, contract, extra) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetContractInfoExtension indicates an expected call of SetContractInfoExtension. +func (mr *MockContractOpsKeeperMockRecorder) SetContractInfoExtension(ctx, contract, extra any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetContractInfoExtension", reflect.TypeOf((*MockContractOpsKeeper)(nil).SetContractInfoExtension), ctx, contract, extra) +} + +// Sudo mocks base method. +func (m *MockContractOpsKeeper) Sudo(ctx types1.Context, contractAddress types1.AccAddress, msg []byte) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Sudo", ctx, contractAddress, msg) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Sudo indicates an expected call of Sudo. +func (mr *MockContractOpsKeeperMockRecorder) Sudo(ctx, contractAddress, msg any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sudo", reflect.TypeOf((*MockContractOpsKeeper)(nil).Sudo), ctx, contractAddress, msg) +} + +// UnpinCode mocks base method. +func (m *MockContractOpsKeeper) UnpinCode(ctx types1.Context, codeID uint64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnpinCode", ctx, codeID) + ret0, _ := ret[0].(error) + return ret0 +} + +// UnpinCode indicates an expected call of UnpinCode. +func (mr *MockContractOpsKeeperMockRecorder) UnpinCode(ctx, codeID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnpinCode", reflect.TypeOf((*MockContractOpsKeeper)(nil).UnpinCode), ctx, codeID) +} + +// UpdateContractAdmin mocks base method. +func (m *MockContractOpsKeeper) UpdateContractAdmin(ctx types1.Context, contractAddress, caller, newAdmin types1.AccAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateContractAdmin", ctx, contractAddress, caller, newAdmin) + ret0, _ := ret[0].(error) + return ret0 +} + +// UpdateContractAdmin indicates an expected call of UpdateContractAdmin. +func (mr *MockContractOpsKeeperMockRecorder) UpdateContractAdmin(ctx, contractAddress, caller, newAdmin any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateContractAdmin", reflect.TypeOf((*MockContractOpsKeeper)(nil).UpdateContractAdmin), ctx, contractAddress, caller, newAdmin) +} + +// MockIBCContractKeeper is a mock of IBCContractKeeper interface. +type MockIBCContractKeeper struct { + ctrl *gomock.Controller + recorder *MockIBCContractKeeperMockRecorder +} + +// MockIBCContractKeeperMockRecorder is the mock recorder for MockIBCContractKeeper. +type MockIBCContractKeeperMockRecorder struct { + mock *MockIBCContractKeeper +} + +// NewMockIBCContractKeeper creates a new mock instance. +func NewMockIBCContractKeeper(ctrl *gomock.Controller) *MockIBCContractKeeper { + mock := &MockIBCContractKeeper{ctrl: ctrl} + mock.recorder = &MockIBCContractKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockIBCContractKeeper) EXPECT() *MockIBCContractKeeperMockRecorder { + return m.recorder +} + +// AuthenticateCapability mocks base method. +func (m *MockIBCContractKeeper) AuthenticateCapability(ctx types1.Context, cap *types2.Capability, name string) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AuthenticateCapability", ctx, cap, name) + ret0, _ := ret[0].(bool) + return ret0 +} + +// AuthenticateCapability indicates an expected call of AuthenticateCapability. +func (mr *MockIBCContractKeeperMockRecorder) AuthenticateCapability(ctx, cap, name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AuthenticateCapability", reflect.TypeOf((*MockIBCContractKeeper)(nil).AuthenticateCapability), ctx, cap, name) +} + +// ClaimCapability mocks base method. +func (m *MockIBCContractKeeper) ClaimCapability(ctx types1.Context, cap *types2.Capability, name string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ClaimCapability", ctx, cap, name) + ret0, _ := ret[0].(error) + return ret0 +} + +// ClaimCapability indicates an expected call of ClaimCapability. +func (mr *MockIBCContractKeeperMockRecorder) ClaimCapability(ctx, cap, name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClaimCapability", reflect.TypeOf((*MockIBCContractKeeper)(nil).ClaimCapability), ctx, cap, name) +} + +// OnAckPacket mocks base method. +func (m *MockIBCContractKeeper) OnAckPacket(ctx types1.Context, contractAddr types1.AccAddress, acknowledgement types0.IBCPacketAckMsg) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OnAckPacket", ctx, contractAddr, acknowledgement) + ret0, _ := ret[0].(error) + return ret0 +} + +// OnAckPacket indicates an expected call of OnAckPacket. +func (mr *MockIBCContractKeeperMockRecorder) OnAckPacket(ctx, contractAddr, acknowledgement any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnAckPacket", reflect.TypeOf((*MockIBCContractKeeper)(nil).OnAckPacket), ctx, contractAddr, acknowledgement) +} + +// OnCloseChannel mocks base method. +func (m *MockIBCContractKeeper) OnCloseChannel(ctx types1.Context, contractAddr types1.AccAddress, msg types0.IBCChannelCloseMsg) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OnCloseChannel", ctx, contractAddr, msg) + ret0, _ := ret[0].(error) + return ret0 +} + +// OnCloseChannel indicates an expected call of OnCloseChannel. +func (mr *MockIBCContractKeeperMockRecorder) OnCloseChannel(ctx, contractAddr, msg any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnCloseChannel", reflect.TypeOf((*MockIBCContractKeeper)(nil).OnCloseChannel), ctx, contractAddr, msg) +} + +// OnConnectChannel mocks base method. +func (m *MockIBCContractKeeper) OnConnectChannel(ctx types1.Context, contractAddr types1.AccAddress, msg types0.IBCChannelConnectMsg) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OnConnectChannel", ctx, contractAddr, msg) + ret0, _ := ret[0].(error) + return ret0 +} + +// OnConnectChannel indicates an expected call of OnConnectChannel. +func (mr *MockIBCContractKeeperMockRecorder) OnConnectChannel(ctx, contractAddr, msg any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnConnectChannel", reflect.TypeOf((*MockIBCContractKeeper)(nil).OnConnectChannel), ctx, contractAddr, msg) +} + +// OnOpenChannel mocks base method. +func (m *MockIBCContractKeeper) OnOpenChannel(ctx types1.Context, contractAddr types1.AccAddress, msg types0.IBCChannelOpenMsg) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OnOpenChannel", ctx, contractAddr, msg) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// OnOpenChannel indicates an expected call of OnOpenChannel. +func (mr *MockIBCContractKeeperMockRecorder) OnOpenChannel(ctx, contractAddr, msg any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnOpenChannel", reflect.TypeOf((*MockIBCContractKeeper)(nil).OnOpenChannel), ctx, contractAddr, msg) +} + +// OnRecvPacket mocks base method. +func (m *MockIBCContractKeeper) OnRecvPacket(ctx types1.Context, contractAddr types1.AccAddress, msg types0.IBCPacketReceiveMsg) (exported.Acknowledgement, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OnRecvPacket", ctx, contractAddr, msg) + ret0, _ := ret[0].(exported.Acknowledgement) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// OnRecvPacket indicates an expected call of OnRecvPacket. +func (mr *MockIBCContractKeeperMockRecorder) OnRecvPacket(ctx, contractAddr, msg any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnRecvPacket", reflect.TypeOf((*MockIBCContractKeeper)(nil).OnRecvPacket), ctx, contractAddr, msg) +} + +// OnTimeoutPacket mocks base method. +func (m *MockIBCContractKeeper) OnTimeoutPacket(ctx types1.Context, contractAddr types1.AccAddress, msg types0.IBCPacketTimeoutMsg) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OnTimeoutPacket", ctx, contractAddr, msg) + ret0, _ := ret[0].(error) + return ret0 +} + +// OnTimeoutPacket indicates an expected call of OnTimeoutPacket. +func (mr *MockIBCContractKeeperMockRecorder) OnTimeoutPacket(ctx, contractAddr, msg any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnTimeoutPacket", reflect.TypeOf((*MockIBCContractKeeper)(nil).OnTimeoutPacket), ctx, contractAddr, msg) +} diff --git a/x/wasm-storage/module.go b/x/wasm-storage/module.go index c1033175..c7fd7b39 100644 --- a/x/wasm-storage/module.go +++ b/x/wasm-storage/module.go @@ -101,18 +101,13 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { // AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement type AppModule struct { AppModuleBasic - - keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + keeper keeper.Keeper } -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper) AppModule { +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), keeper: keeper, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, } } diff --git a/x/wasm-storage/types/params.go b/x/wasm-storage/types/params.go index 75bf2e9d..40d317f2 100644 --- a/x/wasm-storage/types/params.go +++ b/x/wasm-storage/types/params.go @@ -25,12 +25,8 @@ func (p *Params) ValidateBasic() error { if p.WasmTTL < 2 { return errors.Wrapf(ErrInvalidParam, "WasmTTL %d < 2", p.WasmTTL) } - return validateMaxWasmSize(p.MaxWasmSize) -} - -func validateMaxWasmSize(i int64) error { - if i <= 0 { - return fmt.Errorf("invalid max Wasm size: %d", i) + if p.MaxWasmSize <= 0 { + return fmt.Errorf("invalid max Wasm size: %d", p.MaxWasmSize) } return nil }