diff --git a/.circleci/config.yml b/.circleci/config.yml index a63bcb49ca..45fb8d2bda 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -63,7 +63,7 @@ jobs: lint: docker: - - image: golangci/golangci-lint:v1.52.2 + - image: golangci/golangci-lint:v1.54.2 steps: - checkout - run: diff --git a/.github/workflows/codeql-analizer.yml b/.github/workflows/codeql-analizer.yml index f3fb63a680..7595b36a08 100644 --- a/.github/workflows/codeql-analizer.yml +++ b/.github/workflows/codeql-analizer.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v4.0.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/proto-buf-publisher.yml b/.github/workflows/proto-buf-publisher.yml index d0a0b186e6..48c3194228 100644 --- a/.github/workflows/proto-buf-publisher.yml +++ b/.github/workflows/proto-buf-publisher.yml @@ -16,8 +16,8 @@ jobs: push: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.5.3 - - uses: bufbuild/buf-setup-action@v1.25.0 + - uses: actions/checkout@v4.0.0 + - uses: bufbuild/buf-setup-action@v1.26.1 # lint checks - uses: bufbuild/buf-lint-action@v1 diff --git a/.golangci.yml b/.golangci.yml index 227c0c4d66..d155f54e54 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,17 +1,24 @@ run: tests: true - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 5m + timeout: 15m + sort-results: true + allow-parallel-runners: true + exclude-dir: testutil/testdata + skip-files: + - server/grpc/gogoreflection/fix_registration.go + - ".*\\.pb\\.go$" + - ".*\\.pb\\.gw\\.\\.go$" + - ".*\\.pulsar\\.go$" linters: disable-all: true enable: - - bodyclose - - dogsled - errcheck + - dogsled - exportloopref - goconst - gocritic + - gci - gofumpt - gosec - gosimple @@ -20,42 +27,122 @@ linters: - misspell - nakedret - nolintlint - - revive - staticcheck + - revive - stylecheck - typecheck +# - thelper # too many positives with table tests that have custom setup(*testing.T) - unconvert - - unparam - unused issues: exclude-rules: - - text: "Use of weak random number generator" + - text: 'Use of weak random number generator' linters: - gosec - - text: "ST1003:" + - text: 'ST1003:' linters: - stylecheck # FIXME: Disabled until golangci-lint updates stylecheck with this fix: # https://github.com/dominikh/go-tools/issues/389 - - text: "ST1016:" + - text: 'ST1016:' linters: - stylecheck - - path: "migrations" - text: "SA1019:" + - path: 'migrations' + text: 'SA1019:' linters: - staticcheck - + - text: 'SA1019: codec.NewAminoCodec is deprecated' # TODO remove once migration path is set out + linters: + - staticcheck + - text: 'SA1019: legacybech32.MustMarshalPubKey' # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: 'SA1019: legacybech32.MarshalPubKey' # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: 'SA1019: legacybech32.UnmarshalPubKey' # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: 'SA1019: params.SendEnabled is deprecated' # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: 'leading space' + linters: + - nolintlint max-issues-per-linter: 10000 max-same-issues: 10000 linters-settings: + gci: + custom-order: true + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(cosmossdk.io) + - prefix(github.com/cosmos/cosmos-sdk) + - prefix(github.com/CosmWasm/wasmd) revive: - # When set to false, ignores files with "GENERATED" header, similar to golint - ignore-generated-header: true + rules: + - name: redefines-builtin-id + disabled: true + gosec: + # To select a subset of rules to run. + # Available rules: https://github.com/securego/gosec#available-rules + # Default: [] - means include all rules + includes: + # - G101 # Look for hard coded credentials + - G102 # Bind to all interfaces + - G103 # Audit the use of unsafe block + - G104 # Audit errors not checked + - G106 # Audit the use of ssh.InsecureIgnoreHostKey + - G107 # Url provided to HTTP request as taint input + - G108 # Profiling endpoint automatically exposed on /debug/pprof + - G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32 + - G110 # Potential DoS vulnerability via decompression bomb + - G111 # Potential directory traversal + - G112 # Potential slowloris attack + - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772) + - G114 # Use of net/http serve function that has no support for setting timeouts + - G201 # SQL query construction using format string + - G202 # SQL query construction using string concatenation + - G203 # Use of unescaped data in HTML templates + - G204 # Audit use of command execution + - G301 # Poor file permissions used when creating a directory + - G302 # Poor file permissions used with chmod + - G303 # Creating tempfile using a predictable path + - G304 # File path provided as taint input + - G305 # File traversal when extracting zip/tar archive + - G306 # Poor file permissions used when writing to a new file + - G307 # Deferring a method which returns an error + - G401 # Detect the usage of DES, RC4, MD5 or SHA1 + - G402 # Look for bad TLS connection settings + - G403 # Ensure minimum RSA key length of 2048 bits + - G404 # Insecure random number source (rand) + - G501 # Import blocklist: crypto/md5 + - G502 # Import blocklist: crypto/des + - G503 # Import blocklist: crypto/rc4 + - G504 # Import blocklist: net/http/cgi + - G505 # Import blocklist: crypto/sha1 + - G601 # Implicit memory aliasing of items from a range statement + misspell: + locale: US + gofumpt: + extra-rules: true + dogsled: + max-blank-identifiers: 6 + maligned: + suggest-new: true nolintlint: allow-unused: false allow-leading-space: true require-explanation: false require-specific: false + gosimple: + checks: ['all'] + gocritic: + disabled-checks: + - regexpMust + - appendAssign + - ifElseChain diff --git a/CHANGELOG.md b/CHANGELOG.md index 16c56f80c7..4daa475379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,59 @@ It solves some incompatibility problems by improving cache invalidation. See [\# ### Migration notes: - This release does not include any state migrations or breaking changes, therefore a coordinated chain upgrade is not required. -[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.41.0...HEAD) +[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.43.0...HEAD) + +## [v0.43.0](https://github.com/CosmWasm/wasmd/tree/v0.43.0) (2023-10-10) + +[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.42.0...v0.43.0) + +- Make contract label updatable [\#1601](https://github.com/CosmWasm/wasmd/issues/1601) +- Remove gov v1beta1 dependencies and deprecated proposals [\#1608](https://github.com/CosmWasm/wasmd/issues/1608) +- Retract v0.42.0 release [\#1651](https://github.com/CosmWasm/wasmd/issues/1651) +- Bump wasmvm to v1.4.1 [\#1657](https://github.com/CosmWasm/wasmd/issues/1657) + +### Notable changes: +- Wasmd v0.42.0 was retracted because an issue was found in CosmWasm 1.4.0. See https://twitter.com/CosmWasm/status/1709507168448229497 +- This release bundles CosmWasm v1.4.1 patch release. If you are using wasmd v0.42.0 please upgrade to wasmd 0.43.0 as soon as possible. +- Deprecated wasm gov proposals have been removed completely from the codebase together with all the govv1beta1 dependencies. +- MsgUpdateContractLabel was introduced to allow contract label updates. + +### Migration notes: +- This release does not include any state migrations but breaking changes that require a coordinated chain upgrade. + +## [v0.42.0](https://github.com/CosmWasm/wasmd/tree/v0.42.0) (2023-09-20) + +[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.41.0...v0.42.0) + +- Fix label validation error [\#1555](https://github.com/CosmWasm/wasmd/pull/1555) +- Improve ToWasmVMGas/FromWasmVMGas code level documentation [\#1564](https://github.com/CosmWasm/wasmd/pull/1564) +- Fix gas calculation [\#1567](https://github.com/CosmWasm/wasmd/pull/1567) +- Bump cosmos-sdk to v0.47.5 [\#1467](https://github.com/CosmWasm/wasmd/issues/1467) +- fix: make sure wasmvm cache metrics collector registration after VM setup[\#1575](https://github.com/CosmWasm/wasmd/pull/1575) +- Remove legacy gov proposal dependencies [\#1587](https://github.com/CosmWasm/wasmd/pull/1587) +- Upgrade to wasmvm 1.4 [\#1586](https://github.com/CosmWasm/wasmd/issues/1586) +- Custom StoreCode Authorization for authz module [\#1584](https://github.com/CosmWasm/wasmd/issues/1584) +- Bump github.com/cosmos/ibc-go/v7 from 7.2.0 to 7.3.0 [\#1594](https://github.com/CosmWasm/wasmd/pull/1594) +- Log query error before redacting [\#1593](https://github.com/CosmWasm/wasmd/issues/1593) +- Restrict pagination on all-state-query [\#1619](https://github.com/CosmWasm/wasmd/pull/1619) +- Bug in IbcQuery::ListChannels implementation when port is unset [\#1597](https://github.com/CosmWasm/wasmd/issues/1597) +- Ensure some contraints and limits on pin/unpin code ids [\#1624](https://github.com/CosmWasm/wasmd/pull/1624) +- Ensure genesis import works with both address generators [\#1629](https://github.com/CosmWasm/wasmd/issues/1629) +- Set default query limit and ensure constraints [\#1632](https://github.com/CosmWasm/wasmd/pull/1632) + +### Notable changes: +- Fix gas calculation [\#1567](https://github.com/CosmWasm/wasmd/pull/1567) +- Upgrade to wasmvm 1.4 [\#1586](https://github.com/CosmWasm/wasmd/issues/1586) +- Bug in IbcQuery::ListChannels implementation when port is unset [\#1597](https://github.com/CosmWasm/wasmd/issues/1597) + - If `port_id` is omitted, all channels bound to the contract's port will be listed. +- Restrict pagination on all-state-query [\#1619](https://github.com/CosmWasm/wasmd/pull/1619) + - Pagination limit is set to 100 for all-state-query. See also [\#1632](https://github.com/CosmWasm/wasmd/pull/1632) +- Ensure some contraints and limits on pin/unpin code ids [\#1624](https://github.com/CosmWasm/wasmd/pull/1624) + - Total number of code ids is limited to 50 for pin/unpin operations +- Custom StoreCode Authorization for authz module [\#1584](https://github.com/CosmWasm/wasmd/issues/1584) + +### Migration notes: +- This release does not include any state migrations but breaking changes that require a coordinated chain upgrade. ## [v0.41.0](https://github.com/CosmWasm/wasmd/tree/v0.41.0) (2023-07-28) diff --git a/Dockerfile b/Dockerfile index 648fad9f18..49902c3d2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,10 +15,10 @@ RUN apk add git WORKDIR /code COPY . /code/ # See https://github.com/CosmWasm/wasmvm/releases -ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.3.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a -ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.3.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a -RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep b1610f9c8ad8bdebf5b8f819f71d238466f83521c74a2deb799078932e862722 -RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep b4aad4480f9b4c46635b4943beedbb72c929eab1d1b9467fe3b43e6dbf617e32 +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.4.1/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.4.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a +RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep a8259ba852f1b68f2a5f8eb666a9c7f1680196562022f71bb361be1472a83cfd +RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 324c1073cb988478d644861783ed5a7de21cfd090976ccc6b1de0559098fbbad # Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc` RUN cp /lib/libwasmvm_muslc.${arch}.a /lib/libwasmvm_muslc.a diff --git a/Makefile b/Makefile index b4a8a80d3e..0ef07eca21 100644 --- a/Makefile +++ b/Makefile @@ -125,7 +125,7 @@ distclean: clean ### Testing test: test-unit -test-all: check test-race test-cover test-system +test-all: test-race test-cover test-system test-unit: @VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' ./... @@ -165,12 +165,12 @@ format-tools: lint: format-tools golangci-lint run --tests=false - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d + find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d format: format-tools - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/CosmWasm/wasmd + find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w + find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w + find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/CosmWasm/wasmd ############################################################################### diff --git a/README.md b/README.md index a2dd5c05ad..7abbad51d2 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ compatibility list: | wasmd | wasmvm | cosmwasm-vm | cosmwasm-std | |-------|--------------|-------------|--------------| +| 0.42 | v1.4.0 | | 1.0-1.4 | | 0.41 | v1.3.0 | | 1.0-1.3 | | 0.40 | v1.2.3 | | 1.0-1.2 | | 0.31 | v1.2.0 | | 1.0-1.2 | @@ -198,9 +199,6 @@ Available flags: * `-X github.com/CosmWasm/wasmd/app.NodeDir=.corald` - set the config/data directory for the node (default `~/.wasmd`) * `-X github.com/CosmWasm/wasmd/app.Bech32Prefix=coral` - set the bech32 prefix for all accounts (default `wasm`) -* `-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true` - enable all x/wasm governance proposals (default `false`) -* `-X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin` - - enable a subset of the x/wasm governance proposal types (overrides `ProposalsEnabled`) Examples: @@ -227,8 +225,7 @@ We strongly suggest **to limit the max block gas in the genesis** and not use th ``` Tip: if you want to lock this down to a permisisoned network, the following script can edit the genesis file -to only allow permissioned use of code upload or instantiating. (Make sure you set `app.ProposalsEnabled=true` -in this binary): +to only allow permissioned use of code upload or instantiating: `sed -i 's/permission": "Everybody"/permission": "Nobody"/' .../config/genesis.json` diff --git a/UPGRADING.md b/UPGRADING.md index b6cc7dda96..a5e204f2b1 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -208,6 +208,80 @@ docker run --rm -it \ query gov votes 1 ``` +## Vote on the upgrade (Starting from wasmd v0.40.0) + +Starting from `v0.40.0` of `wasmd`, which incorporates cosmos-sdk `v0.47.x`, +there have been changes in how upgrade proposals are handled. Below, +we provide an example of how to achieve the same outcome as described +in the preceding section. + +Please be aware that some commands have been replaced by an interactive +Command Line Interface (CLI), and the process of submitting a proposal +is now divided into two distinct steps: `proposal creation` and `proposal submission`. + +```sh +# create the proposal +docker run --rm -it \ + --mount type=volume,source=musselnet_client,target=/root \ + --network=host \ + cosmwasm/wasmd:v0.40.0 wasmd \ + tx gov draft-proposal \ + --from validator --chain-id testing + +# choose from the interactive CLI and fill all the fields +# of the generated json file draft_proposal.json +# example: +{ + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority": "wasm10d07y265gmmuvt4z0w9aw880jnsr700js7zslc", + "plan": { + "name": "Upgrade", + "time": "0001-01-01T00:00:00Z", + "height": "500", + "info": "", + "upgraded_client_state": null + } + } + ], + "metadata": "ipfs://CID", + "deposit": "100000ustake", + "title": "Upgrade", + "summary": "summary" +} + +# submit the proposal +docker run --rm -it \ + --mount type=volume,source=musselnet_client,target=/root \ + --network=host \ + cosmwasm/wasmd:v0.40.0 wasmd \ + tx gov submit-proposal draft_proposal.json \ + --from validator --chain-id testing + +# make sure it looks good +docker run --rm -it \ + --mount type=volume,source=musselnet_client,target=/root \ + --network=host \ + cosmwasm/wasmd:v0.40.0 wasmd \ + query gov proposal 1 + +# vote for it +docker run --rm -it \ + --mount type=volume,source=musselnet_client,target=/root \ + --network=host \ + cosmwasm/wasmd:v0.40.0 wasmd \ + tx gov vote 1 yes \ + --from validator --chain-id testing + +# ensure vote was counted +docker run --rm -it \ + --mount type=volume,source=musselnet_client,target=/root \ + --network=host \ + cosmwasm/wasmd:v0.40.0 wasmd \ + query gov votes 1 +``` + ## Swap out binaries Now, we just wait about 5 minutes for the vote to pass, and ensure it is passed: diff --git a/app/ante.go b/app/ante.go index e408372fa0..79a73822fa 100644 --- a/app/ante.go +++ b/app/ante.go @@ -1,13 +1,15 @@ package app import ( + ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante" + "github.com/cosmos/ibc-go/v7/modules/core/keeper" + errorsmod "cosmossdk.io/errors" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" - ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante" - "github.com/cosmos/ibc-go/v7/modules/core/keeper" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -19,6 +21,7 @@ type HandlerOptions struct { ante.HandlerOptions IBCKeeper *keeper.Keeper + WasmKeeper *wasmkeeper.Keeper WasmConfig *wasmTypes.WasmConfig TXCounterStoreKey storetypes.StoreKey } @@ -44,6 +47,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey), + wasmkeeper.NewGasRegisterDecorator(options.WasmKeeper.GetGasRegister()), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), diff --git a/app/app.go b/app/app.go index 34c078dd80..093dce11ee 100644 --- a/app/app.go +++ b/app/app.go @@ -8,14 +8,38 @@ import ( "path/filepath" "strings" - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmos "github.com/cometbft/cometbft/libs/os" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" + icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller" + icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" + icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" + ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" + ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" + transfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer" + ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v7/modules/core" + ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client" + ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + "github.com/spf13/cast" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -70,6 +94,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/gov" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -97,31 +122,6 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" - icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller" - icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" - icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" - icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" - icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" - icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" - ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" - ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" - ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" - transfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer" - ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v7/modules/core" - ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client" - ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" - ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" - ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - "github.com/spf13/cast" - - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -134,33 +134,8 @@ const appName = "WasmApp" var ( NodeDir = ".wasmd" Bech32Prefix = "wasm" - - // If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals. - // If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals. - ProposalsEnabled = "false" - // If set to non-empty string it must be comma-separated list of values that are all a subset - // of "EnableAllProposals" (takes precedence over ProposalsEnabled) - // https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34 - EnableSpecificProposals = "" ) -// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to -// produce a list of enabled proposals to pass into wasmd app. -func GetEnabledProposals() []wasmtypes.ProposalType { - if EnableSpecificProposals == "" { - if ProposalsEnabled == "true" { - return wasmtypes.EnableAllProposals - } - return wasmtypes.DisableAllProposals - } - chunks := strings.Split(EnableSpecificProposals, ",") - proposals, err := wasmtypes.ConvertToProposals(chunks) - if err != nil { - panic(err) - } - return proposals -} - // These constants are derived from the above variables. // These are the ones we will want to use in the code, based on // any overrides above @@ -306,14 +281,13 @@ func NewWasmApp( db dbm.DB, traceStore io.Writer, loadLatest bool, - enabledProposals []wasmtypes.ProposalType, appOpts servertypes.AppOptions, wasmOpts []wasmkeeper.Option, baseAppOptions ...func(*baseapp.BaseApp), ) *WasmApp { encodingConfig := MakeEncodingConfig() - appCodec, legacyAmino := encodingConfig.Marshaler, encodingConfig.Amino + appCodec, legacyAmino := encodingConfig.Codec, encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig @@ -605,10 +579,6 @@ func NewWasmApp( wasmOpts..., ) - // The gov proposal types can be individually enabled - if len(enabledProposals) != 0 { - govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) //nolint:staticcheck - } // Set legacy router for backwards compatibility with gov v1beta1 app.GovKeeper.SetLegacyRouter(govRouter) @@ -856,6 +826,7 @@ func (app *WasmApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtype IBCKeeper: app.IBCKeeper, WasmConfig: &wasmConfig, TXCounterStoreKey: txCounterStoreKey, + WasmKeeper: &app.WasmKeeper, }, ) if err != nil { diff --git a/app/app_test.go b/app/app_test.go index 3f724c5961..6dfc76942d 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -6,13 +6,12 @@ import ( dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" + "github.com/stretchr/testify/require" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) var emptyWasmOpts []wasmkeeper.Option @@ -27,7 +26,7 @@ func TestWasmdExport(t *testing.T) { gapp.Commit() // Making a new app object with the db, so that initchain hasn't been called - newGapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, wasmtypes.EnableAllProposals, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), emptyWasmOpts) + newGapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), emptyWasmOpts) _, err := newGapp.ExportAppStateAndValidators(false, []string{}, nil) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } @@ -53,34 +52,3 @@ func TestGetMaccPerms(t *testing.T) { dup := GetMaccPerms() require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions") } - -func TestGetEnabledProposals(t *testing.T) { - cases := map[string]struct { - proposalsEnabled string - specificEnabled string - expected []wasmtypes.ProposalType - }{ - "all disabled": { - proposalsEnabled: "false", - expected: wasmtypes.DisableAllProposals, - }, - "all enabled": { - proposalsEnabled: "true", - expected: wasmtypes.EnableAllProposals, - }, - "some enabled": { - proposalsEnabled: "okay", - specificEnabled: "StoreCode,InstantiateContract", - expected: []wasmtypes.ProposalType{wasmtypes.ProposalTypeStoreCode, wasmtypes.ProposalTypeInstantiateContract}, - }, - } - - for name, tc := range cases { - t.Run(name, func(t *testing.T) { - ProposalsEnabled = tc.proposalsEnabled - EnableSpecificProposals = tc.specificEnabled - proposals := GetEnabledProposals() - assert.Equal(t, tc.expected, proposals) - }) - } -} diff --git a/app/export.go b/app/export.go index 74c69db60c..f7232cc2bd 100644 --- a/app/export.go +++ b/app/export.go @@ -16,7 +16,7 @@ import ( // ExportAppStateAndValidators exports the state of the application for a genesis // file. -func (app *WasmApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error) { +func (app *WasmApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (servertypes.ExportedApp, error) { // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) @@ -46,7 +46,7 @@ func (app *WasmApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedA // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated // -// in favour of export at a block height +// in favor of export at a block height func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false diff --git a/app/params/encoding.go b/app/params/encoding.go index 3d634abf16..8ff9ea04b3 100644 --- a/app/params/encoding.go +++ b/app/params/encoding.go @@ -10,7 +10,7 @@ import ( // This is provided for compatibility between protobuf and amino implementations. type EncodingConfig struct { InterfaceRegistry types.InterfaceRegistry - Marshaler codec.Codec + Codec codec.Codec TxConfig client.TxConfig Amino *codec.LegacyAmino } diff --git a/app/params/proto.go b/app/params/proto.go index 84ff35a399..1855c43538 100644 --- a/app/params/proto.go +++ b/app/params/proto.go @@ -10,12 +10,12 @@ import ( func MakeEncodingConfig() EncodingConfig { amino := codec.NewLegacyAmino() interfaceRegistry := types.NewInterfaceRegistry() - marshaler := codec.NewProtoCodec(interfaceRegistry) - txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) + codec := codec.NewProtoCodec(interfaceRegistry) + txCfg := tx.NewTxConfig(codec, tx.DefaultSignModes) return EncodingConfig{ InterfaceRegistry: interfaceRegistry, - Marshaler: marshaler, + Codec: codec, TxConfig: txCfg, Amino: amino, } diff --git a/app/sim_test.go b/app/sim_test.go index f9c5136f5a..259bef1481 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -8,12 +8,12 @@ import ( "strings" "testing" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -35,7 +35,8 @@ import ( simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) // SimAppChainID hardcoded chainID for simulation @@ -129,7 +130,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, wasmtypes.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) + newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) require.Equal(t, "WasmApp", newApp.Name()) var genesisState GenesisState @@ -232,7 +233,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, wasmtypes.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) + newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) require.Equal(t, "WasmApp", newApp.Name()) newApp.InitChain(abci.RequestInitChain{ @@ -255,6 +256,7 @@ func TestAppSimulationAfterImport(t *testing.T) { } func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *WasmApp) { + t.Helper() config := simcli.NewConfigFromFlags() config.ChainID = SimAppChainID @@ -273,7 +275,7 @@ func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simt appOptions[flags.FlagHome] = dir // ensure a unique folder appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - app := NewWasmApp(logger, db, nil, true, wasmtypes.EnableAllProposals, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) + app := NewWasmApp(logger, db, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) require.Equal(t, "WasmApp", app.Name()) return config, db, appOptions, app } @@ -312,7 +314,7 @@ func TestAppStateDeterminism(t *testing.T) { } db := dbm.NewMemDB() - app := NewWasmApp(logger, db, nil, true, wasmtypes.EnableAllProposals, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID)) + app := NewWasmApp(logger, db, nil, true, appOptions, emptyWasmOpts, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID)) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", diff --git a/app/test_helpers.go b/app/test_helpers.go index 9945cece65..5963ee378d 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -9,14 +9,16 @@ import ( "testing" "time" - "cosmossdk.io/math" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmtypes "github.com/cometbft/cometbft/types" + "github.com/stretchr/testify/require" + + "cosmossdk.io/math" + bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -40,10 +42,8 @@ import ( minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) // SetupOptions defines arguments that are passed into `WasmApp` constructor. @@ -54,21 +54,22 @@ type SetupOptions struct { WasmOpts []wasmkeeper.Option } -func setup(t testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*WasmApp, GenesisState) { +func setup(tb testing.TB, chainID string, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*WasmApp, GenesisState) { + tb.Helper() db := dbm.NewMemDB() - nodeHome := t.TempDir() + nodeHome := tb.TempDir() snapshotDir := filepath.Join(nodeHome, "data", "snapshots") snapshotDB, err := dbm.NewDB("metadata", dbm.GoLevelDBBackend, snapshotDir) - require.NoError(t, err) - t.Cleanup(func() { snapshotDB.Close() }) + require.NoError(tb, err) + tb.Cleanup(func() { snapshotDB.Close() }) snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) - require.NoError(t, err) + require.NoError(tb, err) appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = nodeHome // ensure unique folder appOptions[server.FlagInvCheckPeriod] = invCheckPeriod - app := NewWasmApp(log.NewNopLogger(), db, nil, true, wasmtypes.EnableAllProposals, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2})) + app := NewWasmApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID(chainID), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2})) if withGenesis { return app, NewDefaultGenesisState(app.AppCodec()) } @@ -94,7 +95,7 @@ func NewWasmAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOpti Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), } - app := NewWasmApp(options.Logger, options.DB, nil, true, wasmtypes.EnableAllProposals, options.AppOpts, options.WasmOpts) + app := NewWasmApp(options.Logger, options.DB, nil, true, options.AppOpts, options.WasmOpts) genesisState := NewDefaultGenesisState(app.appCodec) genesisState, err = GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance) require.NoError(t, err) @@ -196,8 +197,10 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs } // SetupWithEmptyStore set up a wasmd app instance with empty DB -func SetupWithEmptyStore(t testing.TB) *WasmApp { - app, _ := setup(t, "testing", false, 0) +func SetupWithEmptyStore(tb testing.TB) *WasmApp { + tb.Helper() + + app, _ := setup(tb, "testing", false, 0) return app } @@ -278,10 +281,10 @@ func NewTestNetworkFixture() network.TestFixture { } defer os.RemoveAll(dir) - app := NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, wasmtypes.EnableAllProposals, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions) + app := NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(dir), emptyWasmOptions) appCtr := func(val network.ValidatorI) servertypes.Application { return NewWasmApp( - val.GetCtx().Logger, dbm.NewMemDB(), nil, true, wasmtypes.EnableAllProposals, + val.GetCtx().Logger, dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), emptyWasmOptions, bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), @@ -307,6 +310,7 @@ func SignAndDeliverWithoutCommit( t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, msgs []sdk.Msg, fees sdk.Coins, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { + t.Helper() tx, err := simtestutil.GenSignedMockTx( rand.New(rand.NewSource(time.Now().UnixNano())), txCfg, diff --git a/app/test_support.go b/app/test_support.go index 8cf73c212f..ac9cd2865b 100644 --- a/app/test_support.go +++ b/app/test_support.go @@ -1,12 +1,13 @@ package app import ( + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/cosmos/cosmos-sdk/baseapp" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" ) diff --git a/app/upgrades.go b/app/upgrades.go index 01aa076a44..775e28bf45 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -1,6 +1,10 @@ package app import ( + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + "github.com/cosmos/cosmos-sdk/baseapp" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,9 +21,6 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" - icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/app/wasm.go b/app/wasm.go index efc4584b31..70f811bc18 100644 --- a/app/wasm.go +++ b/app/wasm.go @@ -11,5 +11,6 @@ func AllCapabilities() []string { "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", + "cosmwasm_1_4", } } diff --git a/benchmarks/app_test.go b/benchmarks/app_test.go index 590e90de4e..4d3e2b87df 100644 --- a/benchmarks/app_test.go +++ b/benchmarks/app_test.go @@ -7,9 +7,6 @@ import ( "testing" "time" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" @@ -18,24 +15,24 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/mock" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" 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" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/CosmWasm/wasmd/app" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" ) func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*app.WasmApp, app.GenesisState) { //nolint:unparam - wasmApp := app.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, wasmtypes.EnableAllProposals, simtestutil.EmptyAppOptions{}, nil) + wasmApp := app.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, simtestutil.EmptyAppOptions{}, nil) if withGenesis { return wasmApp, app.NewDefaultGenesisState(wasmApp.AppCodec()) @@ -45,14 +42,16 @@ func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper. // SetupWithGenesisAccountsAndValSet initializes a new WasmApp with the provided genesis // accounts and possible balances. -func SetupWithGenesisAccountsAndValSet(b testing.TB, db dbm.DB, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *app.WasmApp { +func SetupWithGenesisAccountsAndValSet(tb testing.TB, db dbm.DB, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *app.WasmApp { + tb.Helper() + wasmApp, genesisState := setup(db, true, 0) authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) appCodec := wasmApp.AppCodec() privVal := mock.NewPV() pubKey, err := privVal.GetPubKey() - require.NoError(b, err) + require.NoError(tb, err) genesisState[authtypes.ModuleName] = appCodec.MustMarshalJSON(authGenesis) @@ -136,7 +135,9 @@ type AppInfo struct { TxConfig client.TxConfig } -func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { +func InitializeWasmApp(tb testing.TB, db dbm.DB, numAccounts int) AppInfo { + tb.Helper() + // constants minter := secp256k1.GenPrivKey() addr := sdk.AccAddress(minter.PubKey().Address()) @@ -165,7 +166,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { Coins: sdk.NewCoins(sdk.NewInt64Coin(denom, 100000000000)), } } - wasmApp := SetupWithGenesisAccountsAndValSet(b, db, genAccs, bals...) + wasmApp := SetupWithGenesisAccountsAndValSet(tb, db, genAccs, bals...) // add wasm contract height := int64(2) @@ -174,16 +175,16 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { // upload the code cw20Code, err := os.ReadFile("./testdata/cw20_base.wasm") - require.NoError(b, err) + require.NoError(tb, err) storeMsg := wasmtypes.MsgStoreCode{ Sender: addr.String(), WASMByteCode: cw20Code, } r := rand.New(rand.NewSource(time.Now().UnixNano())) storeTx, err := simtestutil.GenSignedMockTx(r, txGen, []sdk.Msg{&storeMsg}, nil, 55123123, "", []uint64{0}, []uint64{0}, minter) - require.NoError(b, err) + require.NoError(tb, err) _, _, err = wasmApp.SimDeliver(txGen.TxEncoder(), storeTx) - require.NoError(b, err) + require.NoError(tb, err) codeID := uint64(1) // instantiate the contract @@ -205,7 +206,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { InitialBalances: initialBalances, } initBz, err := json.Marshal(init) - require.NoError(b, err) + require.NoError(tb, err) initMsg := wasmtypes.MsgInstantiateContract{ Sender: addr.String(), Admin: addr.String(), @@ -215,9 +216,9 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { } gasWanted := 500000 + 10000*uint64(numAccounts) initTx, err := simtestutil.GenSignedMockTx(r, txGen, []sdk.Msg{&initMsg}, nil, gasWanted, "", []uint64{0}, []uint64{1}, minter) - require.NoError(b, err) + require.NoError(tb, err) _, res, err := wasmApp.SimDeliver(txGen.TxEncoder(), initTx) - require.NoError(b, err) + require.NoError(tb, err) // TODO: parse contract address better evt := res.Events[len(res.Events)-1] @@ -239,14 +240,16 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { } } -func GenSequenceOfTxs(b testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk.Msg, error), numToGenerate int) []sdk.Tx { +func GenSequenceOfTxs(tb testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk.Msg, error), numToGenerate int) []sdk.Tx { + tb.Helper() + fees := sdk.Coins{sdk.NewInt64Coin(info.Denom, 0)} txs := make([]sdk.Tx, numToGenerate) r := rand.New(rand.NewSource(time.Now().UnixNano())) for i := 0; i < numToGenerate; i++ { msgs, err := msgGen(info) - require.NoError(b, err) + require.NoError(tb, err) txs[i], err = simtestutil.GenSignedMockTx( r, info.TxConfig, @@ -258,7 +261,7 @@ func GenSequenceOfTxs(b testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk. []uint64{info.SeqNum}, info.MinterKey, ) - require.NoError(b, err) + require.NoError(tb, err) info.SeqNum++ } diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index c917e91d20..003fd11bdd 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -5,12 +5,11 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" - "github.com/syndtr/goleveldb/leveldb/opt" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + "github.com/syndtr/goleveldb/leveldb/opt" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" @@ -154,6 +153,7 @@ func cw20TransferMsg(info *AppInfo) ([]sdk.Msg, error) { func buildTxFromMsg(builder func(info *AppInfo) ([]sdk.Msg, error)) func(b *testing.B, info *AppInfo) []sdk.Tx { return func(b *testing.B, info *AppInfo) []sdk.Tx { + b.Helper() return GenSequenceOfTxs(b, info, builder, b.N) } } @@ -163,6 +163,7 @@ func buildMemDB(_ *testing.B) dbm.DB { } func buildLevelDB(b *testing.B) dbm.DB { + b.Helper() levelDB, err := dbm.NewGoLevelDBWithOpts("testing", b.TempDir(), &opt.Options{BlockCacher: opt.NoCacher}) require.NoError(b, err) return levelDB diff --git a/cmd/wasmd/root.go b/cmd/wasmd/root.go index d4f0622b2a..7ecdf63e06 100644 --- a/cmd/wasmd/root.go +++ b/cmd/wasmd/root.go @@ -3,17 +3,23 @@ package main import ( "errors" "github.com/cosmos/cosmos-sdk/types/module" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "io" "os" - rosettaCmd "cosmossdk.io/tools/rosetta/cmd" dbm "github.com/cometbft/cometbft-db" tmcfg "github.com/cometbft/cometbft/config" tmcli "github.com/cometbft/cometbft/libs/cli" "github.com/cometbft/cometbft/libs/log" + "github.com/prometheus/client_golang/prometheus" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + rosettaCmd "cosmossdk.io/tools/rosetta/cmd" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" @@ -28,12 +34,9 @@ import ( "github.com/cosmos/cosmos-sdk/version" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - "github.com/prometheus/client_golang/prometheus" - "github.com/spf13/cast" - "github.com/spf13/cobra" - "github.com/spf13/viper" "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/app/params" @@ -56,7 +59,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { cfg.Seal() initClientCtx := client.Context{}. - WithCodec(encodingConfig.Marshaler). + WithCodec(encodingConfig.Codec). WithInterfaceRegistry(encodingConfig.InterfaceRegistry). WithTxConfig(encodingConfig.TxConfig). WithLegacyAmino(encodingConfig.Amino). @@ -180,7 +183,7 @@ func initRootCmd(rootCmd *cobra.Command, moduleBasics module.BasicManager, encod keys.Commands(app.DefaultNodeHome), ) // add rosetta - rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler)) + rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec)) } func addModuleInitFlags(startCmd *cobra.Command) { @@ -263,7 +266,6 @@ func newApp( return app.NewWasmApp( logger, db, traceStore, true, - app.GetEnabledProposals(), appOpts, wasmOpts, baseappOptions..., @@ -302,7 +304,6 @@ func appExport( db, traceStore, height == -1, - app.GetEnabledProposals(), appOpts, emptyWasmOpts, ) diff --git a/cmd/wasmd/testnet.go b/cmd/wasmd/testnet.go index f8ad31f44a..c1d8dfd0fc 100644 --- a/cmd/wasmd/testnet.go +++ b/cmd/wasmd/testnet.go @@ -11,10 +11,6 @@ import ( "path/filepath" "time" - "github.com/cosmos/cosmos-sdk/version" - - "github.com/CosmWasm/wasmd/app" - tmconfig "github.com/cometbft/cometbft/config" tmrand "github.com/cometbft/cometbft/libs/rand" "github.com/cometbft/cometbft/types" @@ -36,11 +32,14 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/version" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/CosmWasm/wasmd/app" ) var ( @@ -522,7 +521,7 @@ func calculateIP(ip string, i int) (string, error) { return ipv4.String(), nil } -func writeFile(name string, dir string, contents []byte) error { +func writeFile(name, dir string, contents []byte) error { file := filepath.Join(dir, name) if err := os.MkdirAll(dir, 0o755); err != nil { diff --git a/contrib/local/04-gov.sh b/contrib/local/04-gov.sh index 8498beb5f3..5c9325c0f0 100755 --- a/contrib/local/04-gov.sh +++ b/contrib/local/04-gov.sh @@ -3,7 +3,6 @@ set -o errexit -o nounset -o pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -echo "Compile with buildflag ''-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true' to enable gov" sleep 1 echo "## Submit a CosmWasm gov proposal" RESP=$(wasmd tx wasm submit-proposal store-instantiate "$DIR/../../x/wasm/keeper/testdata/reflect.wasm" \ diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 41f45bbbf5..2ea6190ed0 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -4,17 +4,6 @@ ## Table of Contents -- [cosmwasm/wasm/v1/authz.proto](#cosmwasm/wasm/v1/authz.proto) - - [AcceptedMessageKeysFilter](#cosmwasm.wasm.v1.AcceptedMessageKeysFilter) - - [AcceptedMessagesFilter](#cosmwasm.wasm.v1.AcceptedMessagesFilter) - - [AllowAllMessagesFilter](#cosmwasm.wasm.v1.AllowAllMessagesFilter) - - [CombinedLimit](#cosmwasm.wasm.v1.CombinedLimit) - - [ContractExecutionAuthorization](#cosmwasm.wasm.v1.ContractExecutionAuthorization) - - [ContractGrant](#cosmwasm.wasm.v1.ContractGrant) - - [ContractMigrationAuthorization](#cosmwasm.wasm.v1.ContractMigrationAuthorization) - - [MaxCallsLimit](#cosmwasm.wasm.v1.MaxCallsLimit) - - [MaxFundsLimit](#cosmwasm.wasm.v1.MaxFundsLimit) - - [cosmwasm/wasm/v1/types.proto](#cosmwasm/wasm/v1/types.proto) - [AbsoluteTxPosition](#cosmwasm.wasm.v1.AbsoluteTxPosition) - [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) @@ -28,41 +17,23 @@ - [AccessType](#cosmwasm.wasm.v1.AccessType) - [ContractCodeHistoryOperationType](#cosmwasm.wasm.v1.ContractCodeHistoryOperationType) -- [cosmwasm/wasm/v1/tx.proto](#cosmwasm/wasm/v1/tx.proto) - - [MsgClearAdmin](#cosmwasm.wasm.v1.MsgClearAdmin) - - [MsgClearAdminResponse](#cosmwasm.wasm.v1.MsgClearAdminResponse) - - [MsgExecuteContract](#cosmwasm.wasm.v1.MsgExecuteContract) - - [MsgExecuteContractResponse](#cosmwasm.wasm.v1.MsgExecuteContractResponse) - - [MsgInstantiateContract](#cosmwasm.wasm.v1.MsgInstantiateContract) - - [MsgInstantiateContract2](#cosmwasm.wasm.v1.MsgInstantiateContract2) - - [MsgInstantiateContract2Response](#cosmwasm.wasm.v1.MsgInstantiateContract2Response) - - [MsgInstantiateContractResponse](#cosmwasm.wasm.v1.MsgInstantiateContractResponse) - - [MsgMigrateContract](#cosmwasm.wasm.v1.MsgMigrateContract) - - [MsgMigrateContractResponse](#cosmwasm.wasm.v1.MsgMigrateContractResponse) - - [MsgPinCodes](#cosmwasm.wasm.v1.MsgPinCodes) - - [MsgPinCodesResponse](#cosmwasm.wasm.v1.MsgPinCodesResponse) - - [MsgStoreAndInstantiateContract](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContract) - - [MsgStoreAndInstantiateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse) - - [MsgStoreCode](#cosmwasm.wasm.v1.MsgStoreCode) - - [MsgStoreCodeResponse](#cosmwasm.wasm.v1.MsgStoreCodeResponse) - - [MsgSudoContract](#cosmwasm.wasm.v1.MsgSudoContract) - - [MsgSudoContractResponse](#cosmwasm.wasm.v1.MsgSudoContractResponse) - - [MsgUnpinCodes](#cosmwasm.wasm.v1.MsgUnpinCodes) - - [MsgUnpinCodesResponse](#cosmwasm.wasm.v1.MsgUnpinCodesResponse) - - [MsgUpdateAdmin](#cosmwasm.wasm.v1.MsgUpdateAdmin) - - [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse) - - [MsgUpdateInstantiateConfig](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfig) - - [MsgUpdateInstantiateConfigResponse](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse) - - [MsgUpdateParams](#cosmwasm.wasm.v1.MsgUpdateParams) - - [MsgUpdateParamsResponse](#cosmwasm.wasm.v1.MsgUpdateParamsResponse) - - - [Msg](#cosmwasm.wasm.v1.Msg) +- [cosmwasm/wasm/v1/authz.proto](#cosmwasm/wasm/v1/authz.proto) + - [AcceptedMessageKeysFilter](#cosmwasm.wasm.v1.AcceptedMessageKeysFilter) + - [AcceptedMessagesFilter](#cosmwasm.wasm.v1.AcceptedMessagesFilter) + - [AllowAllMessagesFilter](#cosmwasm.wasm.v1.AllowAllMessagesFilter) + - [CodeGrant](#cosmwasm.wasm.v1.CodeGrant) + - [CombinedLimit](#cosmwasm.wasm.v1.CombinedLimit) + - [ContractExecutionAuthorization](#cosmwasm.wasm.v1.ContractExecutionAuthorization) + - [ContractGrant](#cosmwasm.wasm.v1.ContractGrant) + - [ContractMigrationAuthorization](#cosmwasm.wasm.v1.ContractMigrationAuthorization) + - [MaxCallsLimit](#cosmwasm.wasm.v1.MaxCallsLimit) + - [MaxFundsLimit](#cosmwasm.wasm.v1.MaxFundsLimit) + - [StoreCodeAuthorization](#cosmwasm.wasm.v1.StoreCodeAuthorization) - [cosmwasm/wasm/v1/genesis.proto](#cosmwasm/wasm/v1/genesis.proto) - [Code](#cosmwasm.wasm.v1.Code) - [Contract](#cosmwasm.wasm.v1.Contract) - [GenesisState](#cosmwasm.wasm.v1.GenesisState) - - [GenesisState.GenMsgs](#cosmwasm.wasm.v1.GenesisState.GenMsgs) - [Sequence](#cosmwasm.wasm.v1.Sequence) - [cosmwasm/wasm/v1/ibc.proto](#cosmwasm/wasm/v1/ibc.proto) @@ -70,21 +41,6 @@ - [MsgIBCSend](#cosmwasm.wasm.v1.MsgIBCSend) - [MsgIBCSendResponse](#cosmwasm.wasm.v1.MsgIBCSendResponse) -- [cosmwasm/wasm/v1/proposal.proto](#cosmwasm/wasm/v1/proposal.proto) - - [AccessConfigUpdate](#cosmwasm.wasm.v1.AccessConfigUpdate) - - [ClearAdminProposal](#cosmwasm.wasm.v1.ClearAdminProposal) - - [ExecuteContractProposal](#cosmwasm.wasm.v1.ExecuteContractProposal) - - [InstantiateContract2Proposal](#cosmwasm.wasm.v1.InstantiateContract2Proposal) - - [InstantiateContractProposal](#cosmwasm.wasm.v1.InstantiateContractProposal) - - [MigrateContractProposal](#cosmwasm.wasm.v1.MigrateContractProposal) - - [PinCodesProposal](#cosmwasm.wasm.v1.PinCodesProposal) - - [StoreAndInstantiateContractProposal](#cosmwasm.wasm.v1.StoreAndInstantiateContractProposal) - - [StoreCodeProposal](#cosmwasm.wasm.v1.StoreCodeProposal) - - [SudoContractProposal](#cosmwasm.wasm.v1.SudoContractProposal) - - [UnpinCodesProposal](#cosmwasm.wasm.v1.UnpinCodesProposal) - - [UpdateAdminProposal](#cosmwasm.wasm.v1.UpdateAdminProposal) - - [UpdateInstantiateConfigProposal](#cosmwasm.wasm.v1.UpdateInstantiateConfigProposal) - - [cosmwasm/wasm/v1/query.proto](#cosmwasm/wasm/v1/query.proto) - [CodeInfoResponse](#cosmwasm.wasm.v1.CodeInfoResponse) - [QueryAllContractStateRequest](#cosmwasm.wasm.v1.QueryAllContractStateRequest) @@ -113,6 +69,7 @@ - [Query](#cosmwasm.wasm.v1.Query) - [cosmwasm/wasm/v1/tx.proto](#cosmwasm/wasm/v1/tx.proto) + - [AccessConfigUpdate](#cosmwasm.wasm.v1.AccessConfigUpdate) - [MsgAddCodeUploadParamsAddresses](#cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses) - [MsgAddCodeUploadParamsAddressesResponse](#cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddressesResponse) - [MsgClearAdmin](#cosmwasm.wasm.v1.MsgClearAdmin) @@ -131,6 +88,8 @@ - [MsgRemoveCodeUploadParamsAddressesResponse](#cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddressesResponse) - [MsgStoreAndInstantiateContract](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContract) - [MsgStoreAndInstantiateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse) + - [MsgStoreAndMigrateContract](#cosmwasm.wasm.v1.MsgStoreAndMigrateContract) + - [MsgStoreAndMigrateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndMigrateContractResponse) - [MsgStoreCode](#cosmwasm.wasm.v1.MsgStoreCode) - [MsgStoreCodeResponse](#cosmwasm.wasm.v1.MsgStoreCodeResponse) - [MsgSudoContract](#cosmwasm.wasm.v1.MsgSudoContract) @@ -139,6 +98,8 @@ - [MsgUnpinCodesResponse](#cosmwasm.wasm.v1.MsgUnpinCodesResponse) - [MsgUpdateAdmin](#cosmwasm.wasm.v1.MsgUpdateAdmin) - [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse) + - [MsgUpdateContractLabel](#cosmwasm.wasm.v1.MsgUpdateContractLabel) + - [MsgUpdateContractLabelResponse](#cosmwasm.wasm.v1.MsgUpdateContractLabelResponse) - [MsgUpdateInstantiateConfig](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfig) - [MsgUpdateInstantiateConfigResponse](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse) - [MsgUpdateParams](#cosmwasm.wasm.v1.MsgUpdateParams) @@ -150,168 +111,6 @@ - -

Top

- -## cosmwasm/wasm/v1/authz.proto - - - - - -### AcceptedMessageKeysFilter -AcceptedMessageKeysFilter accept only the specific contract message keys in -the json object to be executed. -Since: wasmd 0.30 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `keys` | [string](#string) | repeated | Messages is the list of unique keys | - - - - - - - - -### AcceptedMessagesFilter -AcceptedMessagesFilter accept only the specific raw contract messages to be -executed. -Since: wasmd 0.30 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `messages` | [bytes](#bytes) | repeated | Messages is the list of raw contract messages | - - - - - - - - -### AllowAllMessagesFilter -AllowAllMessagesFilter is a wildcard to allow any type of contract payload -message. -Since: wasmd 0.30 - - - - - - - - -### CombinedLimit -CombinedLimit defines the maximal amounts that can be sent to a contract and -the maximal number of calls executable. Both need to remain >0 to be valid. -Since: wasmd 0.30 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `calls_remaining` | [uint64](#uint64) | | Remaining number that is decremented on each execution | -| `amounts` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Amounts is the maximal amount of tokens transferable to the contract. | - - - - - - - - -### ContractExecutionAuthorization -ContractExecutionAuthorization defines authorization for wasm execute. -Since: wasmd 0.30 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `grants` | [ContractGrant](#cosmwasm.wasm.v1.ContractGrant) | repeated | Grants for contract executions | - - - - - - - - -### ContractGrant -ContractGrant a granted permission for a single contract -Since: wasmd 0.30 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | -| `limit` | [google.protobuf.Any](#google.protobuf.Any) | | Limit defines execution limits that are enforced and updated when the grant is applied. When the limit lapsed the grant is removed. | -| `filter` | [google.protobuf.Any](#google.protobuf.Any) | | Filter define more fine-grained control on the message payload passed to the contract in the operation. When no filter applies on execution, the operation is prohibited. | - - - - - - - - -### ContractMigrationAuthorization -ContractMigrationAuthorization defines authorization for wasm contract -migration. Since: wasmd 0.30 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `grants` | [ContractGrant](#cosmwasm.wasm.v1.ContractGrant) | repeated | Grants for contract migrations | - - - - - - - - -### MaxCallsLimit -MaxCallsLimit limited number of calls to the contract. No funds transferable. -Since: wasmd 0.30 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `remaining` | [uint64](#uint64) | | Remaining number that is decremented on each execution | - - - - - - - - -### MaxFundsLimit -MaxFundsLimit defines the maximal amounts that can be sent to the contract. -Since: wasmd 0.30 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `amounts` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Amounts is the maximal amount of tokens transferable to the contract. | - - - - - - - - - - - - - - -

Top

@@ -492,952 +291,335 @@ ContractCodeHistoryOperationType actions that caused a code change - +

Top

-## cosmwasm/wasm/v1/tx.proto - - - - - -### MsgClearAdmin -MsgClearAdmin removes any admin stored for a smart contract - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | Sender is the actor that signed the messages | -| `contract` | [string](#string) | | Contract is the address of the smart contract | - - - - - - - - -### MsgClearAdminResponse -MsgClearAdminResponse returns empty data - - - +## cosmwasm/wasm/v1/authz.proto - + -### MsgExecuteContract -MsgExecuteContract submits the given message data to a smart contract +### AcceptedMessageKeysFilter +AcceptedMessageKeysFilter accept only the specific contract message keys in +the json object to be executed. +Since: wasmd 0.30 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | Sender is the that actor that signed the messages | -| `contract` | [string](#string) | | Contract is the address of the smart contract | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract | -| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on execution | - - - - - - - - -### MsgExecuteContractResponse -MsgExecuteContractResponse returns execution result data. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract | - - - - - - - - -### MsgInstantiateContract -MsgInstantiateContract create a new smart contract instance for the given -code id. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | Sender is the that actor that signed the messages | -| `admin` | [string](#string) | | Admin is an optional address that can execute migrations | -| `code_id` | [uint64](#uint64) | | CodeID is the reference to the stored WASM code | -| `label` | [string](#string) | | Label is optional metadata to be stored with a contract instance. | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on instantiation | -| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on instantiation | - - - - - - - - -### MsgInstantiateContract2 -MsgInstantiateContract2 create a new smart contract instance for the given -code id with a predicable address. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | Sender is the that actor that signed the messages | -| `admin` | [string](#string) | | Admin is an optional address that can execute migrations | -| `code_id` | [uint64](#uint64) | | CodeID is the reference to the stored WASM code | -| `label` | [string](#string) | | Label is optional metadata to be stored with a contract instance. | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on instantiation | -| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on instantiation | -| `salt` | [bytes](#bytes) | | Salt is an arbitrary value provided by the sender. Size can be 1 to 64. | -| `fix_msg` | [bool](#bool) | | FixMsg include the msg value into the hash for the predictable address. Default is false | - - - - - - - - -### MsgInstantiateContract2Response -MsgInstantiateContract2Response return instantiation result data - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | Address is the bech32 address of the new contract instance. | -| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract | - - - - - - - - -### MsgInstantiateContractResponse -MsgInstantiateContractResponse return instantiation result data - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | Address is the bech32 address of the new contract instance. | -| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract | - - - - - - - - -### MsgMigrateContract -MsgMigrateContract runs a code upgrade/ downgrade for a smart contract - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | Sender is the that actor that signed the messages | -| `contract` | [string](#string) | | Contract is the address of the smart contract | -| `code_id` | [uint64](#uint64) | | CodeID references the new WASM code | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on migration | - - - - - - - - -### MsgMigrateContractResponse -MsgMigrateContractResponse returns contract migration result data. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `data` | [bytes](#bytes) | | Data contains same raw bytes returned as data from the wasm contract. (May be empty) | - - - - - - - - -### MsgPinCodes -MsgPinCodes is the MsgPinCodes request type. - -Since: 0.40 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account. | -| `code_ids` | [uint64](#uint64) | repeated | CodeIDs references the new WASM codes | - - - - - - - - -### MsgPinCodesResponse -MsgPinCodesResponse defines the response structure for executing a -MsgPinCodes message. - -Since: 0.40 - - - - - - - - -### MsgStoreAndInstantiateContract -MsgStoreAndInstantiateContract is the MsgStoreAndInstantiateContract -request type. - -Since: 0.40 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account. | -| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed | -| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply on contract creation, optional | -| `unpin_code` | [bool](#bool) | | UnpinCode code on upload, optional. As default the uploaded contract is pinned to cache. | -| `admin` | [string](#string) | | Admin is an optional address that can execute migrations | -| `label` | [string](#string) | | Label is optional metadata to be stored with a constract instance. | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on instantiation | -| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred from the authority account to the contract on instantiation | -| `source` | [string](#string) | | Source is the URL where the code is hosted | -| `builder` | [string](#string) | | Builder is the docker image used to build the code deterministically, used for smart contract verification | -| `code_hash` | [bytes](#bytes) | | CodeHash is the SHA256 sum of the code outputted by builder, used for smart contract verification | - - - - - - - - -### MsgStoreAndInstantiateContractResponse -MsgStoreAndInstantiateContractResponse defines the response structure -for executing a MsgStoreAndInstantiateContract message. - -Since: 0.40 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | Address is the bech32 address of the new contract instance. | -| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract | - - - - - - - - -### MsgStoreCode -MsgStoreCode submit Wasm code to the system - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | Sender is the actor that signed the messages | -| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed | -| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission access control to apply on contract creation, optional | - - - - - - - - -### MsgStoreCodeResponse -MsgStoreCodeResponse returns store result data. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `code_id` | [uint64](#uint64) | | CodeID is the reference to the stored WASM code | -| `checksum` | [bytes](#bytes) | | Checksum is the sha256 hash of the stored code | - - - - - - - - -### MsgSudoContract -MsgSudoContract is the MsgSudoContract request type. - -Since: 0.40 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account. | -| `contract` | [string](#string) | | Contract is the address of the smart contract | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as sudo | - - - - - - - - -### MsgSudoContractResponse -MsgSudoContractResponse defines the response structure for executing a -MsgSudoContract message. - -Since: 0.40 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract | - - - - - - - - -### MsgUnpinCodes -MsgUnpinCodes is the MsgUnpinCodes request type. - -Since: 0.40 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account. | -| `code_ids` | [uint64](#uint64) | repeated | CodeIDs references the WASM codes | - - - - - - - - -### MsgUnpinCodesResponse -MsgUnpinCodesResponse defines the response structure for executing a -MsgUnpinCodes message. - -Since: 0.40 - - - - - - - - -### MsgUpdateAdmin -MsgUpdateAdmin sets a new admin for a smart contract - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | Sender is the that actor that signed the messages | -| `new_admin` | [string](#string) | | NewAdmin address to be set | -| `contract` | [string](#string) | | Contract is the address of the smart contract | - - - - - - - - -### MsgUpdateAdminResponse -MsgUpdateAdminResponse returns empty data - - - - - - - - -### MsgUpdateInstantiateConfig -MsgUpdateInstantiateConfig updates instantiate config for a smart contract - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | Sender is the that actor that signed the messages | -| `code_id` | [uint64](#uint64) | | CodeID references the stored WASM code | -| `new_instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | NewInstantiatePermission is the new access control | - - - - - - - - -### MsgUpdateInstantiateConfigResponse -MsgUpdateInstantiateConfigResponse returns empty data - - - - - - - - -### MsgUpdateParams -MsgUpdateParams is the MsgUpdateParams request type. - -Since: 0.40 - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account. | -| `params` | [Params](#cosmwasm.wasm.v1.Params) | | params defines the x/wasm parameters to update. - -NOTE: All parameters must be supplied. | - - - - - - - - -### MsgUpdateParamsResponse -MsgUpdateParamsResponse defines the response structure for executing a -MsgUpdateParams message. - -Since: 0.40 - - - - - - - - - - - - - - -### Msg -Msg defines the wasm Msg service. - -| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | -| ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `StoreCode` | [MsgStoreCode](#cosmwasm.wasm.v1.MsgStoreCode) | [MsgStoreCodeResponse](#cosmwasm.wasm.v1.MsgStoreCodeResponse) | StoreCode to submit Wasm code to the system | | -| `InstantiateContract` | [MsgInstantiateContract](#cosmwasm.wasm.v1.MsgInstantiateContract) | [MsgInstantiateContractResponse](#cosmwasm.wasm.v1.MsgInstantiateContractResponse) | InstantiateContract creates a new smart contract instance for the given code id. | | -| `InstantiateContract2` | [MsgInstantiateContract2](#cosmwasm.wasm.v1.MsgInstantiateContract2) | [MsgInstantiateContract2Response](#cosmwasm.wasm.v1.MsgInstantiateContract2Response) | InstantiateContract2 creates a new smart contract instance for the given code id with a predictable address | | -| `ExecuteContract` | [MsgExecuteContract](#cosmwasm.wasm.v1.MsgExecuteContract) | [MsgExecuteContractResponse](#cosmwasm.wasm.v1.MsgExecuteContractResponse) | Execute submits the given message data to a smart contract | | -| `MigrateContract` | [MsgMigrateContract](#cosmwasm.wasm.v1.MsgMigrateContract) | [MsgMigrateContractResponse](#cosmwasm.wasm.v1.MsgMigrateContractResponse) | Migrate runs a code upgrade/ downgrade for a smart contract | | -| `UpdateAdmin` | [MsgUpdateAdmin](#cosmwasm.wasm.v1.MsgUpdateAdmin) | [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse) | UpdateAdmin sets a new admin for a smart contract | | -| `ClearAdmin` | [MsgClearAdmin](#cosmwasm.wasm.v1.MsgClearAdmin) | [MsgClearAdminResponse](#cosmwasm.wasm.v1.MsgClearAdminResponse) | ClearAdmin removes any admin stored for a smart contract | | -| `UpdateInstantiateConfig` | [MsgUpdateInstantiateConfig](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfig) | [MsgUpdateInstantiateConfigResponse](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse) | UpdateInstantiateConfig updates instantiate config for a smart contract | | -| `UpdateParams` | [MsgUpdateParams](#cosmwasm.wasm.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#cosmwasm.wasm.v1.MsgUpdateParamsResponse) | UpdateParams defines a governance operation for updating the x/wasm module parameters. The authority is defined in the keeper. - -Since: 0.40 | | -| `SudoContract` | [MsgSudoContract](#cosmwasm.wasm.v1.MsgSudoContract) | [MsgSudoContractResponse](#cosmwasm.wasm.v1.MsgSudoContractResponse) | SudoContract defines a governance operation for calling sudo on a contract. The authority is defined in the keeper. - -Since: 0.40 | | -| `PinCodes` | [MsgPinCodes](#cosmwasm.wasm.v1.MsgPinCodes) | [MsgPinCodesResponse](#cosmwasm.wasm.v1.MsgPinCodesResponse) | PinCodes defines a governance operation for pinning a set of code ids in the wasmvm cache. The authority is defined in the keeper. - -Since: 0.40 | | -| `UnpinCodes` | [MsgUnpinCodes](#cosmwasm.wasm.v1.MsgUnpinCodes) | [MsgUnpinCodesResponse](#cosmwasm.wasm.v1.MsgUnpinCodesResponse) | UnpinCodes defines a governance operation for unpinning a set of code ids in the wasmvm cache. The authority is defined in the keeper. - -Since: 0.40 | | -| `StoreAndInstantiateContract` | [MsgStoreAndInstantiateContract](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContract) | [MsgStoreAndInstantiateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse) | StoreAndInstantiateContract defines a governance operation for storing and instantiating the contract. The authority is defined in the keeper. - -Since: 0.40 | | - - - - - - -

Top

- -## cosmwasm/wasm/v1/genesis.proto - - - - - -### Code -Code struct encompasses CodeInfo and CodeBytes - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `code_id` | [uint64](#uint64) | | | -| `code_info` | [CodeInfo](#cosmwasm.wasm.v1.CodeInfo) | | | -| `code_bytes` | [bytes](#bytes) | | | -| `pinned` | [bool](#bool) | | Pinned to wasmvm cache | - - - - - - - - -### Contract -Contract struct encompasses ContractAddress, ContractInfo, and ContractState - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `contract_address` | [string](#string) | | | -| `contract_info` | [ContractInfo](#cosmwasm.wasm.v1.ContractInfo) | | | -| `contract_state` | [Model](#cosmwasm.wasm.v1.Model) | repeated | | -| `contract_code_history` | [ContractCodeHistoryEntry](#cosmwasm.wasm.v1.ContractCodeHistoryEntry) | repeated | | - - - - - - - - -### GenesisState -GenesisState - genesis state of x/wasm - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `params` | [Params](#cosmwasm.wasm.v1.Params) | | | -| `codes` | [Code](#cosmwasm.wasm.v1.Code) | repeated | | -| `contracts` | [Contract](#cosmwasm.wasm.v1.Contract) | repeated | | -| `sequences` | [Sequence](#cosmwasm.wasm.v1.Sequence) | repeated | | -| `gen_msgs` | [GenesisState.GenMsgs](#cosmwasm.wasm.v1.GenesisState.GenMsgs) | repeated | | - - - - - - - - -### GenesisState.GenMsgs -GenMsgs define the messages that can be executed during genesis phase in -order. The intention is to have more human readable data that is auditable. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `store_code` | [MsgStoreCode](#cosmwasm.wasm.v1.MsgStoreCode) | | | -| `instantiate_contract` | [MsgInstantiateContract](#cosmwasm.wasm.v1.MsgInstantiateContract) | | | -| `execute_contract` | [MsgExecuteContract](#cosmwasm.wasm.v1.MsgExecuteContract) | | MsgInstantiateContract2 intentionally not supported see https://github.com/CosmWasm/wasmd/issues/987 | +| `keys` | [string](#string) | repeated | Messages is the list of unique keys | - + -### Sequence -Sequence key and value of an id generation counter +### AcceptedMessagesFilter +AcceptedMessagesFilter accept only the specific raw contract messages to be +executed. +Since: wasmd 0.30 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `id_key` | [bytes](#bytes) | | | -| `value` | [uint64](#uint64) | | | - - +| `messages` | [bytes](#bytes) | repeated | Messages is the list of raw contract messages | - - - - + +### AllowAllMessagesFilter +AllowAllMessagesFilter is a wildcard to allow any type of contract payload +message. +Since: wasmd 0.30 - -

Top

-## cosmwasm/wasm/v1/ibc.proto - + -### MsgIBCCloseChannel -MsgIBCCloseChannel port and channel need to be owned by the contract +### CodeGrant +CodeGrant a granted permission for a single code | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `channel` | [string](#string) | | | +| `code_hash` | [bytes](#bytes) | | CodeHash is the unique identifier created by wasmvm Wildcard "*" is used to specify any kind of grant. | +| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission is the superset access control to apply on contract creation. Optional | - + -### MsgIBCSend -MsgIBCSend +### CombinedLimit +CombinedLimit defines the maximal amounts that can be sent to a contract and +the maximal number of calls executable. Both need to remain >0 to be valid. +Since: wasmd 0.30 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `channel` | [string](#string) | | the channel by which the packet will be sent | -| `timeout_height` | [uint64](#uint64) | | Timeout height relative to the current block height. The timeout is disabled when set to 0. | -| `timeout_timestamp` | [uint64](#uint64) | | Timeout timestamp (in nanoseconds) relative to the current block timestamp. The timeout is disabled when set to 0. | -| `data` | [bytes](#bytes) | | Data is the payload to transfer. We must not make assumption what format or content is in here. | +| `calls_remaining` | [uint64](#uint64) | | Remaining number that is decremented on each execution | +| `amounts` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Amounts is the maximal amount of tokens transferable to the contract. | - + -### MsgIBCSendResponse -MsgIBCSendResponse +### ContractExecutionAuthorization +ContractExecutionAuthorization defines authorization for wasm execute. +Since: wasmd 0.30 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `sequence` | [uint64](#uint64) | | Sequence number of the IBC packet sent | +| `grants` | [ContractGrant](#cosmwasm.wasm.v1.ContractGrant) | repeated | Grants for contract executions | - - + - +### ContractGrant +ContractGrant a granted permission for a single contract +Since: wasmd 0.30 - +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | +| `limit` | [google.protobuf.Any](#google.protobuf.Any) | | Limit defines execution limits that are enforced and updated when the grant is applied. When the limit lapsed the grant is removed. | +| `filter` | [google.protobuf.Any](#google.protobuf.Any) | | Filter define more fine-grained control on the message payload passed to the contract in the operation. When no filter applies on execution, the operation is prohibited. | - -

Top

-## cosmwasm/wasm/v1/proposal.proto - + -### AccessConfigUpdate -AccessConfigUpdate contains the code id and the access config to be -applied. +### ContractMigrationAuthorization +ContractMigrationAuthorization defines authorization for wasm contract +migration. Since: wasmd 0.30 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `code_id` | [uint64](#uint64) | | CodeID is the reference to the stored WASM code to be updated | -| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply to the set of code ids | +| `grants` | [ContractGrant](#cosmwasm.wasm.v1.ContractGrant) | repeated | Grants for contract migrations | - + -### ClearAdminProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit ClearAdminProposal. To clear the admin of a contract, -a simple MsgClearAdmin can be invoked from the x/gov module via -a v1 governance proposal. +### MaxCallsLimit +MaxCallsLimit limited number of calls to the contract. No funds transferable. +Since: wasmd 0.30 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `contract` | [string](#string) | | Contract is the address of the smart contract | +| `remaining` | [uint64](#uint64) | | Remaining number that is decremented on each execution | - + -### ExecuteContractProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit ExecuteContractProposal. To call execute on a contract, -a simple MsgExecuteContract can be invoked from the x/gov module via -a v1 governance proposal. +### MaxFundsLimit +MaxFundsLimit defines the maximal amounts that can be sent to the contract. +Since: wasmd 0.30 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender | -| `contract` | [string](#string) | | Contract is the address of the smart contract | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as execute | -| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on instantiation | +| `amounts` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Amounts is the maximal amount of tokens transferable to the contract. | - + -### InstantiateContract2Proposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit InstantiateContract2Proposal. To instantiate contract 2, -a simple MsgInstantiateContract2 can be invoked from the x/gov module via -a v1 governance proposal. +### StoreCodeAuthorization +StoreCodeAuthorization defines authorization for wasm code upload. +Since: wasmd 0.42 | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's enviroment as sender | -| `admin` | [string](#string) | | Admin is an optional address that can execute migrations | -| `code_id` | [uint64](#uint64) | | CodeID is the reference to the stored WASM code | -| `label` | [string](#string) | | Label is optional metadata to be stored with a constract instance. | -| `msg` | [bytes](#bytes) | | Msg json encode message to be passed to the contract on instantiation | -| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on instantiation | -| `salt` | [bytes](#bytes) | | Salt is an arbitrary value provided by the sender. Size can be 1 to 64. | -| `fix_msg` | [bool](#bool) | | FixMsg include the msg value into the hash for the predictable address. Default is false | +| `grants` | [CodeGrant](#cosmwasm.wasm.v1.CodeGrant) | repeated | Grants for code upload | + - + -### InstantiateContractProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit InstantiateContractProposal. To instantiate a contract, -a simple MsgInstantiateContract can be invoked from the x/gov module via -a v1 governance proposal. + + -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender | -| `admin` | [string](#string) | | Admin is an optional address that can execute migrations | -| `code_id` | [uint64](#uint64) | | CodeID is the reference to the stored WASM code | -| `label` | [string](#string) | | Label is optional metadata to be stored with a constract instance. | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on instantiation | -| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on instantiation | + +

Top

+## cosmwasm/wasm/v1/genesis.proto - + -### MigrateContractProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit MigrateContractProposal. To migrate a contract, -a simple MsgMigrateContract can be invoked from the x/gov module via -a v1 governance proposal. +### Code +Code struct encompasses CodeInfo and CodeBytes | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text - -Note: skipping 3 as this was previously used for unneeded run_as | -| `contract` | [string](#string) | | Contract is the address of the smart contract | -| `code_id` | [uint64](#uint64) | | CodeID references the new WASM code | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on migration | +| `code_id` | [uint64](#uint64) | | | +| `code_info` | [CodeInfo](#cosmwasm.wasm.v1.CodeInfo) | | | +| `code_bytes` | [bytes](#bytes) | | | +| `pinned` | [bool](#bool) | | Pinned to wasmvm cache | - + -### PinCodesProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit PinCodesProposal. To pin a set of code ids in the wasmvm -cache, a simple MsgPinCodes can be invoked from the x/gov module via -a v1 governance proposal. +### Contract +Contract struct encompasses ContractAddress, ContractInfo, and ContractState | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `code_ids` | [uint64](#uint64) | repeated | CodeIDs references the new WASM codes | +| `contract_address` | [string](#string) | | | +| `contract_info` | [ContractInfo](#cosmwasm.wasm.v1.ContractInfo) | | | +| `contract_state` | [Model](#cosmwasm.wasm.v1.Model) | repeated | | +| `contract_code_history` | [ContractCodeHistoryEntry](#cosmwasm.wasm.v1.ContractCodeHistoryEntry) | repeated | | - + -### StoreAndInstantiateContractProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit StoreAndInstantiateContractProposal. To store and instantiate -the contract, a simple MsgStoreAndInstantiateContract can be invoked from -the x/gov module via a v1 governance proposal. +### GenesisState +GenesisState - genesis state of x/wasm | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender | -| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed | -| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply on contract creation, optional | -| `unpin_code` | [bool](#bool) | | UnpinCode code on upload, optional | -| `admin` | [string](#string) | | Admin is an optional address that can execute migrations | -| `label` | [string](#string) | | Label is optional metadata to be stored with a constract instance. | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on instantiation | -| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on instantiation | -| `source` | [string](#string) | | Source is the URL where the code is hosted | -| `builder` | [string](#string) | | Builder is the docker image used to build the code deterministically, used for smart contract verification | -| `code_hash` | [bytes](#bytes) | | CodeHash is the SHA256 sum of the code outputted by builder, used for smart contract verification | +| `params` | [Params](#cosmwasm.wasm.v1.Params) | | | +| `codes` | [Code](#cosmwasm.wasm.v1.Code) | repeated | | +| `contracts` | [Contract](#cosmwasm.wasm.v1.Contract) | repeated | | +| `sequences` | [Sequence](#cosmwasm.wasm.v1.Sequence) | repeated | | - + -### StoreCodeProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit StoreCodeProposal. To submit WASM code to the system, -a simple MsgStoreCode can be invoked from the x/gov module via -a v1 governance proposal. +### Sequence +Sequence key and value of an id generation counter | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender | -| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed | -| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply on contract creation, optional | -| `unpin_code` | [bool](#bool) | | UnpinCode code on upload, optional | -| `source` | [string](#string) | | Source is the URL where the code is hosted | -| `builder` | [string](#string) | | Builder is the docker image used to build the code deterministically, used for smart contract verification | -| `code_hash` | [bytes](#bytes) | | CodeHash is the SHA256 sum of the code outputted by builder, used for smart contract verification | +| `id_key` | [bytes](#bytes) | | | +| `value` | [uint64](#uint64) | | | + - + -### SudoContractProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit SudoContractProposal. To call sudo on a contract, -a simple MsgSudoContract can be invoked from the x/gov module via -a v1 governance proposal. + + -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `contract` | [string](#string) | | Contract is the address of the smart contract | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as sudo | + +

Top

+## cosmwasm/wasm/v1/ibc.proto - + -### UnpinCodesProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit UnpinCodesProposal. To unpin a set of code ids in the wasmvm -cache, a simple MsgUnpinCodes can be invoked from the x/gov module via -a v1 governance proposal. +### MsgIBCCloseChannel +MsgIBCCloseChannel port and channel need to be owned by the contract | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `code_ids` | [uint64](#uint64) | repeated | CodeIDs references the WASM codes | +| `channel` | [string](#string) | | | - + -### UpdateAdminProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit UpdateAdminProposal. To set an admin for a contract, -a simple MsgUpdateAdmin can be invoked from the x/gov module via -a v1 governance proposal. +### MsgIBCSend +MsgIBCSend | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `new_admin` | [string](#string) | | NewAdmin address to be set | -| `contract` | [string](#string) | | Contract is the address of the smart contract | +| `channel` | [string](#string) | | the channel by which the packet will be sent | +| `timeout_height` | [uint64](#uint64) | | Timeout height relative to the current block height. The timeout is disabled when set to 0. | +| `timeout_timestamp` | [uint64](#uint64) | | Timeout timestamp (in nanoseconds) relative to the current block timestamp. The timeout is disabled when set to 0. | +| `data` | [bytes](#bytes) | | Data is the payload to transfer. We must not make assumption what format or content is in here. | - + -### UpdateInstantiateConfigProposal -Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -an explicit UpdateInstantiateConfigProposal. To update instantiate config -to a set of code ids, a simple MsgUpdateInstantiateConfig can be invoked from -the x/gov module via a v1 governance proposal. +### MsgIBCSendResponse +MsgIBCSendResponse | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `access_config_updates` | [AccessConfigUpdate](#cosmwasm.wasm.v1.AccessConfigUpdate) | repeated | AccessConfigUpdate contains the list of code ids and the access config to be applied. | +| `sequence` | [uint64](#uint64) | | Sequence number of the IBC packet sent | @@ -1869,6 +1051,23 @@ Query provides defines the gRPC querier service + + +### AccessConfigUpdate +AccessConfigUpdate contains the code id and the access config to be +applied. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `code_id` | [uint64](#uint64) | | CodeID is the reference to the stored WASM code to be updated | +| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply to the set of code ids | + + + + + + ### MsgAddCodeUploadParamsAddresses @@ -2171,6 +1370,48 @@ Since: 0.40 + + +### MsgStoreAndMigrateContract +MsgStoreAndMigrateContract is the MsgStoreAndMigrateContract +request type. + +Since: 0.42 + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `authority` | [string](#string) | | Authority is the address of the governance account. | +| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed | +| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply on contract creation, optional | +| `contract` | [string](#string) | | Contract is the address of the smart contract | +| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on migration | + + + + + + + + +### MsgStoreAndMigrateContractResponse +MsgStoreAndMigrateContractResponse defines the response structure +for executing a MsgStoreAndMigrateContract message. + +Since: 0.42 + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `code_id` | [uint64](#uint64) | | CodeID is the reference to the stored WASM code | +| `checksum` | [bytes](#bytes) | | Checksum is the sha256 hash of the stored code | +| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract | + + + + + + ### MsgStoreCode @@ -2299,6 +1540,33 @@ MsgUpdateAdminResponse returns empty data + + +### MsgUpdateContractLabel +MsgUpdateContractLabel sets a new label for a smart contract + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [string](#string) | | Sender is the that actor that signed the messages | +| `new_label` | [string](#string) | | NewLabel string to be set | +| `contract` | [string](#string) | | Contract is the address of the smart contract | + + + + + + + + +### MsgUpdateContractLabelResponse +MsgUpdateContractLabelResponse returns empty data + + + + + + ### MsgUpdateInstantiateConfig @@ -2397,6 +1665,12 @@ Since: 0.40 | | Since: 0.40 | | | `RemoveCodeUploadParamsAddresses` | [MsgRemoveCodeUploadParamsAddresses](#cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddresses) | [MsgRemoveCodeUploadParamsAddressesResponse](#cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddressesResponse) | RemoveCodeUploadParamsAddresses defines a governance operation for removing addresses from code upload params. The authority is defined in the keeper. | | | `AddCodeUploadParamsAddresses` | [MsgAddCodeUploadParamsAddresses](#cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses) | [MsgAddCodeUploadParamsAddressesResponse](#cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddressesResponse) | AddCodeUploadParamsAddresses defines a governance operation for adding addresses to code upload params. The authority is defined in the keeper. | | +| `StoreAndMigrateContract` | [MsgStoreAndMigrateContract](#cosmwasm.wasm.v1.MsgStoreAndMigrateContract) | [MsgStoreAndMigrateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndMigrateContractResponse) | StoreAndMigrateContract defines a governance operation for storing and migrating the contract. The authority is defined in the keeper. + +Since: 0.42 | | +| `UpdateContractLabel` | [MsgUpdateContractLabel](#cosmwasm.wasm.v1.MsgUpdateContractLabel) | [MsgUpdateContractLabelResponse](#cosmwasm.wasm.v1.MsgUpdateContractLabelResponse) | UpdateContractLabel sets a new label for a smart contract + +Since: 0.43 | | diff --git a/go.mod b/go.mod index ce10913af9..fde7081427 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module github.com/CosmWasm/wasmd go 1.20 require ( - github.com/CosmWasm/wasmvm v1.3.0 + github.com/CosmWasm/wasmvm v1.4.1 github.com/cosmos/cosmos-proto v1.0.0-beta.2 - github.com/cosmos/cosmos-sdk v0.47.4 + github.com/cosmos/cosmos-sdk v0.47.5 github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/gogoproto v1.4.10 - github.com/cosmos/iavl v0.20.0 - github.com/cosmos/ibc-go/v7 v7.2.0 + github.com/cosmos/iavl v0.20.1 + github.com/cosmos/ibc-go/v7 v7.3.0 github.com/cosmos/ics23/go v0.10.0 // indirect github.com/docker/distribution v2.8.2+incompatible github.com/dvsekhvalnov/jose2go v1.5.0 // indirect @@ -36,7 +36,7 @@ require ( cosmossdk.io/api v0.3.1 cosmossdk.io/core v0.5.1 cosmossdk.io/errors v1.0.0 - cosmossdk.io/math v1.0.1 + cosmossdk.io/math v1.1.2 cosmossdk.io/tools/rosetta v0.2.1 github.com/cometbft/cometbft v0.37.2 github.com/cometbft/cometbft-db v0.8.0 @@ -49,8 +49,8 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.0 // indirect cloud.google.com/go/storage v1.30.1 // indirect - cosmossdk.io/depinject v1.0.0-alpha.3 // indirect - cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect + cosmossdk.io/depinject v1.0.0-alpha.4 // indirect + cosmossdk.io/log v1.2.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect @@ -66,6 +66,9 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/cockroachdb/apd/v2 v2.0.2 // indirect + github.com/cockroachdb/errors v1.10.0 // indirect + github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect + github.com/cockroachdb/redact v1.1.5 // indirect github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect @@ -83,6 +86,7 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/felixge/httpsnoop v1.0.2 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/getsentry/sentry-go v0.23.0 // indirect github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect @@ -120,6 +124,8 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmhodges/levigo v1.0.0 // indirect github.com/klauspost/compress v1.16.3 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect github.com/lib/pq v1.10.7 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/linxGnu/grocksdb v1.7.16 // indirect @@ -142,8 +148,9 @@ require ( github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/cors v1.8.3 // indirect - github.com/rs/zerolog v1.29.1 // indirect + github.com/rs/zerolog v1.30.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect @@ -156,12 +163,12 @@ require ( go.etcd.io/bbolt v1.3.7 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect + golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/oauth2 v0.8.0 // indirect - golang.org/x/sys v0.10.0 // indirect + golang.org/x/sys v0.11.0 // indirect golang.org/x/term v0.10.0 // indirect - golang.org/x/text v0.11.0 // indirect + golang.org/x/text v0.12.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.126.0 // indirect google.golang.org/appengine v1.6.7 // indirect @@ -186,3 +193,6 @@ replace ( // pin version! 126854af5e6d has issues with the store so that queries fail github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 ) + +// see https://github.com/CosmWasm/wasmd/issues/1651 +retract v0.42.0 diff --git a/go.sum b/go.sum index 9d5c161ba0..27da00b70e 100644 --- a/go.sum +++ b/go.sum @@ -191,14 +191,14 @@ cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= cosmossdk.io/core v0.5.1 h1:vQVtFrIYOQJDV3f7rw4pjjVqc1id4+mE0L9hHP66pyI= cosmossdk.io/core v0.5.1/go.mod h1:KZtwHCLjcFuo0nmDc24Xy6CRNEL9Vl/MeimQ2aC7NLE= -cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= -cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= +cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= +cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0= -cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca h1:msenprh2BLLRwNT7zN56TbBHOGk/7ARQckXHxXyvjoQ= -cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca/go.mod h1:PkIAKXZvaxrTRc++z53XMRvFk8AcGGWYHcMIPzVYX9c= -cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg= -cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= +cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk= +cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4= +cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= +cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw= cosmossdk.io/tools/rosetta v0.2.1/go.mod h1:Pqdc1FdvkNV3LcNIkYWt2RQY6IP1ge6YWZk8MhhO9Hw= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= @@ -211,8 +211,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= -github.com/CosmWasm/wasmvm v1.3.0 h1:x12X4bKlUPS7TT9QQP45+fJo2sp30GEbiSSgb9jsec8= -github.com/CosmWasm/wasmvm v1.3.0/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8J7KFtkc= +github.com/CosmWasm/wasmvm v1.4.1 h1:YgodVlBrXa2HJZzOXjWDH0EIRwQzK3zuA73dDPRRLS4= +github.com/CosmWasm/wasmvm v1.4.1/go.mod h1:fXB+m2gyh4v9839zlIXdMZGeLAxqUdYdFQqYsTha2hc= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= @@ -225,7 +225,6 @@ github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrd github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/adlio/schema v1.3.3 h1:oBJn8I02PyTB466pZO1UZEn1TV5XLlifBSyMrmHl/1I= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= -github.com/alecthomas/participle/v2 v2.0.0-alpha7 h1:cK4vjj0VSgb3lN1nuKA5F7dw+1s1pWBe5bx7nNCnN+c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -298,8 +297,13 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E= github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw= -github.com/cockroachdb/apd/v3 v3.1.0 h1:MK3Ow7LH0W8zkd5GMKA1PvS9qG3bWFI95WaVNfyZJ/w= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= +github.com/cockroachdb/errors v1.10.0 h1:lfxS8zZz1+OjtV4MtNWgboi/W5tyLEB6VQZBXN+0VUU= +github.com/cockroachdb/errors v1.10.0/go.mod h1:lknhIsEVQ9Ss/qKDBQS/UqFSvPQjOwNq2qyKAxtHRqE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= +github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= +github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA= github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c= @@ -320,8 +324,8 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= github.com/cosmos/cosmos-proto v1.0.0-beta.2 h1:X3OKvWgK9Gsejo0F1qs5l8Qn6xJV/AzgIWR2wZ8Nua8= github.com/cosmos/cosmos-proto v1.0.0-beta.2/go.mod h1:+XRCLJ14pr5HFEHIUcn51IKXD1Fy3rkEQqt4WqmN4V0= -github.com/cosmos/cosmos-sdk v0.47.4 h1:FVUpEprm58nMmBX4xkRdMDaIG5Nr4yy92HZAfGAw9bg= -github.com/cosmos/cosmos-sdk v0.47.4/go.mod h1:R5n+uM7vguVPFap4pgkdvQCT1nVo/OtPwrlAU40rvok= +github.com/cosmos/cosmos-sdk v0.47.5 h1:n1+WjP/VM/gAEOx3TqU2/Ny734rj/MX1kpUnn7zVJP8= +github.com/cosmos/cosmos-sdk v0.47.5/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -330,10 +334,10 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoKuI= github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek= -github.com/cosmos/iavl v0.20.0 h1:fTVznVlepH0KK8NyKq8w+U7c2L6jofa27aFX6YGlm38= -github.com/cosmos/iavl v0.20.0/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= -github.com/cosmos/ibc-go/v7 v7.2.0 h1:dx0DLUl7rxdyZ8NiT6UsrbzKOJx/w7s+BOaewFRH6cg= -github.com/cosmos/ibc-go/v7 v7.2.0/go.mod h1:OOcjKIRku/j1Xs1RgKK0yvKRrJ5iFuZYMetR1n3yMlc= +github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg= +github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= +github.com/cosmos/ibc-go/v7 v7.3.0 h1:QtGeVMi/3JeLWuvEuC60sBHpAF40Oenx/y+bP8+wRRw= +github.com/cosmos/ibc-go/v7 v7.3.0/go.mod h1:mUmaHFXpXrEdcxfdXyau+utZf14pGKVUiXwYftRZZfQ= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= @@ -349,8 +353,6 @@ github.com/creachadair/taskgroup v0.4.2 h1:jsBLdAJE42asreGss2xZGZ8fJra7WtwnHWeJF github.com/creachadair/taskgroup v0.4.2/go.mod h1:qiXUOSrbwAY3u0JPGTzObbE3yf9hcXHDKBZ2ZjpCbgM= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbdT9+Q5kgLpmmsHYl0= -github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -406,11 +408,14 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/getsentry/sentry-go v0.23.0 h1:dn+QRCeJv4pPt9OjVXiMcGIBIefaTJPw/h0bZWO05nE= +github.com/getsentry/sentry-go v0.23.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -431,8 +436,8 @@ github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= -github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= +github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -441,12 +446,11 @@ github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofrs/uuid v4.3.0+incompatible h1:CaSVZxm5B+7o45rtab4jC2G37WGYX1zQfuU2i6DSvnc= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/googleapis v1.4.1-0.20201022092350-68b0159b7869/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c= github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0= @@ -693,6 +697,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -811,6 +816,7 @@ github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 h1:hDSdbBuw3Lefr6 github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -858,19 +864,20 @@ github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Ung github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/regen-network/gocuke v0.6.2 h1:pHviZ0kKAq2U2hN2q3smKNxct6hS0mGByFMHGnWA97M= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo= github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc= -github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= +github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -1019,8 +1026,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= -golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU= -golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb h1:xIApU0ow1zwMa2uL1VDNeQlNVFTWMQxZUZCMDy0Q4Us= +golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1047,7 +1054,7 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1250,8 +1257,8 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1268,8 +1275,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/proto/cosmwasm/wasm/v1/authz.proto b/proto/cosmwasm/wasm/v1/authz.proto index cca4f033d7..713369fb5c 100644 --- a/proto/cosmwasm/wasm/v1/authz.proto +++ b/proto/cosmwasm/wasm/v1/authz.proto @@ -4,12 +4,25 @@ package cosmwasm.wasm.v1; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; import "cosmos/base/v1beta1/coin.proto"; +import "cosmwasm/wasm/v1/types.proto"; import "google/protobuf/any.proto"; import "amino/amino.proto"; option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; option (gogoproto.goproto_getters_all) = false; +// StoreCodeAuthorization defines authorization for wasm code upload. +// Since: wasmd 0.42 +message StoreCodeAuthorization { + option (amino.name) = "wasm/StoreCodeAuthorization"; + option (cosmos_proto.implements_interface) = + "cosmos.authz.v1beta1.Authorization"; + + // Grants for code upload + repeated CodeGrant grants = 1 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + // ContractExecutionAuthorization defines authorization for wasm execute. // Since: wasmd 0.30 message ContractExecutionAuthorization { @@ -34,6 +47,18 @@ message ContractMigrationAuthorization { [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; } +// CodeGrant a granted permission for a single code +message CodeGrant { + // CodeHash is the unique identifier created by wasmvm + // Wildcard "*" is used to specify any kind of grant. + bytes code_hash = 1; + + // InstantiatePermission is the superset access control to apply + // on contract creation. + // Optional + AccessConfig instantiate_permission = 2; +} + // ContractGrant a granted permission for a single contract // Since: wasmd 0.30 message ContractGrant { diff --git a/proto/cosmwasm/wasm/v1/proposal.proto b/proto/cosmwasm/wasm/v1/proposal.proto deleted file mode 100644 index af47c6afbd..0000000000 --- a/proto/cosmwasm/wasm/v1/proposal.proto +++ /dev/null @@ -1,330 +0,0 @@ -syntax = "proto3"; -package cosmwasm.wasm.v1; - -import "gogoproto/gogo.proto"; -import "cosmos_proto/cosmos.proto"; -import "cosmos/base/v1beta1/coin.proto"; -import "cosmwasm/wasm/v1/types.proto"; -import "amino/amino.proto"; - -option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; -option (gogoproto.goproto_stringer_all) = false; -option (gogoproto.goproto_getters_all) = false; -option (gogoproto.equal_all) = true; - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit StoreCodeProposal. To submit WASM code to the system, -// a simple MsgStoreCode can be invoked from the x/gov module via -// a v1 governance proposal. -message StoreCodeProposal { - option deprecated = true; - option (amino.name) = "wasm/StoreCodeProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // RunAs is the address that is passed to the contract's environment as sender - string run_as = 3; - // WASMByteCode can be raw or gzip compressed - bytes wasm_byte_code = 4 [ (gogoproto.customname) = "WASMByteCode" ]; - // Used in v1beta1 - reserved 5, 6; - // InstantiatePermission to apply on contract creation, optional - AccessConfig instantiate_permission = 7; - // UnpinCode code on upload, optional - bool unpin_code = 8; - // Source is the URL where the code is hosted - string source = 9; - // Builder is the docker image used to build the code deterministically, used - // for smart contract verification - string builder = 10; - // CodeHash is the SHA256 sum of the code outputted by builder, used for smart - // contract verification - bytes code_hash = 11; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit InstantiateContractProposal. To instantiate a contract, -// a simple MsgInstantiateContract can be invoked from the x/gov module via -// a v1 governance proposal. -message InstantiateContractProposal { - option deprecated = true; - option (amino.name) = "wasm/InstantiateContractProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // RunAs is the address that is passed to the contract's environment as sender - string run_as = 3; - // Admin is an optional address that can execute migrations - string admin = 4; - // CodeID is the reference to the stored WASM code - uint64 code_id = 5 [ (gogoproto.customname) = "CodeID" ]; - // Label is optional metadata to be stored with a constract instance. - string label = 6; - // Msg json encoded message to be passed to the contract on instantiation - bytes msg = 7 [ (gogoproto.casttype) = "RawContractMessage" ]; - // Funds coins that are transferred to the contract on instantiation - repeated cosmos.base.v1beta1.Coin funds = 8 [ - (gogoproto.nullable) = false, - (amino.dont_omitempty) = true, - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" - ]; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit InstantiateContract2Proposal. To instantiate contract 2, -// a simple MsgInstantiateContract2 can be invoked from the x/gov module via -// a v1 governance proposal. -message InstantiateContract2Proposal { - option deprecated = true; - option (amino.name) = "wasm/InstantiateContract2Proposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // RunAs is the address that is passed to the contract's enviroment as sender - string run_as = 3; - // Admin is an optional address that can execute migrations - string admin = 4; - // CodeID is the reference to the stored WASM code - uint64 code_id = 5 [ (gogoproto.customname) = "CodeID" ]; - // Label is optional metadata to be stored with a constract instance. - string label = 6; - // Msg json encode message to be passed to the contract on instantiation - bytes msg = 7 [ (gogoproto.casttype) = "RawContractMessage" ]; - // Funds coins that are transferred to the contract on instantiation - repeated cosmos.base.v1beta1.Coin funds = 8 [ - (gogoproto.nullable) = false, - (amino.dont_omitempty) = true, - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" - ]; - // Salt is an arbitrary value provided by the sender. Size can be 1 to 64. - bytes salt = 9; - // FixMsg include the msg value into the hash for the predictable address. - // Default is false - bool fix_msg = 10; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit MigrateContractProposal. To migrate a contract, -// a simple MsgMigrateContract can be invoked from the x/gov module via -// a v1 governance proposal. -message MigrateContractProposal { - option deprecated = true; - option (amino.name) = "wasm/MigrateContractProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // Note: skipping 3 as this was previously used for unneeded run_as - - // Contract is the address of the smart contract - string contract = 4; - // CodeID references the new WASM code - uint64 code_id = 5 [ (gogoproto.customname) = "CodeID" ]; - // Msg json encoded message to be passed to the contract on migration - bytes msg = 6 [ (gogoproto.casttype) = "RawContractMessage" ]; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit SudoContractProposal. To call sudo on a contract, -// a simple MsgSudoContract can be invoked from the x/gov module via -// a v1 governance proposal. -message SudoContractProposal { - option deprecated = true; - option (amino.name) = "wasm/SudoContractProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // Contract is the address of the smart contract - string contract = 3; - // Msg json encoded message to be passed to the contract as sudo - bytes msg = 4 [ (gogoproto.casttype) = "RawContractMessage" ]; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit ExecuteContractProposal. To call execute on a contract, -// a simple MsgExecuteContract can be invoked from the x/gov module via -// a v1 governance proposal. -message ExecuteContractProposal { - option deprecated = true; - option (amino.name) = "wasm/ExecuteContractProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // RunAs is the address that is passed to the contract's environment as sender - string run_as = 3; - // Contract is the address of the smart contract - string contract = 4; - // Msg json encoded message to be passed to the contract as execute - bytes msg = 5 [ (gogoproto.casttype) = "RawContractMessage" ]; - // Funds coins that are transferred to the contract on instantiation - repeated cosmos.base.v1beta1.Coin funds = 6 [ - (gogoproto.nullable) = false, - (amino.dont_omitempty) = true, - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" - ]; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit UpdateAdminProposal. To set an admin for a contract, -// a simple MsgUpdateAdmin can be invoked from the x/gov module via -// a v1 governance proposal. -message UpdateAdminProposal { - option deprecated = true; - option (amino.name) = "wasm/UpdateAdminProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // NewAdmin address to be set - string new_admin = 3 [ (gogoproto.moretags) = "yaml:\"new_admin\"" ]; - // Contract is the address of the smart contract - string contract = 4; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit ClearAdminProposal. To clear the admin of a contract, -// a simple MsgClearAdmin can be invoked from the x/gov module via -// a v1 governance proposal. -message ClearAdminProposal { - option deprecated = true; - option (amino.name) = "wasm/ClearAdminProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // Contract is the address of the smart contract - string contract = 3; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit PinCodesProposal. To pin a set of code ids in the wasmvm -// cache, a simple MsgPinCodes can be invoked from the x/gov module via -// a v1 governance proposal. -message PinCodesProposal { - option deprecated = true; - option (amino.name) = "wasm/PinCodesProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; - // Description is a human readable text - string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; - // CodeIDs references the new WASM codes - repeated uint64 code_ids = 3 [ - (gogoproto.customname) = "CodeIDs", - (gogoproto.moretags) = "yaml:\"code_ids\"" - ]; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit UnpinCodesProposal. To unpin a set of code ids in the wasmvm -// cache, a simple MsgUnpinCodes can be invoked from the x/gov module via -// a v1 governance proposal. -message UnpinCodesProposal { - option deprecated = true; - option (amino.name) = "wasm/UnpinCodesProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; - // Description is a human readable text - string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; - // CodeIDs references the WASM codes - repeated uint64 code_ids = 3 [ - (gogoproto.customname) = "CodeIDs", - (gogoproto.moretags) = "yaml:\"code_ids\"" - ]; -} - -// AccessConfigUpdate contains the code id and the access config to be -// applied. -message AccessConfigUpdate { - // CodeID is the reference to the stored WASM code to be updated - uint64 code_id = 1 [ (gogoproto.customname) = "CodeID" ]; - // InstantiatePermission to apply to the set of code ids - AccessConfig instantiate_permission = 2 - [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit UpdateInstantiateConfigProposal. To update instantiate config -// to a set of code ids, a simple MsgUpdateInstantiateConfig can be invoked from -// the x/gov module via a v1 governance proposal. -message UpdateInstantiateConfigProposal { - option deprecated = true; - option (amino.name) = "wasm/UpdateInstantiateConfigProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; - // Description is a human readable text - string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; - // AccessConfigUpdate contains the list of code ids and the access config - // to be applied. - repeated AccessConfigUpdate access_config_updates = 3 - [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; -} - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit StoreAndInstantiateContractProposal. To store and instantiate -// the contract, a simple MsgStoreAndInstantiateContract can be invoked from -// the x/gov module via a v1 governance proposal. -message StoreAndInstantiateContractProposal { - option deprecated = true; - option (amino.name) = "wasm/StoreAndInstantiateContractProposal"; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - // Title is a short summary - string title = 1; - // Description is a human readable text - string description = 2; - // RunAs is the address that is passed to the contract's environment as sender - string run_as = 3; - // WASMByteCode can be raw or gzip compressed - bytes wasm_byte_code = 4 [ (gogoproto.customname) = "WASMByteCode" ]; - // InstantiatePermission to apply on contract creation, optional - AccessConfig instantiate_permission = 5; - // UnpinCode code on upload, optional - bool unpin_code = 6; - // Admin is an optional address that can execute migrations - string admin = 7; - // Label is optional metadata to be stored with a constract instance. - string label = 8; - // Msg json encoded message to be passed to the contract on instantiation - bytes msg = 9 [ (gogoproto.casttype) = "RawContractMessage" ]; - // Funds coins that are transferred to the contract on instantiation - repeated cosmos.base.v1beta1.Coin funds = 10 [ - (gogoproto.nullable) = false, - (amino.dont_omitempty) = true, - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" - ]; - // Source is the URL where the code is hosted - string source = 11; - // Builder is the docker image used to build the code deterministically, used - // for smart contract verification - string builder = 12; - // CodeHash is the SHA256 sum of the code outputted by builder, used for smart - // contract verification - bytes code_hash = 13; -} diff --git a/proto/cosmwasm/wasm/v1/tx.proto b/proto/cosmwasm/wasm/v1/tx.proto index 1ce7823c1b..3e0fadb58c 100644 --- a/proto/cosmwasm/wasm/v1/tx.proto +++ b/proto/cosmwasm/wasm/v1/tx.proto @@ -27,7 +27,7 @@ service Msg { rpc ExecuteContract(MsgExecuteContract) returns (MsgExecuteContractResponse); // Migrate runs a code upgrade/ downgrade for a smart contract rpc MigrateContract(MsgMigrateContract) returns (MsgMigrateContractResponse); - // UpdateAdmin sets a new admin for a smart contract + // UpdateAdmin sets a new admin for a smart contract rpc UpdateAdmin(MsgUpdateAdmin) returns (MsgUpdateAdminResponse); // ClearAdmin removes any admin stored for a smart contract rpc ClearAdmin(MsgClearAdmin) returns (MsgClearAdminResponse); @@ -70,6 +70,17 @@ service Msg { // The authority is defined in the keeper. rpc AddCodeUploadParamsAddresses(MsgAddCodeUploadParamsAddresses) returns (MsgAddCodeUploadParamsAddressesResponse); + // StoreAndMigrateContract defines a governance operation for storing + // and migrating the contract. The authority is defined in the keeper. + // + // Since: 0.42 + rpc StoreAndMigrateContract(MsgStoreAndMigrateContract) + returns (MsgStoreAndMigrateContractResponse); + // UpdateContractLabel sets a new label for a smart contract + // + // Since: 0.43 + rpc UpdateContractLabel(MsgUpdateContractLabel) + returns (MsgUpdateContractLabelResponse); } // MsgStoreCode submit Wasm code to the system @@ -241,6 +252,16 @@ message MsgClearAdmin { // MsgClearAdminResponse returns empty data message MsgClearAdminResponse {} +// AccessConfigUpdate contains the code id and the access config to be +// applied. +message AccessConfigUpdate { + // CodeID is the reference to the stored WASM code to be updated + uint64 code_id = 1 [ (gogoproto.customname) = "CodeID" ]; + // InstantiatePermission to apply to the set of code ids + AccessConfig instantiate_permission = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + // MsgUpdateInstantiateConfig updates instantiate config for a smart contract message MsgUpdateInstantiateConfig { option (amino.name) = "wasm/MsgUpdateInstantiateConfig"; @@ -430,4 +451,53 @@ message MsgRemoveCodeUploadParamsAddresses { // MsgRemoveCodeUploadParamsAddressesResponse defines the response // structure for executing a MsgRemoveCodeUploadParamsAddresses message. -message MsgRemoveCodeUploadParamsAddressesResponse {} \ No newline at end of file +message MsgRemoveCodeUploadParamsAddressesResponse {} + +// MsgStoreAndMigrateContract is the MsgStoreAndMigrateContract +// request type. +// +// Since: 0.42 +message MsgStoreAndMigrateContract { + option (amino.name) = "wasm/MsgStoreAndMigrateContract"; + option (cosmos.msg.v1.signer) = "authority"; + + // Authority is the address of the governance account. + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // WASMByteCode can be raw or gzip compressed + bytes wasm_byte_code = 2 [ (gogoproto.customname) = "WASMByteCode" ]; + // InstantiatePermission to apply on contract creation, optional + AccessConfig instantiate_permission = 3; + // Contract is the address of the smart contract + string contract = 4; + // Msg json encoded message to be passed to the contract on migration + bytes msg = 5 [ (gogoproto.casttype) = "RawContractMessage" ]; +} + +// MsgStoreAndMigrateContractResponse defines the response structure +// for executing a MsgStoreAndMigrateContract message. +// +// Since: 0.42 +message MsgStoreAndMigrateContractResponse { + // CodeID is the reference to the stored WASM code + uint64 code_id = 1 [ (gogoproto.customname) = "CodeID" ]; + // Checksum is the sha256 hash of the stored code + bytes checksum = 2; + // Data contains bytes to returned from the contract + bytes data = 3; +} + +// MsgUpdateContractLabel sets a new label for a smart contract +message MsgUpdateContractLabel { + option (amino.name) = "wasm/MsgUpdateContractLabel"; + option (cosmos.msg.v1.signer) = "sender"; + + // Sender is the that actor that signed the messages + string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // NewLabel string to be set + string new_label = 2; + // Contract is the address of the smart contract + string contract = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +// MsgUpdateContractLabelResponse returns empty data +message MsgUpdateContractLabelResponse {} \ No newline at end of file diff --git a/tests/e2e/gov_test.go b/tests/e2e/gov_test.go index 1db5eca931..33b7fd34a4 100644 --- a/tests/e2e/gov_test.go +++ b/tests/e2e/gov_test.go @@ -5,12 +5,13 @@ import ( "time" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/tests/e2e" diff --git a/tests/e2e/grants_test.go b/tests/e2e/grants_test.go index 2a6ed79357..f7102d4133 100644 --- a/tests/e2e/grants_test.go +++ b/tests/e2e/grants_test.go @@ -2,17 +2,21 @@ package e2e_test import ( "fmt" + "os" "testing" "time" + wasmvm "github.com/CosmWasm/wasmvm" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/tests/e2e" "github.com/CosmWasm/wasmd/x/wasm/ibctesting" @@ -117,3 +121,219 @@ func TestGrants(t *testing.T) { }) } } + +func TestStoreCodeGrant(t *testing.T) { + reflectWasmCode, err := os.ReadFile("../../x/wasm/keeper/testdata/reflect_1_1.wasm") + require.NoError(t, err) + + reflectCodeChecksum, err := wasmvm.CreateChecksum(reflectWasmCode) + require.NoError(t, err) + + coord := ibctesting.NewCoordinator(t, 1) + chain := coord.GetChain(ibctesting.GetChainID(1)) + + granterAddr := chain.SenderAccount.GetAddress() + granteePrivKey := secp256k1.GenPrivKey() + granteeAddr := sdk.AccAddress(granteePrivKey.PubKey().Address().Bytes()) + otherPrivKey := secp256k1.GenPrivKey() + otherAddr := sdk.AccAddress(otherPrivKey.PubKey().Address().Bytes()) + + chain.Fund(granteeAddr, sdk.NewInt(1_000_000)) + chain.Fund(otherAddr, sdk.NewInt(1_000_000)) + assert.Equal(t, sdk.NewInt(1_000_000), chain.Balance(granteeAddr, sdk.DefaultBondDenom).Amount) + + specs := map[string]struct { + codeHash []byte + instantiatePermission types.AccessConfig + senderKey cryptotypes.PrivKey + expErr *errorsmod.Error + }{ + "any code hash": { + codeHash: []byte("*"), + instantiatePermission: types.AllowEverybody, + senderKey: granteePrivKey, + }, + "match code hash and permission": { + codeHash: reflectCodeChecksum, + instantiatePermission: types.AllowEverybody, + senderKey: granteePrivKey, + }, + "not match code hash": { + codeHash: []byte("any_valid_checksum"), + instantiatePermission: types.AllowEverybody, + senderKey: granteePrivKey, + expErr: sdkerrors.ErrUnauthorized, + }, + "not match permission": { + codeHash: []byte("*"), + instantiatePermission: types.AllowNobody, + senderKey: granteePrivKey, + expErr: sdkerrors.ErrUnauthorized, + }, + "non authorized sender address": { + codeHash: []byte("*"), + instantiatePermission: types.AllowEverybody, + senderKey: otherPrivKey, + expErr: authz.ErrNoAuthorizationFound, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + // setup grant + grant, err := types.NewCodeGrant(spec.codeHash, &spec.instantiatePermission) + require.NoError(t, err) + authorization := types.NewStoreCodeAuthorization(*grant) + expiry := time.Now().Add(time.Hour) + grantMsg, err := authz.NewMsgGrant(granterAddr, granteeAddr, authorization, &expiry) + require.NoError(t, err) + _, err = chain.SendMsgs(grantMsg) + require.NoError(t, err) + + // when + execMsg := authz.NewMsgExec(spec.senderKey.PubKey().Address().Bytes(), []sdk.Msg{&types.MsgStoreCode{ + Sender: granterAddr.String(), + WASMByteCode: reflectWasmCode, + InstantiatePermission: &types.AllowEverybody, + }}) + _, gotErr := chain.SendNonDefaultSenderMsgs(spec.senderKey, &execMsg) + + // then + if spec.expErr != nil { + require.True(t, spec.expErr.Is(gotErr)) + return + } + require.NoError(t, gotErr) + }) + } +} + +func TestGzipStoreCodeGrant(t *testing.T) { + hackatomWasmCode, err := os.ReadFile("../../x/wasm/keeper/testdata/hackatom.wasm") + require.NoError(t, err) + + hackatomGzipWasmCode, err := os.ReadFile("../../x/wasm/keeper/testdata/hackatom.wasm.gzip") + require.NoError(t, err) + + hackatomCodeChecksum, err := wasmvm.CreateChecksum(hackatomWasmCode) + require.NoError(t, err) + + coord := ibctesting.NewCoordinator(t, 1) + chain := coord.GetChain(ibctesting.GetChainID(1)) + + granterAddr := chain.SenderAccount.GetAddress() + granteePrivKey := secp256k1.GenPrivKey() + granteeAddr := sdk.AccAddress(granteePrivKey.PubKey().Address().Bytes()) + otherPrivKey := secp256k1.GenPrivKey() + otherAddr := sdk.AccAddress(otherPrivKey.PubKey().Address().Bytes()) + + chain.Fund(granteeAddr, sdk.NewInt(1_000_000)) + chain.Fund(otherAddr, sdk.NewInt(1_000_000)) + assert.Equal(t, sdk.NewInt(1_000_000), chain.Balance(granteeAddr, sdk.DefaultBondDenom).Amount) + + specs := map[string]struct { + codeHash []byte + instantiatePermission types.AccessConfig + senderKey cryptotypes.PrivKey + expErr *errorsmod.Error + }{ + "any code hash": { + codeHash: []byte("*"), + instantiatePermission: types.AllowEverybody, + senderKey: granteePrivKey, + }, + "match code hash and permission": { + codeHash: hackatomCodeChecksum, + instantiatePermission: types.AllowEverybody, + senderKey: granteePrivKey, + }, + "not match code hash": { + codeHash: []byte("any_valid_checksum"), + instantiatePermission: types.AllowEverybody, + senderKey: granteePrivKey, + expErr: sdkerrors.ErrUnauthorized, + }, + "not match permission": { + codeHash: []byte("*"), + instantiatePermission: types.AllowNobody, + senderKey: granteePrivKey, + expErr: sdkerrors.ErrUnauthorized, + }, + "non authorized sender address": { + codeHash: []byte("*"), + instantiatePermission: types.AllowEverybody, + senderKey: otherPrivKey, + expErr: authz.ErrNoAuthorizationFound, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + // setup grant + grant, err := types.NewCodeGrant(spec.codeHash, &spec.instantiatePermission) + require.NoError(t, err) + authorization := types.NewStoreCodeAuthorization(*grant) + expiry := time.Now().Add(time.Hour) + grantMsg, err := authz.NewMsgGrant(granterAddr, granteeAddr, authorization, &expiry) + require.NoError(t, err) + _, err = chain.SendMsgs(grantMsg) + require.NoError(t, err) + + // when + execMsg := authz.NewMsgExec(spec.senderKey.PubKey().Address().Bytes(), []sdk.Msg{&types.MsgStoreCode{ + Sender: granterAddr.String(), + WASMByteCode: hackatomGzipWasmCode, + InstantiatePermission: &types.AllowEverybody, + }}) + _, gotErr := chain.SendNonDefaultSenderMsgs(spec.senderKey, &execMsg) + + // then + if spec.expErr != nil { + require.True(t, spec.expErr.Is(gotErr)) + return + } + require.NoError(t, gotErr) + }) + } +} + +func TestBrokenGzipStoreCodeGrant(t *testing.T) { + brokenGzipWasmCode, err := os.ReadFile("../../x/wasm/keeper/testdata/broken_crc.gzip") + require.NoError(t, err) + + coord := ibctesting.NewCoordinator(t, 1) + chain := coord.GetChain(ibctesting.GetChainID(1)) + + granterAddr := chain.SenderAccount.GetAddress() + granteePrivKey := secp256k1.GenPrivKey() + granteeAddr := sdk.AccAddress(granteePrivKey.PubKey().Address().Bytes()) + otherPrivKey := secp256k1.GenPrivKey() + otherAddr := sdk.AccAddress(otherPrivKey.PubKey().Address().Bytes()) + + chain.Fund(granteeAddr, sdk.NewInt(1_000_000)) + chain.Fund(otherAddr, sdk.NewInt(1_000_000)) + assert.Equal(t, sdk.NewInt(1_000_000), chain.Balance(granteeAddr, sdk.DefaultBondDenom).Amount) + + codeHash := []byte("*") + instantiatePermission := types.AllowEverybody + senderKey := granteePrivKey + + // setup grant + grant, err := types.NewCodeGrant(codeHash, &instantiatePermission) + require.NoError(t, err) + authorization := types.NewStoreCodeAuthorization(*grant) + expiry := time.Now().Add(time.Hour) + grantMsg, err := authz.NewMsgGrant(granterAddr, granteeAddr, authorization, &expiry) + require.NoError(t, err) + _, err = chain.SendMsgs(grantMsg) + require.NoError(t, err) + + // when + execMsg := authz.NewMsgExec(senderKey.PubKey().Address().Bytes(), []sdk.Msg{&types.MsgStoreCode{ + Sender: granterAddr.String(), + WASMByteCode: brokenGzipWasmCode, + InstantiatePermission: &types.AllowEverybody, + }}) + _, gotErr := chain.SendNonDefaultSenderMsgs(senderKey, &execMsg) + + // then + require.Error(t, gotErr) +} diff --git a/tests/e2e/group_test.go b/tests/e2e/group_test.go index 5fefc20021..8708c12639 100644 --- a/tests/e2e/group_test.go +++ b/tests/e2e/group_test.go @@ -4,18 +4,18 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/x/wasm/types" - "github.com/cometbft/cometbft/libs/rand" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/group" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/tests/e2e" "github.com/CosmWasm/wasmd/x/wasm/ibctesting" + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestGroupWithContract(t *testing.T) { diff --git a/tests/e2e/ibc_fees_test.go b/tests/e2e/ibc_fees_test.go index 8c8ca4fa63..ea6c72fe69 100644 --- a/tests/e2e/ibc_fees_test.go +++ b/tests/e2e/ibc_fees_test.go @@ -7,8 +7,6 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -17,6 +15,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -28,7 +29,7 @@ func TestIBCFeesTransfer(t *testing.T) { // with an ics-20 channel established // when an ics-29 fee is attached to an ibc package // then the relayer's payee is receiving the fee(s) on success - marshaler := app.MakeEncodingConfig().Marshaler + codec := app.MakeEncodingConfig().Codec coord := wasmibctesting.NewCoordinator(t, 2) chainA := coord.GetChain(wasmibctesting.GetChainID(1)) chainB := coord.GetChain(wasmibctesting.GetChainID(2)) @@ -42,12 +43,12 @@ func TestIBCFeesTransfer(t *testing.T) { path := wasmibctesting.NewPath(chainA, chainB) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: ibctransfertypes.PortID, - Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.Version})), + Version: string(codec.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.Version})), Order: channeltypes.UNORDERED, } path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{ PortID: ibctransfertypes.PortID, - Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.Version})), + Version: string(codec.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.Version})), Order: channeltypes.UNORDERED, } // with an ics-20 transfer channel setup between both chains @@ -113,7 +114,7 @@ func TestIBCFeesWasm(t *testing.T) { // and an ibc channel established // when an ics-29 fee is attached to an ibc package // then the relayer's payee is receiving the fee(s) on success - marshaler := app.MakeEncodingConfig().Marshaler + codec := app.MakeEncodingConfig().Codec coord := wasmibctesting.NewCoordinator(t, 2) chainA := coord.GetChain(wasmibctesting.GetChainID(1)) chainB := coord.GetChain(ibctesting.GetChainID(2)) @@ -137,12 +138,12 @@ func TestIBCFeesWasm(t *testing.T) { path := wasmibctesting.NewPath(chainA, chainB) path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{ PortID: ibcContractPortID, - Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.Version})), + Version: string(codec.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.Version})), Order: channeltypes.UNORDERED, } path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{ PortID: ibctransfertypes.PortID, - Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.Version})), + Version: string(codec.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.Version})), Order: channeltypes.UNORDERED, } // with an ics-29 fee enabled channel setup between both chains diff --git a/tests/e2e/ica_test.go b/tests/e2e/ica_test.go index 4234b0239b..d72617b2ff 100644 --- a/tests/e2e/ica_test.go +++ b/tests/e2e/ica_test.go @@ -5,11 +5,6 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/app" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/gogoproto/proto" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" hosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" @@ -19,6 +14,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" ) diff --git a/tests/e2e/reflect_helper.go b/tests/e2e/reflect_helper.go index c2ebcadbf2..26cb2798cd 100644 --- a/tests/e2e/reflect_helper.go +++ b/tests/e2e/reflect_helper.go @@ -5,9 +5,10 @@ import ( "testing" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/ibctesting" "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" @@ -16,6 +17,7 @@ import ( // InstantiateReflectContract store and instantiate a reflect contract instance func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.AccAddress { + t.Helper() codeID := chain.StoreCodeFile("../../x/wasm/keeper/testdata/reflect_1_1.wasm").CodeID contractAddr := chain.InstantiateContract(codeID, []byte(`{}`)) require.NotEmpty(t, contractAddr) @@ -24,6 +26,7 @@ func InstantiateReflectContract(t *testing.T, chain *ibctesting.TestChain) sdk.A // MustExecViaReflectContract submit execute message to send payload to reflect contract func MustExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...wasmvmtypes.CosmosMsg) *sdk.Result { + t.Helper() rsp, err := ExecViaReflectContract(t, chain, contractAddr, msgs) require.NoError(t, err) return rsp @@ -35,6 +38,7 @@ type sdkMessageType interface { } func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs ...T) *sdk.Result { + t.Helper() vmMsgs := make([]wasmvmtypes.CosmosMsg, len(msgs)) for i, m := range msgs { bz, err := chain.Codec.Marshal(m) @@ -53,6 +57,7 @@ func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *i // ExecViaReflectContract submit execute message to send payload to reflect contract func ExecViaReflectContract(t *testing.T, chain *ibctesting.TestChain, contractAddr sdk.AccAddress, msgs []wasmvmtypes.CosmosMsg) (*sdk.Result, error) { + t.Helper() require.NotEmpty(t, msgs) reflectSend := testdata.ReflectHandleMsg{ Reflect: &testdata.ReflectPayload{Msgs: msgs}, diff --git a/tests/system/cli.go b/tests/system/cli.go index 8d0ab87f9e..7aeddb38ab 100644 --- a/tests/system/cli.go +++ b/tests/system/cli.go @@ -2,6 +2,7 @@ package system import ( "fmt" + "io" "os/exec" "path/filepath" "strconv" @@ -196,6 +197,10 @@ func (c WasmdCli) CustomQuery(args ...string) string { // execute shell command func (c WasmdCli) run(args []string) (output string, ok bool) { + return c.runWithInput(args, nil) +} + +func (c WasmdCli) runWithInput(args []string, input io.Reader) (output string, ok bool) { if c.Debug { c.t.Logf("+++ running `%s %s`", c.execBinary, strings.Join(args, " ")) } @@ -207,6 +212,7 @@ func (c WasmdCli) run(args []string) (output string, ok bool) { }() cmd := exec.Command(locateExecutable("wasmd"), args...) //nolint:gosec cmd.Dir = workDir + cmd.Stdin = input return cmd.CombinedOutput() }() ok = c.assertErrorFn(c.t, gotErr, string(gotOut)) @@ -256,13 +262,22 @@ func (c WasmdCli) WasmExecute(contractAddr, msg, from string, args ...string) st // AddKey add key to default keyring. Returns address func (c WasmdCli) AddKey(name string) string { - cmd := c.withKeyringFlags("keys", "add", name, "--no-backup") + cmd := c.withKeyringFlags("keys", "add", name) //, "--no-backup") out, _ := c.run(cmd) addr := gjson.Get(out, "address").String() require.NotEmpty(c.t, addr, "got %q", out) return addr } +// AddKeyFromSeed recovers the key from given seed and add it to default keyring. Returns address +func (c WasmdCli) AddKeyFromSeed(name, mnemoic string) string { + cmd := c.withKeyringFlags("keys", "add", name, "--recover") + out, _ := c.runWithInput(cmd, strings.NewReader(mnemoic)) + addr := gjson.Get(out, "address").String() + require.NotEmpty(c.t, addr, "got %q", out) + return addr +} + // GetKeyAddr returns address func (c WasmdCli) GetKeyAddr(name string) string { cmd := c.withKeyringFlags("keys", "show", name, "-a") diff --git a/tests/system/fraud_test.go b/tests/system/fraud_test.go index 3fcde936a8..9e5e4d61d5 100644 --- a/tests/system/fraud_test.go +++ b/tests/system/fraud_test.go @@ -13,6 +13,7 @@ import ( ) func TestRecursiveMsgsExternalTrigger(t *testing.T) { + sut.ResetChain(t) const maxBlockGas = 2_000_000 sut.ModifyGenesisJSON(t, SetConsensusMaxGas(t, maxBlockGas)) sut.StartChain(t) diff --git a/tests/system/genesis_io.go b/tests/system/genesis_io.go index 841c18c924..23e54f09e8 100644 --- a/tests/system/genesis_io.go +++ b/tests/system/genesis_io.go @@ -31,3 +31,15 @@ func GetGenesisBalance(rawGenesis []byte, addr string) sdk.Coins { } return r } + +// SetCodeUploadPermission sets the code upload permissions +func SetCodeUploadPermission(t *testing.T, permission string, addresses ...string) GenesisMutator { + return func(genesis []byte) []byte { + t.Helper() + state, err := sjson.Set(string(genesis), "app_state.wasm.params.code_upload_access.permission", permission) + require.NoError(t, err) + state, err = sjson.Set(state, "app_state.wasm.params.code_upload_access.addresses", addresses) + require.NoError(t, err) + return []byte(state) + } +} diff --git a/tests/system/go.mod b/tests/system/go.mod index 87117ced69..28db89cd9f 100644 --- a/tests/system/go.mod +++ b/tests/system/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect - github.com/cosmos/cosmos-sdk v0.47.3 + github.com/cosmos/cosmos-sdk v0.47.5 github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/gogoproto v1.4.10 // indirect github.com/cosmos/iavl v0.20.0 // indirect @@ -18,27 +18,27 @@ require ( github.com/spf13/cast v1.5.1 // indirect github.com/spf13/cobra v1.6.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/stretchr/testify v1.8.2 + github.com/stretchr/testify v1.8.4 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect - google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect - google.golang.org/grpc v1.55.0 // indirect + google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect + google.golang.org/grpc v1.56.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) require ( - cosmossdk.io/math v1.0.1 + cosmossdk.io/math v1.1.2 github.com/cometbft/cometbft v0.37.2 github.com/tidwall/gjson v1.14.2 github.com/tidwall/sjson v1.2.5 - golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc + golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb ) require ( cosmossdk.io/api v0.3.1 // indirect cosmossdk.io/core v0.5.1 // indirect - cosmossdk.io/depinject v1.0.0-alpha.3 // indirect - cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/log v1.1.0 // indirect + cosmossdk.io/depinject v1.0.0-alpha.4 // indirect + cosmossdk.io/errors v1.0.0 // indirect + cosmossdk.io/log v1.2.1 // indirect cosmossdk.io/tools/rosetta v0.2.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -51,6 +51,9 @@ require ( github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cockroachdb/errors v1.10.0 // indirect + github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect + github.com/cockroachdb/redact v1.1.5 // indirect github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect github.com/cometbft/cometbft-db v0.7.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect @@ -69,12 +72,10 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/felixge/httpsnoop v1.0.2 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/gin-gonic/gin v1.8.1 // indirect + github.com/getsentry/sentry-go v0.23.0 // indirect github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect - github.com/go-playground/validator/v10 v10.11.1 // indirect - github.com/goccy/go-json v0.9.11 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -98,11 +99,13 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmhodges/levigo v1.0.0 // indirect github.com/klauspost/compress v1.16.3 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect github.com/lib/pq v1.10.7 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect github.com/minio/highwayhash v1.0.2 // indirect @@ -115,8 +118,9 @@ require ( github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/cors v1.8.3 // indirect - github.com/rs/zerolog v1.29.1 // indirect + github.com/rs/zerolog v1.30.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spf13/afero v1.9.3 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect @@ -130,12 +134,14 @@ require ( github.com/zondax/hid v0.9.1 // indirect github.com/zondax/ledger-go v0.14.1 // indirect go.etcd.io/bbolt v1.3.7 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/net v0.9.0 // indirect - golang.org/x/sys v0.7.0 // indirect - golang.org/x/term v0.7.0 // indirect - golang.org/x/text v0.9.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + golang.org/x/crypto v0.11.0 // indirect + golang.org/x/net v0.12.0 // indirect + golang.org/x/sys v0.11.0 // indirect + golang.org/x/term v0.10.0 // indirect + golang.org/x/text v0.12.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect + google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect diff --git a/tests/system/go.sum b/tests/system/go.sum index c031cbfa12..ff2c855499 100644 --- a/tests/system/go.sum +++ b/tests/system/go.sum @@ -39,14 +39,14 @@ cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= cosmossdk.io/core v0.5.1 h1:vQVtFrIYOQJDV3f7rw4pjjVqc1id4+mE0L9hHP66pyI= cosmossdk.io/core v0.5.1/go.mod h1:KZtwHCLjcFuo0nmDc24Xy6CRNEL9Vl/MeimQ2aC7NLE= -cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= -cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= -cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= -cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= -cosmossdk.io/log v1.1.0 h1:v0ogPHYeTzPcBTcPR1A3j1hkei4pZama8kz8LKlCMv0= -cosmossdk.io/log v1.1.0/go.mod h1:6zjroETlcDs+mm62gd8Ig7mZ+N+fVOZS91V17H+M4N4= -cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg= -cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= +cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= +cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= +cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= +cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0= +cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk= +cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4= +cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= +cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw= cosmossdk.io/tools/rosetta v0.2.1/go.mod h1:Pqdc1FdvkNV3LcNIkYWt2RQY6IP1ge6YWZk8MhhO9Hw= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= @@ -71,7 +71,6 @@ github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrd github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/adlio/schema v1.3.3 h1:oBJn8I02PyTB466pZO1UZEn1TV5XLlifBSyMrmHl/1I= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= -github.com/alecthomas/participle/v2 v2.0.0-alpha7 h1:cK4vjj0VSgb3lN1nuKA5F7dw+1s1pWBe5bx7nNCnN+c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -131,8 +130,13 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E= -github.com/cockroachdb/apd/v3 v3.1.0 h1:MK3Ow7LH0W8zkd5GMKA1PvS9qG3bWFI95WaVNfyZJ/w= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= +github.com/cockroachdb/errors v1.10.0 h1:lfxS8zZz1+OjtV4MtNWgboi/W5tyLEB6VQZBXN+0VUU= +github.com/cockroachdb/errors v1.10.0/go.mod h1:lknhIsEVQ9Ss/qKDBQS/UqFSvPQjOwNq2qyKAxtHRqE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= +github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= +github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA= github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c= @@ -153,8 +157,8 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= github.com/cosmos/cosmos-proto v1.0.0-beta.2 h1:X3OKvWgK9Gsejo0F1qs5l8Qn6xJV/AzgIWR2wZ8Nua8= github.com/cosmos/cosmos-proto v1.0.0-beta.2/go.mod h1:+XRCLJ14pr5HFEHIUcn51IKXD1Fy3rkEQqt4WqmN4V0= -github.com/cosmos/cosmos-sdk v0.47.3 h1:r0hGmZoAzP2D+MaPaFGHwAaTdFQq3pNpHaUp1BsffbM= -github.com/cosmos/cosmos-sdk v0.47.3/go.mod h1:c4OfLdAykA9zsj1CqrxBRqXzVz48I++JSvIMPSPcEmk= +github.com/cosmos/cosmos-sdk v0.47.5 h1:n1+WjP/VM/gAEOx3TqU2/Ny734rj/MX1kpUnn7zVJP8= +github.com/cosmos/cosmos-sdk v0.47.5/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -178,8 +182,6 @@ github.com/creachadair/taskgroup v0.4.2 h1:jsBLdAJE42asreGss2xZGZ8fJra7WtwnHWeJF github.com/creachadair/taskgroup v0.4.2/go.mod h1:qiXUOSrbwAY3u0JPGTzObbE3yf9hcXHDKBZ2ZjpCbgM= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbdT9+Q5kgLpmmsHYl0= -github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -234,11 +236,14 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/getsentry/sentry-go v0.23.0 h1:dn+QRCeJv4pPt9OjVXiMcGIBIefaTJPw/h0bZWO05nE= +github.com/getsentry/sentry-go v0.23.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -261,7 +266,6 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= -github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -272,11 +276,9 @@ github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= -github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofrs/uuid v4.3.0+incompatible h1:CaSVZxm5B+7o45rtab4jC2G37WGYX1zQfuU2i6DSvnc= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/googleapis v1.4.1-0.20201022092350-68b0159b7869/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c= github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0= @@ -475,6 +477,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -500,8 +503,8 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= -github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= @@ -585,6 +588,7 @@ github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 h1:hDSdbBuw3Lefr6 github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -632,19 +636,20 @@ github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Ung github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/regen-network/gocuke v0.6.2 h1:pHviZ0kKAq2U2hN2q3smKNxct6hS0mGByFMHGnWA97M= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo= github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc= -github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= +github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -703,8 +708,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= @@ -777,9 +782,8 @@ golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -791,8 +795,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= -golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU= -golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb h1:xIApU0ow1zwMa2uL1VDNeQlNVFTWMQxZUZCMDy0Q4Us= +golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -816,7 +820,7 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -861,10 +865,9 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= -golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -955,12 +958,12 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= -golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -970,8 +973,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1107,8 +1110,12 @@ google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20220314164441-57ef72a4c106/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= -google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 h1:DdoeryqhaXp1LtT/emMP1BRJPHHKFi5akj/nbx/zNTA= -google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s= +google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 h1:Au6te5hbKUV8pIYWHqOUZ1pva5qK/rwbIhoXEUB9Lu8= +google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:O9kGHb51iE/nOGvQaDUuadVYqovW56s5emA88lQnj6Y= +google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 h1:s5YSX+ZH5b5vS9rnpGymvIyMpLRJizowqDlOuyjXnTk= +google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -1135,8 +1142,8 @@ google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag= -google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= +google.golang.org/grpc v1.56.2 h1:fVRFRnXvU+x6C4IlHZewvJOVHoOv1TUuQyoRsYnB4bI= +google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -1152,8 +1159,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -1185,7 +1192,7 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= -gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/tests/system/permissioned_test.go b/tests/system/permissioned_test.go new file mode 100644 index 0000000000..b2da9b6444 --- /dev/null +++ b/tests/system/permissioned_test.go @@ -0,0 +1,62 @@ +//go:build system_test + +package system + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + "github.com/tidwall/gjson" +) + +func TestGrantStoreCodePermissionedChain(t *testing.T) { + cli := NewWasmdCLI(t, sut, verbose) + // set params to restrict chain + const chainAuthorityAddress = "wasm1pvuujjdk0xt043ga0j9nrfh5u8pzj4rpplyqkm" + sut.ModifyGenesisJSON(t, SetCodeUploadPermission(t, "AnyOfAddresses", chainAuthorityAddress)) + + recoveredAddress := cli.AddKeyFromSeed("chain_authority", "aisle ship absurd wedding arch admit fringe foam cluster tide trim aisle salad shiver tackle palm glance wrist valley hamster couch crystal frozen chronic") + require.Equal(t, chainAuthorityAddress, recoveredAddress) + devAccount := cli.AddKey("dev_account") + + sut.ModifyGenesisCLI(t, + []string{"genesis", "add-genesis-account", chainAuthorityAddress, "100000000stake"}, + ) + sut.ModifyGenesisCLI(t, + []string{"genesis", "add-genesis-account", devAccount, "100000000stake"}, + ) + + sut.StartChain(t) + + // query params + rsp := cli.CustomQuery("q", "wasm", "params") + permission := gjson.Get(rsp, "code_upload_access.permission").String() + addrRes := gjson.Get(rsp, "code_upload_access.addresses").Array() + require.Equal(t, 1, len(addrRes)) + + require.Equal(t, permission, "AnyOfAddresses") + require.Equal(t, chainAuthorityAddress, addrRes[0].Str) + + // chain_authority grant upload permission to dev_account + rsp = cli.CustomCommand("tx", "wasm", "grant", "store-code", devAccount, "*:*", "--from="+chainAuthorityAddress) + RequireTxSuccess(t, rsp) + + // dev_account store code fails as the address is not in the code-upload accept-list + rsp = cli.CustomCommand("tx", "wasm", "store", "./testdata/hackatom.wasm.gzip", "--from="+devAccount, "--gas=1500000", "--fees=2stake") + RequireTxFailure(t, rsp) + + // create tx should work for addresses in the accept-list + args := cli.withTXFlags("tx", "wasm", "store", "./testdata/hackatom.wasm.gzip", "--from="+chainAuthorityAddress, "--generate-only") + tx, ok := cli.run(args) + require.True(t, ok) + + pathToTx := filepath.Join(t.TempDir(), "tx.json") + err := os.WriteFile(pathToTx, []byte(tx), os.FileMode(0o744)) + require.NoError(t, err) + + // store code via authz execution uses the given grant and should succeed + rsp = cli.CustomCommand("tx", "authz", "exec", pathToTx, "--from="+devAccount, "--gas=1500000", "--fees=2stake") + RequireTxSuccess(t, rsp) +} diff --git a/x/wasm/Governance.md b/x/wasm/Governance.md index da47240c14..59033db0fb 100644 --- a/x/wasm/Governance.md +++ b/x/wasm/Governance.md @@ -6,45 +6,28 @@ a high-level, technical introduction meant to provide context before looking into the code, or constructing proposals. ## Proposal Types -We have added 9 new wasm specific proposal types that cover the contract's live cycle and authorization: +We have added 15 new wasm specific proposal messages that cover the contract's live cycle and authorization: -* `StoreCodeProposal` - upload a wasm binary -* `InstantiateContractProposal` - instantiate a wasm contract -* `MigrateContractProposal` - migrate a wasm contract to a new code version -* `SudoContractProposal` - call into the protected `sudo` entry point of a contract -* `ExecuteContractProposal` - execute a wasm contract as an arbitrary user -* `UpdateAdminProposal` - set a new admin for a contract -* `ClearAdminProposal` - clear admin for a contract to prevent further migrations -* `PinCodes` - pin the given code ids in cache. This trades memory for reduced startup time and lowers gas cost -* `UnpinCodes` - unpin the given code ids from the cache. This frees up memory and returns to standard speed and gas cost -* `UpdateInstantiateConfigProposal` - update instantiate permissions to a list of given code ids. -* `StoreAndInstantiateContractProposal` - upload and instantiate a wasm contract. - -For details see the proposal type [implementation](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/proposal.go) - -### Unit tests -[Proposal type validations](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/proposal_test.go) - -## Proposal Handler -The [wasmd proposal_handler](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/keeper/proposal_handler.go) implements the `gov.Handler` function -and executes the wasmd proposal types after a successful tally. - -The proposal handler uses a [`GovAuthorizationPolicy`](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/keeper/authz_policy.go#L29) to bypass the existing contract's authorization policy. - -### Tests -* [Integration: Submit and execute proposal](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/keeper/proposal_integration_test.go) - -## Gov Integration -The wasmd proposal handler can be added to the gov router in the [abci app](https://github.com/CosmWasm/wasmd/blob/master/app/app.go#L306) -to receive proposal execution calls. -```go -govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, enabledProposals)) -``` +* `MsgStoreCode` - upload a wasm binary +* `MsgInstantiateContract` - instantiate a wasm contract +* `MsgInstantiateContract2` - instantiate a wasm contract with a predictable address +* `MsgMigrateContract` - migrate a wasm contract to a new code version +* `MsgSudoContract` - call into the protected `sudo` entry point of a contract +* `MsgExecuteContract` - execute a wasm contract as an arbitrary user +* `MsgUpdateAdmin` - set a new admin for a contract +* `MsgClearAdmin` - clear admin for a contract to prevent further migrations +* `MsgPinCodes` - pin the given code ids in cache. This trades memory for reduced startup time and lowers gas cost +* `MsgUnpinCodes` - unpin the given code ids from the cache. This frees up memory and returns to standard speed and gas cost +* `MsgUpdateInstantiateConfig` - update instantiate permissions to a list of given code ids. +* `MsgStoreAndInstantiateContract` - upload and instantiate a wasm contract. +* `MsgRemoveCodeUploadParamsAddresses` - remove addresses from code upload params. +* `MsgAddCodeUploadParamsAddresses` - add addresses to code upload params. +* `MsgStoreAndMigrateContract` - upload and migrate a wasm contract. ## Wasmd Authorization Settings Settings via sdk `params` module: -- `code_upload_access` - who can upload a wasm binary: `Nobody`, `Everybody`, `OnlyAddress` +- `code_upload_access` - who can upload a wasm binary: `Nobody`, `Everybody`, `AnyOfAddresses` - `instantiate_default_permission` - platform default, who can instantiate a wasm binary when the code owner has not set it See [params.go](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/params.go) @@ -62,12 +45,19 @@ See [params.go](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/param }, ``` -The values can be updated via gov proposal implemented in the `params` module. +The values can be updated via gov proposal `MsgUpdateParams`. -### Update Params Via [ParamChangeProposal](https://github.com/cosmos/cosmos-sdk/blob/v0.45.3/proto/cosmos/params/v1beta1/params.proto#L10) +### Update Params Via [MsgUpdateParams](https://github.com/CosmWasm/wasmd/blob/v0.41.0/proto/cosmwasm/wasm/v1/tx.proto#L263) Example to submit a parameter change gov proposal: + +- First create a draft proposal using the interactive CLI +```sh +wasmd tx gov draft-proposal +``` + +- Submit the proposal ```sh -wasmd tx gov submit-proposal param-change --from validator --chain-id=testing -b block +wasmd tx gov submit-proposal --from validator --chain-id=testing -b block ``` #### Content examples * Disable wasm code uploads @@ -115,14 +105,34 @@ wasmd tx gov submit-proposal param-change --from validator "subspace": "wasm", "key": "uploadAccess", "value": { - "permission": "OnlyAddress", - "address": "cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq0fr2sh" + "permission": "AnyOfAddresses", + "addresses": ["cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq0fr2sh"] } } ], "deposit": "" } ``` + +* Restrict code uploads to two addresses +```json +{ + "title": "Foo", + "description": "Bar", + "changes": [ + { + "subspace": "wasm", + "key": "uploadAccess", + "value": { + "permission": "AnyOfAddresses", + "addresses": ["cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq0fr2sh", "cosmos1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0fr2sh"] + } + } + ], + "deposit": "" +} +``` + * Set chain **default** instantiation settings to nobody ```json { @@ -154,15 +164,6 @@ wasmd tx gov submit-proposal param-change --from validator } ``` -### Enable gov proposals at **compile time**. -As gov proposals bypass the existing authorization policy they are disabled and require to be enabled at compile time. -``` --X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true - enable all x/wasm governance proposals (default false) --X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin - enable a subset of the x/wasm governance proposal types (overrides ProposalsEnabled) -``` - -The `ParamChangeProposal` is always enabled. - ### Tests * [params validation unit tests](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/params_test.go) * [genesis validation tests](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/genesis_test.go) @@ -171,35 +172,25 @@ The `ParamChangeProposal` is always enabled. ## CLI ```shell script - wasmd tx gov submit-proposal [command] + wasmd tx wasm submit-proposal [command] Available Commands: - wasm-store Submit a wasm binary proposal - instantiate-contract Submit an instantiate wasm contract proposal - migrate-contract Submit a migrate wasm contract to a new code version proposal - set-contract-admin Submit a new admin for a contract proposal - clear-contract-admin Submit a clear admin for a contract to prevent further migrations proposal + add-code-upload-params-addresses Submit an add code upload params addresses proposal to add addresses to code upload config params + clear-contract-admin Submit a clear admin for a contract to prevent further migrations proposal + execute-contract Submit a execute wasm contract proposal (run by any address) + instantiate-contract Submit an instantiate wasm contract proposal + instantiate-contract-2 Submit an instantiate wasm contract proposal with predictable address + migrate-contract Submit a migrate wasm contract to a new code version proposal + pin-codes Submit a pin code proposal for pinning a code to cache + remove-code-upload-params-addresses Submit a remove code upload params addresses proposal to remove addresses from code upload config params + set-contract-admin Submit a new admin for a contract proposal + store-instantiate Submit and instantiate a wasm contract proposal + sudo-contract Submit a sudo wasm contract proposal (to call privileged commands) + unpin-codes Submit a unpin code proposal for unpinning a code to cache + update-instantiate-config Submit an update instantiate config proposal. + wasm-store Submit a wasm binary proposal ... ``` -## Rest -New [`ProposalHandlers`](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/client/proposal_handler.go) - -* Integration -```shell script -gov.NewAppModuleBasic(append(wasmclient.ProposalHandlers, paramsclient.ProposalHandler, distr.ProposalHandler, upgradeclient.ProposalHandler)...), -``` -In [abci app](https://github.com/CosmWasm/wasmd/blob/master/app/app.go#L109) - -### Tests -* [Rest Unit tests](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/client/proposal_handler_test.go) -* [Rest smoke LCD test](https://github.com/CosmWasm/wasmd/blob/master/lcd_test/wasm_test.go) -## Pull requests -* https://github.com/CosmWasm/wasmd/pull/190 -* https://github.com/CosmWasm/wasmd/pull/186 -* https://github.com/CosmWasm/wasmd/pull/183 -* https://github.com/CosmWasm/wasmd/pull/180 -* https://github.com/CosmWasm/wasmd/pull/179 -* https://github.com/CosmWasm/wasmd/pull/173 diff --git a/x/wasm/alias.go b/x/wasm/alias.go index 4d22eae17b..fbe2656fa8 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -24,16 +24,6 @@ const ( WasmModuleEventType = types.WasmModuleEventType // Deprecated: Do not use. AttributeKeyContractAddr = types.AttributeKeyContractAddr - // Deprecated: Do not use. - ProposalTypeStoreCode = types.ProposalTypeStoreCode - // Deprecated: Do not use. - ProposalTypeInstantiateContract = types.ProposalTypeInstantiateContract - // Deprecated: Do not use. - ProposalTypeMigrateContract = types.ProposalTypeMigrateContract - // Deprecated: Do not use. - ProposalTypeUpdateAdmin = types.ProposalTypeUpdateAdmin - // Deprecated: Do not use. - ProposalTypeClearAdmin = types.ProposalTypeClearAdmin ) var ( @@ -45,8 +35,6 @@ var ( // Deprecated: Do not use. ValidateGenesis = types.ValidateGenesis // Deprecated: Do not use. - ConvertToProposals = types.ConvertToProposals - // Deprecated: Do not use. GetCodeKey = types.GetCodeKey // Deprecated: Do not use. GetContractAddressKey = types.GetContractAddressKey @@ -99,8 +87,6 @@ var ( // Deprecated: Do not use. TestHandler = keeper.TestHandler // Deprecated: Do not use. - NewWasmProposalHandler = keeper.NewWasmProposalHandler //nolint:staticcheck - // Deprecated: Do not use. NewQuerier = keeper.Querier // Deprecated: Do not use. ContractFromPortID = keeper.ContractFromPortID @@ -133,24 +119,18 @@ var ( // Deprecated: Do not use. ErrInvalidMsg = types.ErrInvalidMsg // Deprecated: Do not use. - KeyLastCodeID = types.KeyLastCodeID + KeyLastCodeID = types.KeySequenceCodeID // Deprecated: Do not use. - KeyLastInstanceID = types.KeyLastInstanceID + KeyLastInstanceID = types.KeySequenceInstanceID // Deprecated: Do not use. CodeKeyPrefix = types.CodeKeyPrefix // Deprecated: Do not use. ContractKeyPrefix = types.ContractKeyPrefix // Deprecated: Do not use. ContractStorePrefix = types.ContractStorePrefix - // Deprecated: Do not use. - EnableAllProposals = types.EnableAllProposals - // Deprecated: Do not use. - DisableAllProposals = types.DisableAllProposals ) type ( - // Deprecated: Do not use. - ProposalType = types.ProposalType // Deprecated: Do not use. GenesisState = types.GenesisState // Deprecated: Do not use. diff --git a/x/wasm/client/cli/genesis_msg.go b/x/wasm/client/cli/genesis_msg.go index b957e63afa..f636ad4e46 100644 --- a/x/wasm/client/cli/genesis_msg.go +++ b/x/wasm/client/cli/genesis_msg.go @@ -443,7 +443,7 @@ func (x DefaultGenesisIO) AlterWasmModuleState(cmd *cobra.Command, callback func func contractSeqValue(state *types.GenesisState) uint64 { var seq uint64 = 1 for _, s := range state.Sequences { - if bytes.Equal(s.IDKey, types.KeyLastInstanceID) { + if bytes.Equal(s.IDKey, types.KeySequenceInstanceID) { seq = s.Value break } @@ -456,7 +456,7 @@ func contractSeqValue(state *types.GenesisState) uint64 { func codeSeqValue(state *types.GenesisState) uint64 { var seq uint64 = 1 for _, s := range state.Sequences { - if bytes.Equal(s.IDKey, types.KeyLastCodeID) { + if bytes.Equal(s.IDKey, types.KeySequenceCodeID) { seq = s.Value break } diff --git a/x/wasm/client/cli/genesis_msg_test.go b/x/wasm/client/cli/genesis_msg_test.go index ff6bb63aa9..416d2461fa 100644 --- a/x/wasm/client/cli/genesis_msg_test.go +++ b/x/wasm/client/cli/genesis_msg_test.go @@ -33,11 +33,11 @@ import ( var wasmIdent = []byte("\x00\x61\x73\x6D") -var myWellFundedAccount = keeper.RandomBech32AccountAddress(nil) - const defaultTestKeyName = "my-key-name" func TestGenesisStoreCodeCmd(t *testing.T) { + myWellFundedAccount := keeper.RandomBech32AccountAddress(t) + minimalWasmGenesis := types.GenesisState{ Params: types.DefaultParams(), } @@ -86,7 +86,7 @@ func TestGenesisStoreCodeCmd(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - homeDir := setupGenesis(t, spec.srcGenesis) + homeDir := setupGenesis(t, spec.srcGenesis, myWellFundedAccount) // when cmd := GenesisStoreCodeCmd(homeDir, NewDefaultGenesisIO()) @@ -105,6 +105,8 @@ func TestGenesisStoreCodeCmd(t *testing.T) { } func TestInstantiateContractCmd(t *testing.T) { + myWellFundedAccount := keeper.RandomBech32AccountAddress(t) + minimalWasmGenesis := types.GenesisState{ Params: types.DefaultParams(), } @@ -184,7 +186,7 @@ func TestInstantiateContractCmd(t *testing.T) { {Sum: &types.GenesisState_GenMsgs_StoreCode{StoreCode: types.MsgStoreCodeFixture()}}, }, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: 100}, + {IDKey: types.KeySequenceCodeID, Value: 100}, }, }, mutator: func(cmd *cobra.Command) { @@ -360,7 +362,7 @@ func TestInstantiateContractCmd(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - homeDir := setupGenesis(t, spec.srcGenesis) + homeDir := setupGenesis(t, spec.srcGenesis, myWellFundedAccount) // when cmd := GenesisInstantiateContractCmd(homeDir, NewDefaultGenesisIO()) @@ -379,6 +381,8 @@ func TestInstantiateContractCmd(t *testing.T) { } func TestExecuteContractCmd(t *testing.T) { + myWellFundedAccount := keeper.RandomBech32AccountAddress(t) + const firstContractAddress = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" anyValidWasmFile, err := os.CreateTemp(t.TempDir(), "wasm") require.NoError(t, err) @@ -454,7 +458,7 @@ func TestExecuteContractCmd(t *testing.T) { {Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: types.MsgInstantiateContractFixture()}}, }, Sequences: []types.Sequence{ - {IDKey: types.KeyLastInstanceID, Value: 100}, + {IDKey: types.KeySequenceInstanceID, Value: 100}, }, }, mutator: func(cmd *cobra.Command) { @@ -525,7 +529,7 @@ func TestExecuteContractCmd(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - homeDir := setupGenesis(t, spec.srcGenesis) + homeDir := setupGenesis(t, spec.srcGenesis, myWellFundedAccount) cmd := GenesisExecuteContractCmd(homeDir, NewDefaultGenesisIO()) spec.mutator(cmd) @@ -593,7 +597,7 @@ func TestGetAllContracts(t *testing.T) { "read from message state with contract sequence": { src: types.GenesisState{ Sequences: []types.Sequence{ - {IDKey: types.KeyLastInstanceID, Value: 100}, + {IDKey: types.KeySequenceInstanceID, Value: 100}, }, GenMsgs: []types.GenesisState_GenMsgs{ {Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: &types.MsgInstantiateContract{Label: "hundred"}}}, @@ -615,7 +619,7 @@ func TestGetAllContracts(t *testing.T) { }, }, Sequences: []types.Sequence{ - {IDKey: types.KeyLastInstanceID, Value: 100}, + {IDKey: types.KeySequenceInstanceID, Value: 100}, }, GenMsgs: []types.GenesisState_GenMsgs{ {Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: &types.MsgInstantiateContract{Label: "hundred"}}}, @@ -641,8 +645,9 @@ func TestGetAllContracts(t *testing.T) { } } -func setupGenesis(t *testing.T, wasmGenesis types.GenesisState) string { - appCodec := keeper.MakeEncodingConfig(t).Marshaler +func setupGenesis(t *testing.T, wasmGenesis types.GenesisState, myWellFundedAccount string) string { + + appCodec := keeper.MakeEncodingConfig(t).Codec homeDir := t.TempDir() require.NoError(t, os.Mkdir(path.Join(homeDir, "config"), 0o700)) @@ -675,7 +680,7 @@ func executeCmdWithContext(t *testing.T, homeDir string, cmd *cobra.Command) err logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultTendermintConfig(homeDir) require.NoError(t, err) - appCodec := keeper.MakeEncodingConfig(t).Marshaler + appCodec := keeper.MakeEncodingConfig(t).Codec serverCtx := server.NewContext(viper.New(), cfg, logger) clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(homeDir) @@ -700,7 +705,7 @@ func loadModuleState(t *testing.T, homeDir string) types.GenesisState { require.NoError(t, err) require.Contains(t, appState, types.ModuleName) - appCodec := keeper.MakeEncodingConfig(t).Marshaler + appCodec := keeper.MakeEncodingConfig(t).Codec var moduleState types.GenesisState require.NoError(t, appCodec.UnmarshalJSON(appState[types.ModuleName], &moduleState)) return moduleState diff --git a/x/wasm/client/cli/gov_tx.go b/x/wasm/client/cli/gov_tx.go index 0a46ac6ecf..928dee6b69 100644 --- a/x/wasm/client/cli/gov_tx.go +++ b/x/wasm/client/cli/gov_tx.go @@ -8,6 +8,11 @@ import ( "strings" wasmvm "github.com/CosmWasm/wasmvm" + "github.com/docker/distribution/reference" + "github.com/pkg/errors" + "github.com/spf13/cobra" + flag "github.com/spf13/pflag" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -16,10 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/docker/distribution/reference" - "github.com/pkg/errors" - "github.com/spf13/cobra" - flag "github.com/spf13/pflag" "github.com/CosmWasm/wasmd/x/wasm/ioutils" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -50,6 +51,7 @@ func SubmitProposalCmd() *cobra.Command { ProposalUpdateInstantiateConfigCmd(), ProposalAddCodeUploadParamsAddresses(), ProposalRemoveCodeUploadParamsAddresses(), + ProposalStoreAndMigrateContractCmd(), ) return cmd } @@ -245,7 +247,7 @@ func ProposalStoreAndInstantiateContractCmd() *cobra.Command { cmd := &cobra.Command{ Use: "store-instantiate [wasm file] [json_encoded_init_args] --authority [address] --label [text] --title [text] --summary [text]" + "--unpin-code [unpin_code,optional] --source [source,optional] --builder [builder,optional] --code-hash [code_hash,optional] --admin [address,optional] --amount [coins,optional]", - Short: "Submit and instantiate a wasm contract proposal", + Short: "Submit a store and instantiate wasm contract proposal", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, proposalTitle, summary, deposit, err := getProposalInfo(cmd) @@ -411,7 +413,7 @@ func ProposalMigrateContractCmd() *cobra.Command { func ProposalExecuteContractCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "execute-contract [contract_addr_bech32] [json_encoded_migration_args] --title [text] --summary [text] --authority [address]", + Use: "execute-contract [contract_addr_bech32] [json_encoded_execution_args] --title [text] --summary [text] --authority [address]", Short: "Submit a execute wasm contract proposal (run by any address)", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -927,3 +929,55 @@ func getProposalInfo(cmd *cobra.Command) (client.Context, string, string, sdk.Co return clientCtx, proposalTitle, summary, deposit, nil } + +func ProposalStoreAndMigrateContractCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "store-migrate [wasm file] [contract_addr_bech32] [json_encoded_migration_args] --title [text] --summary [text] --authority [address]", + Short: "Submit a store and migrate wasm contract proposal", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, proposalTitle, summary, deposit, err := getProposalInfo(cmd) + if err != nil { + return err + } + + authority, err := cmd.Flags().GetString(flagAuthority) + if err != nil { + return fmt.Errorf("authority: %s", err) + } + + if len(authority) == 0 { + return errors.New("authority address is required") + } + + src, err := parseStoreCodeArgs(args[0], authority, cmd.Flags()) + if err != nil { + return err + } + + msg := types.MsgStoreAndMigrateContract{ + Authority: authority, + WASMByteCode: src.WASMByteCode, + InstantiatePermission: src.InstantiatePermission, + Msg: []byte(args[2]), + Contract: args[1], + } + + proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&msg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary) + if err != nil { + return err + } + if err = proposalMsg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposalMsg) + }, + SilenceUsage: true, + } + + addInstantiatePermissionFlags(cmd) + // proposal flags + addCommonProposalFlags(cmd) + return cmd +} diff --git a/x/wasm/client/cli/gov_tx_test.go b/x/wasm/client/cli/gov_tx_test.go index 87621912c6..d6dea668ef 100644 --- a/x/wasm/client/cli/gov_tx_test.go +++ b/x/wasm/client/cli/gov_tx_test.go @@ -2,11 +2,13 @@ package cli import ( "os" + "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -104,7 +106,7 @@ func TestParseCodeInfoFlags(t *testing.T) { wasmBin, err := os.ReadFile("../../keeper/testdata/hackatom.wasm.gzip") require.NoError(t, err) - checksumStr := "5ca46abb8e9b1b754a5c906f9c0f4eec9121ee09e3cee55ea0faba54763706e2" + checksumStr := strings.ToUpper(testdata.ChecksumHackatom) specs := map[string]struct { args []string diff --git a/x/wasm/client/cli/new_tx.go b/x/wasm/client/cli/new_tx.go index 16b9b1bacf..9fe212eebd 100644 --- a/x/wasm/client/cli/new_tx.go +++ b/x/wasm/client/cli/new_tx.go @@ -3,11 +3,13 @@ package cli import ( "strconv" + "github.com/spf13/cobra" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/spf13/cobra" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -158,3 +160,31 @@ func UpdateInstantiateConfigCmd() *cobra.Command { flags.AddTxFlagsToCmd(cmd) return cmd } + +// UpdateContractLabelCmd sets an new label for a contract +func UpdateContractLabelCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "set-contract-label [contract_addr_bech32] [new_label]", + Short: "Set new label for a contract", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.MsgUpdateContractLabel{ + Sender: clientCtx.GetFromAddress().String(), + Contract: args[0], + NewLabel: args[1], + } + if err = msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + SilenceUsage: true, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/wasm/client/cli/query.go b/x/wasm/client/cli/query.go index 3053737274..7dd820e3fb 100644 --- a/x/wasm/client/cli/query.go +++ b/x/wasm/client/cli/query.go @@ -11,11 +11,12 @@ import ( "strconv" wasmvm "github.com/CosmWasm/wasmvm" + "github.com/spf13/cobra" + flag "github.com/spf13/pflag" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/spf13/cobra" - flag "github.com/spf13/pflag" "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -143,7 +144,7 @@ func GetCmdListCode() *cobra.Command { SilenceUsage: true, } flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "list codes") + addPaginationFlags(cmd, "list codes") return cmd } @@ -189,7 +190,7 @@ func GetCmdListContractByCode() *cobra.Command { SilenceUsage: true, } flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "list contracts by code") + addPaginationFlags(cmd, "list contracts by code") return cmd } @@ -367,7 +368,7 @@ func GetCmdGetContractStateAll() *cobra.Command { SilenceUsage: true, } flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "contract state") + addPaginationFlags(cmd, "contract state") return cmd } @@ -503,7 +504,7 @@ func GetCmdGetContractHistory() *cobra.Command { } flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "contract history") + addPaginationFlags(cmd, "contract history") return cmd } @@ -539,7 +540,7 @@ func GetCmdListPinnedCode() *cobra.Command { SilenceUsage: true, } flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "list codes") + addPaginationFlags(cmd, "list codes") return cmd } @@ -580,7 +581,7 @@ func GetCmdListContractsByCreator() *cobra.Command { SilenceUsage: true, } flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "list contracts by creator") + addPaginationFlags(cmd, "list contracts by creator") return cmd } @@ -673,3 +674,10 @@ func GetCmdQueryParams() *cobra.Command { return cmd } + +// supports a subset of the SDK pagination params for better resource utilization +func addPaginationFlags(cmd *cobra.Command, query string) { + cmd.Flags().String(flags.FlagPageKey, "", fmt.Sprintf("pagination page-key of %s to query for", query)) + cmd.Flags().Uint64(flags.FlagLimit, 100, fmt.Sprintf("pagination limit of %s to query for", query)) + cmd.Flags().Bool(flags.FlagReverse, false, "results are sorted in descending order") +} diff --git a/x/wasm/client/cli/tx.go b/x/wasm/client/cli/tx.go index 4edd317b0b..49a326d333 100644 --- a/x/wasm/client/cli/tx.go +++ b/x/wasm/client/cli/tx.go @@ -6,8 +6,12 @@ import ( "fmt" "os" "strconv" + "strings" "time" + "github.com/spf13/cobra" + flag "github.com/spf13/pflag" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -15,8 +19,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/spf13/cobra" - flag "github.com/spf13/pflag" "github.com/CosmWasm/wasmd/x/wasm/ioutils" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -43,7 +45,7 @@ const ( flagMaxCalls = "max-calls" flagMaxFunds = "max-funds" flagAllowAllMsgs = "allow-all-messages" - flagNoTokenTransfer = "no-token-transfer" //nolint:gosec + flagNoTokenTransfer = "no-token-transfer" flagAuthority = "authority" ) @@ -65,9 +67,10 @@ func GetTxCmd() *cobra.Command { MigrateContractCmd(), UpdateContractAdminCmd(), ClearContractAdminCmd(), - GrantAuthorizationCmd(), + GrantCmd(), UpdateInstantiateConfigCmd(), SubmitProposalCmd(), + UpdateContractLabelCmd(), ) return txCmd } @@ -102,7 +105,7 @@ func StoreCodeCmd() *cobra.Command { } // Prepares MsgStoreCode object from flags with gzipped wasm byte code field -func parseStoreCodeArgs(file string, sender string, flags *flag.FlagSet) (types.MsgStoreCode, error) { +func parseStoreCodeArgs(file, sender string, flags *flag.FlagSet) (types.MsgStoreCode, error) { wasm, err := os.ReadFile(file) if err != nil { return types.MsgStoreCode{}, err @@ -393,7 +396,7 @@ func ExecuteContractCmd() *cobra.Command { return cmd } -func parseExecuteArgs(contractAddr string, execMsg string, sender sdk.AccAddress, flags *flag.FlagSet) (types.MsgExecuteContract, error) { +func parseExecuteArgs(contractAddr, execMsg string, sender sdk.AccAddress, flags *flag.FlagSet) (types.MsgExecuteContract, error) { amountStr, err := flags.GetString(flagAmount) if err != nil { return types.MsgExecuteContract{}, fmt.Errorf("amount: %s", err) @@ -412,17 +415,31 @@ func parseExecuteArgs(contractAddr string, execMsg string, sender sdk.AccAddress }, nil } +func GrantCmd() *cobra.Command { + txCmd := &cobra.Command{ + Use: "grant", + Short: "Grant a authz permission", + DisableFlagParsing: true, + SilenceUsage: true, + } + txCmd.AddCommand( + GrantAuthorizationCmd(), + GrantStoreCodeAuthorizationCmd(), + ) + return txCmd +} + func GrantAuthorizationCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "grant [grantee] [message_type=\"execution\"|\"migration\"] [contract_addr_bech32] --allow-raw-msgs [msg1,msg2,...] --allow-msg-keys [key1,key2,...] --allow-all-messages", - Short: "Grant authorization to an address", + Use: "contract [message_type=\"execution\"|\"migration\"] [grantee] [contract_addr_bech32] --allow-raw-msgs [msg1,msg2,...] --allow-msg-keys [key1,key2,...] --allow-all-messages", + Short: "Grant authorization to interact with a contract on behalf of you", Long: fmt.Sprintf(`Grant authorization to an address. Examples: -$ %s tx grant execution --allow-all-messages --max-calls 1 --no-token-transfer --expiration 1667979596 +$ %s tx grant contract execution --allow-all-messages --max-calls 1 --no-token-transfer --expiration 1667979596 -$ %s tx grant execution --allow-all-messages --max-funds 100000uwasm --expiration 1667979596 +$ %s tx grant contract execution --allow-all-messages --max-funds 100000uwasm --expiration 1667979596 -$ %s tx grant execution --allow-all-messages --max-calls 5 --max-funds 100000uwasm --expiration 1667979596 +$ %s tx grant contract execution --allow-all-messages --max-calls 5 --max-funds 100000uwasm --expiration 1667979596 `, version.AppName, version.AppName, version.AppName), Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { @@ -555,6 +572,52 @@ $ %s tx grant execution --allow-all-messages --ma return cmd } +func GrantStoreCodeAuthorizationCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "store-code [grantee] [code_hash:permission]", + Short: "Grant authorization to upload contract code on behalf of you", + Long: fmt.Sprintf(`Grant authorization to an address. +Examples: +$ %s tx grant store-code 13a1fc994cc6d1c81b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5:everybody 1wqrtry681b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5:nobody --expiration 1667979596 + +$ %s tx grant store-code *:%s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm,%s1vx8knpllrj7n963p9ttd80w47kpacrhuts497x +`, version.AppName, version.AppName, version.AppName, version.AppName), + Args: cobra.MinimumNArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + grantee, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + grants, err := parseStoreCodeGrants(args[1:]) + if err != nil { + return err + } + + authorization := types.NewStoreCodeAuthorization(grants...) + + expire, err := getExpireTime(cmd) + if err != nil { + return err + } + + grantMsg, err := authz.NewMsgGrant(clientCtx.GetFromAddress(), grantee, authorization, expire) + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), grantMsg) + }, + } + flags.AddTxFlagsToCmd(cmd) + cmd.Flags().Int64(flagExpiration, 0, "The Unix timestamp.") + return cmd +} + func getExpireTime(cmd *cobra.Command) (*time.Time, error) { exp, err := cmd.Flags().GetInt64(flagExpiration) if err != nil { @@ -566,3 +629,32 @@ func getExpireTime(cmd *cobra.Command) (*time.Time, error) { e := time.Unix(exp, 0) return &e, nil } + +func parseStoreCodeGrants(args []string) ([]types.CodeGrant, error) { + grants := make([]types.CodeGrant, len(args)) + for i, c := range args { + // format: code_hash:access_config + // access_config: nobody|everybody|address(es) + parts := strings.Split(c, ":") + if len(parts) != 2 { + return nil, fmt.Errorf("invalid format") + } + + if parts[1] == "*" { + grants[i] = types.CodeGrant{ + CodeHash: []byte(parts[0]), + } + continue + } + + accessConfig, err := parseAccessConfig(parts[1]) + if err != nil { + return nil, err + } + grants[i] = types.CodeGrant{ + CodeHash: []byte(parts[0]), + InstantiatePermission: &accessConfig, + } + } + return grants, nil +} diff --git a/x/wasm/client/cli/tx_test.go b/x/wasm/client/cli/tx_test.go index 04f80fc28b..72e3967ab6 100644 --- a/x/wasm/client/cli/tx_test.go +++ b/x/wasm/client/cli/tx_test.go @@ -4,11 +4,13 @@ import ( "encoding/hex" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/ioutils" + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -26,22 +28,22 @@ func TestParseVerificationFlags(t *testing.T) { "gov store zipped": { srcPath: "../../keeper/testdata/hackatom.wasm.gzip", args: []string{ - "--instantiate-everybody=true", "--code-hash=5ca46abb8e9b1b754a5c906f9c0f4eec9121ee09e3cee55ea0faba54763706e2", + "--instantiate-everybody=true", "--code-hash=" + testdata.ChecksumHackatom, "--code-source-url=https://example.com", "--builder=cosmwasm/workspace-optimizer:0.12.11", }, expBuilder: "cosmwasm/workspace-optimizer:0.12.11", expSource: "https://example.com", - expCodeHash: "5ca46abb8e9b1b754a5c906f9c0f4eec9121ee09e3cee55ea0faba54763706e2", + expCodeHash: testdata.ChecksumHackatom, }, "gov store raw": { srcPath: "../../keeper/testdata/hackatom.wasm", args: []string{ - "--instantiate-everybody=true", "--code-hash=5ca46abb8e9b1b754a5c906f9c0f4eec9121ee09e3cee55ea0faba54763706e2", + "--instantiate-everybody=true", "--code-hash=" + testdata.ChecksumHackatom, "--code-source-url=https://example.com", "--builder=cosmwasm/workspace-optimizer:0.12.11", }, expBuilder: "cosmwasm/workspace-optimizer:0.12.11", expSource: "https://example.com", - expCodeHash: "5ca46abb8e9b1b754a5c906f9c0f4eec9121ee09e3cee55ea0faba54763706e2", + expCodeHash: testdata.ChecksumHackatom, }, "gov store checksum mismatch": { srcPath: "../../keeper/testdata/hackatom.wasm", @@ -122,3 +124,106 @@ func TestParseAccessConfigFlags(t *testing.T) { }) } } + +func TestParseStoreCodeGrants(t *testing.T) { + specs := map[string]struct { + src []string + exp []types.CodeGrant + expErr bool + }{ + "wildcard : nobody": { + src: []string{"*:nobody"}, + exp: []types.CodeGrant{{ + CodeHash: []byte("*"), + InstantiatePermission: &types.AccessConfig{Permission: types.AccessTypeNobody}, + }}, + }, + "wildcard : wildcard": { + src: []string{"*:*"}, + exp: []types.CodeGrant{{ + CodeHash: []byte("*"), + }}, + }, + "wildcard : everybody": { + src: []string{"*:everybody"}, + exp: []types.CodeGrant{{ + CodeHash: []byte("*"), + InstantiatePermission: &types.AccessConfig{Permission: types.AccessTypeEverybody}, + }}, + }, + "wildcard : any of addresses - single": { + src: []string{"*:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"}, + exp: []types.CodeGrant{ + { + CodeHash: []byte("*"), + InstantiatePermission: &types.AccessConfig{ + Permission: types.AccessTypeAnyOfAddresses, + Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"}, + }, + }, + }, + }, + "wildcard : any of addresses - multiple": { + src: []string{"*:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"}, + exp: []types.CodeGrant{ + { + CodeHash: []byte("*"), + InstantiatePermission: &types.AccessConfig{ + Permission: types.AccessTypeAnyOfAddresses, + Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x", "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"}, + }, + }, + }, + }, + "multiple code hashes with different permissions": { + src: []string{"any_checksum_1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", "any_checksum_2:nobody"}, + exp: []types.CodeGrant{ + { + CodeHash: []byte("any_checksum_1"), + InstantiatePermission: &types.AccessConfig{ + Permission: types.AccessTypeAnyOfAddresses, + Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x", "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"}, + }, + }, { + CodeHash: []byte("any_checksum_2"), + InstantiatePermission: &types.AccessConfig{ + Permission: types.AccessTypeNobody, + }, + }, + }, + }, + "code hash : wildcard": { + src: []string{"any_checksum_1:*"}, + exp: []types.CodeGrant{{ + CodeHash: []byte("any_checksum_1"), + }}, + }, + "code hash : any of addresses - empty list": { + src: []string{"any_checksum_1:"}, + expErr: true, + }, + "code hash : any of addresses - invalid address": { + src: []string{"any_checksum_1:foo"}, + expErr: true, + }, + "code hash : any of addresses - duplicate address": { + src: []string{"any_checksum_1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"}, + expErr: true, + }, + "empty code hash": { + src: []string{":everyone"}, + expErr: true, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + got, gotErr := parseStoreCodeGrants(spec.src) + if spec.expErr { + require.Error(t, gotErr) + return + } + require.NoError(t, gotErr) + assert.Equal(t, spec.exp, got) + }) + } +} diff --git a/x/wasm/client/cli/utils.go b/x/wasm/client/cli/utils.go index 963b8f94e0..f6c0c6bf88 100644 --- a/x/wasm/client/cli/utils.go +++ b/x/wasm/client/cli/utils.go @@ -4,10 +4,10 @@ import ( "os" "path/filepath" - "github.com/cosmos/cosmos-sdk/server" + tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" "github.com/spf13/cobra" - tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" + "github.com/cosmos/cosmos-sdk/server" ) // ExtendUnsafeResetAllCmd - also clear wasm dir diff --git a/x/wasm/common_test.go b/x/wasm/common_test.go index 9b26c41b03..202770aa60 100644 --- a/x/wasm/common_test.go +++ b/x/wasm/common_test.go @@ -3,9 +3,10 @@ package wasm import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -13,13 +14,15 @@ const firstCodeID = 1 // ensure store code returns the expected response func assertStoreCodeResponse(t *testing.T, data []byte, expected uint64) { + t.Helper() var pStoreResp types.MsgStoreCodeResponse require.NoError(t, pStoreResp.Unmarshal(data)) require.Equal(t, pStoreResp.CodeID, expected) } // ensure execution returns the expected data -func assertExecuteResponse(t *testing.T, data []byte, expected []byte) { +func assertExecuteResponse(t *testing.T, data, expected []byte) { + t.Helper() var pExecResp types.MsgExecuteContractResponse require.NoError(t, pExecResp.Unmarshal(data)) require.Equal(t, pExecResp.Data, expected) @@ -27,6 +30,7 @@ func assertExecuteResponse(t *testing.T, data []byte, expected []byte) { // ensures this returns a valid bech32 address and returns it func parseInitResponse(t *testing.T, data []byte) string { + t.Helper() var pInstResp types.MsgInstantiateContractResponse require.NoError(t, pInstResp.Unmarshal(data)) require.NotEmpty(t, pInstResp.Address) diff --git a/x/wasm/genesis_test.go b/x/wasm/genesis_test.go index a6f7899d10..8928645750 100644 --- a/x/wasm/genesis_test.go +++ b/x/wasm/genesis_test.go @@ -4,9 +4,10 @@ import ( "encoding/json" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -66,16 +67,16 @@ func TestInitGenesis(t *testing.T) { assertExecuteResponse(t, res.Data, []byte{0xf0, 0x0b, 0xaa}) // ensure all contract state is as after init - assertCodeList(t, q, data.ctx, 1, data.encConf.Marshaler) - assertCodeBytes(t, q, data.ctx, 1, testContract, data.encConf.Marshaler) + assertCodeList(t, q, data.ctx, 1, data.encConf.Codec) + assertCodeBytes(t, q, data.ctx, 1, testContract, data.encConf.Codec) - assertContractList(t, q, data.ctx, 1, []string{contractBech32Addr}, data.encConf.Marshaler) - assertContractInfo(t, q, data.ctx, contractBech32Addr, 1, creator, data.encConf.Marshaler) + assertContractList(t, q, data.ctx, 1, []string{contractBech32Addr}, data.encConf.Codec) + assertContractInfo(t, q, data.ctx, contractBech32Addr, 1, creator, data.encConf.Codec) assertContractState(t, q, data.ctx, contractBech32Addr, state{ Verifier: fred.String(), Beneficiary: bob.String(), Funder: creator.String(), - }, data.encConf.Marshaler) + }, data.encConf.Codec) // export into genstate genState := keeper.ExportGenesis(data.ctx, &data.keeper) @@ -89,14 +90,14 @@ func TestInitGenesis(t *testing.T) { require.NoError(t, err) // run same checks again on newdata, to make sure it was reinitialized correctly - assertCodeList(t, q2, newData.ctx, 1, data.encConf.Marshaler) - assertCodeBytes(t, q2, newData.ctx, 1, testContract, data.encConf.Marshaler) + assertCodeList(t, q2, newData.ctx, 1, data.encConf.Codec) + assertCodeBytes(t, q2, newData.ctx, 1, testContract, data.encConf.Codec) - assertContractList(t, q2, newData.ctx, 1, []string{contractBech32Addr}, data.encConf.Marshaler) - assertContractInfo(t, q2, newData.ctx, contractBech32Addr, 1, creator, data.encConf.Marshaler) + assertContractList(t, q2, newData.ctx, 1, []string{contractBech32Addr}, data.encConf.Codec) + assertContractInfo(t, q2, newData.ctx, contractBech32Addr, 1, creator, data.encConf.Codec) assertContractState(t, q2, newData.ctx, contractBech32Addr, state{ Verifier: fred.String(), Beneficiary: bob.String(), Funder: creator.String(), - }, data.encConf.Marshaler) + }, data.encConf.Codec) } diff --git a/x/wasm/ibc.go b/x/wasm/ibc.go index 314cc79ef2..4cd6f8fd21 100644 --- a/x/wasm/ibc.go +++ b/x/wasm/ibc.go @@ -3,15 +3,17 @@ package wasm import ( "math" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/ibc_integration_test.go b/x/wasm/ibc_integration_test.go index 97030f44c3..c5403759dd 100644 --- a/x/wasm/ibc_integration_test.go +++ b/x/wasm/ibc_integration_test.go @@ -3,12 +3,6 @@ package wasm_test import ( "testing" - "github.com/CosmWasm/wasmd/app" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/CosmWasm/wasmd/x/wasm/types" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" @@ -17,9 +11,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestOnChanOpenInitVersion(t *testing.T) { @@ -50,7 +48,7 @@ func TestOnChanOpenInitVersion(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContract)), + wasmtesting.NewIBCContractMockWasmEngine(myContract)), } coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) @@ -102,7 +100,7 @@ func TestOnChanOpenTryVersion(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContract)), + wasmtesting.NewIBCContractMockWasmEngine(myContract)), } coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) @@ -210,7 +208,7 @@ func TestOnIBCPacketReceive(t *testing.T) { // then if spec.expPacketNotHandled { - const contractPanicToErrMsg = `recovered: Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: Aborted: panicked at 'This page intentionally faulted', src/contract.rs:316:5` + const contractPanicToErrMsg = `recovered: Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: Aborted: panicked at 'This page intentionally faulted'` assert.ErrorContains(t, err, contractPanicToErrMsg) require.Nil(t, *capturedAck) return @@ -227,12 +225,12 @@ func TestOnIBCPacketReceive(t *testing.T) { // mock to submit an ibc data package from given chain and capture the ack type captureAckTestContractEngine struct { - *wasmtesting.MockWasmer + *wasmtesting.MockWasmEngine } // NewCaptureAckTestContractEngine constructor func NewCaptureAckTestContractEngine() *captureAckTestContractEngine { - m := wasmtesting.NewIBCContractMockWasmer(&wasmtesting.MockIBCContractCallbacks{ + m := wasmtesting.NewIBCContractMockWasmEngine(&wasmtesting.MockIBCContractCallbacks{ IBCChannelOpenFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) { return &wasmvmtypes.IBC3ChannelOpenResponse{}, 0, nil }, @@ -245,8 +243,9 @@ func NewCaptureAckTestContractEngine() *captureAckTestContractEngine { // SubmitIBCPacket starts an IBC packet transfer on given chain and captures the ack returned func (x *captureAckTestContractEngine) SubmitIBCPacket(t *testing.T, path *wasmibctesting.Path, chainA *wasmibctesting.TestChain, senderContractAddr sdk.AccAddress, packetData []byte) *[]byte { + t.Helper() // prepare a bridge to send an ibc packet by an ordinary wasm execute message - x.MockWasmer.ExecuteFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { + x.MockWasmEngine.ExecuteFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { return &wasmvmtypes.Response{ Messages: []wasmvmtypes.SubMsg{{ID: 1, ReplyOn: wasmvmtypes.ReplyNever, Msg: wasmvmtypes.CosmosMsg{IBC: &wasmvmtypes.IBCMsg{SendPacket: &wasmvmtypes.SendPacketMsg{ ChannelID: path.EndpointA.ChannelID, Data: executeMsg, Timeout: wasmvmtypes.IBCTimeout{Block: &wasmvmtypes.IBCTimeoutBlock{Revision: 1, Height: 10000000}}, @@ -255,7 +254,7 @@ func (x *captureAckTestContractEngine) SubmitIBCPacket(t *testing.T, path *wasmi } // capture acknowledgement var gotAck []byte - x.MockWasmer.IBCPacketAckFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketAckMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { + x.MockWasmEngine.IBCPacketAckFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketAckMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { gotAck = msg.Acknowledgement.Data return &wasmvmtypes.IBCBasicResponse{}, 0, nil } diff --git a/x/wasm/ibc_reflect_test.go b/x/wasm/ibc_reflect_test.go index efb47e7e6a..7151b27150 100644 --- a/x/wasm/ibc_reflect_test.go +++ b/x/wasm/ibc_reflect_test.go @@ -3,12 +3,10 @@ package wasm_test import ( "testing" - "github.com/stretchr/testify/assert" - + wasmvmtypes "github.com/CosmWasm/wasmvm/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" - - wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" diff --git a/x/wasm/ibc_test.go b/x/wasm/ibc_test.go index 9728967516..f25622c8ee 100644 --- a/x/wasm/ibc_test.go +++ b/x/wasm/ibc_test.go @@ -6,14 +6,15 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/rand" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/ibctesting/chain.go b/x/wasm/ibctesting/chain.go index 101798c2c1..504e82f283 100644 --- a/x/wasm/ibctesting/chain.go +++ b/x/wasm/ibctesting/chain.go @@ -5,15 +5,27 @@ import ( "testing" "time" - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/math" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/crypto/tmhash" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmprotoversion "github.com/cometbft/cometbft/proto/tendermint/version" tmtypes "github.com/cometbft/cometbft/types" tmversion "github.com/cometbft/cometbft/version" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/cosmos/ibc-go/v7/modules/core/types" + ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + ibctesting "github.com/cosmos/ibc-go/v7/testing" + "github.com/cosmos/ibc-go/v7/testing/mock" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -30,17 +42,6 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" - "github.com/cosmos/ibc-go/v7/modules/core/exported" - ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - "github.com/cosmos/ibc-go/v7/modules/core/types" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - ibctesting "github.com/cosmos/ibc-go/v7/testing" - "github.com/cosmos/ibc-go/v7/testing/mock" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -117,18 +118,21 @@ type ChainAppFactory func(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs [] // DefaultWasmAppFactory instantiates and sets up the default wasmd app func DefaultWasmAppFactory(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, opts []wasmkeeper.Option, balances ...banktypes.Balance) ChainApp { + t.Helper() return app.SetupWithGenesisValSet(t, valSet, genAccs, chainID, opts, balances...) } // NewDefaultTestChain initializes a new test chain with a default of 4 validators // Use this function if the tests do not need custom control over the validator set func NewDefaultTestChain(t *testing.T, coord *Coordinator, chainID string, opts ...wasmkeeper.Option) *TestChain { + t.Helper() return NewTestChain(t, coord, DefaultWasmAppFactory, chainID, opts...) } // NewTestChain initializes a new test chain with a default of 4 validators // Use this function if the tests do not need custom control over the validator set func NewTestChain(t *testing.T, coord *Coordinator, appFactory ChainAppFactory, chainID string, opts ...wasmkeeper.Option) *TestChain { + t.Helper() // generate validators private/public key var ( validatorsPerChain = 4 @@ -168,6 +172,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, appFactory ChainAppFactory, // CONTRACT: Validator array must be provided in the order expected by Tendermint. // i.e. sorted first by power and then lexicographically by address. func NewTestChainWithValSet(t *testing.T, coord *Coordinator, appFactory ChainAppFactory, chainID string, valSet *tmtypes.ValidatorSet, signers map[string]tmtypes.PrivValidator, opts ...wasmkeeper.Option) *TestChain { + t.Helper() genAccs := []authtypes.GenesisAccount{} genBals := []banktypes.Balance{} senderAccs := []SenderAccount{} diff --git a/x/wasm/ibctesting/coordinator.go b/x/wasm/ibctesting/coordinator.go index 4c7428a325..b5000d733b 100644 --- a/x/wasm/ibctesting/coordinator.go +++ b/x/wasm/ibctesting/coordinator.go @@ -30,11 +30,13 @@ type Coordinator struct { // NewCoordinator initializes Coordinator with n default wasm TestChain instances func NewCoordinator(t *testing.T, n int, opts ...[]wasmkeeper.Option) *Coordinator { + t.Helper() return NewCoordinatorX(t, n, DefaultWasmAppFactory, opts...) } // NewCoordinatorX initializes Coordinator with N TestChain instances using the given app factory func NewCoordinatorX(t *testing.T, n int, appFactory ChainAppFactory, opts ...[]wasmkeeper.Option) *Coordinator { + t.Helper() chains := make(map[string]*TestChain) coord := &Coordinator{ t: t, diff --git a/x/wasm/ibctesting/endpoint.go b/x/wasm/ibctesting/endpoint.go index 726aca22dc..2e22ec802b 100644 --- a/x/wasm/ibctesting/endpoint.go +++ b/x/wasm/ibctesting/endpoint.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "github.com/cosmos/cosmos-sdk/baseapp" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -15,6 +13,9 @@ import ( ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" ) // Endpoint is a which represents a channel endpoint and its associated diff --git a/x/wasm/ibctesting/event_utils.go b/x/wasm/ibctesting/event_utils.go index 3ca72f8bb1..71df2784a5 100644 --- a/x/wasm/ibctesting/event_utils.go +++ b/x/wasm/ibctesting/event_utils.go @@ -6,11 +6,11 @@ import ( "strconv" "strings" - sdk "github.com/cosmos/cosmos-sdk/types" - abci "github.com/cometbft/cometbft/abci/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func GetSendPackets(evts []abci.Event) []channeltypes.Packet { diff --git a/x/wasm/ibctesting/faucet.go b/x/wasm/ibctesting/faucet.go index d36feceb2f..559149906f 100644 --- a/x/wasm/ibctesting/faucet.go +++ b/x/wasm/ibctesting/faucet.go @@ -1,11 +1,13 @@ package ibctesting import ( + "github.com/stretchr/testify/require" + "cosmossdk.io/math" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" ) diff --git a/x/wasm/ibctesting/path.go b/x/wasm/ibctesting/path.go index 5c39e36152..fe0ace44f4 100644 --- a/x/wasm/ibctesting/path.go +++ b/x/wasm/ibctesting/path.go @@ -4,9 +4,10 @@ import ( "bytes" "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" + + sdk "github.com/cosmos/cosmos-sdk/types" ) // Path contains two endpoints representing two chains connected over IBC diff --git a/x/wasm/ibctesting/wasm.go b/x/wasm/ibctesting/wasm.go index 24f6135061..b01611a8b5 100644 --- a/x/wasm/ibctesting/wasm.go +++ b/x/wasm/ibctesting/wasm.go @@ -8,14 +8,14 @@ import ( "os" "strings" - ibctesting "github.com/cosmos/ibc-go/v7/testing" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/rand" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" + ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -23,7 +23,7 @@ var wasmIdent = []byte("\x00\x61\x73\x6D") // SeedNewContractInstance stores some wasm code and instantiates a new contract on this chain. // This method can be called to prepare the store with some valid CodeInfo and ContractInfo. The returned -// Address is the contract address for this instance. Test should make use of this data and/or use NewIBCContractMockWasmer +// Address is the contract address for this instance. Test should make use of this data and/or use NewIBCContractMockWasmEngine // for using a contract mock in Go. func (chain *TestChain) SeedNewContractInstance() sdk.AccAddress { pInstResp := chain.StoreCode(append(wasmIdent, rand.Bytes(10)...)) @@ -117,7 +117,7 @@ func (chain *TestChain) RawQuery(contractAddr string, queryData []byte) ([]byte, // SmartQuery This will serialize the query message and submit it to the contract. // The response is parsed into the provided interface. // Usage: SmartQuery(addr, QueryMsg{Foo: 1}, &response) -func (chain *TestChain) SmartQuery(contractAddr string, queryMsg interface{}, response interface{}) error { +func (chain *TestChain) SmartQuery(contractAddr string, queryMsg, response interface{}) error { msg, err := json.Marshal(queryMsg) if err != nil { return err diff --git a/x/wasm/ioutils/ioutil.go b/x/wasm/ioutils/ioutil.go index 71c2e56d78..f380fb5a1e 100644 --- a/x/wasm/ioutils/ioutil.go +++ b/x/wasm/ioutils/ioutil.go @@ -3,18 +3,19 @@ package ioutils import ( "bytes" "compress/gzip" + "errors" "encoding/json" "io" errorsmod "cosmossdk.io/errors" - - "github.com/CosmWasm/wasmd/x/wasm/types" ) +var errLimit = errors.New("exceeds limit") + // Uncompress expects a valid gzip source to unpack or fails. See IsGzip func Uncompress(gzipSrc []byte, limit int64) ([]byte, error) { if int64(len(gzipSrc)) > limit { - return nil, types.ErrLimit.Wrapf("max %d bytes", limit) + return nil, errorsmod.Wrapf(errLimit, "max %d bytes", limit) } zr, err := gzip.NewReader(bytes.NewReader(gzipSrc)) if err != nil { @@ -23,14 +24,14 @@ func Uncompress(gzipSrc []byte, limit int64) ([]byte, error) { zr.Multistream(false) defer zr.Close() bz, err := io.ReadAll(LimitReader(zr, limit)) - if types.ErrLimit.Is(err) { - return nil, errorsmod.Wrapf(err, "max %d bytes", limit) + if errors.Is(err, errLimit) { + return nil, errorsmod.Wrapf(errLimit, "max %d bytes", limit) } return bz, err } // LimitReader returns a Reader that reads from r -// but stops with types.ErrLimit after n bytes. +// but stops with "limit error" after n bytes. // The underlying implementation is a *io.LimitedReader. func LimitReader(r io.Reader, n int64) io.Reader { return &LimitedReader{r: &io.LimitedReader{R: r, N: n}} @@ -42,7 +43,7 @@ type LimitedReader struct { func (l *LimitedReader) Read(p []byte) (n int, err error) { if l.r.N <= 0 { - return 0, types.ErrLimit + return 0, errLimit } return l.r.Read(p) } diff --git a/x/wasm/ioutils/ioutil_test.go b/x/wasm/ioutils/ioutil_test.go index 3cd1b5c2dc..9a2e026dfe 100644 --- a/x/wasm/ioutils/ioutil_test.go +++ b/x/wasm/ioutils/ioutil_test.go @@ -9,11 +9,8 @@ import ( "testing" "github.com/cometbft/cometbft/libs/rand" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestUncompress(t *testing.T) { @@ -52,17 +49,17 @@ func TestUncompress(t *testing.T) { }, "handle big gzip output": { src: asGzip(bytes.Repeat([]byte{0x1}, maxSize+1)), - expError: types.ErrLimit, + expError: errLimit, }, "handle big gzip archive": { src: asGzip(rand.Bytes(2 * maxSize)), - expError: types.ErrLimit, + expError: errLimit, }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { r, err := Uncompress(spec.src, maxSize) - require.True(t, errors.Is(spec.expError, err), "exp %v got %+v", spec.expError, err) + require.True(t, errors.Is(err, spec.expError), "exp %v got %+v", spec.expError, err) if spec.expError != nil { return } diff --git a/x/wasm/keeper/addresses.go b/x/wasm/keeper/addresses.go index 67eabb4403..9df74f40da 100644 --- a/x/wasm/keeper/addresses.go +++ b/x/wasm/keeper/addresses.go @@ -16,13 +16,13 @@ type AddressGenerator func(ctx sdk.Context, codeID uint64, checksum []byte) sdk. // ClassicAddressGenerator generates a contract address using codeID and instanceID sequence func (k Keeper) ClassicAddressGenerator() AddressGenerator { return func(ctx sdk.Context, codeID uint64, _ []byte) sdk.AccAddress { - instanceID := k.autoIncrementID(ctx, types.KeyLastInstanceID) + instanceID := k.autoIncrementID(ctx, types.KeySequenceInstanceID) return BuildContractAddressClassic(codeID, instanceID) } } // PredicableAddressGenerator generates a predictable contract address -func PredicableAddressGenerator(creator sdk.AccAddress, salt []byte, msg []byte, fixMsg bool) AddressGenerator { +func PredicableAddressGenerator(creator sdk.AccAddress, salt, msg []byte, fixMsg bool) AddressGenerator { return func(ctx sdk.Context, _ uint64, checksum []byte) sdk.AccAddress { if !fixMsg { // clear msg to not be included in the address generation msg = []byte{} diff --git a/x/wasm/keeper/addresses_test.go b/x/wasm/keeper/addresses_test.go index 399c3e7b2d..84f3e54b22 100644 --- a/x/wasm/keeper/addresses_test.go +++ b/x/wasm/keeper/addresses_test.go @@ -6,8 +6,9 @@ import ( "testing" tmbytes "github.com/cometbft/cometbft/libs/bytes" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestBuildContractAddress(t *testing.T) { diff --git a/x/wasm/keeper/ante.go b/x/wasm/keeper/ante.go index 08dfdf64b4..1718c1ce11 100644 --- a/x/wasm/keeper/ante.go +++ b/x/wasm/keeper/ante.go @@ -95,3 +95,18 @@ func (d LimitSimulationGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu } return next(ctx, tx, simulate) } + +// GasRegisterDecorator ante decorator to store gas register in the context +type GasRegisterDecorator struct { + gasRegister types.GasRegister +} + +// NewGasRegisterDecorator constructor. +func NewGasRegisterDecorator(gr types.GasRegister) *GasRegisterDecorator { + return &GasRegisterDecorator{gasRegister: gr} +} + +// AnteHandle adds the gas register to the context. +func (g GasRegisterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { + return next(types.WithGasRegister(ctx, g.gasRegister), tx, simulate) +} diff --git a/x/wasm/keeper/ante_test.go b/x/wasm/keeper/ante_test.go index 1ac746427c..c1e59c4aa2 100644 --- a/x/wasm/keeper/ante_test.go +++ b/x/wasm/keeper/ante_test.go @@ -7,13 +7,15 @@ import ( dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -29,10 +31,11 @@ func TestCountTxDecorator(t *testing.T) { setupDB func(t *testing.T, ctx sdk.Context) simulate bool nextAssertAnte func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) - expErr bool }{ "no initial counter set": { - setupDB: func(t *testing.T, ctx sdk.Context) {}, + setupDB: func(t *testing.T, ctx sdk.Context) { + t.Helper() + }, nextAssertAnte: func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { gotCounter, ok := types.TXCounter(ctx) require.True(t, ok) @@ -45,6 +48,7 @@ func TestCountTxDecorator(t *testing.T) { }, "persistent counter incremented - big endian": { setupDB: func(t *testing.T, ctx sdk.Context) { + t.Helper() bz := []byte{0, 0, 0, 0, 0, 0, 0, myCurrentBlockHeight, 1, 0, 0, 2} ctx.MultiStore().GetKVStore(keyWasm).Set(types.TXCounterPrefix, bz) }, @@ -60,6 +64,7 @@ func TestCountTxDecorator(t *testing.T) { }, "old height counter replaced": { setupDB: func(t *testing.T, ctx sdk.Context) { + t.Helper() previousHeight := byte(myCurrentBlockHeight - 1) bz := []byte{0, 0, 0, 0, 0, 0, 0, previousHeight, 0, 0, 0, 1} ctx.MultiStore().GetKVStore(keyWasm).Set(types.TXCounterPrefix, bz) @@ -76,6 +81,7 @@ func TestCountTxDecorator(t *testing.T) { }, "simulation not persisted": { setupDB: func(t *testing.T, ctx sdk.Context) { + t.Helper() }, simulate: true, nextAssertAnte: func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { @@ -101,10 +107,6 @@ func TestCountTxDecorator(t *testing.T) { // when ante := keeper.NewCountTXDecorator(keyWasm) _, gotErr := ante.AnteHandle(ctx, anyTx, spec.simulate, spec.nextAssertAnte) - if spec.expErr { - require.Error(t, gotErr) - return - } require.NoError(t, gotErr) }) } @@ -187,3 +189,48 @@ func consumeGasAnteHandler(gasToConsume sdk.Gas) sdk.AnteHandler { return ctx, nil } } + +func TestGasRegisterDecorator(t *testing.T) { + db := dbm.NewMemDB() + ms := store.NewCommitMultiStore(db) + + specs := map[string]struct { + simulate bool + nextAssertAnte func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) + }{ + "simulation": { + simulate: true, + nextAssertAnte: func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { + _, ok := types.GasRegisterFromContext(ctx) + assert.True(t, ok) + require.True(t, simulate) + return ctx, nil + }, + }, + "not simulation": { + simulate: false, + nextAssertAnte: func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { + _, ok := types.GasRegisterFromContext(ctx) + assert.True(t, ok) + require.False(t, simulate) + return ctx, nil + }, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + ctx := sdk.NewContext(ms, tmproto.Header{ + Height: 100, + Time: time.Now(), + }, false, log.NewNopLogger()) + var anyTx sdk.Tx + + // when + ante := keeper.NewGasRegisterDecorator(&wasmtesting.MockGasRegister{}) + _, gotErr := ante.AnteHandle(ctx, anyTx, spec.simulate, spec.nextAssertAnte) + + // then + require.NoError(t, gotErr) + }) + } +} diff --git a/x/wasm/keeper/api.go b/x/wasm/keeper/api.go index 88f3b828b5..0a6f37c123 100644 --- a/x/wasm/keeper/api.go +++ b/x/wasm/keeper/api.go @@ -3,7 +3,10 @@ package keeper import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/CosmWasm/wasmd/x/wasm/types" ) const ( @@ -17,10 +20,10 @@ const ( ) var ( - costHumanize = DefaultGasCostHumanAddress * DefaultGasMultiplier - costCanonical = DefaultGasCostCanonicalAddress * DefaultGasMultiplier + costHumanize = DefaultGasCostHumanAddress * types.DefaultGasMultiplier + costCanonical = DefaultGasCostCanonicalAddress * types.DefaultGasMultiplier costJSONDeserialization = wasmvmtypes.UFraction{ - Numerator: DefaultDeserializationCostPerByte * DefaultGasMultiplier, + Numerator: DefaultDeserializationCostPerByte * types.DefaultGasMultiplier, Denominator: 1, } ) diff --git a/x/wasm/keeper/authz_policy_test.go b/x/wasm/keeper/authz_policy_test.go index 2230620daf..4d918e512a 100644 --- a/x/wasm/keeper/authz_policy_test.go +++ b/x/wasm/keeper/authz_policy_test.go @@ -3,9 +3,10 @@ package keeper import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/bench_test.go b/x/wasm/keeper/bench_test.go index ff0240afaf..500d97cc54 100644 --- a/x/wasm/keeper/bench_test.go +++ b/x/wasm/keeper/bench_test.go @@ -5,9 +5,10 @@ import ( "testing" dbm "github.com/cometbft/cometbft-db" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/contract_keeper.go b/x/wasm/keeper/contract_keeper.go index bebe8a7e94..2cd482970e 100644 --- a/x/wasm/keeper/contract_keeper.go +++ b/x/wasm/keeper/contract_keeper.go @@ -23,11 +23,11 @@ type decoratedKeeper interface { authZ types.AuthorizationPolicy, ) (sdk.AccAddress, []byte, error) - migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte, authZ types.AuthorizationPolicy) ([]byte, error) + migrate(ctx sdk.Context, contractAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte, authZ types.AuthorizationPolicy) ([]byte, error) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ types.AuthorizationPolicy) error pinCode(ctx sdk.Context, codeID uint64) error unpinCode(ctx sdk.Context, codeID uint64) error - execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) + execute(ctx sdk.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) setContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra types.ContractInfoExtension) error setAccessConfig(ctx sdk.Context, codeID uint64, caller sdk.AccAddress, newConfig types.AccessConfig, autz types.AuthorizationPolicy) error @@ -91,11 +91,11 @@ func (p PermissionedKeeper) Instantiate2( ) } -func (p PermissionedKeeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) { +func (p PermissionedKeeper) Execute(ctx sdk.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) { return p.nested.execute(ctx, contractAddress, caller, msg, coins) } -func (p PermissionedKeeper) Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) { +func (p PermissionedKeeper) Migrate(ctx sdk.Context, contractAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) { return p.nested.migrate(ctx, contractAddress, caller, newCodeID, msg, p.authZPolicy) } @@ -103,11 +103,11 @@ func (p PermissionedKeeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress return p.nested.Sudo(ctx, contractAddress, msg) } -func (p PermissionedKeeper) UpdateContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newAdmin sdk.AccAddress) error { +func (p PermissionedKeeper) UpdateContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress) error { return p.nested.setContractAdmin(ctx, contractAddress, caller, newAdmin, p.authZPolicy) } -func (p PermissionedKeeper) ClearContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress) error { +func (p PermissionedKeeper) ClearContractAdmin(ctx sdk.Context, contractAddress, caller sdk.AccAddress) error { return p.nested.setContractAdmin(ctx, contractAddress, caller, nil, p.authZPolicy) } diff --git a/x/wasm/keeper/contract_keeper_test.go b/x/wasm/keeper/contract_keeper_test.go index 46ec4f6576..e816ac096b 100644 --- a/x/wasm/keeper/contract_keeper_test.go +++ b/x/wasm/keeper/contract_keeper_test.go @@ -7,12 +7,12 @@ import ( "strings" "testing" - "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" - - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -22,7 +22,7 @@ func TestInstantiate2(t *testing.T) { example := StoreHackatomExampleContract(t, parentCtx, keepers) otherExample := StoreReflectContract(t, parentCtx, keepers) - mock := &wasmtesting.MockWasmer{} + mock := &wasmtesting.MockWasmEngine{} wasmtesting.MakeInstantiable(mock) keepers.WasmKeeper.wasmVM = mock // set mock to not fail on contract init message @@ -37,6 +37,7 @@ func TestInstantiate2(t *testing.T) { ) // create instances for duplicate checks exampleContract := func(t *testing.T, ctx sdk.Context, fixMsg bool) { + t.Helper() _, _, err := keepers.ContractKeeper.Instantiate2( ctx, example.CodeID, @@ -51,9 +52,11 @@ func TestInstantiate2(t *testing.T) { require.NoError(t, err) } exampleWithFixMsg := func(t *testing.T, ctx sdk.Context) { + t.Helper() exampleContract(t, ctx, true) } exampleWithoutFixMsg := func(t *testing.T, ctx sdk.Context) { + t.Helper() exampleContract(t, ctx, false) } specs := map[string]struct { diff --git a/x/wasm/keeper/events.go b/x/wasm/keeper/events.go index 06807f1c25..ef738b10d6 100644 --- a/x/wasm/keeper/events.go +++ b/x/wasm/keeper/events.go @@ -4,9 +4,10 @@ import ( "fmt" "strings" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + errorsmod "cosmossdk.io/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/keeper/events_test.go b/x/wasm/keeper/events_test.go index b305df4204..b091eb452d 100644 --- a/x/wasm/keeper/events_test.go +++ b/x/wasm/keeper/events_test.go @@ -5,9 +5,10 @@ import ( "testing" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/genesis.go b/x/wasm/keeper/genesis.go index e0f07cfee8..d2862c5b1a 100644 --- a/x/wasm/keeper/genesis.go +++ b/x/wasm/keeper/genesis.go @@ -1,8 +1,10 @@ package keeper import ( - errorsmod "cosmossdk.io/errors" abci "github.com/cometbft/cometbft/abci/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -40,17 +42,15 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, msgRo } } - var maxContractID int for i, contract := range data.Contracts { contractAddr, err := sdk.AccAddressFromBech32(contract.ContractAddress) if err != nil { return nil, errorsmod.Wrapf(err, "address in contract number %d", i) } - err = keeper.importContract(ctx, contractAddr, &contract.ContractInfo, contract.ContractState, contract.ContractCodeHistory) + err = keeper.importContract(ctx, contractAddr, &contract.ContractInfo, contract.ContractState, contract.ContractCodeHistory) //nolint:gosec if err != nil { return nil, errorsmod.Wrapf(err, "contract number %d", i) } - maxContractID = i + 1 // not ideal but max(contractID) is not persisted otherwise } for i, seq := range data.Sequences { @@ -61,13 +61,16 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, msgRo } // sanity check seq values - seqVal := keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID) + seqVal := keeper.PeekAutoIncrementID(ctx, types.KeySequenceCodeID) if seqVal <= maxCodeID { - return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastCodeID), seqVal, maxCodeID) + return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeySequenceCodeID), seqVal, maxCodeID) } - seqVal = keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID) - if seqVal <= uint64(maxContractID) { - return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastInstanceID), seqVal, maxContractID) + // ensure next classic address is unused so that we know the sequence is good + rCtx, _ := ctx.CacheContext() + seqVal = keeper.PeekAutoIncrementID(rCtx, types.KeySequenceInstanceID) + addr := keeper.ClassicAddressGenerator()(rCtx, seqVal, nil) + if keeper.HasContractInfo(ctx, addr) { + return nil, errorsmod.Wrapf(types.ErrInvalid, "value: %d for seq %s was used already", seqVal, string(types.KeySequenceInstanceID)) } if len(data.GenMsgs) == 0 { @@ -125,7 +128,7 @@ func ExportGenesis(ctx sdk.Context, keeper *Keeper) *types.GenesisState { return false }) - for _, k := range [][]byte{types.KeyLastCodeID, types.KeyLastInstanceID} { + for _, k := range [][]byte{types.KeySequenceCodeID, types.KeySequenceInstanceID} { genState.Sequences = append(genState.Sequences, types.Sequence{ IDKey: k, Value: keeper.PeekAutoIncrementID(ctx, k), diff --git a/x/wasm/keeper/genesis_test.go b/x/wasm/keeper/genesis_test.go index 273dfd7b7a..9fdf5dd912 100644 --- a/x/wasm/keeper/genesis_test.go +++ b/x/wasm/keeper/genesis_test.go @@ -11,26 +11,25 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" - - "github.com/cosmos/cosmos-sdk/baseapp" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - wasmvm "github.com/CosmWasm/wasmvm" dbm "github.com/cometbft/cometbft-db" + abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + fuzz "github.com/google/gofuzz" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - fuzz "github.com/google/gofuzz" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -157,6 +156,21 @@ func TestGenesisExportImport(t *testing.T) { } } +func TestGenesisExportImportWithPredictableAddress(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) + k := keepers.WasmKeeper + contractKeeper := NewGovPermissionKeeper(k) + eCtx, _ := ctx.CacheContext() + codeID := StoreReflectContract(t, eCtx, keepers).CodeID + creator := RandomAccountAddress(t) + _, _, err := keepers.ContractKeeper.Instantiate2(eCtx, codeID, creator, nil, []byte("{}"), "testing", nil, []byte("my_salt"), false) + require.NoError(t, err) + genesisState := ExportGenesis(eCtx, k) + // when imported + _, err = InitGenesis(ctx, k, *genesisState, TestHandler(contractKeeper)) + require.NoError(t, err) +} + func TestGenesisInit(t *testing.T) { wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) @@ -176,8 +190,8 @@ func TestGenesisInit(t *testing.T) { CodeBytes: wasmCode, }}, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: 2}, - {IDKey: types.KeyLastInstanceID, Value: 1}, + {IDKey: types.KeySequenceCodeID, Value: 2}, + {IDKey: types.KeySequenceInstanceID, Value: 1}, }, Params: types.DefaultParams(), }, @@ -195,8 +209,8 @@ func TestGenesisInit(t *testing.T) { CodeBytes: wasmCode, }}, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: 10}, - {IDKey: types.KeyLastInstanceID, Value: 1}, + {IDKey: types.KeySequenceCodeID, Value: 10}, + {IDKey: types.KeySequenceInstanceID, Value: 1}, }, Params: types.DefaultParams(), }, @@ -215,8 +229,8 @@ func TestGenesisInit(t *testing.T) { }}, Contracts: nil, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: 3}, - {IDKey: types.KeyLastInstanceID, Value: 1}, + {IDKey: types.KeySequenceCodeID, Value: 3}, + {IDKey: types.KeySequenceInstanceID, Value: 1}, }, Params: types.DefaultParams(), }, @@ -286,8 +300,8 @@ func TestGenesisInit(t *testing.T) { }, }, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: 2}, - {IDKey: types.KeyLastInstanceID, Value: 2}, + {IDKey: types.KeySequenceCodeID, Value: 2}, + {IDKey: types.KeySequenceInstanceID, Value: 2}, }, Params: types.DefaultParams(), }, @@ -326,8 +340,8 @@ func TestGenesisInit(t *testing.T) { }, }, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: 2}, - {IDKey: types.KeyLastInstanceID, Value: 3}, + {IDKey: types.KeySequenceCodeID, Value: 2}, + {IDKey: types.KeySequenceInstanceID, Value: 3}, }, Params: types.DefaultParams(), }, @@ -438,12 +452,12 @@ func TestGenesisInit(t *testing.T) { CodeBytes: wasmCode, }}, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: 1}, + {IDKey: types.KeySequenceCodeID, Value: 1}, }, Params: types.DefaultParams(), }, }, - "prevent contract id seq init value == count contracts": { + "prevent contract id seq init value not high enough": { src: types.GenesisState{ Codes: []types.Code{{ CodeID: firstCodeID, @@ -465,8 +479,8 @@ func TestGenesisInit(t *testing.T) { }, }, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: 2}, - {IDKey: types.KeyLastInstanceID, Value: 1}, + {IDKey: types.KeySequenceCodeID, Value: 2}, + {IDKey: types.KeySequenceInstanceID, Value: 1}, }, Params: types.DefaultParams(), }, @@ -659,8 +673,8 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) { }, } assert.Equal(t, expHistory, keeper.GetContractHistory(ctx, contractAddr)) - assert.Equal(t, uint64(2), keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID)) - assert.Equal(t, uint64(3), keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID)) + assert.Equal(t, uint64(2), keeper.PeekAutoIncrementID(ctx, types.KeySequenceCodeID)) + assert.Equal(t, uint64(3), keeper.PeekAutoIncrementID(ctx, types.KeySequenceInstanceID)) } func TestSupportedGenMsgTypes(t *testing.T) { @@ -764,7 +778,7 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context) { wasmConfig := types.DefaultWasmConfig() srcKeeper := NewKeeper( - encodingConfig.Marshaler, + encodingConfig.Codec, keyWasm, authkeeper.AccountKeeper{}, &bankkeeper.BaseKeeper{}, diff --git a/x/wasm/keeper/handler_plugin.go b/x/wasm/keeper/handler_plugin.go index 3e38e09fa3..e812411c51 100644 --- a/x/wasm/keeper/handler_plugin.go +++ b/x/wasm/keeper/handler_plugin.go @@ -4,15 +4,16 @@ import ( "errors" "fmt" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + errorsmod "cosmossdk.io/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/handler_plugin_encoders.go b/x/wasm/keeper/handler_plugin_encoders.go index 984815cdd7..5e07ac7e69 100644 --- a/x/wasm/keeper/handler_plugin_encoders.go +++ b/x/wasm/keeper/handler_plugin_encoders.go @@ -4,19 +4,20 @@ import ( "encoding/json" "fmt" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + errorsmod "cosmossdk.io/errors" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/handler_plugin_encoders_test.go b/x/wasm/keeper/handler_plugin_encoders_test.go index c4417f5dba..6ef32a3d53 100644 --- a/x/wasm/keeper/handler_plugin_encoders_test.go +++ b/x/wasm/keeper/handler_plugin_encoders_test.go @@ -4,13 +4,6 @@ import ( "testing" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/gogoproto/proto" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -18,6 +11,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -47,13 +47,14 @@ func TestEncoding(t *testing.T) { bankMsgBin, err := proto.Marshal(bankMsg) require.NoError(t, err) - content, err := codectypes.NewAnyWithValue(types.StoreCodeProposalFixture()) + msg, err := codectypes.NewAnyWithValue(types.MsgStoreCodeFixture()) require.NoError(t, err) - - proposalMsg := &v1beta1.MsgSubmitProposal{ + proposalMsg := &v1.MsgSubmitProposal{ Proposer: addr1.String(), + Messages: []*codectypes.Any{msg}, InitialDeposit: sdk.NewCoins(sdk.NewInt64Coin("uatom", 12345)), - Content: content, + Title: "proposal", + Summary: "proposal summary", } proposalMsgBin, err := proto.Marshal(proposalMsg) require.NoError(t, err) @@ -293,7 +294,7 @@ func TestEncoding(t *testing.T) { }, }, }, - "staking delegate to non-validator": { + "staking delegate to non-validator - invalid": { sender: addr1, srcMsg: wasmvmtypes.CosmosMsg{ Staking: &wasmvmtypes.StakingMsg{ @@ -419,7 +420,7 @@ func TestEncoding(t *testing.T) { sender: addr2, srcMsg: wasmvmtypes.CosmosMsg{ Stargate: &wasmvmtypes.StargateMsg{ - TypeURL: "/cosmos.gov.v1beta1.MsgSubmitProposal", + TypeURL: "/cosmos.gov.v1.MsgSubmitProposal", Value: proposalMsgBin, }, }, @@ -560,7 +561,7 @@ func TestEncoding(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { var ctx sdk.Context - encoder := DefaultEncoders(encodingConfig.Marshaler, tc.transferPortSource) + encoder := DefaultEncoders(encodingConfig.Codec, tc.transferPortSource) res, err := encoder.Encode(ctx, tc.sender, tc.srcContractIBCPort, tc.srcMsg) if tc.expError { assert.Error(t, err) @@ -715,7 +716,7 @@ func TestEncodeGovMsg(t *testing.T) { }, }, }, - "Gov weighted vote: duplicate option": { + "Gov weighted vote: duplicate option - invalid": { sender: myAddr, srcMsg: wasmvmtypes.CosmosMsg{ Gov: &wasmvmtypes.GovMsg{ @@ -740,7 +741,7 @@ func TestEncodeGovMsg(t *testing.T) { }, expInvalid: true, }, - "Gov weighted vote: weight sum exceeds 1": { + "Gov weighted vote: weight sum exceeds 1- invalid": { sender: myAddr, srcMsg: wasmvmtypes.CosmosMsg{ Gov: &wasmvmtypes.GovMsg{ @@ -765,7 +766,7 @@ func TestEncodeGovMsg(t *testing.T) { }, expInvalid: true, }, - "Gov weighted vote: weight sum less than 1": { + "Gov weighted vote: weight sum less than 1 - invalid": { sender: myAddr, srcMsg: wasmvmtypes.CosmosMsg{ Gov: &wasmvmtypes.GovMsg{ @@ -795,7 +796,7 @@ func TestEncodeGovMsg(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { var ctx sdk.Context - encoder := DefaultEncoders(encodingConfig.Marshaler, tc.transferPortSource) + encoder := DefaultEncoders(encodingConfig.Codec, tc.transferPortSource) res, gotEncErr := encoder.Encode(ctx, tc.sender, "myIBCPort", tc.srcMsg) if tc.expError { assert.Error(t, gotEncErr) diff --git a/x/wasm/keeper/handler_plugin_test.go b/x/wasm/keeper/handler_plugin_test.go index beea6dafd8..9fc666b101 100644 --- a/x/wasm/keeper/handler_plugin_test.go +++ b/x/wasm/keeper/handler_plugin_test.go @@ -4,20 +4,21 @@ import ( "encoding/json" "testing" - errorsmod "cosmossdk.io/errors" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/log" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -237,7 +238,7 @@ func TestIBCRawPacketHandler(t *testing.T) { var capturedPacket *CapturedPacket capturePacketsSenderMock := &wasmtesting.MockIBCPacketSender{ - SendPacketFn: func(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) { + SendPacketFn: func(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) { capturedPacket = &CapturedPacket{ sourcePort: sourcePort, sourceChannel: sourceChannel, @@ -306,7 +307,7 @@ func TestIBCRawPacketHandler(t *testing.T) { capturedPacket = nil // when h := NewIBCRawPacketHandler(capturePacketsSenderMock, spec.chanKeeper, spec.capKeeper) - evts, data, gotErr := h.DispatchMsg(ctx, RandomAccountAddress(t), ibcPort, wasmvmtypes.CosmosMsg{IBC: &wasmvmtypes.IBCMsg{SendPacket: &spec.srcMsg}}) + evts, data, gotErr := h.DispatchMsg(ctx, RandomAccountAddress(t), ibcPort, wasmvmtypes.CosmosMsg{IBC: &wasmvmtypes.IBCMsg{SendPacket: &spec.srcMsg}}) //nolint:gosec // then require.True(t, spec.expErr.Is(gotErr), "exp %v but got %#+v", spec.expErr, gotErr) if spec.expErr != nil { @@ -386,10 +387,10 @@ func TestBurnCoinMessageHandlerIntegration(t *testing.T) { for name, spec := range specs { t.Run(name, func(t *testing.T) { ctx, _ = parentCtx.CacheContext() - k.wasmVM = &wasmtesting.MockWasmer{ExecuteFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { + k.wasmVM = &wasmtesting.MockWasmEngine{ExecuteFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { return &wasmvmtypes.Response{ Messages: []wasmvmtypes.SubMsg{ - {Msg: wasmvmtypes.CosmosMsg{Bank: &wasmvmtypes.BankMsg{Burn: &spec.msg}}, ReplyOn: wasmvmtypes.ReplyNever}, + {Msg: wasmvmtypes.CosmosMsg{Bank: &wasmvmtypes.BankMsg{Burn: &spec.msg}}, ReplyOn: wasmvmtypes.ReplyNever}, //nolint:gosec }, }, 0, nil }} diff --git a/x/wasm/keeper/ibc.go b/x/wasm/keeper/ibc.go index 30eb34875a..ac31dfac66 100644 --- a/x/wasm/keeper/ibc.go +++ b/x/wasm/keeper/ibc.go @@ -3,10 +3,12 @@ package keeper import ( "strings" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/ibc_test.go b/x/wasm/keeper/ibc_test.go index 063dfb7f7d..01ed35b3fa 100644 --- a/x/wasm/keeper/ibc_test.go +++ b/x/wasm/keeper/ibc_test.go @@ -4,10 +4,10 @@ import ( "fmt" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestDontBindPortNonIBCContract(t *testing.T) { diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index fef5dd685b..6c8d45dc91 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -11,14 +11,15 @@ import ( "strings" "time" - errorsmod "cosmossdk.io/errors" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/log" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -46,7 +47,7 @@ type WasmVMQueryHandler interface { type CoinTransferrer interface { // TransferCoins sends the coin amounts from the source to the destination with rules applied. - TransferCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + TransferCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error } // AccountPruner handles the balances and data cleanup for accounts that are pruned on contract instantiate. @@ -76,7 +77,7 @@ var defaultAcceptedAccountTypes = map[reflect.Type]struct{}{ reflect.TypeOf(&authtypes.BaseAccount{}): {}, } -// Keeper will have a reference to Wasmer with it's own data directory. +// Keeper will have a reference to Wasm Engine with it's own data directory. type Keeper struct { storeKey storetypes.StoreKey cdc codec.Codec @@ -84,13 +85,13 @@ type Keeper struct { bank CoinTransferrer portKeeper types.PortKeeper capabilityKeeper types.CapabilityKeeper - wasmVM types.WasmerEngine + wasmVM types.WasmEngine wasmVMQueryHandler WasmVMQueryHandler wasmVMResponseHandler WasmVMResponseHandler messenger Messenger // queryGasLimit is the max wasmvm gas that can be spent on executing a query with a contract queryGasLimit uint64 - gasRegister GasRegister + gasRegister types.GasRegister maxQueryStackSize uint32 acceptedAccountTypes map[reflect.Type]struct{} accountPruner AccountPruner @@ -144,6 +145,11 @@ func (k Keeper) GetAuthority() string { return k.authority } +// GetGasRegister returns the x/wasm module's gas register. +func (k Keeper) GetGasRegister() types.GasRegister { + return k.gasRegister +} + func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *types.AccessConfig, authZ types.AuthorizationPolicy) (codeID uint64, checksum []byte, err error) { if creator == nil { return 0, checksum, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "cannot be nil") @@ -180,7 +186,7 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, if err != nil { return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error()) } - codeID = k.autoIncrementID(ctx, types.KeyLastCodeID) + codeID = k.autoIncrementID(ctx, types.KeySequenceCodeID) k.Logger(ctx).Debug("storing new contract", "capabilities", report.RequiredCapabilities, "code_id", codeID) codeInfo := types.NewCodeInfo(checksum, creator, *instantiateAccess) k.storeCodeInfo(ctx, codeID, codeInfo) @@ -365,7 +371,7 @@ func (k Keeper) instantiate( } // Execute executes the contract instance -func (k Keeper) execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) { +func (k Keeper) execute(ctx sdk.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) { defer telemetry.MeasureSince(time.Now(), "wasm", "contract", "execute") contractInfo, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddress) if err != nil { @@ -635,6 +641,25 @@ func (k Keeper) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAd return nil } +func (k Keeper) setContractLabel(ctx sdk.Context, contractAddress, caller sdk.AccAddress, newLabel string, authZ types.AuthorizationPolicy) error { + contractInfo := k.GetContractInfo(ctx, contractAddress) + if contractInfo == nil { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract") + } + if !authZ.CanModifyContract(contractInfo.AdminAddr(), caller) { + return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "can not modify contract") + } + contractInfo.Label = newLabel + k.storeContractInfo(ctx, contractAddress, contractInfo) + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeUpdateContractLabel, + sdk.NewAttribute(types.AttributeKeyContractAddr, contractAddress.String()), + sdk.NewAttribute(types.AttributeKeyNewLabel, newLabel), + )) + + return nil +} + func (k Keeper) appendToContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress, newEntries ...types.ContractCodeHistoryEntry) { store := ctx.KVStore(k.storeKey) // find last element position @@ -1036,26 +1061,26 @@ func (k Keeper) consumeRuntimeGas(ctx sdk.Context, gas uint64) { ctx.GasMeter().ConsumeGas(consumed, "wasm contract") // throw OutOfGas error if we ran out (got exactly to zero due to better limit enforcing) if ctx.GasMeter().IsOutOfGas() { - panic(sdk.ErrorOutOfGas{Descriptor: "Wasmer function execution"}) + panic(sdk.ErrorOutOfGas{Descriptor: "Wasm engine function execution"}) } } -func (k Keeper) autoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 { +func (k Keeper) autoIncrementID(ctx sdk.Context, sequenceKey []byte) uint64 { store := ctx.KVStore(k.storeKey) - bz := store.Get(lastIDKey) + bz := store.Get(sequenceKey) id := uint64(1) if bz != nil { id = binary.BigEndian.Uint64(bz) } bz = sdk.Uint64ToBigEndian(id + 1) - store.Set(lastIDKey, bz) + store.Set(sequenceKey, bz) return id } // PeekAutoIncrementID reads the current value without incrementing it. -func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 { +func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, sequenceKey []byte) uint64 { store := ctx.KVStore(k.storeKey) - bz := store.Get(lastIDKey) + bz := store.Get(sequenceKey) id := uint64(1) if bz != nil { id = binary.BigEndian.Uint64(bz) @@ -1063,13 +1088,13 @@ func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 { return id } -func (k Keeper) importAutoIncrementID(ctx sdk.Context, lastIDKey []byte, val uint64) error { +func (k Keeper) importAutoIncrementID(ctx sdk.Context, sequenceKey []byte, val uint64) error { store := ctx.KVStore(k.storeKey) - if store.Has(lastIDKey) { - return errorsmod.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(lastIDKey)) + if store.Has(sequenceKey) { + return errorsmod.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(sequenceKey)) } bz := sdk.Uint64ToBigEndian(val) - store.Set(lastIDKey, bz) + store.Set(sequenceKey, bz) return nil } @@ -1100,10 +1125,10 @@ func (k Keeper) newQueryHandler(ctx sdk.Context, contractAddress sdk.AccAddress) // MultipliedGasMeter wraps the GasMeter from context and multiplies all reads by out defined multiplier type MultipliedGasMeter struct { originalMeter sdk.GasMeter - GasRegister GasRegister + GasRegister types.GasRegister } -func NewMultipliedGasMeter(originalMeter sdk.GasMeter, gr GasRegister) MultipliedGasMeter { +func NewMultipliedGasMeter(originalMeter sdk.GasMeter, gr types.GasRegister) MultipliedGasMeter { return MultipliedGasMeter{originalMeter: originalMeter, GasRegister: gr} } @@ -1136,7 +1161,7 @@ func (k Keeper) QueryGasLimit() sdk.Gas { return k.queryGasLimit } -// BankCoinTransferrer replicates the cosmos-sdk behaviour as in +// BankCoinTransferrer replicates the cosmos-sdk behavior as in // https://github.com/cosmos/cosmos-sdk/blob/v0.41.4/x/bank/keeper/msg_server.go#L26 type BankCoinTransferrer struct { keeper types.BankKeeper @@ -1150,7 +1175,7 @@ func NewBankCoinTransferrer(keeper types.BankKeeper) BankCoinTransferrer { // TransferCoins transfers coins from source to destination account when coin send was enabled for them and the recipient // is not in the blocked address list. -func (c BankCoinTransferrer) TransferCoins(parentCtx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amount sdk.Coins) error { +func (c BankCoinTransferrer) TransferCoins(parentCtx sdk.Context, fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) error { em := sdk.NewEventManager() ctx := parentCtx.WithEventManager(em) if err := c.keeper.IsSendEnabledCoins(ctx, amount...); err != nil { diff --git a/x/wasm/keeper/keeper_cgo.go b/x/wasm/keeper/keeper_cgo.go index 166f9b8918..743ac64de4 100644 --- a/x/wasm/keeper/keeper_cgo.go +++ b/x/wasm/keeper/keeper_cgo.go @@ -5,10 +5,10 @@ package keeper import ( "path/filepath" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - wasmvm "github.com/CosmWasm/wasmvm" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -46,7 +46,7 @@ func NewKeeper( capabilityKeeper: capabilityKeeper, messenger: NewDefaultMessageHandler(router, ics4Wrapper, channelKeeper, capabilityKeeper, bankKeeper, cdc, portSource), queryGasLimit: wasmConfig.SmartQueryGasLimit, - gasRegister: NewDefaultWasmGasRegister(), + gasRegister: types.NewDefaultWasmGasRegister(), maxQueryStackSize: types.DefaultMaxQueryStackSize, acceptedAccountTypes: defaultAcceptedAccountTypes, propagateGovAuthorization: map[types.AuthorizationPolicyAction]struct{}{ diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index ce5ccfcd2d..c55e738d5c 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -8,17 +8,20 @@ import ( "fmt" stdrand "math/rand" "os" - "strings" "testing" "time" - errorsmod "cosmossdk.io/errors" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/rand" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + fuzz "github.com/google/gofuzz" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" stypes "github.com/cosmos/cosmos-sdk/store/types" @@ -30,10 +33,8 @@ import ( vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - fuzz "github.com/google/gofuzz" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -41,7 +42,7 @@ import ( //go:embed testdata/hackatom.wasm var hackatomWasm []byte -const AvailableCapabilities = "iterator,staking,stargate,cosmwasm_1_1" +const AvailableCapabilities = "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4" func TestNewKeeper(t *testing.T) { _, keepers := CreateTestInput(t, false, AvailableCapabilities) @@ -64,7 +65,7 @@ func TestCreateSuccess(t *testing.T) { require.NoError(t, err) require.Equal(t, hackatomWasm, storedCode) // and events emitted - codeHash := strings.ToLower("5ca46abb8e9b1b754a5c906f9c0f4eec9121ee09e3cee55ea0faba54763706e2") + codeHash := testdata.ChecksumHackatom exp := sdk.Events{sdk.NewEvent("store_code", sdk.NewAttribute("code_checksum", codeHash), sdk.NewAttribute("code_id", "1"))} assert.Equal(t, exp, em.Events()) } @@ -547,7 +548,7 @@ func TestInstantiateWithPermissions(t *testing.T) { accKeeper, bankKeeper, keeper := keepers.AccountKeeper, keepers.BankKeeper, keepers.ContractKeeper fundAccounts(t, ctx, accKeeper, bankKeeper, spec.srcActor, deposit) - contractID, _, err := keeper.Create(ctx, myAddr, hackatomWasm, &spec.srcPermission) + contractID, _, err := keeper.Create(ctx, myAddr, hackatomWasm, &spec.srcPermission) //nolint:gosec require.NoError(t, err) _, _, err = keepers.ContractKeeper.Instantiate(ctx, contractID, spec.srcActor, nil, initMsgBz, "demo contract 1", nil) @@ -564,6 +565,7 @@ func TestInstantiateWithAccounts(t *testing.T) { senderAddr := DeterministicAccountAddress(t, 1) keepers.Faucet.Fund(parentCtx, senderAddr, sdk.NewInt64Coin("denom", 100000000)) + myTestLabel := "testing" mySalt := []byte(`my salt`) contractAddr := BuildContractAddressPredictable(example.Checksum, senderAddr, mySalt, []byte{}) @@ -710,7 +712,7 @@ func TestInstantiateWithNonExistingCodeID(t *testing.T) { func TestInstantiateWithContractDataResponse(t *testing.T) { ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) - wasmerMock := &wasmtesting.MockWasmer{ + wasmEngineMock := &wasmtesting.MockWasmEngine{ InstantiateFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { return &wasmvmtypes.Response{Data: []byte("my-response-data")}, 0, nil }, @@ -718,7 +720,7 @@ func TestInstantiateWithContractDataResponse(t *testing.T) { StoreCodeFn: wasmtesting.NoOpStoreCodeFn, } - example := StoreRandomContract(t, ctx, keepers, wasmerMock) + example := StoreRandomContract(t, ctx, keepers, wasmEngineMock) _, data, err := keepers.ContractKeeper.Instantiate(ctx, example.CodeID, example.CreatorAddr, nil, nil, "test", nil) require.NoError(t, err) assert.Equal(t, []byte("my-response-data"), data) @@ -737,7 +739,7 @@ func TestInstantiateWithContractFactoryChildQueriesParent(t *testing.T) { var instantiationCount int callbacks := make([]func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error), 2) - wasmerMock := &wasmtesting.MockWasmer{ + wasmEngineMock := &wasmtesting.MockWasmEngine{ // dispatch instantiation calls to callbacks InstantiateFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { require.Greater(t, len(callbacks), instantiationCount, "unexpected call to instantiation") @@ -753,11 +755,11 @@ func TestInstantiateWithContractFactoryChildQueriesParent(t *testing.T) { router := baseapp.NewMsgServiceRouter() router.SetInterfaceRegistry(keepers.EncodingConfig.InterfaceRegistry) types.RegisterMsgServer(router, NewMsgServerImpl(keeper)) - keeper.messenger = NewDefaultMessageHandler(router, nil, nil, nil, nil, keepers.EncodingConfig.Marshaler, nil) + keeper.messenger = NewDefaultMessageHandler(router, nil, nil, nil, nil, keepers.EncodingConfig.Codec, nil) // overwrite wasmvm in response handler keeper.wasmVMResponseHandler = NewDefaultWasmVMContractResponseHandler(NewMessageDispatcher(keeper.messenger, keeper)) - example := StoreRandomContract(t, ctx, keepers, wasmerMock) + example := StoreRandomContract(t, ctx, keepers, wasmEngineMock) // factory contract callbacks[0] = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { t.Log("called factory") @@ -860,7 +862,7 @@ func TestExecute(t *testing.T) { // make sure gas is properly deducted from ctx gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x1a154), gasAfter-gasBefore) + require.Equal(t, uint64(0x1a155), gasAfter-gasBefore) } // ensure bob now exists and got both payments released bobAcct = accKeeper.GetAccount(ctx, bob) @@ -1366,11 +1368,10 @@ func TestMigrateWithDispatchedMessage(t *testing.T) { contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, originalContractID, creator, fred, initMsgBz, "demo contract", deposit) require.NoError(t, err) - migMsgBz := BurnerExampleInitMsg{Payout: myPayoutAddr}.GetBytes(t) + migMsgBz := BurnerExampleInitMsg{Payout: myPayoutAddr, Delete: 100}.GetBytes(t) ctx = ctx.WithEventManager(sdk.NewEventManager()).WithBlockHeight(ctx.BlockHeight() + 1) - data, err := keeper.Migrate(ctx, contractAddr, fred, burnerContractID, migMsgBz) + _, err = keeper.Migrate(ctx, contractAddr, fred, burnerContractID, migMsgBz) require.NoError(t, err) - assert.Equal(t, "burnt 1 keys", string(data)) type dict map[string]interface{} expEvents := []dict{ { @@ -1384,8 +1385,9 @@ func TestMigrateWithDispatchedMessage(t *testing.T) { "Type": "wasm", "Attr": []dict{ {"_contract_address": contractAddr}, - {"action": "burn"}, + {"action": "migrate"}, {"payout": myPayoutAddr}, + {"deleted_entries": "1"}, }, }, { @@ -1466,7 +1468,7 @@ func TestIterateContractsByCode(t *testing.T) { func TestIterateContractsByCodeWithMigration(t *testing.T) { // mock migration so that it does not fail when migrate example1 to example2.codeID - mockWasmVM := wasmtesting.MockWasmer{MigrateFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, migrateMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { + mockWasmVM := wasmtesting.MockWasmEngine{MigrateFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, migrateMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { return &wasmvmtypes.Response{}, 1, nil }} wasmtesting.MakeInstantiable(&mockWasmVM) @@ -1732,7 +1734,7 @@ func TestPinCode(t *testing.T) { k := keepers.WasmKeeper var capturedChecksums []wasmvm.Checksum - mock := wasmtesting.MockWasmer{PinFn: func(checksum wasmvm.Checksum) error { + mock := wasmtesting.MockWasmEngine{PinFn: func(checksum wasmvm.Checksum) error { capturedChecksums = append(capturedChecksums, checksum) return nil }} @@ -1759,7 +1761,7 @@ func TestUnpinCode(t *testing.T) { k := keepers.WasmKeeper var capturedChecksums []wasmvm.Checksum - mock := wasmtesting.MockWasmer{ + mock := wasmtesting.MockWasmEngine{ PinFn: func(checksum wasmvm.Checksum) error { return nil }, @@ -1793,7 +1795,7 @@ func TestInitializePinnedCodes(t *testing.T) { k := keepers.WasmKeeper var capturedChecksums []wasmvm.Checksum - mock := wasmtesting.MockWasmer{PinFn: func(checksum wasmvm.Checksum) error { + mock := wasmtesting.MockWasmEngine{PinFn: func(checksum wasmvm.Checksum) error { capturedChecksums = append(capturedChecksums, checksum) return nil }} @@ -1821,7 +1823,7 @@ func TestInitializePinnedCodes(t *testing.T) { func TestPinnedContractLoops(t *testing.T) { var capturedChecksums []wasmvm.Checksum - mock := wasmtesting.MockWasmer{PinFn: func(checksum wasmvm.Checksum) error { + mock := wasmtesting.MockWasmEngine{PinFn: func(checksum wasmvm.Checksum) error { capturedChecksums = append(capturedChecksums, checksum) return nil }} @@ -1947,7 +1949,7 @@ func TestNewDefaultWasmVMContractResponseHandler(t *testing.T) { func TestReply(t *testing.T) { ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) k := keepers.WasmKeeper - var mock wasmtesting.MockWasmer + var mock wasmtesting.MockWasmEngine wasmtesting.MakeInstantiable(&mock) example := SeedNewContractInstance(t, ctx, keepers, &mock) @@ -1970,7 +1972,7 @@ func TestReply(t *testing.T) { Bank: &wasmvmtypes.BankQuery{ Balance: &wasmvmtypes.BalanceQuery{Address: env.Contract.Address, Denom: "stake"}, }, - }, 10_000*DefaultGasMultiplier) + }, 10_000*types.DefaultGasMultiplier) require.NoError(t, err) var gotBankRsp wasmvmtypes.BalanceResponse require.NoError(t, json.Unmarshal(bzRsp, &gotBankRsp)) @@ -2016,7 +2018,7 @@ func TestReply(t *testing.T) { func TestQueryIsolation(t *testing.T) { ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) k := keepers.WasmKeeper - var mock wasmtesting.MockWasmer + var mock wasmtesting.MockWasmEngine wasmtesting.MakeInstantiable(&mock) example := SeedNewContractInstance(t, ctx, keepers, &mock) WithQueryHandlerDecorator(func(other WasmVMQueryHandler) WasmVMQueryHandler { @@ -2034,7 +2036,7 @@ func TestQueryIsolation(t *testing.T) { mock.ReplyFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, reply wasmvmtypes.Reply, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { _, err := querier.Query(wasmvmtypes.QueryRequest{ Custom: []byte(`{}`), - }, 10000*DefaultGasMultiplier) + }, 10000*types.DefaultGasMultiplier) require.NoError(t, err) return &wasmvmtypes.Response{}, 0, nil } @@ -2226,12 +2228,16 @@ func TestCoinBurnerPruneBalances(t *testing.T) { expErr *errorsmod.Error }{ "vesting account - all removed": { - setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { return myVestingAccount }, + setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { + t.Helper() + return myVestingAccount + }, expBalances: sdk.NewCoins(), expHandled: true, }, "vesting account with other tokens - only original denoms removed": { setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { + t.Helper() keepers.Faucet.Fund(ctx, vestingAddr, sdk.NewCoin("other", sdk.NewInt(2))) return myVestingAccount }, @@ -2240,6 +2246,7 @@ func TestCoinBurnerPruneBalances(t *testing.T) { }, "non vesting account - not handled": { setupAcc: func(t *testing.T, ctx sdk.Context) authtypes.AccountI { + t.Helper() return &authtypes.BaseAccount{Address: myVestingAccount.GetAddress().String()} }, expBalances: sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(100))), @@ -2426,6 +2433,124 @@ func TestSetContractAdmin(t *testing.T) { } } +func TestGasConsumed(t *testing.T) { + specs := map[string]struct { + originalMeter stypes.GasMeter + gasRegister types.WasmGasRegister + consumeGas sdk.Gas + expPanic bool + expMultipliedGasConsumed uint64 + }{ + "all good": { + originalMeter: sdk.NewGasMeter(100), + gasRegister: types.NewWasmGasRegister(types.DefaultGasRegisterConfig()), + consumeGas: sdk.Gas(1), + expMultipliedGasConsumed: 140000000, + }, + "consumeGas = limit": { + originalMeter: sdk.NewGasMeter(1), + gasRegister: types.NewWasmGasRegister(types.DefaultGasRegisterConfig()), + consumeGas: sdk.Gas(1), + expMultipliedGasConsumed: 140000000, + }, + "consumeGas > limit": { + originalMeter: sdk.NewGasMeter(10), + gasRegister: types.NewWasmGasRegister(types.DefaultGasRegisterConfig()), + consumeGas: sdk.Gas(11), + expPanic: true, + }, + "nil original meter": { + gasRegister: types.NewWasmGasRegister(types.DefaultGasRegisterConfig()), + consumeGas: sdk.Gas(1), + expPanic: true, + }, + "nil gas register": { + originalMeter: sdk.NewGasMeter(100), + consumeGas: sdk.Gas(1), + expPanic: true, + }, + } + + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + m := NewMultipliedGasMeter(spec.originalMeter, spec.gasRegister) + if spec.expPanic { + assert.Panics(t, func() { + m.originalMeter.ConsumeGas(spec.consumeGas, "test-panic") + _ = m.GasConsumed() + }) + return + } + + m.originalMeter.ConsumeGas(spec.consumeGas, "test") + assert.Equal(t, spec.expMultipliedGasConsumed, m.GasConsumed()) + }) + } +} + +func TestSetContractLabel(t *testing.T) { + parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities) + k := keepers.WasmKeeper + example := InstantiateReflectExampleContract(t, parentCtx, keepers) + + specs := map[string]struct { + newLabel string + caller sdk.AccAddress + policy types.AuthorizationPolicy + contract sdk.AccAddress + expErr bool + }{ + "update label - default policy": { + newLabel: "new label", + caller: example.CreatorAddr, + policy: DefaultAuthorizationPolicy{}, + contract: example.Contract, + }, + "update label - gov policy": { + newLabel: "new label", + policy: GovAuthorizationPolicy{}, + caller: RandomAccountAddress(t), + contract: example.Contract, + }, + "update label - unauthorized": { + newLabel: "new label", + caller: RandomAccountAddress(t), + policy: DefaultAuthorizationPolicy{}, + contract: example.Contract, + expErr: true, + }, + "update label - unknown contract": { + newLabel: "new label", + caller: example.CreatorAddr, + policy: DefaultAuthorizationPolicy{}, + contract: RandomAccountAddress(t), + expErr: true, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + ctx, _ := parentCtx.CacheContext() + em := sdk.NewEventManager() + ctx = ctx.WithEventManager(em) + gotErr := k.setContractLabel(ctx, spec.contract, spec.caller, spec.newLabel, spec.policy) + if spec.expErr { + require.Error(t, gotErr) + return + } + require.NoError(t, gotErr) + assert.Equal(t, spec.newLabel, k.GetContractInfo(ctx, spec.contract).Label) + // and event emitted + require.Len(t, em.Events(), 1) + assert.Equal(t, "update_contract_label", em.Events()[0].Type) + exp := map[string]string{ + "_contract_address": spec.contract.String(), + "new_label": spec.newLabel, + } + assert.Equal(t, exp, attrsToStringMap(em.Events()[0].Attributes)) + }) + } +} + func attrsToStringMap(attrs []abci.EventAttribute) map[string]string { r := make(map[string]string, len(attrs)) for _, v := range attrs { diff --git a/x/wasm/keeper/metrics.go b/x/wasm/keeper/metrics.go index 4c4b959f50..93f88581ca 100644 --- a/x/wasm/keeper/metrics.go +++ b/x/wasm/keeper/metrics.go @@ -29,6 +29,9 @@ type WasmVMMetricsCollector struct { // NewWasmVMMetricsCollector constructor func NewWasmVMMetricsCollector(s metricSource) *WasmVMMetricsCollector { + if s == nil { + panic("wasmvm instance must not be nil") + } return &WasmVMMetricsCollector{ source: s, CacheHitsDescr: prometheus.NewDesc("wasmvm_cache_hits_total", "Total number of cache hits", []string{"type"}, nil), diff --git a/x/wasm/keeper/migrations.go b/x/wasm/keeper/migrations.go index 8bf0f96c34..a7209035fc 100644 --- a/x/wasm/keeper/migrations.go +++ b/x/wasm/keeper/migrations.go @@ -3,11 +3,10 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/exported" v1 "github.com/CosmWasm/wasmd/x/wasm/migrations/v1" v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2" v3 "github.com/CosmWasm/wasmd/x/wasm/migrations/v3" - - "github.com/CosmWasm/wasmd/x/wasm/exported" ) // Migrator is a struct for handling in-place store migrations. diff --git a/x/wasm/keeper/migrations_integration_test.go b/x/wasm/keeper/migrations_integration_test.go index ca8414bad1..5cd5a78283 100644 --- a/x/wasm/keeper/migrations_integration_test.go +++ b/x/wasm/keeper/migrations_integration_test.go @@ -3,16 +3,16 @@ package keeper_test import ( "testing" - "github.com/CosmWasm/wasmd/x/wasm/types" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestModuleMigrations(t *testing.T) { diff --git a/x/wasm/keeper/msg_dispatcher.go b/x/wasm/keeper/msg_dispatcher.go index f82697d8ea..c9f5c9b864 100644 --- a/x/wasm/keeper/msg_dispatcher.go +++ b/x/wasm/keeper/msg_dispatcher.go @@ -6,9 +6,11 @@ import ( "sort" "strings" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/wasm/keeper/msg_dispatcher_test.go b/x/wasm/keeper/msg_dispatcher_test.go index d3acd547e1..54a316a2cc 100644 --- a/x/wasm/keeper/msg_dispatcher_test.go +++ b/x/wasm/keeper/msg_dispatcher_test.go @@ -8,10 +8,11 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/libs/log" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" ) diff --git a/x/wasm/keeper/msg_server.go b/x/wasm/keeper/msg_server.go index ace3059d66..06963f9083 100644 --- a/x/wasm/keeper/msg_server.go +++ b/x/wasm/keeper/msg_server.go @@ -4,6 +4,7 @@ import ( "context" errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -327,10 +328,6 @@ func (m msgServer) StoreAndInstantiateContract(goCtx context.Context, req *types return nil, errorsmod.Wrap(err, "authority") } - if err = req.ValidateBasic(); err != nil { - return nil, err - } - var adminAddr sdk.AccAddress if req.Admin != "" { if adminAddr, err = sdk.AccAddressFromBech32(req.Admin); err != nil { @@ -441,3 +438,63 @@ func (m msgServer) selectAuthorizationPolicy(ctx sdk.Context, actor string) type } return DefaultAuthorizationPolicy{} } + +// StoreAndMigrateContract stores and migrates the contract. +func (m msgServer) StoreAndMigrateContract(goCtx context.Context, req *types.MsgStoreAndMigrateContract) (*types.MsgStoreAndMigrateContractResponse, error) { + authorityAddr, err := sdk.AccAddressFromBech32(req.Authority) + if err != nil { + return nil, errorsmod.Wrap(err, "authority") + } + + if err = req.ValidateBasic(); err != nil { + return nil, err + } + + ctx := sdk.UnwrapSDKContext(goCtx) + policy := m.selectAuthorizationPolicy(ctx, req.Authority) + + codeID, checksum, err := m.keeper.create(ctx, authorityAddr, req.WASMByteCode, req.InstantiatePermission, policy) + if err != nil { + return nil, err + } + + contractAddr, err := sdk.AccAddressFromBech32(req.Contract) + if err != nil { + return nil, errorsmod.Wrap(err, "contract") + } + + data, err := m.keeper.migrate(ctx, contractAddr, authorityAddr, codeID, req.Msg, policy) + if err != nil { + return nil, err + } + + return &types.MsgStoreAndMigrateContractResponse{ + CodeID: codeID, + Checksum: checksum, + Data: data, + }, nil +} + +func (m msgServer) UpdateContractLabel(goCtx context.Context, msg *types.MsgUpdateContractLabel) (*types.MsgUpdateContractLabelResponse, error) { + if err := msg.ValidateBasic(); err != nil { + return nil, err + } + + ctx := sdk.UnwrapSDKContext(goCtx) + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, errorsmod.Wrap(err, "sender") + } + contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) + if err != nil { + return nil, errorsmod.Wrap(err, "contract") + } + + policy := m.selectAuthorizationPolicy(ctx, msg.Sender) + + if err := m.keeper.setContractLabel(ctx, contractAddr, senderAddr, msg.NewLabel, policy); err != nil { + return nil, err + } + + return &types.MsgUpdateContractLabelResponse{}, nil +} diff --git a/x/wasm/keeper/msg_server_integration_test.go b/x/wasm/keeper/msg_server_integration_test.go index e4b3ed6b45..27b73400fb 100644 --- a/x/wasm/keeper/msg_server_integration_test.go +++ b/x/wasm/keeper/msg_server_integration_test.go @@ -8,13 +8,13 @@ import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -132,7 +132,7 @@ func TestUpdateParams(t *testing.T) { require.NoError(t, err) // when - rsp, err := wasmApp.MsgServiceRouter().Handler(&spec.src)(ctx, &spec.src) + rsp, err := wasmApp.MsgServiceRouter().Handler(&spec.src)(ctx, &spec.src) //nolint:gosec require.NoError(t, err) var result types.MsgUpdateParamsResponse require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &result)) @@ -223,7 +223,7 @@ func TestAddCodeUploadParamsAddresses(t *testing.T) { require.NoError(t, err) // when - rsp, err := wasmApp.MsgServiceRouter().Handler(&spec.src)(ctx, &spec.src) + rsp, err := wasmApp.MsgServiceRouter().Handler(&spec.src)(ctx, &spec.src) //nolint:gosec if spec.expErr { require.Error(t, err) require.Nil(t, rsp) @@ -319,7 +319,7 @@ func TestRemoveCodeUploadParamsAddresses(t *testing.T) { require.NoError(t, err) // when - rsp, err := wasmApp.MsgServiceRouter().Handler(&spec.src)(ctx, &spec.src) + rsp, err := wasmApp.MsgServiceRouter().Handler(&spec.src)(ctx, &spec.src) //nolint:gosec if spec.expErr { require.Error(t, err) require.Nil(t, rsp) @@ -1048,3 +1048,182 @@ func TestUpdateInstantiateConfig(t *testing.T) { }) } } + +func TestStoreAndMigrateContract(t *testing.T) { + wasmApp := app.Setup(t) + ctx := wasmApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()}) + + checksum, err := wasmvm.CreateChecksum(hackatomContract) + require.NoError(t, err) + + var ( + myAddress sdk.AccAddress = make([]byte, types.ContractAddrLen) + authority = wasmApp.WasmKeeper.GetAuthority() + ) + + specs := map[string]struct { + addr string + permission *types.AccessConfig + expChecksum []byte + expErr bool + }{ + "authority can store and migrate a contract when permission is nobody": { + addr: authority, + permission: &types.AllowNobody, + expChecksum: checksum, + }, + "authority can store and migrate a contract when permission is everybody": { + addr: authority, + permission: &types.AllowEverybody, + expChecksum: checksum, + }, + "other address can store and migrate a contract when permission is everybody": { + addr: myAddress.String(), + permission: &types.AllowEverybody, + expChecksum: checksum, + }, + "other address cannot store and migrate a contract when permission is nobody": { + addr: myAddress.String(), + permission: &types.AllowNobody, + expErr: true, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + // setup + initMsg := keeper.HackatomExampleInitMsg{ + Verifier: myAddress, + Beneficiary: myAddress, + } + initMsgBz, err := json.Marshal(initMsg) + require.NoError(t, err) + storeAndInstantiateMsg := &types.MsgStoreAndInstantiateContract{ + Authority: spec.addr, + WASMByteCode: hackatomContract, + InstantiatePermission: &types.AllowEverybody, + Admin: myAddress.String(), + UnpinCode: false, + Label: "test", + Msg: initMsgBz, + Funds: sdk.Coins{}, + } + rsp, err := wasmApp.MsgServiceRouter().Handler(storeAndInstantiateMsg)(ctx, storeAndInstantiateMsg) + require.NoError(t, err) + var storeAndInstantiateResponse types.MsgStoreAndInstantiateContractResponse + require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &storeAndInstantiateResponse)) + + contractAddr := storeAndInstantiateResponse.Address + + // when + migMsg := struct { + Verifier sdk.AccAddress `json:"verifier"` + }{Verifier: myAddress} + migMsgBz, err := json.Marshal(migMsg) + require.NoError(t, err) + msg := &types.MsgStoreAndMigrateContract{ + Authority: spec.addr, + WASMByteCode: hackatomContract, + InstantiatePermission: spec.permission, + Msg: migMsgBz, + Contract: contractAddr, + } + rsp, err = wasmApp.MsgServiceRouter().Handler(msg)(ctx, msg) + + // then + if spec.expErr { + require.Error(t, err) + require.Nil(t, rsp) + return + } + + require.NoError(t, err) + var result types.MsgStoreAndMigrateContractResponse + require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &result)) + assert.Equal(t, spec.expChecksum, result.Checksum) + require.NotZero(t, result.CodeID) + }) + } +} + +func TestUpdateContractLabel(t *testing.T) { + wasmApp := app.Setup(t) + ctx := wasmApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()}) + + var ( + myAddress sdk.AccAddress = make([]byte, types.ContractAddrLen) + authority = wasmApp.WasmKeeper.GetAuthority() + _, _, otherAddr = testdata.KeyTestPubAddr() + ) + + specs := map[string]struct { + addr string + newLabel string + expErr bool + }{ + "authority can update contract label": { + addr: authority, + newLabel: "new label", + expErr: false, + }, + "admin can update contract label": { + addr: myAddress.String(), + newLabel: "new label", + expErr: false, + }, + "other address cannot update contract label": { + addr: otherAddr.String(), + newLabel: "new label", + expErr: true, + }, + "empty new label": { + addr: authority, + expErr: true, + }, + "invalid new label": { + addr: authority, + newLabel: " start with space ", + expErr: true, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + // setup + msg := &types.MsgStoreAndInstantiateContract{ + Authority: spec.addr, + WASMByteCode: wasmContract, + InstantiatePermission: &types.AllowEverybody, + Admin: myAddress.String(), + UnpinCode: false, + Label: "old label", + Msg: []byte(`{}`), + Funds: sdk.Coins{}, + } + rsp, err := wasmApp.MsgServiceRouter().Handler(msg)(ctx, msg) + require.NoError(t, err) + var storeAndInstantiateResponse types.MsgStoreAndInstantiateContractResponse + require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &storeAndInstantiateResponse)) + + contract := storeAndInstantiateResponse.Address + contractAddr, err := sdk.AccAddressFromBech32(contract) + require.NoError(t, err) + require.Equal(t, "old label", wasmApp.WasmKeeper.GetContractInfo(ctx, contractAddr).Label) + + // when + msgUpdateLabel := &types.MsgUpdateContractLabel{ + Sender: spec.addr, + NewLabel: spec.newLabel, + Contract: storeAndInstantiateResponse.Address, + } + _, err = wasmApp.MsgServiceRouter().Handler(msgUpdateLabel)(ctx, msgUpdateLabel) + + // then + if spec.expErr { + require.Error(t, err) + require.Equal(t, "old label", wasmApp.WasmKeeper.GetContractInfo(ctx, contractAddr).Label) + } else { + require.NoError(t, err) + require.Equal(t, spec.newLabel, wasmApp.WasmKeeper.GetContractInfo(ctx, contractAddr).Label) + } + }) + } +} diff --git a/x/wasm/keeper/msg_server_test.go b/x/wasm/keeper/msg_server_test.go index 6a064e50bf..61d05f65b1 100644 --- a/x/wasm/keeper/msg_server_test.go +++ b/x/wasm/keeper/msg_server_test.go @@ -5,9 +5,10 @@ import ( "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/assert" + "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/options.go b/x/wasm/keeper/options.go index a79253e75e..7ccf7d9e52 100644 --- a/x/wasm/keeper/options.go +++ b/x/wasm/keeper/options.go @@ -4,9 +4,10 @@ import ( "fmt" "reflect" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/prometheus/client_golang/prometheus" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -25,14 +26,14 @@ func (f postOptsFn) apply(keeper *Keeper) { // WithWasmEngine is an optional constructor parameter to replace the default wasmVM engine with the // given one. -func WithWasmEngine(x types.WasmerEngine) Option { +func WithWasmEngine(x types.WasmEngine) Option { return optsFn(func(k *Keeper) { k.wasmVM = x }) } // WithWasmEngineDecorator is an optional constructor parameter to decorate the default wasmVM engine. -func WithWasmEngineDecorator(d func(old types.WasmerEngine) types.WasmerEngine) Option { +func WithWasmEngineDecorator(d func(old types.WasmEngine) types.WasmEngine) Option { return postOptsFn(func(k *Keeper) { k.wasmVM = d(k.wasmVM) }) @@ -125,7 +126,7 @@ func WithAccountPruner(x AccountPruner) Option { } func WithVMCacheMetrics(r prometheus.Registerer) Option { - return optsFn(func(k *Keeper) { + return postOptsFn(func(k *Keeper) { NewWasmVMMetricsCollector(k.wasmVM).Register(r) }) } @@ -133,7 +134,7 @@ func WithVMCacheMetrics(r prometheus.Registerer) Option { // WithGasRegister set a new gas register to implement custom gas costs. // When the "gas multiplier" for wasmvm gas conversion is modified inside the new register, // make sure to also use `WithApiCosts` option for non default values -func WithGasRegister(x GasRegister) Option { +func WithGasRegister(x types.GasRegister) Option { if x == nil { panic("must not be nil") } diff --git a/x/wasm/keeper/options_test.go b/x/wasm/keeper/options_test.go index fe6640b35d..b26e1af7c2 100644 --- a/x/wasm/keeper/options_test.go +++ b/x/wasm/keeper/options_test.go @@ -5,14 +5,15 @@ import ( "testing" wasmvm "github.com/CosmWasm/wasmvm" + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" @@ -25,30 +26,43 @@ func TestConstructorOptions(t *testing.T) { isPostOpt bool }{ "wasm engine": { - srcOpt: WithWasmEngine(&wasmtesting.MockWasmer{}), + srcOpt: WithWasmEngine(&wasmtesting.MockWasmEngine{}), verify: func(t *testing.T, k Keeper) { - assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM) + t.Helper() + assert.IsType(t, &wasmtesting.MockWasmEngine{}, k.wasmVM) }, }, + "vm cache metrics": { + srcOpt: WithVMCacheMetrics(prometheus.DefaultRegisterer), + verify: func(t *testing.T, k Keeper) { + t.Helper() + registered := prometheus.DefaultRegisterer.Unregister(NewWasmVMMetricsCollector(k.wasmVM)) + assert.True(t, registered) + }, + isPostOpt: true, + }, "decorate wasmvm": { - srcOpt: WithWasmEngineDecorator(func(old types.WasmerEngine) types.WasmerEngine { + srcOpt: WithWasmEngineDecorator(func(old types.WasmEngine) types.WasmEngine { require.IsType(t, &wasmvm.VM{}, old) - return &wasmtesting.MockWasmer{} + return &wasmtesting.MockWasmEngine{} }), verify: func(t *testing.T, k Keeper) { - assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM) + t.Helper() + assert.IsType(t, &wasmtesting.MockWasmEngine{}, k.wasmVM) }, isPostOpt: true, }, "message handler": { srcOpt: WithMessageHandler(&wasmtesting.MockMessageHandler{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockMessageHandler{}, k.messenger) }, }, "query plugins": { srcOpt: WithQueryHandler(&wasmtesting.MockQueryHandler{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockQueryHandler{}, k.wasmVMQueryHandler) }, }, @@ -58,6 +72,7 @@ func TestConstructorOptions(t *testing.T) { return &wasmtesting.MockMessageHandler{} }), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockMessageHandler{}, k.messenger) }, isPostOpt: true, @@ -68,6 +83,7 @@ func TestConstructorOptions(t *testing.T) { return &wasmtesting.MockQueryHandler{} }), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockQueryHandler{}, k.wasmVMQueryHandler) }, isPostOpt: true, @@ -75,18 +91,21 @@ func TestConstructorOptions(t *testing.T) { "coin transferrer": { srcOpt: WithCoinTransferrer(&wasmtesting.MockCoinTransferrer{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockCoinTransferrer{}, k.bank) }, }, "costs": { srcOpt: WithGasRegister(&wasmtesting.MockGasRegister{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, &wasmtesting.MockGasRegister{}, k.gasRegister) }, }, "api costs": { srcOpt: WithAPICosts(1, 2), verify: func(t *testing.T, k Keeper) { + t.Helper() t.Cleanup(setAPIDefaults) assert.Equal(t, uint64(1), costHumanize) assert.Equal(t, uint64(2), costCanonical) @@ -95,12 +114,14 @@ func TestConstructorOptions(t *testing.T) { "max recursion query limit": { srcOpt: WithMaxQueryStackSize(1), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.IsType(t, uint32(1), k.maxQueryStackSize) }, }, "accepted account types": { srcOpt: WithAcceptedAccountTypesOnContractInstantiation(&authtypes.BaseAccount{}, &vestingtypes.ContinuousVestingAccount{}), verify: func(t *testing.T, k Keeper) { + t.Helper() exp := map[reflect.Type]struct{}{ reflect.TypeOf(&authtypes.BaseAccount{}): {}, reflect.TypeOf(&vestingtypes.ContinuousVestingAccount{}): {}, @@ -111,12 +132,14 @@ func TestConstructorOptions(t *testing.T) { "account pruner": { srcOpt: WithAccountPruner(VestingCoinBurner{}), verify: func(t *testing.T, k Keeper) { + t.Helper() assert.Equal(t, VestingCoinBurner{}, k.accountPruner) }, }, "gov propagation": { srcOpt: WitGovSubMsgAuthZPropagated(types.AuthZActionInstantiate, types.AuthZActionMigrateContract), verify: func(t *testing.T, k Keeper) { + t.Helper() exp := map[types.AuthorizationPolicyAction]struct{}{ types.AuthZActionInstantiate: {}, types.AuthZActionMigrateContract: {}, @@ -137,8 +160,8 @@ func TestConstructorOptions(t *testing.T) { } func setAPIDefaults() { - costHumanize = DefaultGasCostHumanAddress * DefaultGasMultiplier - costCanonical = DefaultGasCostCanonicalAddress * DefaultGasMultiplier + costHumanize = DefaultGasCostHumanAddress * types.DefaultGasMultiplier + costCanonical = DefaultGasCostCanonicalAddress * types.DefaultGasMultiplier } func TestSplitOpts(t *testing.T) { diff --git a/x/wasm/keeper/proposal_handler.go b/x/wasm/keeper/proposal_handler.go deleted file mode 100644 index 82048ca3e8..0000000000 --- a/x/wasm/keeper/proposal_handler.go +++ /dev/null @@ -1,342 +0,0 @@ -package keeper - -import ( - "bytes" - "encoding/hex" - "fmt" - - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - "github.com/CosmWasm/wasmd/x/wasm/types" -) - -// NewWasmProposalHandler creates a new governance Handler for wasm proposals -// -// Deprecated: Do not use. -func NewWasmProposalHandler(k decoratedKeeper, enabledProposalTypes []types.ProposalType) v1beta1.Handler { - return NewWasmProposalHandlerX(NewGovPermissionKeeper(k), enabledProposalTypes) -} - -// NewWasmProposalHandlerX creates a new governance Handler for wasm proposals -// -// Deprecated: Do not use. -func NewWasmProposalHandlerX(k types.ContractOpsKeeper, enabledProposalTypes []types.ProposalType) v1beta1.Handler { - enabledTypes := make(map[string]struct{}, len(enabledProposalTypes)) - for i := range enabledProposalTypes { - enabledTypes[string(enabledProposalTypes[i])] = struct{}{} - } - return func(ctx sdk.Context, content v1beta1.Content) error { - if content == nil { - return errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "content must not be empty") - } - if _, ok := enabledTypes[content.ProposalType()]; !ok { - return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unsupported wasm proposal content type: %q", content.ProposalType()) - } - switch c := content.(type) { - case *types.StoreCodeProposal: - return handleStoreCodeProposal(ctx, k, *c) - case *types.InstantiateContractProposal: - return handleInstantiateProposal(ctx, k, *c) - case *types.InstantiateContract2Proposal: - return handleInstantiate2Proposal(ctx, k, *c) - case *types.MigrateContractProposal: - return handleMigrateProposal(ctx, k, *c) - case *types.SudoContractProposal: - return handleSudoProposal(ctx, k, *c) - case *types.ExecuteContractProposal: - return handleExecuteProposal(ctx, k, *c) - case *types.UpdateAdminProposal: - return handleUpdateAdminProposal(ctx, k, *c) - case *types.ClearAdminProposal: - return handleClearAdminProposal(ctx, k, *c) - case *types.PinCodesProposal: - return handlePinCodesProposal(ctx, k, *c) - case *types.UnpinCodesProposal: - return handleUnpinCodesProposal(ctx, k, *c) - case *types.UpdateInstantiateConfigProposal: - return handleUpdateInstantiateConfigProposal(ctx, k, *c) - case *types.StoreAndInstantiateContractProposal: - return handleStoreAndInstantiateContractProposal(ctx, k, *c) - default: - return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized wasm proposal content type: %T", c) - } - } -} - -//nolint:staticcheck -func handleStoreCodeProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.StoreCodeProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - - runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) - if err != nil { - return errorsmod.Wrap(err, "run as address") - } - codeID, checksum, err := k.Create(ctx, runAsAddr, p.WASMByteCode, p.InstantiatePermission) - if err != nil { - return err - } - - if len(p.CodeHash) != 0 && !bytes.Equal(checksum, p.CodeHash) { - return fmt.Errorf("code-hash mismatch: %X, checksum: %X", p.CodeHash, checksum) - } - - // if code should not be pinned return earlier - if p.UnpinCode { - return nil - } - return k.PinCode(ctx, codeID) -} - -//nolint:staticcheck -func handleInstantiateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.InstantiateContractProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) - if err != nil { - return errorsmod.Wrap(err, "run as address") - } - var adminAddr sdk.AccAddress - if p.Admin != "" { - if adminAddr, err = sdk.AccAddressFromBech32(p.Admin); err != nil { - return errorsmod.Wrap(err, "admin") - } - } - - _, data, err := k.Instantiate(ctx, p.CodeID, runAsAddr, adminAddr, p.Msg, p.Label, p.Funds) - if err != nil { - return err - } - - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeGovContractResult, - sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), - )) - return nil -} - -//nolint:staticcheck -func handleInstantiate2Proposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.InstantiateContract2Proposal) error { - // Validatebasic with proposal - if err := p.ValidateBasic(); err != nil { - return err - } - - // Get runAsAddr as AccAddress - runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) - if err != nil { - return errorsmod.Wrap(err, "run as address") - } - - // Get admin address - var adminAddr sdk.AccAddress - if p.Admin != "" { - if adminAddr, err = sdk.AccAddressFromBech32(p.Admin); err != nil { - return errorsmod.Wrap(err, "admin") - } - } - - _, data, err := k.Instantiate2(ctx, p.CodeID, runAsAddr, adminAddr, p.Msg, p.Label, p.Funds, p.Salt, p.FixMsg) - if err != nil { - return err - } - - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeGovContractResult, - sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), - )) - return nil -} - -//nolint:staticcheck -func handleStoreAndInstantiateContractProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.StoreAndInstantiateContractProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) - if err != nil { - return errorsmod.Wrap(err, "run as address") - } - var adminAddr sdk.AccAddress - if p.Admin != "" { - if adminAddr, err = sdk.AccAddressFromBech32(p.Admin); err != nil { - return errorsmod.Wrap(err, "admin") - } - } - - codeID, checksum, err := k.Create(ctx, runAsAddr, p.WASMByteCode, p.InstantiatePermission) - if err != nil { - return err - } - - if p.CodeHash != nil && !bytes.Equal(checksum, p.CodeHash) { - return errorsmod.Wrap(fmt.Errorf("code-hash mismatch: %X, checksum: %X", p.CodeHash, checksum), "code-hash mismatch") - } - - if !p.UnpinCode { - if err := k.PinCode(ctx, codeID); err != nil { - return err - } - } - - _, data, err := k.Instantiate(ctx, codeID, runAsAddr, adminAddr, p.Msg, p.Label, p.Funds) - if err != nil { - return err - } - - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeGovContractResult, - sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), - )) - return nil -} - -//nolint:staticcheck -func handleMigrateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.MigrateContractProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - - contractAddr, err := sdk.AccAddressFromBech32(p.Contract) - if err != nil { - return errorsmod.Wrap(err, "contract") - } - - // runAs is not used if this is permissioned, so just put any valid address there (second contractAddr) - data, err := k.Migrate(ctx, contractAddr, contractAddr, p.CodeID, p.Msg) - if err != nil { - return err - } - - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeGovContractResult, - sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), - )) - return nil -} - -//nolint:staticcheck -func handleSudoProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.SudoContractProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - - contractAddr, err := sdk.AccAddressFromBech32(p.Contract) - if err != nil { - return errorsmod.Wrap(err, "contract") - } - data, err := k.Sudo(ctx, contractAddr, p.Msg) - if err != nil { - return err - } - - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeGovContractResult, - sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), - )) - return nil -} - -//nolint:staticcheck -func handleExecuteProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.ExecuteContractProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - - contractAddr, err := sdk.AccAddressFromBech32(p.Contract) - if err != nil { - return errorsmod.Wrap(err, "contract") - } - runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) - if err != nil { - return errorsmod.Wrap(err, "run as address") - } - data, err := k.Execute(ctx, contractAddr, runAsAddr, p.Msg, p.Funds) - if err != nil { - return err - } - - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeGovContractResult, - sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), - )) - return nil -} - -//nolint:staticcheck -func handleUpdateAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.UpdateAdminProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - contractAddr, err := sdk.AccAddressFromBech32(p.Contract) - if err != nil { - return errorsmod.Wrap(err, "contract") - } - newAdminAddr, err := sdk.AccAddressFromBech32(p.NewAdmin) - if err != nil { - return errorsmod.Wrap(err, "run as address") - } - - return k.UpdateContractAdmin(ctx, contractAddr, nil, newAdminAddr) -} - -//nolint:staticcheck -func handleClearAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.ClearAdminProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - - contractAddr, err := sdk.AccAddressFromBech32(p.Contract) - if err != nil { - return errorsmod.Wrap(err, "contract") - } - err = k.ClearContractAdmin(ctx, contractAddr, nil) - return err -} - -//nolint:staticcheck -func handlePinCodesProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.PinCodesProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - for _, v := range p.CodeIDs { - if err := k.PinCode(ctx, v); err != nil { - return errorsmod.Wrapf(err, "code id: %d", v) - } - } - return nil -} - -//nolint:staticcheck -func handleUnpinCodesProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.UnpinCodesProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - for _, v := range p.CodeIDs { - if err := k.UnpinCode(ctx, v); err != nil { - return errorsmod.Wrapf(err, "code id: %d", v) - } - } - return nil -} - -//nolint:staticcheck -func handleUpdateInstantiateConfigProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.UpdateInstantiateConfigProposal) error { - if err := p.ValidateBasic(); err != nil { - return err - } - - var emptyCaller sdk.AccAddress - for _, accessConfigUpdate := range p.AccessConfigUpdates { - if err := k.SetAccessConfig(ctx, accessConfigUpdate.CodeID, emptyCaller, accessConfigUpdate.InstantiatePermission); err != nil { - return errorsmod.Wrapf(err, "code id: %d", accessConfigUpdate.CodeID) - } - } - return nil -} diff --git a/x/wasm/keeper/proposal_integration_test.go b/x/wasm/keeper/proposal_integration_test.go deleted file mode 100644 index acfa30a413..0000000000 --- a/x/wasm/keeper/proposal_integration_test.go +++ /dev/null @@ -1,926 +0,0 @@ -package keeper - -import ( - "bytes" - "encoding/hex" - "encoding/json" - "errors" - "os" - "testing" - - wasmvm "github.com/CosmWasm/wasmvm" - sdk "github.com/cosmos/cosmos-sdk/types" - govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" - "github.com/CosmWasm/wasmd/x/wasm/types" -) - -const myTestLabel = "testing" - -func TestStoreCodeProposal(t *testing.T) { - parentCtx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - err := wasmKeeper.SetParams(parentCtx, types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, - }) - require.NoError(t, err) - rawWasmCode, err := os.ReadFile("./testdata/hackatom.wasm") - require.NoError(t, err) - gzippedWasmCode, err := os.ReadFile("./testdata/hackatom.wasm.gzip") - require.NoError(t, err) - checksum, err := hex.DecodeString("5ca46abb8e9b1b754a5c906f9c0f4eec9121ee09e3cee55ea0faba54763706e2") - require.NoError(t, err) - - specs := map[string]struct { - codeID int64 - code []byte - unpinCode bool - }{ - "upload with pinning (default)": { - unpinCode: false, - code: rawWasmCode, - }, - "upload with code unpin": { - unpinCode: true, - code: rawWasmCode, - }, - "upload with raw wasm code": { - code: rawWasmCode, - }, - "upload with zipped wasm code": { - code: gzippedWasmCode, - }, - } - - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - ctx, _ := parentCtx.CacheContext() - myActorAddress := RandomBech32AccountAddress(t) - - src := types.StoreCodeProposalFixture(func(p *types.StoreCodeProposal) { //nolint:staticcheck // testing deprecated function - p.RunAs = myActorAddress - p.WASMByteCode = spec.code - p.UnpinCode = spec.unpinCode - p.CodeHash = checksum - }) - - // when - mustSubmitAndExecuteLegacyProposal(t, ctx, src, myActorAddress, keepers) - - // then - cInfo := wasmKeeper.GetCodeInfo(ctx, 1) - require.NotNil(t, cInfo) - assert.Equal(t, myActorAddress, cInfo.Creator) - assert.Equal(t, !spec.unpinCode, wasmKeeper.IsPinnedCode(ctx, 1)) - - storedCode, err := wasmKeeper.GetByteCode(ctx, 1) - require.NoError(t, err) - assert.Equal(t, rawWasmCode, storedCode) - }) - } -} - -func mustSubmitAndExecuteLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content, myActorAddress string, keepers TestKeepers) { - t.Helper() - govAuthority := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String() - msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper) - // ignore all submit events - contentMsg, err := submitLegacyProposal(t, ctx.WithEventManager(sdk.NewEventManager()), content, myActorAddress, govAuthority, msgServer) - require.NoError(t, err) - - _, err = msgServer.ExecLegacyContent(sdk.WrapSDKContext(ctx), v1.NewMsgExecLegacyContent(contentMsg.Content, govAuthority)) - require.NoError(t, err) -} - -// does not fail on submit proposal -func submitLegacyProposal(t *testing.T, ctx sdk.Context, content v1beta1.Content, myActorAddress string, govAuthority string, msgServer v1.MsgServer) (*v1.MsgExecLegacyContent, error) { - t.Helper() - contentMsg, err := v1.NewLegacyContent(content, govAuthority) - require.NoError(t, err) - - proposal, err := v1.NewMsgSubmitProposal( - []sdk.Msg{contentMsg}, - sdk.Coins{}, - myActorAddress, - "", - "my title", - "my description", - ) - require.NoError(t, err) - - // when stored - _, err = msgServer.SubmitProposal(sdk.WrapSDKContext(ctx), proposal) - return contentMsg, err -} - -func TestInstantiateProposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - err := wasmKeeper.SetParams(ctx, types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, - }) - require.NoError(t, err) - - wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") - require.NoError(t, err) - - require.NoError(t, wasmKeeper.importCode(ctx, 1, - types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)), - wasmCode), - ) - - var ( - oneAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, types.ContractAddrLen) - otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen) - ) - src := types.InstantiateContractProposalFixture(func(p *types.InstantiateContractProposal) { //nolint:staticcheck // testing deprecated function - p.CodeID = firstCodeID - p.RunAs = oneAddress.String() - p.Admin = otherAddress.String() - p.Label = myTestLabel - }) - em := sdk.NewEventManager() - - // when - mustSubmitAndExecuteLegacyProposal(t, ctx.WithEventManager(em), src, oneAddress.String(), keepers) - - // then - contractAddr, err := sdk.AccAddressFromBech32("cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr") - require.NoError(t, err) - - cInfo := wasmKeeper.GetContractInfo(ctx, contractAddr) - require.NotNil(t, cInfo) - assert.Equal(t, uint64(1), cInfo.CodeID) - assert.Equal(t, oneAddress.String(), cInfo.Creator) - assert.Equal(t, otherAddress.String(), cInfo.Admin) - assert.Equal(t, myTestLabel, cInfo.Label) - expHistory := []types.ContractCodeHistoryEntry{{ - Operation: types.ContractCodeHistoryOperationTypeInit, - CodeID: src.CodeID, - Updated: types.NewAbsoluteTxPosition(ctx), - Msg: src.Msg, - }} - assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddr)) - // and event - require.Len(t, em.Events(), 3, "%#v", em.Events()) - require.Equal(t, types.EventTypeInstantiate, em.Events()[0].Type) - require.Equal(t, types.WasmModuleEventType, em.Events()[1].Type) - require.Equal(t, types.EventTypeGovContractResult, em.Events()[2].Type) - require.Len(t, em.Events()[2].Attributes, 1) - require.NotEmpty(t, em.Events()[2].Attributes[0]) -} - -func TestInstantiate2Proposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - err := wasmKeeper.SetParams(ctx, types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, - }) - require.NoError(t, err) - - wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") - require.NoError(t, err) - - codeInfo := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)) - err = wasmKeeper.importCode(ctx, 1, codeInfo, wasmCode) - require.NoError(t, err) - - var ( - oneAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, types.ContractAddrLen) - otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen) - label = "label" - salt = []byte("mySalt") - ) - src := types.InstantiateContract2ProposalFixture(func(p *types.InstantiateContract2Proposal) { //nolint:staticcheck // testing deprecated function - p.CodeID = firstCodeID - p.RunAs = oneAddress.String() - p.Admin = otherAddress.String() - p.Label = label - p.Salt = salt - }) - contractAddress := BuildContractAddressPredictable(codeInfo.CodeHash, oneAddress, salt, []byte{}) - - em := sdk.NewEventManager() - - // when - mustSubmitAndExecuteLegacyProposal(t, ctx.WithEventManager(em), src, oneAddress.String(), keepers) - - cInfo := wasmKeeper.GetContractInfo(ctx, contractAddress) - require.NotNil(t, cInfo) - - assert.Equal(t, uint64(1), cInfo.CodeID) - assert.Equal(t, oneAddress.String(), cInfo.Creator) - assert.Equal(t, otherAddress.String(), cInfo.Admin) - assert.Equal(t, "label", cInfo.Label) - expHistory := []types.ContractCodeHistoryEntry{{ - Operation: types.ContractCodeHistoryOperationTypeInit, - CodeID: src.CodeID, - Updated: types.NewAbsoluteTxPosition(ctx), - Msg: src.Msg, - }} - assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddress)) - // and event - require.Len(t, em.Events(), 3, prettyEvents(t, em.Events())) - require.Equal(t, types.EventTypeInstantiate, em.Events()[0].Type) - require.Equal(t, types.WasmModuleEventType, em.Events()[1].Type) - require.Equal(t, types.EventTypeGovContractResult, em.Events()[2].Type) - require.Len(t, em.Events()[2].Attributes, 1) - require.NotEmpty(t, em.Events()[2].Attributes[0]) -} - -func TestInstantiateProposal_NoAdmin(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - err := wasmKeeper.SetParams(ctx, types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, - }) - require.NoError(t, err) - - wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") - require.NoError(t, err) - - require.NoError(t, wasmKeeper.importCode(ctx, 1, - types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)), - wasmCode), - ) - - var oneAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, types.ContractAddrLen) - - specs := map[string]struct { - srcAdmin string - expErr bool - }{ - "empty admin": { - srcAdmin: "", - }, - "invalid admin": { - srcAdmin: "invalid", - expErr: true, - }, - } - for name, spec := range specs { - t.Run(name, func(t *testing.T) { - src := types.InstantiateContractProposalFixture(func(p *types.InstantiateContractProposal) { //nolint:staticcheck // testing deprecated function - p.CodeID = firstCodeID - p.RunAs = oneAddress.String() - p.Admin = spec.srcAdmin - p.Label = myTestLabel - }) - govAuthority := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String() - msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper) - // when - contentMsg, gotErr := submitLegacyProposal(t, ctx, src, oneAddress.String(), govAuthority, msgServer) - // then - if spec.expErr { - require.Error(t, gotErr) - return - } - require.NoError(t, gotErr) - // and when - em := sdk.NewEventManager() - _, err = msgServer.ExecLegacyContent(sdk.WrapSDKContext(ctx.WithEventManager(em)), v1.NewMsgExecLegacyContent(contentMsg.Content, govAuthority)) - // then - require.NoError(t, err) - contractAddr, err := sdk.AccAddressFromBech32("cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr") - require.NoError(t, err) - - cInfo := wasmKeeper.GetContractInfo(ctx, contractAddr) - require.NotNil(t, cInfo) - assert.Equal(t, uint64(1), cInfo.CodeID) - assert.Equal(t, oneAddress.String(), cInfo.Creator) - assert.Equal(t, "", cInfo.Admin) - assert.Equal(t, myTestLabel, cInfo.Label) - expHistory := []types.ContractCodeHistoryEntry{{ - Operation: types.ContractCodeHistoryOperationTypeInit, - CodeID: src.CodeID, - Updated: types.NewAbsoluteTxPosition(ctx), - Msg: src.Msg, - }} - assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddr)) - // and event - require.Len(t, em.Events(), 3, "%#v", em.Events()) - require.Equal(t, types.EventTypeInstantiate, em.Events()[0].Type) - require.Equal(t, types.WasmModuleEventType, em.Events()[1].Type) - require.Equal(t, types.EventTypeGovContractResult, em.Events()[2].Type) - require.Len(t, em.Events()[2].Attributes, 1) - require.NotEmpty(t, em.Events()[2].Attributes[0]) - }) - } -} - -func TestStoreAndInstantiateContractProposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - err := wasmKeeper.SetParams(ctx, types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, - }) - require.NoError(t, err) - - wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") - require.NoError(t, err) - - checksum, err := hex.DecodeString("5ca46abb8e9b1b754a5c906f9c0f4eec9121ee09e3cee55ea0faba54763706e2") - require.NoError(t, err) - - var ( - oneAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, types.ContractAddrLen) - otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen) - ) - - src := types.StoreAndInstantiateContractProposalFixture(func(p *types.StoreAndInstantiateContractProposal) { //nolint:staticcheck // testing deprecated function - p.WASMByteCode = wasmCode - p.RunAs = oneAddress.String() - p.Admin = otherAddress.String() - p.Label = myTestLabel - p.CodeHash = checksum - }) - em := sdk.NewEventManager() - - // when - mustSubmitAndExecuteLegacyProposal(t, ctx.WithEventManager(em), src, oneAddress.String(), keepers) - - // then - contractAddr, err := sdk.AccAddressFromBech32("cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr") - require.NoError(t, err) - - cInfo := wasmKeeper.GetContractInfo(ctx, contractAddr) - require.NotNil(t, cInfo) - assert.Equal(t, oneAddress.String(), cInfo.Creator) - assert.Equal(t, otherAddress.String(), cInfo.Admin) - assert.Equal(t, myTestLabel, cInfo.Label) - expHistory := []types.ContractCodeHistoryEntry{{ - Operation: types.ContractCodeHistoryOperationTypeInit, - CodeID: cInfo.CodeID, - Updated: types.NewAbsoluteTxPosition(ctx), - Msg: src.Msg, - }} - assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddr)) - // and event - require.Len(t, em.Events(), 5, "%#v", em.Events()) - require.Equal(t, types.EventTypeStoreCode, em.Events()[0].Type) - require.Equal(t, types.EventTypePinCode, em.Events()[1].Type) - require.Equal(t, types.EventTypeInstantiate, em.Events()[2].Type) - require.Equal(t, types.WasmModuleEventType, em.Events()[3].Type) - require.Equal(t, types.EventTypeGovContractResult, em.Events()[4].Type) - require.Len(t, em.Events()[4].Attributes, 1) - require.NotEmpty(t, em.Events()[4].Attributes[0]) -} - -func TestMigrateProposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - err := wasmKeeper.SetParams(ctx, types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, - }) - require.NoError(t, err) - - wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") - require.NoError(t, err) - - codeInfoFixture := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)) - require.NoError(t, wasmKeeper.importCode(ctx, 1, codeInfoFixture, wasmCode)) - require.NoError(t, wasmKeeper.importCode(ctx, 2, codeInfoFixture, wasmCode)) - - var ( - anyAddress = DeterministicAccountAddress(t, 1) - otherAddress = DeterministicAccountAddress(t, 2) - contractAddr = BuildContractAddressClassic(1, 1) - ) - - contractInfo := types.ContractInfoFixture(func(c *types.ContractInfo) { - c.Label = myTestLabel - c.Admin = anyAddress.String() - c.Created = types.NewAbsoluteTxPosition(ctx) - }) - entries := []types.ContractCodeHistoryEntry{ - {Operation: types.ContractCodeHistoryOperationTypeInit, CodeID: 1, Updated: contractInfo.Created}, - } - key, err := hex.DecodeString("636F6E666967") - require.NoError(t, err) - m := types.Model{Key: key, Value: []byte(`{"verifier":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","beneficiary":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","funder":"AQEBAQEBAQEBAQEBAQEBAQEBAQE="}`)} - require.NoError(t, wasmKeeper.importContract(ctx, contractAddr, &contractInfo, []types.Model{m}, entries)) - - migMsg := struct { - Verifier sdk.AccAddress `json:"verifier"` - }{Verifier: otherAddress} - migMsgBz, err := json.Marshal(migMsg) - require.NoError(t, err) - - src := &types.MigrateContractProposal{ //nolint:staticcheck // testing deprecated function - Title: "Foo", - Description: "Bar", - CodeID: 2, - Contract: contractAddr.String(), - Msg: migMsgBz, - } - - em := sdk.NewEventManager() - - // when - mustSubmitAndExecuteLegacyProposal(t, ctx.WithEventManager(em), src, anyAddress.String(), keepers) - - // then - require.NoError(t, err) - cInfo := wasmKeeper.GetContractInfo(ctx, contractAddr) - require.NotNil(t, cInfo) - assert.Equal(t, uint64(2), cInfo.CodeID) - assert.Equal(t, anyAddress.String(), cInfo.Admin) - assert.Equal(t, myTestLabel, cInfo.Label) - expHistory := []types.ContractCodeHistoryEntry{{ - Operation: types.ContractCodeHistoryOperationTypeInit, - CodeID: firstCodeID, - Updated: types.NewAbsoluteTxPosition(ctx), - }, { - Operation: types.ContractCodeHistoryOperationTypeMigrate, - CodeID: src.CodeID, - Updated: types.NewAbsoluteTxPosition(ctx), - Msg: src.Msg, - }} - assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddr)) - // and events emitted - require.Len(t, em.Events(), 2) - assert.Equal(t, types.EventTypeMigrate, em.Events()[0].Type) - require.Equal(t, types.EventTypeGovContractResult, em.Events()[1].Type) - require.Len(t, em.Events()[1].Attributes, 1) - assert.Equal(t, types.AttributeKeyResultDataHex, em.Events()[1].Attributes[0].Key) -} - -func TestExecuteProposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - bankKeeper := keepers.BankKeeper - - exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) - contractAddr := exampleContract.Contract - - // check balance - bal := bankKeeper.GetBalance(ctx, contractAddr, "denom") - require.Equal(t, bal.Amount, sdk.NewInt(100)) - - releaseMsg := struct { - Release struct{} `json:"release"` - }{} - releaseMsgBz, err := json.Marshal(releaseMsg) - require.NoError(t, err) - - // try with runAs that doesn't have pemission - badSrc := &types.ExecuteContractProposal{ //nolint:staticcheck // testing deprecated function - Title: "First", - Description: "Beneficiary has no permission to run", - Contract: contractAddr.String(), - Msg: releaseMsgBz, - RunAs: exampleContract.BeneficiaryAddr.String(), - } - - // fails on store - this doesn't have permission - govAuthority := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String() - msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper) - _, err = submitLegacyProposal(t, ctx, badSrc, exampleContract.BeneficiaryAddr.String(), govAuthority, msgServer) - require.Error(t, err) - - // balance should not change - bal = bankKeeper.GetBalance(ctx, contractAddr, "denom") - require.Equal(t, bal.Amount, sdk.NewInt(100)) - - // try again with the proper run-as - src := &types.ExecuteContractProposal{ //nolint:staticcheck // testing deprecated function - Title: "Second", - Description: "Verifier can execute", - Contract: contractAddr.String(), - Msg: releaseMsgBz, - RunAs: exampleContract.VerifierAddr.String(), - } - - em := sdk.NewEventManager() - - // when - mustSubmitAndExecuteLegacyProposal(t, ctx.WithEventManager(em), src, exampleContract.BeneficiaryAddr.String(), keepers) - - // balance should be empty (proper release) - bal = bankKeeper.GetBalance(ctx, contractAddr, "denom") - require.Equal(t, bal.Amount, sdk.NewInt(0)) -} - -func TestSudoProposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - bankKeeper := keepers.BankKeeper - - exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) - contractAddr := exampleContract.Contract - _, anyAddr := keyPubAddr() - - // check balance - bal := bankKeeper.GetBalance(ctx, contractAddr, "denom") - require.Equal(t, bal.Amount, sdk.NewInt(100)) - bal = bankKeeper.GetBalance(ctx, anyAddr, "denom") - require.Equal(t, bal.Amount, sdk.NewInt(0)) - - type StealMsg struct { - Recipient string `json:"recipient"` - Amount []sdk.Coin `json:"amount"` - } - stealMsg := struct { - Steal StealMsg `json:"steal_funds"` - }{Steal: StealMsg{ - Recipient: anyAddr.String(), - Amount: []sdk.Coin{sdk.NewInt64Coin("denom", 75)}, - }} - stealMsgBz, err := json.Marshal(stealMsg) - require.NoError(t, err) - - // sudo can do anything - src := &types.SudoContractProposal{ //nolint:staticcheck // testing deprecated function - Title: "Sudo", - Description: "Steal funds for the verifier", - Contract: contractAddr.String(), - Msg: stealMsgBz, - } - - em := sdk.NewEventManager() - - // when - mustSubmitAndExecuteLegacyProposal(t, ctx.WithEventManager(em), src, exampleContract.BeneficiaryAddr.String(), keepers) - - // balance should be empty (and verifier richer) - bal = bankKeeper.GetBalance(ctx, contractAddr, "denom") - require.Equal(t, bal.Amount, sdk.NewInt(25)) - bal = bankKeeper.GetBalance(ctx, anyAddr, "denom") - require.Equal(t, bal.Amount, sdk.NewInt(75)) -} - -func TestAdminProposals(t *testing.T) { - var ( - otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen) - contractAddr = BuildContractAddressClassic(1, 1) - ) - wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") - require.NoError(t, err) - - specs := map[string]struct { - state types.ContractInfo - srcProposal v1beta1.Content - expAdmin sdk.AccAddress - }{ - "update with different admin": { - state: types.ContractInfoFixture(), - srcProposal: &types.UpdateAdminProposal{ //nolint:staticcheck // testing deprecated function - Title: "Foo", - Description: "Bar", - Contract: contractAddr.String(), - NewAdmin: otherAddress.String(), - }, - expAdmin: otherAddress, - }, - "update with old admin empty": { - state: types.ContractInfoFixture(func(info *types.ContractInfo) { - info.Admin = "" - }), - srcProposal: &types.UpdateAdminProposal{ //nolint:staticcheck // testing deprecated function - Title: "Foo", - Description: "Bar", - Contract: contractAddr.String(), - NewAdmin: otherAddress.String(), - }, - expAdmin: otherAddress, - }, - "clear admin": { - state: types.ContractInfoFixture(), - srcProposal: &types.ClearAdminProposal{ //nolint:staticcheck // testing deprecated function - Title: "Foo", - Description: "Bar", - Contract: contractAddr.String(), - }, - expAdmin: nil, - }, - "clear with old admin empty": { - state: types.ContractInfoFixture(func(info *types.ContractInfo) { - info.Admin = "" - }), - srcProposal: &types.ClearAdminProposal{ //nolint:staticcheck // testing deprecated function - Title: "Foo", - Description: "Bar", - Contract: contractAddr.String(), - }, - expAdmin: nil, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - err := wasmKeeper.SetParams(ctx, types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, - }) - require.NoError(t, err) - - codeInfo := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)) - require.NoError(t, wasmKeeper.importCode(ctx, 1, codeInfo, wasmCode)) - - entries := []types.ContractCodeHistoryEntry{ - { - Operation: types.ContractCodeHistoryOperationTypeInit, - CodeID: 1, - Updated: spec.state.Created, - }, - } - - require.NoError(t, wasmKeeper.importContract(ctx, contractAddr, &spec.state, []types.Model{}, entries)) - - // when - mustSubmitAndExecuteLegacyProposal(t, ctx, spec.srcProposal, otherAddress.String(), keepers) - - // then - cInfo := wasmKeeper.GetContractInfo(ctx, contractAddr) - require.NotNil(t, cInfo) - assert.Equal(t, spec.expAdmin.String(), cInfo.Admin) - }) - } -} - -func TestPinCodesProposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - - mock := wasmtesting.MockWasmer{ - StoreCodeFn: wasmtesting.NoOpStoreCodeFn, - AnalyzeCodeFn: wasmtesting.WithoutIBCAnalyzeFn, - } - var ( - hackatom = StoreHackatomExampleContract(t, ctx, keepers) - hackatomDuplicate = StoreHackatomExampleContract(t, ctx, keepers) - otherContract = StoreRandomContract(t, ctx, keepers, &mock) - gotPinnedChecksums []wasmvm.Checksum - ) - checksumCollector := func(checksum wasmvm.Checksum) error { - gotPinnedChecksums = append(gotPinnedChecksums, checksum) - return nil - } - specs := map[string]struct { - srcCodeIDs []uint64 - mockFn func(checksum wasmvm.Checksum) error - expPinned []wasmvm.Checksum - expErr bool - }{ - "pin one": { - srcCodeIDs: []uint64{hackatom.CodeID}, - mockFn: checksumCollector, - }, - "pin multiple": { - srcCodeIDs: []uint64{hackatom.CodeID, otherContract.CodeID}, - mockFn: checksumCollector, - }, - "pin same code id": { - srcCodeIDs: []uint64{hackatom.CodeID, hackatomDuplicate.CodeID}, - mockFn: checksumCollector, - }, - "pin non existing code id": { - srcCodeIDs: []uint64{999}, - mockFn: checksumCollector, - expErr: true, - }, - "pin empty code id list": { - srcCodeIDs: []uint64{}, - mockFn: checksumCollector, - expErr: true, - }, - "wasmvm failed with error": { - srcCodeIDs: []uint64{hackatom.CodeID}, - mockFn: func(_ wasmvm.Checksum) error { - return errors.New("test, ignore") - }, - expErr: true, - }, - } - parentCtx := ctx - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - myActorAddress := RandomBech32AccountAddress(t) - gotPinnedChecksums = nil - ctx, _ := parentCtx.CacheContext() - mock.PinFn = spec.mockFn - proposal := &types.PinCodesProposal{ //nolint:staticcheck // testing deprecated function - Title: "Foo", - Description: "Bar", - CodeIDs: spec.srcCodeIDs, - } - - govAuthority := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String() - msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper) - - // when - contentMsg, gotErr := submitLegacyProposal(t, ctx, proposal, myActorAddress, govAuthority, msgServer) - if spec.expErr { - require.Error(t, gotErr) - return - } - require.NoError(t, gotErr) - - // and proposal execute - _, err := msgServer.ExecLegacyContent(sdk.WrapSDKContext(ctx), v1.NewMsgExecLegacyContent(contentMsg.Content, govAuthority)) - require.NoError(t, err) - - // then - for i := range spec.srcCodeIDs { - c := wasmKeeper.GetCodeInfo(ctx, spec.srcCodeIDs[i]) - require.Equal(t, wasmvm.Checksum(c.CodeHash), gotPinnedChecksums[i]) - } - }) - } -} - -func TestUnpinCodesProposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - - mock := wasmtesting.MockWasmer{ - StoreCodeFn: wasmtesting.NoOpStoreCodeFn, - AnalyzeCodeFn: wasmtesting.WithoutIBCAnalyzeFn, - } - var ( - hackatom = StoreHackatomExampleContract(t, ctx, keepers) - hackatomDuplicate = StoreHackatomExampleContract(t, ctx, keepers) - otherContract = StoreRandomContract(t, ctx, keepers, &mock) - gotUnpinnedChecksums []wasmvm.Checksum - ) - checksumCollector := func(checksum wasmvm.Checksum) error { - gotUnpinnedChecksums = append(gotUnpinnedChecksums, checksum) - return nil - } - specs := map[string]struct { - srcCodeIDs []uint64 - mockFn func(checksum wasmvm.Checksum) error - expUnpinned []wasmvm.Checksum - expErr bool - }{ - "unpin one": { - srcCodeIDs: []uint64{hackatom.CodeID}, - mockFn: checksumCollector, - }, - "unpin multiple": { - srcCodeIDs: []uint64{hackatom.CodeID, otherContract.CodeID}, - mockFn: checksumCollector, - }, - "unpin same code id": { - srcCodeIDs: []uint64{hackatom.CodeID, hackatomDuplicate.CodeID}, - mockFn: checksumCollector, - }, - "unpin non existing code id": { - srcCodeIDs: []uint64{999}, - mockFn: checksumCollector, - expErr: true, - }, - "unpin empty code id list": { - srcCodeIDs: []uint64{}, - mockFn: checksumCollector, - expErr: true, - }, - "wasmvm failed with error": { - srcCodeIDs: []uint64{hackatom.CodeID}, - mockFn: func(_ wasmvm.Checksum) error { - return errors.New("test, ignore") - }, - expErr: true, - }, - } - parentCtx := ctx - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - gotUnpinnedChecksums = nil - ctx, _ := parentCtx.CacheContext() - mock.UnpinFn = spec.mockFn - proposal := &types.UnpinCodesProposal{ //nolint:staticcheck // testing deprecated function - Title: "Foo", - Description: "Bar", - CodeIDs: spec.srcCodeIDs, - } - - govAuthority := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String() - msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper) - - // when - contentMsg, gotErr := submitLegacyProposal(t, ctx, proposal, RandomBech32AccountAddress(t), govAuthority, msgServer) - if spec.expErr { - require.Error(t, gotErr) - return - } - require.NoError(t, gotErr) - - // and proposal execute - _, err := msgServer.ExecLegacyContent(sdk.WrapSDKContext(ctx), v1.NewMsgExecLegacyContent(contentMsg.Content, govAuthority)) - require.NoError(t, err) - - // then - for i := range spec.srcCodeIDs { - c := wasmKeeper.GetCodeInfo(ctx, spec.srcCodeIDs[i]) - require.Equal(t, wasmvm.Checksum(c.CodeHash), gotUnpinnedChecksums[i]) - } - }) - } -} - -func TestUpdateInstantiateConfigProposal(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, "staking") - wasmKeeper := keepers.WasmKeeper - - mock := wasmtesting.MockWasmer{ - StoreCodeFn: wasmtesting.NoOpStoreCodeFn, - AnalyzeCodeFn: wasmtesting.WithoutIBCAnalyzeFn, - } - anyAddress, err := sdk.AccAddressFromBech32("cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz") - require.NoError(t, err) - - withAddressAccessConfig := types.AccessTypeAnyOfAddresses.With(anyAddress) - var ( - nobody = StoreRandomContractWithAccessConfig(t, ctx, keepers, &mock, &types.AllowNobody) - everybody = StoreRandomContractWithAccessConfig(t, ctx, keepers, &mock, &types.AllowEverybody) - withAddress = StoreRandomContractWithAccessConfig(t, ctx, keepers, &mock, &withAddressAccessConfig) - ) - - specs := map[string]struct { - accessConfigUpdates []types.AccessConfigUpdate - expErr bool - }{ - "update one": { - accessConfigUpdates: []types.AccessConfigUpdate{ - {CodeID: nobody.CodeID, InstantiatePermission: types.AllowEverybody}, - }, - }, - "update multiple": { - accessConfigUpdates: []types.AccessConfigUpdate{ - {CodeID: everybody.CodeID, InstantiatePermission: types.AllowNobody}, - {CodeID: nobody.CodeID, InstantiatePermission: withAddressAccessConfig}, - {CodeID: withAddress.CodeID, InstantiatePermission: types.AllowEverybody}, - }, - }, - "update same code id": { - accessConfigUpdates: []types.AccessConfigUpdate{ - {CodeID: everybody.CodeID, InstantiatePermission: types.AllowNobody}, - {CodeID: everybody.CodeID, InstantiatePermission: types.AllowEverybody}, - }, - expErr: true, - }, - "update non existing code id": { - accessConfigUpdates: []types.AccessConfigUpdate{ - {CodeID: 100, InstantiatePermission: types.AllowNobody}, - {CodeID: everybody.CodeID, InstantiatePermission: types.AllowEverybody}, - }, - expErr: true, - }, - "update empty list": { - accessConfigUpdates: make([]types.AccessConfigUpdate, 0), - expErr: true, - }, - } - parentCtx := ctx - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - ctx, _ := parentCtx.CacheContext() - - updates := make([]types.AccessConfigUpdate, 0) - for _, cu := range spec.accessConfigUpdates { - updates = append(updates, types.AccessConfigUpdate{ - CodeID: cu.CodeID, - InstantiatePermission: cu.InstantiatePermission, - }) - } - - govAuthority := keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String() - msgServer := govkeeper.NewMsgServerImpl(keepers.GovKeeper) - proposal := &types.UpdateInstantiateConfigProposal{ //nolint:staticcheck // testing deprecated function - Title: "Foo", - Description: "Bar", - AccessConfigUpdates: updates, - } - - // when - contentMsg, gotErr := submitLegacyProposal(t, ctx, proposal, RandomBech32AccountAddress(t), govAuthority, msgServer) - if spec.expErr { - require.Error(t, gotErr) - return - } - require.NoError(t, gotErr) - - // and proposal execute - _, err := msgServer.ExecLegacyContent(sdk.WrapSDKContext(ctx), v1.NewMsgExecLegacyContent(contentMsg.Content, govAuthority)) - require.NoError(t, err) - - // then - for i := range spec.accessConfigUpdates { - c := wasmKeeper.GetCodeInfo(ctx, spec.accessConfigUpdates[i].CodeID) - require.Equal(t, spec.accessConfigUpdates[i].InstantiatePermission, c.InstantiateConfig) - } - }) - } -} diff --git a/x/wasm/keeper/querier.go b/x/wasm/keeper/querier.go index 0d31364ddd..3cc80d2d6e 100644 --- a/x/wasm/keeper/querier.go +++ b/x/wasm/keeper/querier.go @@ -5,15 +5,17 @@ import ( "encoding/binary" "runtime/debug" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -59,12 +61,15 @@ func (q GrpcQuerier) ContractHistory(c context.Context, req *types.QueryContract if err != nil { return nil, err } + paginationParams, err := ensurePaginationParams(req.Pagination) + if err != nil { + return nil, err + } ctx := sdk.UnwrapSDKContext(c) r := make([]types.ContractCodeHistoryEntry, 0) - prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractCodeHistoryElementPrefix(contractAddr)) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, paginationParams, func(key, value []byte, accumulate bool) (bool, error) { if accumulate { var e types.ContractCodeHistoryEntry if err := q.cdc.Unmarshal(value, &e); err != nil { @@ -91,11 +96,15 @@ func (q GrpcQuerier) ContractsByCode(c context.Context, req *types.QueryContract if req.CodeId == 0 { return nil, errorsmod.Wrap(types.ErrInvalid, "code id") } + paginationParams, err := ensurePaginationParams(req.Pagination) + if err != nil { + return nil, err + } + ctx := sdk.UnwrapSDKContext(c) r := make([]string, 0) - prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractByCodeIDSecondaryIndexPrefix(req.CodeId)) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, paginationParams, func(key, value []byte, accumulate bool) (bool, error) { if accumulate { var contractAddr sdk.AccAddress = key[types.AbsoluteTxPositionLen:] r = append(r, contractAddr.String()) @@ -115,10 +124,16 @@ func (q GrpcQuerier) AllContractState(c context.Context, req *types.QueryAllCont if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } + contractAddr, err := sdk.AccAddressFromBech32(req.Address) if err != nil { return nil, err } + paginationParams, err := ensurePaginationParams(req.Pagination) + if err != nil { + return nil, err + } + ctx := sdk.UnwrapSDKContext(c) if !q.keeper.HasContractInfo(ctx, contractAddr) { return nil, types.ErrNoSuchContractFn(contractAddr.String()). @@ -127,7 +142,7 @@ func (q GrpcQuerier) AllContractState(c context.Context, req *types.QueryAllCont r := make([]types.Model, 0) prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractStorePrefix(contractAddr)) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, paginationParams, func(key, value []byte, accumulate bool) (bool, error) { if accumulate { r = append(r, types.Model{ Key: key, @@ -232,10 +247,15 @@ func (q GrpcQuerier) Codes(c context.Context, req *types.QueryCodesRequest) (*ty if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } + paginationParams, err := ensurePaginationParams(req.Pagination) + if err != nil { + return nil, err + } + ctx := sdk.UnwrapSDKContext(c) r := make([]types.CodeInfoResponse, 0) prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.CodeKeyPrefix) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, paginationParams, func(key, value []byte, accumulate bool) (bool, error) { if accumulate { var c types.CodeInfo if err := q.cdc.Unmarshal(value, &c); err != nil { @@ -296,11 +316,15 @@ func (q GrpcQuerier) PinnedCodes(c context.Context, req *types.QueryPinnedCodesR if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } + paginationParams, err := ensurePaginationParams(req.Pagination) + if err != nil { + return nil, err + } + ctx := sdk.UnwrapSDKContext(c) r := make([]uint64, 0) - prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.PinnedCodeIndexPrefix) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, _ []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, paginationParams, func(key, _ []byte, accumulate bool) (bool, error) { if accumulate { r = append(r, sdk.BigEndianToUint64(key)) } @@ -326,6 +350,11 @@ func (q GrpcQuerier) ContractsByCreator(c context.Context, req *types.QueryContr if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } + paginationParams, err := ensurePaginationParams(req.Pagination) + if err != nil { + return nil, err + } + ctx := sdk.UnwrapSDKContext(c) contracts := make([]string, 0) @@ -334,7 +363,7 @@ func (q GrpcQuerier) ContractsByCreator(c context.Context, req *types.QueryContr return nil, err } prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractsByCreatorPrefix(creatorAddress)) - pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, _ []byte, accumulate bool) (bool, error) { + pageRes, err := query.FilteredPaginate(prefixStore, paginationParams, func(key, _ []byte, accumulate bool) (bool, error) { if accumulate { accAddres := sdk.AccAddress(key[types.AbsoluteTxPositionLen:]) contracts = append(contracts, accAddres.String()) @@ -350,3 +379,25 @@ func (q GrpcQuerier) ContractsByCreator(c context.Context, req *types.QueryContr Pagination: pageRes, }, nil } + +// max limit to pagination queries +const maxResultEntries = 100 + +var errLegacyPaginationUnsupported = status.Error(codes.InvalidArgument, "offset and count queries not supported") + +// ensure that pagination is done via key iterator with reasonable limit +func ensurePaginationParams(req *query.PageRequest) (*query.PageRequest, error) { + if req == nil { + return &query.PageRequest{ + Key: nil, + Limit: query.DefaultLimit, + }, nil + } + if req.Offset != 0 || req.CountTotal { + return nil, errLegacyPaginationUnsupported + } + if req.Limit > maxResultEntries || req.Limit <= 0 { + req.Limit = maxResultEntries + } + return req, nil +} diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 4326bf835c..8de6b6aabf 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -9,19 +9,21 @@ import ( "testing" "time" - errorsmod "cosmossdk.io/errors" wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/log" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/query" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/query" + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -62,12 +64,16 @@ func TestQueryAllContractState(t *testing.T) { Offset: 1, }, }, - expModelContains: []types.Model{ - {Key: []byte("foo"), Value: []byte(`"bar"`)}, - }, - expModelContainsNot: []types.Model{ - {Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)}, + expErr: errLegacyPaginationUnsupported, + }, + "with pagination count": { + srcQuery: &types.QueryAllContractStateRequest{ + Address: contractAddr.String(), + Pagination: &query.PageRequest{ + CountTotal: true, + }, }, + expErr: errLegacyPaginationUnsupported, }, "with pagination limit": { srcQuery: &types.QueryAllContractStateRequest{ @@ -106,6 +112,7 @@ func TestQueryAllContractState(t *testing.T) { require.Equal(t, spec.expErr.Error(), err.Error()) return } + require.NoError(t, err) for _, exp := range spec.expModelContains { assert.Contains(t, got.Models, exp) } @@ -169,7 +176,7 @@ func TestQuerySmartContractPanics(t *testing.T) { CodeID: 1, Created: types.NewAbsoluteTxPosition(ctx), }) - ctx = ctx.WithGasMeter(sdk.NewGasMeter(DefaultInstanceCost)).WithLogger(log.TestingLogger()) + ctx = ctx.WithGasMeter(sdk.NewGasMeter(types.DefaultInstanceCost)).WithLogger(log.TestingLogger()) specs := map[string]struct { doInContract func() @@ -190,7 +197,7 @@ func TestQuerySmartContractPanics(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - keepers.WasmKeeper.wasmVM = &wasmtesting.MockWasmer{QueryFn: func(checksum wasmvm.Checksum, env wasmvmtypes.Env, queryMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) ([]byte, uint64, error) { + keepers.WasmKeeper.wasmVM = &wasmtesting.MockWasmEngine{QueryFn: func(checksum wasmvm.Checksum, env wasmvmtypes.Env, queryMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) ([]byte, uint64, error) { spec.doInContract() return nil, 0, nil }} @@ -263,7 +270,7 @@ func TestQueryRawContractState(t *testing.T) { } } -func TestQueryContractListByCodeOrdering(t *testing.T) { +func TestQueryContractsByCode(t *testing.T) { ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper @@ -296,6 +303,7 @@ func TestQueryContractListByCodeOrdering(t *testing.T) { return ctx } + contractAddrs := make([]string, 0, 10) // create 10 contracts with real block/gas setup for i := 0; i < 10; i++ { // 3 tx per block, so we ensure both comparisons work @@ -303,19 +311,85 @@ func TestQueryContractListByCodeOrdering(t *testing.T) { ctx = setBlock(ctx, h) h++ } - _, _, err = keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contract %d", i), topUp) + addr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contract %d", i), topUp) + contractAddrs = append(contractAddrs, addr.String()) require.NoError(t, err) } - // query and check the results are properly sorted q := Querier(keeper) - res, err := q.ContractsByCode(sdk.WrapSDKContext(ctx), &types.QueryContractsByCodeRequest{CodeId: codeID}) - require.NoError(t, err) - - require.Equal(t, 10, len(res.Contracts)) + specs := map[string]struct { + req *types.QueryContractsByCodeRequest + expAddr []string + expErr error + }{ + "with empty request": { + req: nil, + expErr: status.Error(codes.InvalidArgument, "empty request"), + }, + "req.CodeId=0": { + req: &types.QueryContractsByCodeRequest{CodeId: 0}, + expErr: errorsmod.Wrap(types.ErrInvalid, "code id"), + }, + "not exist codeID": { + req: &types.QueryContractsByCodeRequest{CodeId: codeID + 1}, + expAddr: []string{}, + }, + "query all and check the results are properly sorted": { + req: &types.QueryContractsByCodeRequest{ + CodeId: codeID, + }, + expAddr: contractAddrs, + }, + "with pagination offset": { + req: &types.QueryContractsByCodeRequest{ + CodeId: codeID, + Pagination: &query.PageRequest{ + Offset: 5, + }, + }, + expErr: errLegacyPaginationUnsupported, + }, + "with invalid pagination key": { + req: &types.QueryContractsByCodeRequest{ + CodeId: codeID, + Pagination: &query.PageRequest{ + Offset: 1, + Key: []byte("test"), + }, + }, + expErr: errLegacyPaginationUnsupported, + }, + "with pagination limit": { + req: &types.QueryContractsByCodeRequest{ + CodeId: codeID, + Pagination: &query.PageRequest{ + Limit: 5, + }, + }, + expAddr: contractAddrs[0:5], + }, + "with pagination next key": { + req: &types.QueryContractsByCodeRequest{ + CodeId: codeID, + Pagination: &query.PageRequest{ + Key: fromBase64("AAAAAAAAAAoAAAAAAAOc/4cuhNIMvyvID4NhhfROlbQNuZ0fl0clmBPoWHtKYazH"), + }, + }, + expAddr: contractAddrs[1:10], + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + got, err := q.ContractsByCode(sdk.WrapSDKContext(ctx), spec.req) - for _, contractAddr := range res.Contracts { - assert.NotEmpty(t, contractAddr) + if spec.expErr != nil { + assert.NotNil(t, err) + assert.EqualError(t, err, spec.expErr.Error()) + return + } + assert.NotNil(t, got) + assert.Equal(t, spec.expAddr, got.Contracts) + }) } } @@ -332,6 +406,7 @@ func TestQueryContractHistory(t *testing.T) { srcHistory []types.ContractCodeHistoryEntry req types.QueryContractHistoryRequest expContent []types.ContractCodeHistoryEntry + expErr error }{ "response with internal fields cleared": { srcHistory: []types.ContractCodeHistoryEntry{{ @@ -401,12 +476,7 @@ func TestQueryContractHistory(t *testing.T) { Offset: 1, }, }, - expContent: []types.ContractCodeHistoryEntry{{ - Operation: types.ContractCodeHistoryOperationTypeMigrate, - CodeID: 2, - Msg: []byte(`"migrate message 1"`), - Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4}, - }}, + expErr: errLegacyPaginationUnsupported, }, "with pagination limit": { srcHistory: []types.ContractCodeHistoryEntry{{ @@ -441,7 +511,7 @@ func TestQueryContractHistory(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: []byte(`"init message"`), }}, - expContent: nil, + expContent: []types.ContractCodeHistoryEntry{}, }, } for msg, spec := range specs { @@ -453,14 +523,14 @@ func TestQueryContractHistory(t *testing.T) { // when q := Querier(keeper) - got, err := q.ContractHistory(sdk.WrapSDKContext(xCtx), &spec.req) - + got, gotErr := q.ContractHistory(sdk.WrapSDKContext(xCtx), &spec.req) //nolint:gosec // then - if spec.expContent == nil { - require.Error(t, types.ErrEmpty) + if spec.expErr != nil { + require.Error(t, gotErr) + assert.ErrorIs(t, gotErr, spec.expErr) return } - require.NoError(t, err) + require.NoError(t, gotErr) assert.Equal(t, spec.expContent, got.Entries) }) } @@ -477,6 +547,7 @@ func TestQueryCodeList(t *testing.T) { storedCodeIDs []uint64 req types.QueryCodesRequest expCodeIDs []uint64 + expErr error }{ "none": {}, "no gaps": { @@ -494,7 +565,7 @@ func TestQueryCodeList(t *testing.T) { Offset: 1, }, }, - expCodeIDs: []uint64{2, 3}, + expErr: errLegacyPaginationUnsupported, }, "with pagination limit": { storedCodeIDs: []uint64{1, 2, 3}, @@ -528,10 +599,15 @@ func TestQueryCodeList(t *testing.T) { } // when q := Querier(keeper) - got, err := q.Codes(sdk.WrapSDKContext(xCtx), &spec.req) + got, gotErr := q.Codes(sdk.WrapSDKContext(xCtx), &spec.req) //nolint:gosec // then - require.NoError(t, err) + if spec.expErr != nil { + require.Error(t, gotErr) + require.ErrorIs(t, gotErr, spec.expErr) + return + } + require.NoError(t, gotErr) require.NotNil(t, got.CodeInfos) require.Len(t, got.CodeInfos, len(spec.expCodeIDs)) for i, exp := range spec.expCodeIDs { @@ -595,7 +671,7 @@ func TestQueryContractInfo(t *testing.T) { for name, spec := range specs { t.Run(name, func(t *testing.T) { xCtx, _ := ctx.CacheContext() - k.storeContractInfo(xCtx, contractAddr, &spec.stored) + k.storeContractInfo(xCtx, contractAddr, &spec.stored) //nolint:gosec // when gotRsp, gotErr := querier.ContractInfo(sdk.WrapSDKContext(xCtx), spec.src) if spec.expErr { @@ -621,7 +697,7 @@ func TestQueryPinnedCodes(t *testing.T) { specs := map[string]struct { srcQuery *types.QueryPinnedCodesRequest expCodeIDs []uint64 - expErr *errorsmod.Error + expErr error }{ "query all": { srcQuery: &types.QueryPinnedCodesRequest{}, @@ -633,7 +709,7 @@ func TestQueryPinnedCodes(t *testing.T) { Offset: 1, }, }, - expCodeIDs: []uint64{exampleContract2.CodeID}, + expErr: errLegacyPaginationUnsupported, }, "with pagination limit": { srcQuery: &types.QueryPinnedCodesRequest{ @@ -654,11 +730,13 @@ func TestQueryPinnedCodes(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - got, err := q.PinnedCodes(sdk.WrapSDKContext(ctx), spec.srcQuery) - require.True(t, spec.expErr.Is(err), err) + got, gotErr := q.PinnedCodes(sdk.WrapSDKContext(ctx), spec.srcQuery) if spec.expErr != nil { + require.Error(t, gotErr) + assert.ErrorIs(t, gotErr, spec.expErr) return } + require.NoError(t, gotErr) require.NotNil(t, got) assert.Equal(t, spec.expCodeIDs, got.CodeIDs) }) @@ -874,8 +952,7 @@ func TestQueryContractsByCreatorList(t *testing.T) { Offset: 1, }, }, - expContractAddr: allExpecedContracts[1:], - expErr: nil, + expErr: errLegacyPaginationUnsupported, }, "with pagination limit": { srcQuery: &types.QueryContractsByCreatorRequest{ @@ -904,13 +981,13 @@ func TestQueryContractsByCreatorList(t *testing.T) { q := Querier(keepers.WasmKeeper) for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - got, err := q.ContractsByCreator(sdk.WrapSDKContext(ctx), spec.srcQuery) - + got, gotErr := q.ContractsByCreator(sdk.WrapSDKContext(ctx), spec.srcQuery) if spec.expErr != nil { - require.Equal(t, spec.expErr, err) + require.Error(t, gotErr) + assert.ErrorContains(t, gotErr, spec.expErr.Error()) return } - require.NoError(t, err) + require.NoError(t, gotErr) require.NotNil(t, got) assert.Equal(t, spec.expContractAddr, got.ContractAddresses) }) @@ -924,3 +1001,47 @@ func fromBase64(s string) []byte { } return r } + +func TestEnsurePaginationParams(t *testing.T) { + specs := map[string]struct { + src *query.PageRequest + exp *query.PageRequest + expErr error + }{ + "custom limit": { + src: &query.PageRequest{Limit: 10}, + exp: &query.PageRequest{Limit: 10}, + }, + "limit not set": { + src: &query.PageRequest{}, + exp: &query.PageRequest{Limit: 100}, + }, + "limit > max": { + src: &query.PageRequest{Limit: 101}, + exp: &query.PageRequest{Limit: 100}, + }, + "no pagination params set": { + exp: &query.PageRequest{Limit: 100}, + }, + "non empty offset": { + src: &query.PageRequest{Offset: 1}, + expErr: errLegacyPaginationUnsupported, + }, + "count enabled": { + src: &query.PageRequest{CountTotal: true}, + expErr: errLegacyPaginationUnsupported, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + got, gotErr := ensurePaginationParams(spec.src) + if spec.expErr != nil { + require.Error(t, gotErr) + assert.ErrorIs(t, gotErr, spec.expErr) + return + } + require.NoError(t, gotErr) + assert.Equal(t, spec.exp, got) + }) + } +} diff --git a/x/wasm/keeper/query_plugin_integration_test.go b/x/wasm/keeper/query_plugin_integration_test.go new file mode 100644 index 0000000000..83dea003b0 --- /dev/null +++ b/x/wasm/keeper/query_plugin_integration_test.go @@ -0,0 +1,883 @@ +package keeper + +import ( + "bytes" + "encoding/json" + "fmt" + "strings" + "testing" + + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/cosmos/gogoproto/proto" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" + "github.com/CosmWasm/wasmd/x/wasm/types" +) + +func TestMaskReflectCustomQuery(t *testing.T) { + cdc := MakeEncodingConfig(t).Codec + ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) + keeper := keepers.WasmKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...) + + // upload code + codeID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) + require.NoError(t, err) + require.Equal(t, uint64(1), codeID) + + // creator instantiates a contract and gives it tokens + contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) + contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "reflect contract 1", contractStart) + require.NoError(t, err) + require.NotEmpty(t, contractAddr) + + // let's perform a normal query of state + ownerQuery := testdata.ReflectQueryMsg{ + Owner: &struct{}{}, + } + ownerQueryBz, err := json.Marshal(ownerQuery) + require.NoError(t, err) + ownerRes, err := keeper.QuerySmart(ctx, contractAddr, ownerQueryBz) + require.NoError(t, err) + var res testdata.OwnerResponse + err = json.Unmarshal(ownerRes, &res) + require.NoError(t, err) + assert.Equal(t, res.Owner, creator.String()) + + // and now making use of the custom querier callbacks + customQuery := testdata.ReflectQueryMsg{ + Capitalized: &testdata.Text{ + Text: "all Caps noW", + }, + } + customQueryBz, err := json.Marshal(customQuery) + require.NoError(t, err) + custom, err := keeper.QuerySmart(ctx, contractAddr, customQueryBz) + require.NoError(t, err) + var resp capitalizedResponse + err = json.Unmarshal(custom, &resp) + require.NoError(t, err) + assert.Equal(t, resp.Text, "ALL CAPS NOW") +} + +func TestReflectStargateQuery(t *testing.T) { + cdc := MakeEncodingConfig(t).Codec + ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) + keeper := keepers.WasmKeeper + + funds := sdk.NewCoins(sdk.NewInt64Coin("denom", 320000)) + contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) + expectedBalance := funds.Sub(contractStart...) + creator := keepers.Faucet.NewFundedRandomAccount(ctx, funds...) + + // upload code + codeID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) + require.NoError(t, err) + require.Equal(t, uint64(1), codeID) + + // creator instantiates a contract and gives it tokens + contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "reflect contract 1", contractStart) + require.NoError(t, err) + require.NotEmpty(t, contractAddr) + + // first, normal query for the bank balance (to make sure our query is proper) + bankQuery := wasmvmtypes.QueryRequest{ + Bank: &wasmvmtypes.BankQuery{ + AllBalances: &wasmvmtypes.AllBalancesQuery{ + Address: creator.String(), + }, + }, + } + simpleQueryBz, err := json.Marshal(testdata.ReflectQueryMsg{ + Chain: &testdata.ChainQuery{Request: &bankQuery}, + }) + require.NoError(t, err) + simpleRes, err := keeper.QuerySmart(ctx, contractAddr, simpleQueryBz) + require.NoError(t, err) + var simpleChain testdata.ChainResponse + mustUnmarshal(t, simpleRes, &simpleChain) + var simpleBalance wasmvmtypes.AllBalancesResponse + mustUnmarshal(t, simpleChain.Data, &simpleBalance) + require.Equal(t, len(expectedBalance), len(simpleBalance.Amount)) + assert.Equal(t, simpleBalance.Amount[0].Amount, expectedBalance[0].Amount.String()) + assert.Equal(t, simpleBalance.Amount[0].Denom, expectedBalance[0].Denom) +} + +func TestReflectTotalSupplyQuery(t *testing.T) { + cdc := MakeEncodingConfig(t).Codec + ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) + keeper := keepers.WasmKeeper + // upload code + codeID := StoreReflectContract(t, ctx, keepers).CodeID + // creator instantiates a contract and gives it tokens + creator := RandomAccountAddress(t) + contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "testing", nil) + require.NoError(t, err) + + currentStakeSupply := keepers.BankKeeper.GetSupply(ctx, "stake") + require.NotEmpty(t, currentStakeSupply.Amount) // ensure we have real data + specs := map[string]struct { + denom string + expAmount wasmvmtypes.Coin + }{ + "known denom": { + denom: "stake", + expAmount: ConvertSdkCoinToWasmCoin(currentStakeSupply), + }, + "unknown denom": { + denom: "unknown", + expAmount: wasmvmtypes.Coin{Denom: "unknown", Amount: "0"}, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + // when + queryBz := mustMarshal(t, testdata.ReflectQueryMsg{ + Chain: &testdata.ChainQuery{ + Request: &wasmvmtypes.QueryRequest{ + Bank: &wasmvmtypes.BankQuery{ + Supply: &wasmvmtypes.SupplyQuery{Denom: spec.denom}, + }, + }, + }, + }) + simpleRes, err := keeper.QuerySmart(ctx, contractAddr, queryBz) + + // then + require.NoError(t, err) + var rsp testdata.ChainResponse + mustUnmarshal(t, simpleRes, &rsp) + var supplyRsp wasmvmtypes.SupplyResponse + mustUnmarshal(t, rsp.Data, &supplyRsp) + assert.Equal(t, spec.expAmount, supplyRsp.Amount, spec.expAmount) + }) + } +} + +func TestReflectInvalidStargateQuery(t *testing.T) { + cdc := MakeEncodingConfig(t).Codec + ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) + keeper := keepers.WasmKeeper + + funds := sdk.NewCoins(sdk.NewInt64Coin("denom", 320000)) + contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) + creator := keepers.Faucet.NewFundedRandomAccount(ctx, funds...) + + // upload code + codeID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) + require.NoError(t, err) + require.Equal(t, uint64(1), codeID) + + // creator instantiates a contract and gives it tokens + contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "reflect contract 1", contractStart) + require.NoError(t, err) + require.NotEmpty(t, contractAddr) + + // now, try to build a protobuf query + protoQuery := banktypes.QueryAllBalancesRequest{ + Address: creator.String(), + } + protoQueryBin, err := proto.Marshal(&protoQuery) + require.NoError(t, err) + + protoRequest := wasmvmtypes.QueryRequest{ + Stargate: &wasmvmtypes.StargateQuery{ + Path: "/cosmos.bank.v1beta1.Query/AllBalances", + Data: protoQueryBin, + }, + } + protoQueryBz, err := json.Marshal(testdata.ReflectQueryMsg{ + Chain: &testdata.ChainQuery{Request: &protoRequest}, + }) + require.NoError(t, err) + + // make a query on the chain, should not be whitelisted + _, err = keeper.QuerySmart(ctx, contractAddr, protoQueryBz) + require.Error(t, err) + require.Contains(t, err.Error(), "Unsupported query") + + // now, try to build a protobuf query + protoRequest = wasmvmtypes.QueryRequest{ + Stargate: &wasmvmtypes.StargateQuery{ + Path: "/cosmos.tx.v1beta1.Service/GetTx", + Data: []byte{}, + }, + } + protoQueryBz, err = json.Marshal(testdata.ReflectQueryMsg{ + Chain: &testdata.ChainQuery{Request: &protoRequest}, + }) + require.NoError(t, err) + + // make a query on the chain, should be blacklisted + _, err = keeper.QuerySmart(ctx, contractAddr, protoQueryBz) + require.Error(t, err) + require.Contains(t, err.Error(), "Unsupported query") + + // and another one + protoRequest = wasmvmtypes.QueryRequest{ + Stargate: &wasmvmtypes.StargateQuery{ + Path: "/cosmos.base.tendermint.v1beta1.Service/GetNodeInfo", + Data: []byte{}, + }, + } + protoQueryBz, err = json.Marshal(testdata.ReflectQueryMsg{ + Chain: &testdata.ChainQuery{Request: &protoRequest}, + }) + require.NoError(t, err) + + // make a query on the chain, should be blacklisted + _, err = keeper.QuerySmart(ctx, contractAddr, protoQueryBz) + require.Error(t, err) + require.Contains(t, err.Error(), "Unsupported query") +} + +type reflectState struct { + Owner string `json:"owner"` +} + +func TestMaskReflectWasmQueries(t *testing.T) { + cdc := MakeEncodingConfig(t).Codec + ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) + keeper := keepers.WasmKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...) + + // upload reflect code + reflectID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) + require.NoError(t, err) + require.Equal(t, uint64(1), reflectID) + + // creator instantiates a contract and gives it tokens + reflectStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) + reflectAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, reflectID, creator, nil, []byte("{}"), "reflect contract 2", reflectStart) + require.NoError(t, err) + require.NotEmpty(t, reflectAddr) + + // for control, let's make some queries directly on the reflect + ownerQuery := buildReflectQuery(t, &testdata.ReflectQueryMsg{Owner: &struct{}{}}) + res, err := keeper.QuerySmart(ctx, reflectAddr, ownerQuery) + require.NoError(t, err) + var ownerRes testdata.OwnerResponse + mustUnmarshal(t, res, &ownerRes) + require.Equal(t, ownerRes.Owner, creator.String()) + + // and a raw query: cosmwasm_storage::Singleton uses 2 byte big-endian length-prefixed to store data + configKey := append([]byte{0, 6}, []byte("config")...) + raw := keeper.QueryRaw(ctx, reflectAddr, configKey) + var stateRes reflectState + mustUnmarshal(t, raw, &stateRes) + require.Equal(t, stateRes.Owner, creator.String()) + + // now, let's reflect a smart query into the x/wasm handlers and see if we get the same result + reflectOwnerQuery := testdata.ReflectQueryMsg{Chain: &testdata.ChainQuery{Request: &wasmvmtypes.QueryRequest{Wasm: &wasmvmtypes.WasmQuery{ + Smart: &wasmvmtypes.SmartQuery{ + ContractAddr: reflectAddr.String(), + Msg: ownerQuery, + }, + }}}} + reflectOwnerBin := buildReflectQuery(t, &reflectOwnerQuery) + res, err = keeper.QuerySmart(ctx, reflectAddr, reflectOwnerBin) + require.NoError(t, err) + // first we pull out the data from chain response, before parsing the original response + var reflectRes testdata.ChainResponse + mustUnmarshal(t, res, &reflectRes) + var reflectOwnerRes testdata.OwnerResponse + mustUnmarshal(t, reflectRes.Data, &reflectOwnerRes) + require.Equal(t, reflectOwnerRes.Owner, creator.String()) + + // and with queryRaw + reflectStateQuery := testdata.ReflectQueryMsg{Chain: &testdata.ChainQuery{Request: &wasmvmtypes.QueryRequest{Wasm: &wasmvmtypes.WasmQuery{ + Raw: &wasmvmtypes.RawQuery{ + ContractAddr: reflectAddr.String(), + Key: configKey, + }, + }}}} + reflectStateBin := buildReflectQuery(t, &reflectStateQuery) + res, err = keeper.QuerySmart(ctx, reflectAddr, reflectStateBin) + require.NoError(t, err) + // first we pull out the data from chain response, before parsing the original response + var reflectRawRes testdata.ChainResponse + mustUnmarshal(t, res, &reflectRawRes) + // now, with the raw data, we can parse it into state + var reflectStateRes reflectState + mustUnmarshal(t, reflectRawRes.Data, &reflectStateRes) + require.Equal(t, reflectStateRes.Owner, creator.String()) +} + +func TestWasmRawQueryWithNil(t *testing.T) { + cdc := MakeEncodingConfig(t).Codec + ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) + keeper := keepers.WasmKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...) + + // upload reflect code + reflectID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) + require.NoError(t, err) + require.Equal(t, uint64(1), reflectID) + + // creator instantiates a contract and gives it tokens + reflectStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) + reflectAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, reflectID, creator, nil, []byte("{}"), "reflect contract 2", reflectStart) + require.NoError(t, err) + require.NotEmpty(t, reflectAddr) + + // control: query directly + missingKey := []byte{0, 1, 2, 3, 4} + raw := keeper.QueryRaw(ctx, reflectAddr, missingKey) + require.Nil(t, raw) + + // and with queryRaw + reflectQuery := testdata.ReflectQueryMsg{Chain: &testdata.ChainQuery{Request: &wasmvmtypes.QueryRequest{Wasm: &wasmvmtypes.WasmQuery{ + Raw: &wasmvmtypes.RawQuery{ + ContractAddr: reflectAddr.String(), + Key: missingKey, + }, + }}}} + reflectStateBin := buildReflectQuery(t, &reflectQuery) + res, err := keeper.QuerySmart(ctx, reflectAddr, reflectStateBin) + require.NoError(t, err) + + // first we pull out the data from chain response, before parsing the original response + var reflectRawRes testdata.ChainResponse + mustUnmarshal(t, res, &reflectRawRes) + // and make sure there is no data + require.Empty(t, reflectRawRes.Data) + // we get an empty byte slice not nil (if anyone care in go-land) + require.Equal(t, []byte{}, reflectRawRes.Data) +} + +func TestQueryDenomsIntegration(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, CyberpunkFeatures) + ck, k := keepers.ContractKeeper, keepers.WasmKeeper + creator := keepers.Faucet.NewFundedRandomAccount(ctx, sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))...) + + // upload code + codeID, _, err := ck.Create(ctx, creator, testdata.CyberpunkContractWasm(), nil) + require.NoError(t, err) + + contractAddr, _, err := ck.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "cyberpunk contract", nil) + require.NoError(t, err) + + var ( + metadata1 = banktypes.Metadata{ + Description: "testing", + DenomUnits: []*banktypes.DenomUnit{ + {Denom: "ualx", Exponent: 0, Aliases: []string{"microalx"}}, + {Denom: "alx", Exponent: 6, Aliases: []string{"ALX"}}, + }, + Base: "ualx", + Display: "alx", + Name: "my test denom", + Symbol: "XALX", + URI: "https://example.com/ualx", + URIHash: "my_hash", + } + metadata2 = banktypes.Metadata{ + Description: "testing2", + DenomUnits: []*banktypes.DenomUnit{ + {Denom: "ublx", Exponent: 0, Aliases: []string{"microblx"}}, + {Denom: "blx", Exponent: 6, Aliases: []string{"BLX"}}, + }, + Base: "ublx", + Display: "blx", + Name: "my other test denom", + Symbol: "XBLX", + } + ) + type dict map[string]any + + keepers.BankKeeper.SetDenomMetaData(ctx, metadata1) + keepers.BankKeeper.SetDenomMetaData(ctx, metadata2) + + specs := map[string]struct { + query string + exp []byte + expErr *errorsmod.Error + }{ + "all denoms": { + query: `{"denoms":{}}`, + exp: mustMarshal(t, []dict{ + { + "description": "testing", + "denom_units": []dict{ + {"denom": "ualx", "exponent": 0, "aliases": []string{"microalx"}}, + {"denom": "alx", "exponent": 6, "aliases": []string{"ALX"}}, + }, + "base": "ualx", + "display": "alx", + "name": "my test denom", + "symbol": "XALX", + "uri": "https://example.com/ualx", + "uri_hash": "my_hash", + }, { + "description": "testing2", + "denom_units": []dict{ + {"denom": "ublx", "exponent": 0, "aliases": []string{"microblx"}}, + {"denom": "blx", "exponent": 6, "aliases": []string{"BLX"}}, + }, + "base": "ublx", + "display": "blx", + "name": "my other test denom", + "symbol": "XBLX", + "uri": "", + "uri_hash": "", + }, + }), + }, + "single denom": { + query: `{"denom":{"denom":"ublx"}}`, + exp: mustMarshal(t, dict{ + "description": "testing2", + "denom_units": []dict{ + {"denom": "ublx", "exponent": 0, "aliases": []string{"microblx"}}, + {"denom": "blx", "exponent": 6, "aliases": []string{"BLX"}}, + }, + "base": "ublx", + "display": "blx", + "name": "my other test denom", + "symbol": "XBLX", + "uri": "", + "uri_hash": "", + }), + }, + "unknown denom": { + query: `{"denom":{"denom":"unknown"}}`, + expErr: sdkerrors.ErrNotFound, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + gotData, gotErr := k.QuerySmart(ctx, contractAddr, []byte(spec.query)) + if spec.expErr != nil { + require.Error(t, gotErr) + assert.Contains(t, gotErr.Error(), fmt.Sprintf("codespace: %s, code: %d:", spec.expErr.Codespace(), spec.expErr.ABCICode())) + return + } + require.NoError(t, gotErr) + assert.JSONEq(t, string(spec.exp), string(gotData), string(gotData)) + }) + } +} + +func TestDistributionQuery(t *testing.T) { + cdc := MakeEncodingConfig(t).Codec + pCtx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) + keeper := keepers.WasmKeeper + + example := InstantiateReflectExampleContract(t, pCtx, keepers) + delegator := keepers.Faucet.NewFundedRandomAccount(pCtx, sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100_000_000))...) + otherAddr := keepers.Faucet.NewFundedRandomAccount(pCtx, sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 100_000_000))...) + + val1Addr := addValidator(t, pCtx, keepers.StakingKeeper, keepers.Faucet, sdk.NewInt64Coin(sdk.DefaultBondDenom, 10_000_000)) + val2Addr := addValidator(t, pCtx, keepers.StakingKeeper, keepers.Faucet, sdk.NewInt64Coin(sdk.DefaultBondDenom, 20_000_000)) + _ = val2Addr + pCtx = nextBlock(pCtx, keepers.StakingKeeper) + + noopSetup := func(t *testing.T, ctx sdk.Context) sdk.Context { return ctx } + specs := map[string]struct { + setup func(t *testing.T, ctx sdk.Context) sdk.Context + query *wasmvmtypes.DistributionQuery + expErr bool + assert func(t *testing.T, d []byte) + }{ + "delegator address - no withdrawal addr set": { + setup: noopSetup, + query: &wasmvmtypes.DistributionQuery{ + DelegatorWithdrawAddress: &wasmvmtypes.DelegatorWithdrawAddressQuery{DelegatorAddress: delegator.String()}, + }, + assert: func(t *testing.T, d []byte) { + rsp := unmarshalReflect[wasmvmtypes.DelegatorWithdrawAddressResponse](t, d) + assert.Equal(t, delegator.String(), rsp.WithdrawAddress) + }, + }, + "delegator address - withdrawal addr set": { + setup: func(t *testing.T, ctx sdk.Context) sdk.Context { + require.NoError(t, keepers.DistKeeper.SetWithdrawAddr(ctx, delegator, otherAddr)) + return ctx + }, + query: &wasmvmtypes.DistributionQuery{ + DelegatorWithdrawAddress: &wasmvmtypes.DelegatorWithdrawAddressQuery{DelegatorAddress: delegator.String()}, + }, + assert: func(t *testing.T, d []byte) { + var rsp wasmvmtypes.DelegatorWithdrawAddressResponse + mustUnmarshal(t, d, &rsp) + assert.Equal(t, otherAddr.String(), rsp.WithdrawAddress) + }, + }, + "delegator address - empty": { + setup: noopSetup, + query: &wasmvmtypes.DistributionQuery{ + DelegatorWithdrawAddress: &wasmvmtypes.DelegatorWithdrawAddressQuery{}, + }, + expErr: true, + }, + "delegation rewards - existing delegation": { + setup: func(t *testing.T, ctx sdk.Context) sdk.Context { + val1, ok := keepers.StakingKeeper.GetValidator(ctx, val1Addr) + require.True(t, ok) + _, err := keepers.StakingKeeper.Delegate(ctx, delegator, sdk.NewInt(10_000_000), stakingtypes.Unbonded, val1, true) + require.NoError(t, err) + setValidatorRewards(ctx, keepers.StakingKeeper, keepers.DistKeeper, val1Addr, "100000000") + return nextBlock(ctx, keepers.StakingKeeper) + }, + query: &wasmvmtypes.DistributionQuery{ + DelegationRewards: &wasmvmtypes.DelegationRewardsQuery{DelegatorAddress: delegator.String(), ValidatorAddress: val1Addr.String()}, + }, + assert: func(t *testing.T, d []byte) { + var rsp wasmvmtypes.DelegationRewardsResponse + mustUnmarshal(t, d, &rsp) + expRewards := []wasmvmtypes.DecCoin{{Amount: "45000000.000000000000000000", Denom: "stake"}} + assert.Equal(t, expRewards, rsp.Rewards) + }, + }, + "delegation rewards - no delegation": { + setup: func(t *testing.T, ctx sdk.Context) sdk.Context { + setValidatorRewards(ctx, keepers.StakingKeeper, keepers.DistKeeper, val1Addr, "100000000") + return nextBlock(ctx, keepers.StakingKeeper) + }, + query: &wasmvmtypes.DistributionQuery{ + DelegationRewards: &wasmvmtypes.DelegationRewardsQuery{DelegatorAddress: delegator.String(), ValidatorAddress: val1Addr.String()}, + }, + expErr: true, + }, + "delegation rewards - validator empty": { + setup: func(t *testing.T, ctx sdk.Context) sdk.Context { + val, found := keepers.StakingKeeper.GetValidator(ctx, val1Addr) + require.True(t, found) + _, err := keepers.StakingKeeper.Delegate(ctx, delegator, sdk.NewInt(10_000_000), stakingtypes.Unbonded, val, true) + require.NoError(t, err) + return ctx + }, + query: &wasmvmtypes.DistributionQuery{ + DelegationRewards: &wasmvmtypes.DelegationRewardsQuery{DelegatorAddress: delegator.String()}, + }, + expErr: true, + }, + "delegation total rewards": { + setup: func(t *testing.T, ctx sdk.Context) sdk.Context { + val, found := keepers.StakingKeeper.GetValidator(ctx, val1Addr) + require.True(t, found) + _, err := keepers.StakingKeeper.Delegate(ctx, delegator, sdk.NewInt(10_000_000), stakingtypes.Unbonded, val, true) + require.NoError(t, err) + setValidatorRewards(ctx, keepers.StakingKeeper, keepers.DistKeeper, val1Addr, "100000000") + return nextBlock(ctx, keepers.StakingKeeper) + }, + query: &wasmvmtypes.DistributionQuery{ + DelegationTotalRewards: &wasmvmtypes.DelegationTotalRewardsQuery{DelegatorAddress: delegator.String()}, + }, + assert: func(t *testing.T, d []byte) { + var rsp wasmvmtypes.DelegationTotalRewardsResponse + mustUnmarshal(t, d, &rsp) + expRewards := []wasmvmtypes.DelegatorReward{ + { + Reward: []wasmvmtypes.DecCoin{{Amount: "45000000.000000000000000000", Denom: "stake"}}, + ValidatorAddress: val1Addr.String(), + }, + } + assert.Equal(t, expRewards, rsp.Rewards) + expTotal := []wasmvmtypes.DecCoin{{Amount: "45000000.000000000000000000", Denom: "stake"}} + assert.Equal(t, expTotal, rsp.Total) + }, + }, + "delegator validators": { + setup: func(t *testing.T, ctx sdk.Context) sdk.Context { + for _, v := range []sdk.ValAddress{val1Addr, val2Addr} { + val, found := keepers.StakingKeeper.GetValidator(ctx, v) + require.True(t, found) + _, err := keepers.StakingKeeper.Delegate(ctx, delegator, sdk.NewInt(10_000_000), stakingtypes.Unbonded, val, true) + require.NoError(t, err) + } + return ctx + }, + query: &wasmvmtypes.DistributionQuery{ + DelegatorValidators: &wasmvmtypes.DelegatorValidatorsQuery{DelegatorAddress: delegator.String()}, + }, + assert: func(t *testing.T, d []byte) { + var rsp wasmvmtypes.DelegatorValidatorsResponse + mustUnmarshal(t, d, &rsp) + expVals := []string{val1Addr.String(), val2Addr.String()} + if bytes.Compare(val1Addr, val2Addr) > 0 { + expVals = []string{expVals[1], expVals[0]} + } + assert.Equal(t, expVals, rsp.Validators) + }, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + ctx, _ := pCtx.CacheContext() + ctx = spec.setup(t, ctx) + + // when + queryBz := mustMarshal(t, testdata.ReflectQueryMsg{ + Chain: &testdata.ChainQuery{ + Request: &wasmvmtypes.QueryRequest{Distribution: spec.query}, + }, + }) + simpleRes, gotErr := keeper.QuerySmart(ctx, example.Contract, queryBz) + if spec.expErr { + require.Error(t, gotErr) + return + } + // then + require.NoError(t, gotErr) + var rsp testdata.ChainResponse + mustUnmarshal(t, simpleRes, &rsp) + spec.assert(t, rsp.Data) + }) + } +} + +func TestIBCListChannelsQuery(t *testing.T) { + cdc := MakeEncodingConfig(t).Codec + pCtx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) + keeper := keepers.WasmKeeper + nonIbcExample := InstantiateReflectExampleContract(t, pCtx, keepers) + ibcExample := InstantiateReflectExampleContract(t, pCtx, keepers) + // add an ibc port for testing + myIBCPortID := "myValidPortID" + cInfo := keeper.GetContractInfo(pCtx, ibcExample.Contract) + cInfo.IBCPortID = myIBCPortID + keeper.storeContractInfo(pCtx, ibcExample.Contract, cInfo) + // store a random channel to be ignored in queries + unusedChan := channeltypes.Channel{ + State: channeltypes.OPEN, + Ordering: channeltypes.UNORDERED, + Counterparty: channeltypes.Counterparty{ + PortId: "counterPartyPortID", + ChannelId: "counterPartyChannelID", + }, + ConnectionHops: []string{"any"}, + Version: "any", + } + keepers.IBCKeeper.ChannelKeeper.SetChannel(pCtx, "nonContractPortID", "channel-99", unusedChan) + + // mixed channel examples for testing + myExampleChannels := []channeltypes.Channel{ + { + State: channeltypes.OPEN, + Ordering: channeltypes.ORDERED, + Counterparty: channeltypes.Counterparty{ + PortId: "counterPartyPortID", + ChannelId: "counterPartyChannelID", + }, + ConnectionHops: []string{"one"}, + Version: "v1", + }, + { + State: channeltypes.INIT, + Ordering: channeltypes.UNORDERED, + Counterparty: channeltypes.Counterparty{ + PortId: "foobar", + }, + ConnectionHops: []string{"one"}, + Version: "initversion", + }, + { + State: channeltypes.OPEN, + Ordering: channeltypes.UNORDERED, + Counterparty: channeltypes.Counterparty{ + PortId: "otherCounterPartyPortID", + ChannelId: "otherCounterPartyChannelID", + }, + ConnectionHops: []string{"other", "second"}, + Version: "otherVersion", + }, + { + State: channeltypes.CLOSED, + Ordering: channeltypes.ORDERED, + Counterparty: channeltypes.Counterparty{ + PortId: "super", + ChannelId: "duper", + }, + ConnectionHops: []string{"no-more"}, + Version: "closedVersion", + }, + } + + withChannelsStored := func(portID string, channels ...channeltypes.Channel) func(t *testing.T, ctx sdk.Context) sdk.Context { + return func(t *testing.T, ctx sdk.Context) sdk.Context { + for i, v := range channels { + keepers.IBCKeeper.ChannelKeeper.SetChannel(ctx, portID, fmt.Sprintf("channel-%d", i), v) + } + return ctx + } + } + noopSetup := func(t *testing.T, ctx sdk.Context) sdk.Context { return ctx } + + specs := map[string]struct { + setup func(t *testing.T, ctx sdk.Context) sdk.Context + contract sdk.AccAddress + query *wasmvmtypes.IBCQuery + expErr bool + assert func(t *testing.T, d []byte) + }{ + "open channels - with query portID empty": { + contract: ibcExample.Contract, + setup: withChannelsStored(myIBCPortID, myExampleChannels...), + query: &wasmvmtypes.IBCQuery{ListChannels: &wasmvmtypes.ListChannelsQuery{}}, + assert: func(t *testing.T, d []byte) { + rsp := unmarshalReflect[wasmvmtypes.ListChannelsResponse](t, d) + exp := wasmvmtypes.ListChannelsResponse{Channels: []wasmvmtypes.IBCChannel{ + { + Endpoint: wasmvmtypes.IBCEndpoint{PortID: myIBCPortID, ChannelID: "channel-0"}, + CounterpartyEndpoint: wasmvmtypes.IBCEndpoint{ + PortID: "counterPartyPortID", + ChannelID: "counterPartyChannelID", + }, + Order: channeltypes.ORDERED.String(), + Version: "v1", + ConnectionID: "one", + }, { + Endpoint: wasmvmtypes.IBCEndpoint{PortID: myIBCPortID, ChannelID: "channel-2"}, + CounterpartyEndpoint: wasmvmtypes.IBCEndpoint{ + PortID: "otherCounterPartyPortID", + ChannelID: "otherCounterPartyChannelID", + }, + Order: channeltypes.UNORDERED.String(), + Version: "otherVersion", + ConnectionID: "other", + }, + }} + assert.Equal(t, exp, rsp) + }, + }, + "open channels - with query portID passed": { + contract: ibcExample.Contract, + setup: withChannelsStored("OtherPortID", myExampleChannels...), + query: &wasmvmtypes.IBCQuery{ListChannels: &wasmvmtypes.ListChannelsQuery{PortID: "OtherPortID"}}, + assert: func(t *testing.T, d []byte) { + rsp := unmarshalReflect[wasmvmtypes.ListChannelsResponse](t, d) + exp := wasmvmtypes.ListChannelsResponse{Channels: []wasmvmtypes.IBCChannel{ + { + Endpoint: wasmvmtypes.IBCEndpoint{PortID: "OtherPortID", ChannelID: "channel-0"}, + CounterpartyEndpoint: wasmvmtypes.IBCEndpoint{ + PortID: "counterPartyPortID", + ChannelID: "counterPartyChannelID", + }, + Order: channeltypes.ORDERED.String(), + Version: "v1", + ConnectionID: "one", + }, { + Endpoint: wasmvmtypes.IBCEndpoint{PortID: "OtherPortID", ChannelID: "channel-2"}, + CounterpartyEndpoint: wasmvmtypes.IBCEndpoint{ + PortID: "otherCounterPartyPortID", + ChannelID: "otherCounterPartyChannelID", + }, + Order: channeltypes.UNORDERED.String(), + Version: "otherVersion", + ConnectionID: "other", + }, + }} + assert.Equal(t, exp, rsp) + }, + }, + "non ibc contract - with query portID empty": { + contract: nonIbcExample.Contract, + setup: withChannelsStored(myIBCPortID, myExampleChannels...), + query: &wasmvmtypes.IBCQuery{ListChannels: &wasmvmtypes.ListChannelsQuery{}}, + assert: func(t *testing.T, d []byte) { + rsp := unmarshalReflect[wasmvmtypes.ListChannelsResponse](t, d) + assert.Nil(t, rsp.Channels) + }, + }, + "no matching channels": { + contract: ibcExample.Contract, + setup: noopSetup, + query: &wasmvmtypes.IBCQuery{ListChannels: &wasmvmtypes.ListChannelsQuery{}}, + assert: func(t *testing.T, d []byte) { + rsp := unmarshalReflect[wasmvmtypes.ListChannelsResponse](t, d) + assert.Empty(t, rsp.Channels) + }, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + ctx, _ := pCtx.CacheContext() + ctx = spec.setup(t, ctx) + + // when + queryBz := mustMarshal(t, testdata.ReflectQueryMsg{ + Chain: &testdata.ChainQuery{ + Request: &wasmvmtypes.QueryRequest{IBC: spec.query}, + }, + }) + simpleRes, gotErr := keeper.QuerySmart(ctx, spec.contract, queryBz) + if spec.expErr { + require.Error(t, gotErr) + return + } + // then + require.NoError(t, gotErr) + var rsp testdata.ChainResponse + mustUnmarshal(t, simpleRes, &rsp) + spec.assert(t, rsp.Data) + }) + } +} + +func unmarshalReflect[T any](t *testing.T, d []byte) T { + var v T + mustUnmarshal(t, d, &v) + return v +} + +type reflectCustomQuery struct { + Ping *struct{} `json:"ping,omitempty"` + Capitalized *testdata.Text `json:"capitalized,omitempty"` +} + +// this is from the go code back to the contract (capitalized or ping) +type customQueryResponse struct { + Msg string `json:"msg"` +} + +// this is from the contract to the go code (capitalized or ping) +type capitalizedResponse struct { + Text string `json:"text"` +} + +// reflectPlugins needs to be registered in test setup to handle custom query callbacks +func reflectPlugins() *QueryPlugins { + return &QueryPlugins{ + Custom: performCustomQuery, + } +} + +func performCustomQuery(_ sdk.Context, request json.RawMessage) ([]byte, error) { + var custom reflectCustomQuery + err := json.Unmarshal(request, &custom) + if err != nil { + return nil, errorsmod.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) + } + if custom.Capitalized != nil { + msg := strings.ToUpper(custom.Capitalized.Text) + return json.Marshal(customQueryResponse{Msg: msg}) + } + if custom.Ping != nil { + return json.Marshal(customQueryResponse{Msg: "pong"}) + } + return nil, errorsmod.Wrap(types.ErrInvalidMsg, "Unknown Custom query variant") +} + +func buildReflectQuery(t *testing.T, query *testdata.ReflectQueryMsg) []byte { + t.Helper() + bz, err := json.Marshal(query) + require.NoError(t, err) + return bz +} diff --git a/x/wasm/keeper/query_plugins.go b/x/wasm/keeper/query_plugins.go index 007f588ed6..24e76f3720 100644 --- a/x/wasm/keeper/query_plugins.go +++ b/x/wasm/keeper/query_plugins.go @@ -5,18 +5,20 @@ import ( "errors" "fmt" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -25,10 +27,10 @@ type QueryHandler struct { Ctx sdk.Context Plugins WasmVMQueryHandler Caller sdk.AccAddress - gasRegister GasRegister + gasRegister types.GasRegister } -func NewQueryHandler(ctx sdk.Context, vmQueryHandler WasmVMQueryHandler, caller sdk.AccAddress, gasRegister GasRegister) QueryHandler { +func NewQueryHandler(ctx sdk.Context, vmQueryHandler WasmVMQueryHandler, caller sdk.AccAddress, gasRegister types.GasRegister) QueryHandler { return QueryHandler{ Ctx: ctx, Plugins: vmQueryHandler, @@ -69,11 +71,12 @@ func (q QueryHandler) Query(request wasmvmtypes.QueryRequest, gasLimit uint64) ( } // Issue #759 - we don't return error string for worries of non-determinism + moduleLogger(q.Ctx).Debug("Redacting submessage error", "cause", err) return nil, redactError(err) } func (q QueryHandler) GasConsumed() uint64 { - return q.Ctx.GasMeter().GasConsumed() + return q.gasRegister.ToWasmVMGas(q.Ctx.GasMeter().GasConsumed()) } type CustomQuerier func(ctx sdk.Context, request json.RawMessage) ([]byte, error) @@ -246,11 +249,18 @@ func IBCQuerier(wasm contractMetaDataSource, channelKeeper types.ChannelKeeper) } if request.ListChannels != nil { portID := request.ListChannels.PortID - channels := make(wasmvmtypes.IBCChannels, 0) - channelKeeper.IterateChannels(ctx, func(ch channeltypes.IdentifiedChannel) bool { - // it must match the port and be in open state - if (portID == "" || portID == ch.PortId) && ch.State == channeltypes.OPEN { - newChan := wasmvmtypes.IBCChannel{ + if portID == "" { // then fallback to contract port address + portID = wasm.GetContractInfo(ctx, caller).IBCPortID + } + var channels wasmvmtypes.IBCChannels + if portID != "" { // then return empty list for non ibc contracts; no channels possible + gotChannels := channelKeeper.GetAllChannelsWithPortPrefix(ctx, portID) + channels = make(wasmvmtypes.IBCChannels, 0, len(gotChannels)) + for _, ch := range gotChannels { + if ch.State != channeltypes.OPEN { + continue + } + channels = append(channels, wasmvmtypes.IBCChannel{ Endpoint: wasmvmtypes.IBCEndpoint{ PortID: ch.PortId, ChannelID: ch.ChannelId, @@ -262,11 +272,9 @@ func IBCQuerier(wasm contractMetaDataSource, channelKeeper types.ChannelKeeper) Order: ch.Ordering.String(), Version: ch.Version, ConnectionID: ch.ConnectionHops[0], - } - channels = append(channels, newChan) + }) } - return false - }) + } res := wasmvmtypes.ListChannelsResponse{ Channels: channels, } @@ -322,7 +330,7 @@ type AcceptedStargateQueries map[string]codec.ProtoMarshaler // All arguments must be non nil. // // Warning: Chains need to test and maintain their accept list carefully. -// There were critical consensus breaking issues in the past with non-deterministic behaviour in the SDK. +// There were critical consensus breaking issues in the past with non-deterministic behavior in the SDK. // // This queries can be set via WithQueryPlugins option in the wasm keeper constructor: // WithQueryPlugins(&QueryPlugins{Stargate: AcceptListStargateQuerier(acceptList, queryRouter, codec)}) @@ -516,7 +524,7 @@ func sdkToFullDelegation(ctx sdk.Context, keeper types.StakingKeeper, distKeeper // https://github.com/cosmos/cosmos-sdk/issues/7466 is merged func getAccumulatedRewards(ctx sdk.Context, distKeeper types.DistributionKeeper, delegation stakingtypes.Delegation) ([]wasmvmtypes.Coin, error) { // Try to get *delegator* reward info! - params := distributiontypes.QueryDelegationRewardsRequest{ + params := distrtypes.QueryDelegationRewardsRequest{ DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, } @@ -598,18 +606,74 @@ func WasmQuerier(k wasmQueryKeeper) func(ctx sdk.Context, request *wasmvmtypes.W func DistributionQuerier(k types.DistributionKeeper) func(ctx sdk.Context, request *wasmvmtypes.DistributionQuery) ([]byte, error) { return func(ctx sdk.Context, req *wasmvmtypes.DistributionQuery) ([]byte, error) { - if req.DelegatorWithdrawAddress == nil { - return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown distribution query"} + switch { + case req.DelegatorWithdrawAddress != nil: + got, err := k.DelegatorWithdrawAddress(ctx, &distrtypes.QueryDelegatorWithdrawAddressRequest{DelegatorAddress: req.DelegatorWithdrawAddress.DelegatorAddress}) + if err != nil { + return nil, err + } + return json.Marshal(wasmvmtypes.DelegatorWithdrawAddressResponse{ + WithdrawAddress: got.WithdrawAddress, + }) + case req.DelegationRewards != nil: + got, err := k.DelegationRewards(ctx, &distrtypes.QueryDelegationRewardsRequest{ + DelegatorAddress: req.DelegationRewards.DelegatorAddress, + ValidatorAddress: req.DelegationRewards.ValidatorAddress, + }) + if err != nil { + return nil, err + } + return json.Marshal(wasmvmtypes.DelegationRewardsResponse{ + Rewards: ConvertSDKDecCoinsToWasmDecCoins(got.Rewards), + }) + case req.DelegationTotalRewards != nil: + got, err := k.DelegationTotalRewards(ctx, &distrtypes.QueryDelegationTotalRewardsRequest{ + DelegatorAddress: req.DelegationTotalRewards.DelegatorAddress, + }) + if err != nil { + return nil, err + } + return json.Marshal(wasmvmtypes.DelegationTotalRewardsResponse{ + Rewards: ConvertSDKDelegatorRewardsToWasmRewards(got.Rewards), + Total: ConvertSDKDecCoinsToWasmDecCoins(got.Total), + }) + case req.DelegatorValidators != nil: + got, err := k.DelegatorValidators(ctx, &distrtypes.QueryDelegatorValidatorsRequest{ + DelegatorAddress: req.DelegatorValidators.DelegatorAddress, + }) + if err != nil { + return nil, err + } + return json.Marshal(wasmvmtypes.DelegatorValidatorsResponse{ + Validators: got.Validators, + }) } - addr, err := sdk.AccAddressFromBech32(req.DelegatorWithdrawAddress.DelegatorAddress) - if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap("delegator address") + return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown distribution query"} + } +} + +// ConvertSDKDelegatorRewardsToWasmRewards convert sdk to wasmvm type +func ConvertSDKDelegatorRewardsToWasmRewards(rewards []distrtypes.DelegationDelegatorReward) []wasmvmtypes.DelegatorReward { + r := make([]wasmvmtypes.DelegatorReward, len(rewards)) + for i, v := range rewards { + r[i] = wasmvmtypes.DelegatorReward{ + Reward: ConvertSDKDecCoinsToWasmDecCoins(v.Reward), + ValidatorAddress: v.ValidatorAddress, } - res := wasmvmtypes.DelegatorWithdrawAddressResponse{ - WithdrawAddress: k.GetDelegatorWithdrawAddr(ctx, addr).String(), + } + return r +} + +// ConvertSDKDecCoinsToWasmDecCoins convert sdk to wasmvm type +func ConvertSDKDecCoinsToWasmDecCoins(src sdk.DecCoins) []wasmvmtypes.DecCoin { + r := make([]wasmvmtypes.DecCoin, len(src)) + for i, v := range src { + r[i] = wasmvmtypes.DecCoin{ + Amount: v.Amount.String(), + Denom: v.Denom, } - return json.Marshal(res) } + return r } // ConvertSdkCoinsToWasmCoins covert sdk type to wasmvm coins type @@ -676,7 +740,7 @@ func ConvertSdkDenomUnitsToWasmDenomUnits(denomUnits []*banktypes.DenomUnit) []w // ConvertProtoToJSONMarshal unmarshals the given bytes into a proto message and then marshals it to json. // This is done so that clients calling stargate queries do not need to define their own proto unmarshalers, -// being able to use response directly by json marshalling, which is supported in cosmwasm. +// being able to use response directly by json marshaling, which is supported in cosmwasm. func ConvertProtoToJSONMarshal(cdc codec.Codec, protoResponse codec.ProtoMarshaler, bz []byte) ([]byte, error) { // unmarshal binary into stargate response data structure err := cdc.Unmarshal(bz, protoResponse) diff --git a/x/wasm/keeper/query_plugins_test.go b/x/wasm/keeper/query_plugins_test.go index c7b240b543..78666f3cd3 100644 --- a/x/wasm/keeper/query_plugins_test.go +++ b/x/wasm/keeper/query_plugins_test.go @@ -5,30 +5,33 @@ import ( "encoding/hex" "encoding/json" "fmt" + "math" "testing" "time" - "github.com/cometbft/cometbft/libs/rand" - "github.com/cosmos/cosmos-sdk/types/address" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" dbm "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/libs/log" + "github.com/cometbft/cometbft/libs/rand" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/gogoproto/proto" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/query" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/gogoproto/proto" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -37,59 +40,6 @@ import ( ) func TestIBCQuerier(t *testing.T) { - myExampleChannels := []channeltypes.IdentifiedChannel{ - // this is returned - { - State: channeltypes.OPEN, - Ordering: channeltypes.ORDERED, - Counterparty: channeltypes.Counterparty{ - PortId: "counterPartyPortID", - ChannelId: "counterPartyChannelID", - }, - ConnectionHops: []string{"one"}, - Version: "v1", - PortId: "myPortID", - ChannelId: "myChannelID", - }, - // this is filtered out - { - State: channeltypes.INIT, - Ordering: channeltypes.UNORDERED, - Counterparty: channeltypes.Counterparty{ - PortId: "foobar", - }, - ConnectionHops: []string{"one"}, - Version: "initversion", - PortId: "initPortID", - ChannelId: "initChannelID", - }, - // this is returned - { - State: channeltypes.OPEN, - Ordering: channeltypes.UNORDERED, - Counterparty: channeltypes.Counterparty{ - PortId: "otherCounterPartyPortID", - ChannelId: "otherCounterPartyChannelID", - }, - ConnectionHops: []string{"other", "second"}, - Version: "otherVersion", - PortId: "otherPortID", - ChannelId: "otherChannelID", - }, - // this is filtered out - { - State: channeltypes.CLOSED, - Ordering: channeltypes.ORDERED, - Counterparty: channeltypes.Counterparty{ - PortId: "super", - ChannelId: "duper", - }, - ConnectionHops: []string{"no-more"}, - Version: "closedVersion", - PortId: "closedPortID", - ChannelId: "closedChannelID", - }, - } specs := map[string]struct { srcQuery *wasmvmtypes.IBCQuery wasmKeeper *mockWasmQueryKeeper @@ -109,82 +59,6 @@ func TestIBCQuerier(t *testing.T) { channelKeeper: &wasmtesting.MockChannelKeeper{}, expJSONResult: `{"port_id":"myIBCPortID"}`, }, - "query list channels - all": { - srcQuery: &wasmvmtypes.IBCQuery{ - ListChannels: &wasmvmtypes.ListChannelsQuery{}, - }, - channelKeeper: &wasmtesting.MockChannelKeeper{ - IterateChannelsFn: wasmtesting.MockChannelKeeperIterator(myExampleChannels), - }, - expJSONResult: `{ - "channels": [ - { - "endpoint": { - "port_id": "myPortID", - "channel_id": "myChannelID" - }, - "counterparty_endpoint": { - "port_id": "counterPartyPortID", - "channel_id": "counterPartyChannelID" - }, - "order": "ORDER_ORDERED", - "version": "v1", - "connection_id": "one" - }, - { - "endpoint": { - "port_id": "otherPortID", - "channel_id": "otherChannelID" - }, - "counterparty_endpoint": { - "port_id": "otherCounterPartyPortID", - "channel_id": "otherCounterPartyChannelID" - }, - "order": "ORDER_UNORDERED", - "version": "otherVersion", - "connection_id": "other" - } - ] -}`, - }, - "query list channels - filtered": { - srcQuery: &wasmvmtypes.IBCQuery{ - ListChannels: &wasmvmtypes.ListChannelsQuery{ - PortID: "otherPortID", - }, - }, - channelKeeper: &wasmtesting.MockChannelKeeper{ - IterateChannelsFn: wasmtesting.MockChannelKeeperIterator(myExampleChannels), - }, - expJSONResult: `{ - "channels": [ - { - "endpoint": { - "port_id": "otherPortID", - "channel_id": "otherChannelID" - }, - "counterparty_endpoint": { - "port_id": "otherCounterPartyPortID", - "channel_id": "otherCounterPartyChannelID" - }, - "order": "ORDER_UNORDERED", - "version": "otherVersion", - "connection_id": "other" - } - ] -}`, - }, - "query list channels - filtered empty": { - srcQuery: &wasmvmtypes.IBCQuery{ - ListChannels: &wasmvmtypes.ListChannelsQuery{ - PortID: "none-existing", - }, - }, - channelKeeper: &wasmtesting.MockChannelKeeper{ - IterateChannelsFn: wasmtesting.MockChannelKeeperIterator(myExampleChannels), - }, - expJSONResult: `{"channels": []}`, - }, "query channel": { srcQuery: &wasmvmtypes.IBCQuery{ Channel: &wasmvmtypes.ChannelQuery{ @@ -687,8 +561,8 @@ func TestQueryErrors(t *testing.T) { mock := keeper.WasmVMQueryHandlerFn(func(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error) { return nil, spec.src }) - ctx := sdk.Context{}.WithGasMeter(sdk.NewInfiniteGasMeter()).WithMultiStore(store.NewCommitMultiStore(dbm.NewMemDB())) - q := keeper.NewQueryHandler(ctx, mock, sdk.AccAddress{}, keeper.NewDefaultWasmGasRegister()) + ctx := sdk.Context{}.WithGasMeter(sdk.NewInfiniteGasMeter()).WithMultiStore(store.NewCommitMultiStore(dbm.NewMemDB())).WithLogger(log.TestingLogger()) + q := keeper.NewQueryHandler(ctx, mock, sdk.AccAddress{}, types.NewDefaultWasmGasRegister()) _, gotErr := q.Query(wasmvmtypes.QueryRequest{}, 1) assert.Equal(t, spec.expErr, gotErr) }) @@ -762,6 +636,7 @@ func TestAcceptListStargateQuerier(t *testing.T) { } func TestDistributionQuerier(t *testing.T) { + t.Skip("not implemented") ctx := sdk.Context{} var myAddr sdk.AccAddress = rand.Bytes(address.Len) var myOtherAddr sdk.AccAddress = rand.Bytes(address.Len) @@ -802,10 +677,11 @@ func TestDistributionQuerier(t *testing.T) { } for name, spec := range specs { t.Run(name, func(t *testing.T) { - mock := distrKeeperMock{GetDelegatorWithdrawAddrFn: spec.mockFn} + // mock := distrKeeperMock{GetDelegatorWithdrawAddrFn: spec.mockFn} + var mock types.DistributionKeeper q := keeper.DistributionQuerier(mock) - gotBz, gotErr := q(ctx, &spec.q) + gotBz, gotErr := q(ctx, &spec.q) //nolint:gosec if spec.expErr { require.Error(t, gotErr) return @@ -818,25 +694,6 @@ func TestDistributionQuerier(t *testing.T) { } } -type distrKeeperMock struct { - DelegationRewardsFn func(c context.Context, req *distributiontypes.QueryDelegationRewardsRequest) (*distributiontypes.QueryDelegationRewardsResponse, error) - GetDelegatorWithdrawAddrFn func(ctx sdk.Context, delAddr sdk.AccAddress) sdk.AccAddress -} - -func (m distrKeeperMock) DelegationRewards(ctx context.Context, req *distributiontypes.QueryDelegationRewardsRequest) (*distributiontypes.QueryDelegationRewardsResponse, error) { - if m.DelegationRewardsFn == nil { - panic("not expected to be called") - } - return m.DelegationRewardsFn(ctx, req) -} - -func (m distrKeeperMock) GetDelegatorWithdrawAddr(ctx sdk.Context, delAddr sdk.AccAddress) sdk.AccAddress { - if m.GetDelegatorWithdrawAddrFn == nil { - panic("not expected to be called") - } - return m.GetDelegatorWithdrawAddrFn(ctx, delAddr) -} - type mockWasmQueryKeeper struct { GetContractInfoFn func(ctx sdk.Context, contractAddress sdk.AccAddress) *types.ContractInfo QueryRawFn func(ctx sdk.Context, contractAddress sdk.AccAddress, key []byte) []byte @@ -933,7 +790,7 @@ func TestConvertProtoToJSONMarshal(t *testing.T) { expectedError bool }{ { - name: "successful conversion from proto response to json marshalled response", + name: "successful conversion from proto response to json marshaled response", queryPath: "/cosmos.bank.v1beta1.Query/AllBalances", originalResponse: "0a090a036261721202333012050a03666f6f", protoResponseStruct: &banktypes.QueryAllBalancesResponse{}, @@ -957,7 +814,7 @@ func TestConvertProtoToJSONMarshal(t *testing.T) { t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) { originalVersionBz, err := hex.DecodeString(tc.originalResponse) require.NoError(t, err) - appCodec := app.MakeEncodingConfig().Marshaler + appCodec := app.MakeEncodingConfig().Codec jsonMarshalledResponse, err := keeper.ConvertProtoToJSONMarshal(appCodec, tc.protoResponseStruct, originalVersionBz) if tc.expectedError { @@ -966,7 +823,7 @@ func TestConvertProtoToJSONMarshal(t *testing.T) { } require.NoError(t, err) - // check response by json marshalling proto response into json response manually + // check response by json marshaling proto response into json response manually jsonMarshalExpectedResponse, err := appCodec.MarshalJSON(tc.expectedProtoResponse) require.NoError(t, err) require.JSONEq(t, string(jsonMarshalledResponse), string(jsonMarshalExpectedResponse)) @@ -974,8 +831,45 @@ func TestConvertProtoToJSONMarshal(t *testing.T) { } } +func TestConvertSDKDecCoinToWasmDecCoin(t *testing.T) { + specs := map[string]struct { + src sdk.DecCoins + exp []wasmvmtypes.DecCoin + }{ + "one coin": { + src: sdk.NewDecCoins(sdk.NewInt64DecCoin("alx", 1)), + exp: []wasmvmtypes.DecCoin{{Amount: "1.000000000000000000", Denom: "alx"}}, + }, + "multiple coins": { + src: sdk.NewDecCoins(sdk.NewInt64DecCoin("alx", 1), sdk.NewInt64DecCoin("blx", 2)), + exp: []wasmvmtypes.DecCoin{{Amount: "1.000000000000000000", Denom: "alx"}, {Amount: "2.000000000000000000", Denom: "blx"}}, + }, + "small amount": { + src: sdk.NewDecCoins(sdk.NewDecCoinFromDec("alx", sdkmath.LegacyNewDecWithPrec(1, 18))), + exp: []wasmvmtypes.DecCoin{{Amount: "0.000000000000000001", Denom: "alx"}}, + }, + "big amount": { + src: sdk.NewDecCoins(sdk.NewDecCoin("alx", sdkmath.NewIntFromUint64(math.MaxUint64))), + exp: []wasmvmtypes.DecCoin{{Amount: "18446744073709551615.000000000000000000", Denom: "alx"}}, + }, + "empty": { + src: sdk.NewDecCoins(), + exp: []wasmvmtypes.DecCoin{}, + }, + "nil": { + exp: []wasmvmtypes.DecCoin{}, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + got := keeper.ConvertSDKDecCoinsToWasmDecCoins(spec.src) + assert.Equal(t, spec.exp, got) + }) + } +} + func TestResetProtoMarshalerAfterJsonMarshal(t *testing.T) { - appCodec := app.MakeEncodingConfig().Marshaler + appCodec := app.MakeEncodingConfig().Codec protoMarshaler := &banktypes.QueryAllBalancesResponse{} expected := appCodec.MustMarshalJSON(&banktypes.QueryAllBalancesResponse{ @@ -999,7 +893,7 @@ func TestResetProtoMarshalerAfterJsonMarshal(t *testing.T) { require.Equal(t, expected, response) } -// TestDeterministicJsonMarshal tests that we get deterministic JSON marshalled response upon +// TestDeterministicJsonMarshal tests that we get deterministic JSON marshaled response upon // proto struct update in the state machine. func TestDeterministicJsonMarshal(t *testing.T) { testCases := []struct { @@ -1051,7 +945,7 @@ func TestDeterministicJsonMarshal(t *testing.T) { for _, tc := range testCases { t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) { - appCodec := app.MakeEncodingConfig().Marshaler + appCodec := app.MakeEncodingConfig().Codec originVersionBz, err := hex.DecodeString(tc.originalResponse) require.NoError(t, err) @@ -1063,7 +957,7 @@ func TestDeterministicJsonMarshal(t *testing.T) { jsonMarshalledUpdatedBz, err := keeper.ConvertProtoToJSONMarshal(appCodec, tc.responseProtoStruct, newVersionBz) require.NoError(t, err) - // json marshalled bytes should be the same since we use the same proto struct for unmarshalling + // json marshaled bytes should be the same since we use the same proto struct for unmarshalling require.Equal(t, jsonMarshalledOriginalBz, jsonMarshalledUpdatedBz) // raw build also make same result diff --git a/x/wasm/keeper/recurse_test.go b/x/wasm/keeper/recurse_test.go index cab895b148..4d10d12e64 100644 --- a/x/wasm/keeper/recurse_test.go +++ b/x/wasm/keeper/recurse_test.go @@ -4,15 +4,14 @@ import ( "encoding/json" "testing" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/CosmWasm/wasmd/x/wasm/types" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/CosmWasm/wasmd/x/wasm/types" ) type Recurse struct { @@ -25,6 +24,7 @@ type recurseWrapper struct { } func buildRecurseQuery(t *testing.T, msg Recurse) []byte { + t.Helper() wrapper := recurseWrapper{Recurse: msg} bz, err := json.Marshal(wrapper) require.NoError(t, err) @@ -39,6 +39,7 @@ type recurseResponse struct { var totalWasmQueryCounter int func initRecurseContract(t *testing.T) (contract sdk.AccAddress, ctx sdk.Context, keeper *Keeper) { + t.Helper() countingQuerierDec := func(realWasmQuerier WasmVMQueryHandler) WasmVMQueryHandler { return WasmVMQueryHandlerFn(func(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error) { totalWasmQueryCounter++ @@ -54,11 +55,11 @@ func initRecurseContract(t *testing.T) (contract sdk.AccAddress, ctx sdk.Context func TestGasCostOnQuery(t *testing.T) { const ( GasNoWork uint64 = 63_950 - // Note: about 100 SDK gas (10k wasmer gas) for each round of sha256 + // Note: about 100 SDK gas (10k CosmWasm gas) for each round of sha256 GasWork50 uint64 = 64_218 // this is a little shy of 50k gas - to keep an eye on the limit - GasReturnUnhashed uint64 = 29 - GasReturnHashed uint64 = 24 + GasReturnUnhashed uint64 = 32 + GasReturnHashed uint64 = 26 ) cases := map[string]struct { @@ -139,7 +140,7 @@ func TestGasCostOnQuery(t *testing.T) { func TestGasOnExternalQuery(t *testing.T) { const ( - GasWork50 uint64 = DefaultInstanceCost + 8_464 + GasWork50 uint64 = types.DefaultInstanceCost + 8_464 ) cases := map[string]struct { @@ -207,10 +208,10 @@ func TestLimitRecursiveQueryGas(t *testing.T) { // eventually hitting an OutOfGas panic. const ( - // Note: about 100 SDK gas (10k wasmer gas) for each round of sha256 + // Note: about 100 SDK gas (10k CosmWasm gas) for each round of sha256 GasWork2k uint64 = 77_161 // = NewContractInstanceCosts + x // we have 6x gas used in cpu than in the instance // This is overhead for calling into a sub-contract - GasReturnHashed uint64 = 25 + GasReturnHashed uint64 = 27 ) cases := map[string]struct { @@ -261,7 +262,7 @@ func TestLimitRecursiveQueryGas(t *testing.T) { expectQueriesFromContract: 10, expectOutOfGas: false, expectError: "query wasm contract failed", // Error we get from the contract instance doing the failing query, not wasmd - expectedGas: 10*(GasWork2k+GasReturnHashed) - 229, + expectedGas: 10*(GasWork2k+GasReturnHashed) - 249, }, } diff --git a/x/wasm/keeper/reflect_test.go b/x/wasm/keeper/reflect_test.go index a641ffe156..e5cf79ff65 100644 --- a/x/wasm/keeper/reflect_test.go +++ b/x/wasm/keeper/reflect_test.go @@ -2,13 +2,15 @@ package keeper import ( "encoding/json" - "fmt" "os" - "strings" "testing" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,34 +18,24 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/gogoproto/proto" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" "github.com/CosmWasm/wasmd/x/wasm/types" ) -// ReflectInitMsg is {} - -func buildReflectQuery(t *testing.T, query *testdata.ReflectQueryMsg) []byte { - bz, err := json.Marshal(query) - require.NoError(t, err) - return bz -} +const ( + CyberpunkFeatures = "staking,mask,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4" + ReflectFeatures = CyberpunkFeatures +) -func mustParse(t *testing.T, data []byte, res interface{}) { +func mustUnmarshal(t *testing.T, data []byte, res interface{}) { + t.Helper() err := json.Unmarshal(data, res) require.NoError(t, err) } -const ( - ReflectFeatures = "staking,mask,stargate,cosmwasm_1_1" - CyberpunkFeatures = "staking,mask,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3" -) - func TestReflectContractSend(t *testing.T) { - cdc := MakeEncodingConfig(t).Marshaler + cdc := MakeEncodingConfig(t).Codec ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc))) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.ContractKeeper, keepers.BankKeeper @@ -122,7 +114,7 @@ func TestReflectContractSend(t *testing.T) { } func TestReflectCustomMsg(t *testing.T) { - cdc := MakeEncodingConfig(t).Marshaler + cdc := MakeEncodingConfig(t).Codec ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.ContractKeeper, keepers.BankKeeper @@ -212,343 +204,6 @@ func TestReflectCustomMsg(t *testing.T) { checkAccount(t, ctx, accKeeper, bankKeeper, bob, deposit) } -func TestMaskReflectCustomQuery(t *testing.T) { - cdc := MakeEncodingConfig(t).Marshaler - ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) - keeper := keepers.WasmKeeper - - deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) - creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...) - - // upload code - codeID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) - require.NoError(t, err) - require.Equal(t, uint64(1), codeID) - - // creator instantiates a contract and gives it tokens - contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "reflect contract 1", contractStart) - require.NoError(t, err) - require.NotEmpty(t, contractAddr) - - // let's perform a normal query of state - ownerQuery := testdata.ReflectQueryMsg{ - Owner: &struct{}{}, - } - ownerQueryBz, err := json.Marshal(ownerQuery) - require.NoError(t, err) - ownerRes, err := keeper.QuerySmart(ctx, contractAddr, ownerQueryBz) - require.NoError(t, err) - var res testdata.OwnerResponse - err = json.Unmarshal(ownerRes, &res) - require.NoError(t, err) - assert.Equal(t, res.Owner, creator.String()) - - // and now making use of the custom querier callbacks - customQuery := testdata.ReflectQueryMsg{ - Capitalized: &testdata.Text{ - Text: "all Caps noW", - }, - } - customQueryBz, err := json.Marshal(customQuery) - require.NoError(t, err) - custom, err := keeper.QuerySmart(ctx, contractAddr, customQueryBz) - require.NoError(t, err) - var resp capitalizedResponse - err = json.Unmarshal(custom, &resp) - require.NoError(t, err) - assert.Equal(t, resp.Text, "ALL CAPS NOW") -} - -func TestReflectStargateQuery(t *testing.T) { - cdc := MakeEncodingConfig(t).Marshaler - ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) - keeper := keepers.WasmKeeper - - funds := sdk.NewCoins(sdk.NewInt64Coin("denom", 320000)) - contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - expectedBalance := funds.Sub(contractStart...) - creator := keepers.Faucet.NewFundedRandomAccount(ctx, funds...) - - // upload code - codeID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) - require.NoError(t, err) - require.Equal(t, uint64(1), codeID) - - // creator instantiates a contract and gives it tokens - contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "reflect contract 1", contractStart) - require.NoError(t, err) - require.NotEmpty(t, contractAddr) - - // first, normal query for the bank balance (to make sure our query is proper) - bankQuery := wasmvmtypes.QueryRequest{ - Bank: &wasmvmtypes.BankQuery{ - AllBalances: &wasmvmtypes.AllBalancesQuery{ - Address: creator.String(), - }, - }, - } - simpleQueryBz, err := json.Marshal(testdata.ReflectQueryMsg{ - Chain: &testdata.ChainQuery{Request: &bankQuery}, - }) - require.NoError(t, err) - simpleRes, err := keeper.QuerySmart(ctx, contractAddr, simpleQueryBz) - require.NoError(t, err) - var simpleChain testdata.ChainResponse - mustParse(t, simpleRes, &simpleChain) - var simpleBalance wasmvmtypes.AllBalancesResponse - mustParse(t, simpleChain.Data, &simpleBalance) - require.Equal(t, len(expectedBalance), len(simpleBalance.Amount)) - assert.Equal(t, simpleBalance.Amount[0].Amount, expectedBalance[0].Amount.String()) - assert.Equal(t, simpleBalance.Amount[0].Denom, expectedBalance[0].Denom) -} - -func TestReflectTotalSupplyQuery(t *testing.T) { - cdc := MakeEncodingConfig(t).Marshaler - ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) - keeper := keepers.WasmKeeper - // upload code - codeID := StoreReflectContract(t, ctx, keepers).CodeID - // creator instantiates a contract and gives it tokens - creator := RandomAccountAddress(t) - contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "testing", nil) - require.NoError(t, err) - - currentStakeSupply := keepers.BankKeeper.GetSupply(ctx, "stake") - require.NotEmpty(t, currentStakeSupply.Amount) // ensure we have real data - specs := map[string]struct { - denom string - expAmount wasmvmtypes.Coin - }{ - "known denom": { - denom: "stake", - expAmount: ConvertSdkCoinToWasmCoin(currentStakeSupply), - }, - "unknown denom": { - denom: "unknown", - expAmount: wasmvmtypes.Coin{Denom: "unknown", Amount: "0"}, - }, - } - for name, spec := range specs { - t.Run(name, func(t *testing.T) { - // when - queryBz := mustMarshal(t, testdata.ReflectQueryMsg{ - Chain: &testdata.ChainQuery{ - Request: &wasmvmtypes.QueryRequest{ - Bank: &wasmvmtypes.BankQuery{ - Supply: &wasmvmtypes.SupplyQuery{Denom: spec.denom}, - }, - }, - }, - }) - simpleRes, err := keeper.QuerySmart(ctx, contractAddr, queryBz) - - // then - require.NoError(t, err) - var rsp testdata.ChainResponse - mustParse(t, simpleRes, &rsp) - var supplyRsp wasmvmtypes.SupplyResponse - mustParse(t, rsp.Data, &supplyRsp) - assert.Equal(t, spec.expAmount, supplyRsp.Amount, spec.expAmount) - }) - } -} - -func TestReflectInvalidStargateQuery(t *testing.T) { - cdc := MakeEncodingConfig(t).Marshaler - ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) - keeper := keepers.WasmKeeper - - funds := sdk.NewCoins(sdk.NewInt64Coin("denom", 320000)) - contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - creator := keepers.Faucet.NewFundedRandomAccount(ctx, funds...) - - // upload code - codeID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) - require.NoError(t, err) - require.Equal(t, uint64(1), codeID) - - // creator instantiates a contract and gives it tokens - contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "reflect contract 1", contractStart) - require.NoError(t, err) - require.NotEmpty(t, contractAddr) - - // now, try to build a protobuf query - protoQuery := banktypes.QueryAllBalancesRequest{ - Address: creator.String(), - } - protoQueryBin, err := proto.Marshal(&protoQuery) - require.NoError(t, err) - - protoRequest := wasmvmtypes.QueryRequest{ - Stargate: &wasmvmtypes.StargateQuery{ - Path: "/cosmos.bank.v1beta1.Query/AllBalances", - Data: protoQueryBin, - }, - } - protoQueryBz, err := json.Marshal(testdata.ReflectQueryMsg{ - Chain: &testdata.ChainQuery{Request: &protoRequest}, - }) - require.NoError(t, err) - - // make a query on the chain, should not be whitelisted - _, err = keeper.QuerySmart(ctx, contractAddr, protoQueryBz) - require.Error(t, err) - require.Contains(t, err.Error(), "Unsupported query") - - // now, try to build a protobuf query - protoRequest = wasmvmtypes.QueryRequest{ - Stargate: &wasmvmtypes.StargateQuery{ - Path: "/cosmos.tx.v1beta1.Service/GetTx", - Data: []byte{}, - }, - } - protoQueryBz, err = json.Marshal(testdata.ReflectQueryMsg{ - Chain: &testdata.ChainQuery{Request: &protoRequest}, - }) - require.NoError(t, err) - - // make a query on the chain, should be blacklisted - _, err = keeper.QuerySmart(ctx, contractAddr, protoQueryBz) - require.Error(t, err) - require.Contains(t, err.Error(), "Unsupported query") - - // and another one - protoRequest = wasmvmtypes.QueryRequest{ - Stargate: &wasmvmtypes.StargateQuery{ - Path: "/cosmos.base.tendermint.v1beta1.Service/GetNodeInfo", - Data: []byte{}, - }, - } - protoQueryBz, err = json.Marshal(testdata.ReflectQueryMsg{ - Chain: &testdata.ChainQuery{Request: &protoRequest}, - }) - require.NoError(t, err) - - // make a query on the chain, should be blacklisted - _, err = keeper.QuerySmart(ctx, contractAddr, protoQueryBz) - require.Error(t, err) - require.Contains(t, err.Error(), "Unsupported query") -} - -type reflectState struct { - Owner string `json:"owner"` -} - -func TestMaskReflectWasmQueries(t *testing.T) { - cdc := MakeEncodingConfig(t).Marshaler - ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) - keeper := keepers.WasmKeeper - - deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) - creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...) - - // upload reflect code - reflectID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) - require.NoError(t, err) - require.Equal(t, uint64(1), reflectID) - - // creator instantiates a contract and gives it tokens - reflectStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - reflectAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, reflectID, creator, nil, []byte("{}"), "reflect contract 2", reflectStart) - require.NoError(t, err) - require.NotEmpty(t, reflectAddr) - - // for control, let's make some queries directly on the reflect - ownerQuery := buildReflectQuery(t, &testdata.ReflectQueryMsg{Owner: &struct{}{}}) - res, err := keeper.QuerySmart(ctx, reflectAddr, ownerQuery) - require.NoError(t, err) - var ownerRes testdata.OwnerResponse - mustParse(t, res, &ownerRes) - require.Equal(t, ownerRes.Owner, creator.String()) - - // and a raw query: cosmwasm_storage::Singleton uses 2 byte big-endian length-prefixed to store data - configKey := append([]byte{0, 6}, []byte("config")...) - raw := keeper.QueryRaw(ctx, reflectAddr, configKey) - var stateRes reflectState - mustParse(t, raw, &stateRes) - require.Equal(t, stateRes.Owner, creator.String()) - - // now, let's reflect a smart query into the x/wasm handlers and see if we get the same result - reflectOwnerQuery := testdata.ReflectQueryMsg{Chain: &testdata.ChainQuery{Request: &wasmvmtypes.QueryRequest{Wasm: &wasmvmtypes.WasmQuery{ - Smart: &wasmvmtypes.SmartQuery{ - ContractAddr: reflectAddr.String(), - Msg: ownerQuery, - }, - }}}} - reflectOwnerBin := buildReflectQuery(t, &reflectOwnerQuery) - res, err = keeper.QuerySmart(ctx, reflectAddr, reflectOwnerBin) - require.NoError(t, err) - // first we pull out the data from chain response, before parsing the original response - var reflectRes testdata.ChainResponse - mustParse(t, res, &reflectRes) - var reflectOwnerRes testdata.OwnerResponse - mustParse(t, reflectRes.Data, &reflectOwnerRes) - require.Equal(t, reflectOwnerRes.Owner, creator.String()) - - // and with queryRaw - reflectStateQuery := testdata.ReflectQueryMsg{Chain: &testdata.ChainQuery{Request: &wasmvmtypes.QueryRequest{Wasm: &wasmvmtypes.WasmQuery{ - Raw: &wasmvmtypes.RawQuery{ - ContractAddr: reflectAddr.String(), - Key: configKey, - }, - }}}} - reflectStateBin := buildReflectQuery(t, &reflectStateQuery) - res, err = keeper.QuerySmart(ctx, reflectAddr, reflectStateBin) - require.NoError(t, err) - // first we pull out the data from chain response, before parsing the original response - var reflectRawRes testdata.ChainResponse - mustParse(t, res, &reflectRawRes) - // now, with the raw data, we can parse it into state - var reflectStateRes reflectState - mustParse(t, reflectRawRes.Data, &reflectStateRes) - require.Equal(t, reflectStateRes.Owner, creator.String()) -} - -func TestWasmRawQueryWithNil(t *testing.T) { - cdc := MakeEncodingConfig(t).Marshaler - ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins())) - keeper := keepers.WasmKeeper - - deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) - creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...) - - // upload reflect code - reflectID, _, err := keepers.ContractKeeper.Create(ctx, creator, testdata.ReflectContractWasm(), nil) - require.NoError(t, err) - require.Equal(t, uint64(1), reflectID) - - // creator instantiates a contract and gives it tokens - reflectStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - reflectAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, reflectID, creator, nil, []byte("{}"), "reflect contract 2", reflectStart) - require.NoError(t, err) - require.NotEmpty(t, reflectAddr) - - // control: query directly - missingKey := []byte{0, 1, 2, 3, 4} - raw := keeper.QueryRaw(ctx, reflectAddr, missingKey) - require.Nil(t, raw) - - // and with queryRaw - reflectQuery := testdata.ReflectQueryMsg{Chain: &testdata.ChainQuery{Request: &wasmvmtypes.QueryRequest{Wasm: &wasmvmtypes.WasmQuery{ - Raw: &wasmvmtypes.RawQuery{ - ContractAddr: reflectAddr.String(), - Key: missingKey, - }, - }}}} - reflectStateBin := buildReflectQuery(t, &reflectQuery) - res, err := keeper.QuerySmart(ctx, reflectAddr, reflectStateBin) - require.NoError(t, err) - - // first we pull out the data from chain response, before parsing the original response - var reflectRawRes testdata.ChainResponse - mustParse(t, res, &reflectRawRes) - // and make sure there is no data - require.Empty(t, reflectRawRes.Data) - // we get an empty byte slice not nil (if anyone care in go-land) - require.Equal(t, []byte{}, reflectRawRes.Data) -} - func TestRustPanicIsHandled(t *testing.T) { ctx, keepers := CreateTestInput(t, false, CyberpunkFeatures) keeper := keepers.ContractKeeper @@ -572,120 +227,8 @@ func TestRustPanicIsHandled(t *testing.T) { assert.Nil(t, gotData) } -func TestQueryDenomsIntegration(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, CyberpunkFeatures) - ck, k := keepers.ContractKeeper, keepers.WasmKeeper - creator := keepers.Faucet.NewFundedRandomAccount(ctx, sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))...) - - // upload code - codeID, _, err := ck.Create(ctx, creator, testdata.CyberpunkContractWasm(), nil) - require.NoError(t, err) - - contractAddr, _, err := ck.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "cyberpunk contract", nil) - require.NoError(t, err) - - var ( - metadata1 = banktypes.Metadata{ - Description: "testing", - DenomUnits: []*banktypes.DenomUnit{ - {Denom: "ualx", Exponent: 0, Aliases: []string{"microalx"}}, - {Denom: "alx", Exponent: 6, Aliases: []string{"ALX"}}, - }, - Base: "ualx", - Display: "alx", - Name: "my test denom", - Symbol: "XALX", - URI: "https://example.com/ualx", - URIHash: "my_hash", - } - metadata2 = banktypes.Metadata{ - Description: "testing2", - DenomUnits: []*banktypes.DenomUnit{ - {Denom: "ublx", Exponent: 0, Aliases: []string{"microblx"}}, - {Denom: "blx", Exponent: 6, Aliases: []string{"BLX"}}, - }, - Base: "ublx", - Display: "blx", - Name: "my other test denom", - Symbol: "XBLX", - } - ) - type dict map[string]any - - keepers.BankKeeper.SetDenomMetaData(ctx, metadata1) - keepers.BankKeeper.SetDenomMetaData(ctx, metadata2) - - specs := map[string]struct { - query string - exp []byte - expErr *errorsmod.Error - }{ - "all denoms": { - query: `{"denoms":{}}`, - exp: mustMarshal(t, []dict{ - { - "description": "testing", - "denom_units": []dict{ - {"denom": "ualx", "exponent": 0, "aliases": []string{"microalx"}}, - {"denom": "alx", "exponent": 6, "aliases": []string{"ALX"}}, - }, - "base": "ualx", - "display": "alx", - "name": "my test denom", - "symbol": "XALX", - "uri": "https://example.com/ualx", - "uri_hash": "my_hash", - }, { - "description": "testing2", - "denom_units": []dict{ - {"denom": "ublx", "exponent": 0, "aliases": []string{"microblx"}}, - {"denom": "blx", "exponent": 6, "aliases": []string{"BLX"}}, - }, - "base": "ublx", - "display": "blx", - "name": "my other test denom", - "symbol": "XBLX", - "uri": "", - "uri_hash": "", - }, - }), - }, - "single denom": { - query: `{"denom":{"denom":"ublx"}}`, - exp: mustMarshal(t, dict{ - "description": "testing2", - "denom_units": []dict{ - {"denom": "ublx", "exponent": 0, "aliases": []string{"microblx"}}, - {"denom": "blx", "exponent": 6, "aliases": []string{"BLX"}}, - }, - "base": "ublx", - "display": "blx", - "name": "my other test denom", - "symbol": "XBLX", - "uri": "", - "uri_hash": "", - }), - }, - "unknown denom": { - query: `{"denom":{"denom":"unknown"}}`, - expErr: sdkerrors.ErrNotFound, - }, - } - for name, spec := range specs { - t.Run(name, func(t *testing.T) { - gotData, gotErr := k.QuerySmart(ctx, contractAddr, []byte(spec.query)) - if spec.expErr != nil { - require.Error(t, gotErr) - assert.Contains(t, gotErr.Error(), fmt.Sprintf("codespace: %s, code: %d:", spec.expErr.Codespace(), spec.expErr.ABCICode())) - return - } - require.NoError(t, gotErr) - assert.JSONEq(t, string(spec.exp), string(gotData), string(gotData)) - }) - } -} - func checkAccount(t *testing.T, ctx sdk.Context, accKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, expected sdk.Coins) { + t.Helper() acct := accKeeper.GetAccount(ctx, addr) if expected == nil { assert.Nil(t, acct) @@ -760,41 +303,3 @@ func fromReflectRawMsg(cdc codec.Codec) CustomEncoder { return nil, errorsmod.Wrap(types.ErrInvalidMsg, "Unknown Custom message variant") } } - -type reflectCustomQuery struct { - Ping *struct{} `json:"ping,omitempty"` - Capitalized *testdata.Text `json:"capitalized,omitempty"` -} - -// this is from the go code back to the contract (capitalized or ping) -type customQueryResponse struct { - Msg string `json:"msg"` -} - -// this is from the contract to the go code (capitalized or ping) -type capitalizedResponse struct { - Text string `json:"text"` -} - -// reflectPlugins needs to be registered in test setup to handle custom query callbacks -func reflectPlugins() *QueryPlugins { - return &QueryPlugins{ - Custom: performCustomQuery, - } -} - -func performCustomQuery(_ sdk.Context, request json.RawMessage) ([]byte, error) { - var custom reflectCustomQuery - err := json.Unmarshal(request, &custom) - if err != nil { - return nil, errorsmod.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - if custom.Capitalized != nil { - msg := strings.ToUpper(custom.Capitalized.Text) - return json.Marshal(customQueryResponse{Msg: msg}) - } - if custom.Ping != nil { - return json.Marshal(customQueryResponse{Msg: "pong"}) - } - return nil, errorsmod.Wrap(types.ErrInvalidMsg, "Unknown Custom query variant") -} diff --git a/x/wasm/keeper/relay.go b/x/wasm/keeper/relay.go index 4aaeee9571..209218b86c 100644 --- a/x/wasm/keeper/relay.go +++ b/x/wasm/keeper/relay.go @@ -3,11 +3,12 @@ package keeper import ( "time" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" errorsmod "cosmossdk.io/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/wasm/keeper/relay_test.go b/x/wasm/keeper/relay_test.go index ade43a1e01..b1ee4f3438 100644 --- a/x/wasm/keeper/relay_test.go +++ b/x/wasm/keeper/relay_test.go @@ -8,16 +8,17 @@ import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestOnOpenChannel(t *testing.T) { - var m wasmtesting.MockWasmer + var m wasmtesting.MockWasmEngine wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) @@ -38,8 +39,8 @@ func TestOnOpenChannel(t *testing.T) { }, "consume max gas": { contractAddr: example.Contract, - contractGas: math.MaxUint64 / DefaultGasMultiplier, - expGas: math.MaxUint64 / DefaultGasMultiplier, + contractGas: math.MaxUint64 / types.DefaultGasMultiplier, + expGas: math.MaxUint64 / types.DefaultGasMultiplier, }, "consume gas on error": { contractAddr: example.Contract, @@ -58,7 +59,7 @@ func TestOnOpenChannel(t *testing.T) { myMsg := wasmvmtypes.IBCChannelOpenMsg{OpenTry: &wasmvmtypes.IBCOpenTry{Channel: myChannel, CounterpartyVersion: "foo"}} m.IBCChannelOpenFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) { assert.Equal(t, myMsg, msg) - return &wasmvmtypes.IBC3ChannelOpenResponse{}, spec.contractGas * DefaultGasMultiplier, spec.contractErr + return &wasmvmtypes.IBC3ChannelOpenResponse{}, spec.contractGas * types.DefaultGasMultiplier, spec.contractErr } ctx, _ := parentCtx.CacheContext() @@ -87,7 +88,7 @@ func TestOnOpenChannel(t *testing.T) { } func TestOnConnectChannel(t *testing.T) { - var m wasmtesting.MockWasmer + var m wasmtesting.MockWasmEngine wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) @@ -155,7 +156,7 @@ func TestOnConnectChannel(t *testing.T) { myMsg := wasmvmtypes.IBCChannelConnectMsg{OpenConfirm: &wasmvmtypes.IBCOpenConfirm{Channel: myChannel}} m.IBCChannelConnectFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelConnectMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { assert.Equal(t, msg, myMsg) - return spec.contractResp, myContractGas * DefaultGasMultiplier, spec.contractErr + return spec.contractResp, myContractGas * types.DefaultGasMultiplier, spec.contractErr } ctx, _ := parentCtx.CacheContext() @@ -199,7 +200,7 @@ func TestOnConnectChannel(t *testing.T) { } func TestOnCloseChannel(t *testing.T) { - var m wasmtesting.MockWasmer + var m wasmtesting.MockWasmEngine wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) @@ -267,7 +268,7 @@ func TestOnCloseChannel(t *testing.T) { myMsg := wasmvmtypes.IBCChannelCloseMsg{CloseInit: &wasmvmtypes.IBCCloseInit{Channel: myChannel}} m.IBCChannelCloseFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelCloseMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { assert.Equal(t, msg, myMsg) - return spec.contractResp, myContractGas * DefaultGasMultiplier, spec.contractErr + return spec.contractResp, myContractGas * types.DefaultGasMultiplier, spec.contractErr } ctx, _ := parentCtx.CacheContext() @@ -309,7 +310,7 @@ func TestOnCloseChannel(t *testing.T) { } func TestOnRecvPacket(t *testing.T) { - var m wasmtesting.MockWasmer + var m wasmtesting.MockWasmEngine wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) @@ -440,7 +441,7 @@ func TestOnRecvPacket(t *testing.T) { m.IBCPacketReceiveFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketReceiveMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCReceiveResult, uint64, error) { assert.Equal(t, myPacket, msg.Packet) - return spec.contractResp, myContractGas * DefaultGasMultiplier, spec.contractErr + return spec.contractResp, myContractGas * types.DefaultGasMultiplier, spec.contractErr } if spec.mockReplyFn != nil { m.ReplyFn = spec.mockReplyFn @@ -499,7 +500,7 @@ func TestOnRecvPacket(t *testing.T) { } func TestOnAckPacket(t *testing.T) { - var m wasmtesting.MockWasmer + var m wasmtesting.MockWasmEngine wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) @@ -566,7 +567,7 @@ func TestOnAckPacket(t *testing.T) { myAck := wasmvmtypes.IBCPacketAckMsg{Acknowledgement: wasmvmtypes.IBCAcknowledgement{Data: []byte("myAck")}} m.IBCPacketAckFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketAckMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { assert.Equal(t, myAck, msg) - return spec.contractResp, myContractGas * DefaultGasMultiplier, spec.contractErr + return spec.contractResp, myContractGas * types.DefaultGasMultiplier, spec.contractErr } ctx, _ := parentCtx.CacheContext() @@ -604,7 +605,7 @@ func TestOnAckPacket(t *testing.T) { } func TestOnTimeoutPacket(t *testing.T) { - var m wasmtesting.MockWasmer + var m wasmtesting.MockWasmEngine wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) @@ -686,7 +687,7 @@ func TestOnTimeoutPacket(t *testing.T) { myPacket := wasmvmtypes.IBCPacket{Data: []byte("my test packet")} m.IBCPacketTimeoutFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketTimeoutMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { assert.Equal(t, myPacket, msg.Packet) - return spec.contractResp, myContractGas * DefaultGasMultiplier, spec.contractErr + return spec.contractResp, myContractGas * types.DefaultGasMultiplier, spec.contractErr } ctx, _ := parentCtx.CacheContext() diff --git a/x/wasm/keeper/snapshotter.go b/x/wasm/keeper/snapshotter.go index ca4423917d..d527d44b2c 100644 --- a/x/wasm/keeper/snapshotter.go +++ b/x/wasm/keeper/snapshotter.go @@ -5,9 +5,11 @@ import ( "io" "math" - errorsmod "cosmossdk.io/errors" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + + errorsmod "cosmossdk.io/errors" + snapshot "github.com/cosmos/cosmos-sdk/snapshots/types" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/wasm/keeper/snapshotter_integration_test.go b/x/wasm/keeper/snapshotter_integration_test.go index dacbef0987..d93d782282 100644 --- a/x/wasm/keeper/snapshotter_integration_test.go +++ b/x/wasm/keeper/snapshotter_integration_test.go @@ -5,23 +5,22 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/x/wasm/types" - - "github.com/stretchr/testify/assert" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmtypes "github.com/cometbft/cometbft/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestSnapshotter(t *testing.T) { @@ -112,6 +111,7 @@ func TestSnapshotter(t *testing.T) { } func newWasmExampleApp(t *testing.T) (*app.WasmApp, sdk.AccAddress) { + t.Helper() senderPrivKey := ed25519.GenPrivKey() pubKey, err := cryptocodec.ToTmPubKeyInterface(senderPrivKey.PubKey()) require.NoError(t, err) diff --git a/x/wasm/keeper/staking_test.go b/x/wasm/keeper/staking_test.go index 224cc90cd6..f7a1809c4f 100644 --- a/x/wasm/keeper/staking_test.go +++ b/x/wasm/keeper/staking_test.go @@ -6,6 +6,9 @@ import ( "testing" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,8 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -166,6 +167,7 @@ type initInfo struct { } func initializeStaking(t *testing.T) initInfo { + t.Helper() ctx, k := CreateTestInput(t, false, AvailableCapabilities) accKeeper, stakingKeeper, keeper, bankKeeper := k.AccountKeeper, k.StakingKeeper, k.WasmKeeper, k.BankKeeper @@ -458,9 +460,9 @@ func TestQueryStakingInfo(t *testing.T) { require.NoError(t, err) // first we pull out the data from chain response, before parsing the original response var reflectRes testdata.ChainResponse - mustParse(t, res, &reflectRes) + mustUnmarshal(t, res, &reflectRes) var bondedRes wasmvmtypes.BondedDenomResponse - mustParse(t, reflectRes.Data, &bondedRes) + mustUnmarshal(t, reflectRes.Data, &bondedRes) assert.Equal(t, "stake", bondedRes.Denom) // now, let's reflect a smart query into the x/wasm handlers and see if we get the same result @@ -471,9 +473,9 @@ func TestQueryStakingInfo(t *testing.T) { res, err = keeper.QuerySmart(ctx, maskAddr, reflectAllValidatorsBin) require.NoError(t, err) // first we pull out the data from chain response, before parsing the original response - mustParse(t, res, &reflectRes) + mustUnmarshal(t, res, &reflectRes) var allValidatorsRes wasmvmtypes.AllValidatorsResponse - mustParse(t, reflectRes.Data, &allValidatorsRes) + mustUnmarshal(t, reflectRes.Data, &allValidatorsRes) require.Len(t, allValidatorsRes.Validators, 1, string(res)) valInfo := allValidatorsRes.Validators[0] // Note: this ValAddress not AccAddress, may change with #264 @@ -492,9 +494,9 @@ func TestQueryStakingInfo(t *testing.T) { res, err = keeper.QuerySmart(ctx, maskAddr, reflectValidatorBin) require.NoError(t, err) // first we pull out the data from chain response, before parsing the original response - mustParse(t, res, &reflectRes) + mustUnmarshal(t, res, &reflectRes) var validatorRes wasmvmtypes.ValidatorResponse - mustParse(t, reflectRes.Data, &validatorRes) + mustUnmarshal(t, reflectRes.Data, &validatorRes) require.NotNil(t, validatorRes.Validator) valInfo = *validatorRes.Validator // Note: this ValAddress not AccAddress, may change with #264 @@ -514,9 +516,9 @@ func TestQueryStakingInfo(t *testing.T) { res, err = keeper.QuerySmart(ctx, maskAddr, reflectNoValidatorBin) require.NoError(t, err) // first we pull out the data from chain response, before parsing the original response - mustParse(t, res, &reflectRes) + mustUnmarshal(t, res, &reflectRes) var noValidatorRes wasmvmtypes.ValidatorResponse - mustParse(t, reflectRes.Data, &noValidatorRes) + mustUnmarshal(t, reflectRes.Data, &noValidatorRes) require.Nil(t, noValidatorRes.Validator) // test to get all my delegations @@ -529,9 +531,9 @@ func TestQueryStakingInfo(t *testing.T) { res, err = keeper.QuerySmart(ctx, maskAddr, reflectAllDelegationsBin) require.NoError(t, err) // first we pull out the data from chain response, before parsing the original response - mustParse(t, res, &reflectRes) + mustUnmarshal(t, res, &reflectRes) var allDelegationsRes wasmvmtypes.AllDelegationsResponse - mustParse(t, reflectRes.Data, &allDelegationsRes) + mustUnmarshal(t, reflectRes.Data, &allDelegationsRes) require.Len(t, allDelegationsRes.Delegations, 1) delInfo := allDelegationsRes.Delegations[0] // Note: this ValAddress not AccAddress, may change with #264 @@ -553,10 +555,10 @@ func TestQueryStakingInfo(t *testing.T) { res, err = keeper.QuerySmart(ctx, maskAddr, reflectDelegationBin) require.NoError(t, err) // first we pull out the data from chain response, before parsing the original response - mustParse(t, res, &reflectRes) + mustUnmarshal(t, res, &reflectRes) var delegationRes wasmvmtypes.DelegationResponse - mustParse(t, reflectRes.Data, &delegationRes) + mustUnmarshal(t, reflectRes.Data, &delegationRes) assert.NotEmpty(t, delegationRes.Delegation) delInfo2 := delegationRes.Delegation // Note: this ValAddress not AccAddress, may change with #264 @@ -622,7 +624,7 @@ func TestQueryStakingPlugin(t *testing.T) { raw, err := StakingQuerier(stakingKeeper, distributionkeeper.NewQuerier(distKeeper))(ctx, &query) require.NoError(t, err) var res wasmvmtypes.DelegationResponse - mustParse(t, raw, &res) + mustUnmarshal(t, raw, &res) assert.NotEmpty(t, res.Delegation) delInfo := res.Delegation // Note: this ValAddress not AccAddress, may change with #264 @@ -645,6 +647,7 @@ func TestQueryStakingPlugin(t *testing.T) { // adds a few validators and returns a list of validators that are registered func addValidator(t *testing.T, ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper, faucet *TestFaucet, value sdk.Coin) sdk.ValAddress { + t.Helper() owner := faucet.NewFundedRandomAccount(ctx, value) privKey := secp256k1.GenPrivKey() @@ -693,7 +696,8 @@ func setValidatorRewards(ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper, d distKeeper.AllocateTokensToValidator(ctx, vali, payout) } -func assertBalance(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.AccAddress, addr sdk.AccAddress, expected string) { +func assertBalance(t *testing.T, ctx sdk.Context, keeper Keeper, contract, addr sdk.AccAddress, expected string) { + t.Helper() query := StakingQueryMsg{ Balance: &addressQuery{ Address: addr, @@ -709,7 +713,8 @@ func assertBalance(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.Ac assert.Equal(t, expected, balance.Balance) } -func assertClaims(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.AccAddress, addr sdk.AccAddress, expected string) { +func assertClaims(t *testing.T, ctx sdk.Context, keeper Keeper, contract, addr sdk.AccAddress, expected string) { + t.Helper() query := StakingQueryMsg{ Claims: &addressQuery{ Address: addr, @@ -726,6 +731,7 @@ func assertClaims(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.Acc } func assertSupply(t *testing.T, ctx sdk.Context, keeper Keeper, contract sdk.AccAddress, expectedIssued string, expectedBonded sdk.Coin) { + t.Helper() query := StakingQueryMsg{Investment: &struct{}{}} queryBz, err := json.Marshal(query) require.NoError(t, err) diff --git a/x/wasm/keeper/submsg_test.go b/x/wasm/keeper/submsg_test.go index f7a075f3c1..fe301dc37b 100644 --- a/x/wasm/keeper/submsg_test.go +++ b/x/wasm/keeper/submsg_test.go @@ -7,19 +7,18 @@ import ( "strconv" "testing" - errorsmod "cosmossdk.io/errors" - wasmvm "github.com/CosmWasm/wasmvm" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -194,12 +193,14 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { assertReturnedEvents := func(expectedEvents int) assertion { return func(t *testing.T, ctx sdk.Context, contract, emptyAccount string, response wasmvmtypes.SubMsgResult) { + t.Helper() require.Len(t, response.Ok.Events, expectedEvents) } } assertGasUsed := func(minGas, maxGas uint64) assertion { return func(t *testing.T, ctx sdk.Context, contract, emptyAccount string, response wasmvmtypes.SubMsgResult) { + t.Helper() gasUsed := ctx.GasMeter().GasConsumed() assert.True(t, gasUsed >= minGas, "Used %d gas (less than expected %d)", gasUsed, minGas) assert.True(t, gasUsed <= maxGas, "Used %d gas (more than expected %d)", gasUsed, maxGas) @@ -208,11 +209,13 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { assertErrorString := func(shouldContain string) assertion { return func(t *testing.T, ctx sdk.Context, contract, emptyAccount string, response wasmvmtypes.SubMsgResult) { + t.Helper() assert.Contains(t, response.Err, shouldContain) } } assertGotContractAddr := func(t *testing.T, ctx sdk.Context, contract, emptyAccount string, response wasmvmtypes.SubMsgResult) { + t.Helper() // should get the events emitted on new contract event := response.Ok.Events[0] require.Equal(t, event.Type, "instantiate") @@ -221,7 +224,7 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { assert.NotEqual(t, contract, eventAddr) var res types.MsgInstantiateContractResponse - keepers.EncodingConfig.Marshaler.MustUnmarshal(response.Ok.Data, &res) + keepers.EncodingConfig.Codec.MustUnmarshal(response.Ok.Data, &res) assert.Equal(t, eventAddr, res.Address) } @@ -559,7 +562,7 @@ func TestDispatchSubMsgConditionalReplyOn(t *testing.T) { } func TestInstantiateGovSubMsgAuthzPropagated(t *testing.T) { - mockWasmVM := &wasmtesting.MockWasmer{} + mockWasmVM := &wasmtesting.MockWasmEngine{} wasmtesting.MakeInstantiable(mockWasmVM) var instanceLevel int // mock wasvm to return new instantiate msgs with the response @@ -640,7 +643,7 @@ func TestInstantiateGovSubMsgAuthzPropagated(t *testing.T) { } func TestMigrateGovSubMsgAuthzPropagated(t *testing.T) { - mockWasmVM := &wasmtesting.MockWasmer{} + mockWasmVM := &wasmtesting.MockWasmEngine{} wasmtesting.MakeInstantiable(mockWasmVM) ctx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithWasmEngine(mockWasmVM)) k := keepers.WasmKeeper diff --git a/x/wasm/keeper/test_common.go b/x/wasm/keeper/test_common.go index 7f2d8cd0e2..1c8a415ffc 100644 --- a/x/wasm/keeper/test_common.go +++ b/x/wasm/keeper/test_common.go @@ -9,19 +9,23 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" - - icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" - icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - - errorsmod "cosmossdk.io/errors" - dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/crypto" "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/libs/log" "github.com/cometbft/cometbft/libs/rand" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + "github.com/cosmos/ibc-go/v7/modules/apps/transfer" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v7/modules/core" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/std" @@ -55,14 +59,12 @@ import ( govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/mint" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/params" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/cosmos/cosmos-sdk/x/slashing" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" @@ -72,14 +74,9 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/cosmos/ibc-go/v7/modules/apps/transfer" - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v7/modules/core" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" - ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - "github.com/stretchr/testify/require" wasmappparams "github.com/CosmWasm/wasmd/app/params" + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -106,8 +103,10 @@ var moduleBasics = module.NewBasicManager( vesting.AppModuleBasic{}, ) -func MakeTestCodec(t testing.TB) codec.Codec { - return MakeEncodingConfig(t).Marshaler +func MakeTestCodec(tb testing.TB) codec.Codec { + tb.Helper() + + return MakeEncodingConfig(tb).Codec } func MakeEncodingConfig(_ testing.TB) wasmappparams.EncodingConfig { @@ -144,9 +143,11 @@ type TestFaucet struct { minterModuleName string } -func NewTestFaucet(t testing.TB, ctx sdk.Context, bankKeeper bankkeeper.Keeper, minterModuleName string, initialAmount ...sdk.Coin) *TestFaucet { - require.NotEmpty(t, initialAmount) - r := &TestFaucet{t: t, bankKeeper: bankKeeper, minterModuleName: minterModuleName} +func NewTestFaucet(tb testing.TB, ctx sdk.Context, bankKeeper bankkeeper.Keeper, minterModuleName string, initialAmount ...sdk.Coin) *TestFaucet { + tb.Helper() + + require.NotEmpty(tb, initialAmount) + r := &TestFaucet{t: tb, bankKeeper: bankKeeper, minterModuleName: minterModuleName} _, addr := keyPubAddr() r.sender = addr r.Mint(ctx, addr, initialAmount...) @@ -200,26 +201,32 @@ type TestKeepers struct { } // CreateDefaultTestInput common settings for CreateTestInput -func CreateDefaultTestInput(t testing.TB) (sdk.Context, TestKeepers) { - return CreateTestInput(t, false, "staking") +func CreateDefaultTestInput(tb testing.TB) (sdk.Context, TestKeepers) { + tb.Helper() + + return CreateTestInput(tb, false, "staking") } // CreateTestInput encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default) -func CreateTestInput(t testing.TB, isCheckTx bool, availableCapabilities string, opts ...Option) (sdk.Context, TestKeepers) { +func CreateTestInput(tb testing.TB, isCheckTx bool, availableCapabilities string, opts ...Option) (sdk.Context, TestKeepers) { + tb.Helper() + // Load default wasm config - return createTestInput(t, isCheckTx, availableCapabilities, types.DefaultWasmConfig(), dbm.NewMemDB(), opts...) + return createTestInput(tb, isCheckTx, availableCapabilities, types.DefaultWasmConfig(), dbm.NewMemDB(), opts...) } // encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default) func createTestInput( - t testing.TB, + tb testing.TB, isCheckTx bool, availableCapabilities string, wasmConfig types.WasmConfig, db dbm.DB, opts ...Option, ) (sdk.Context, TestKeepers) { - tempDir := t.TempDir() + tb.Helper() + + tempDir := tb.TempDir() keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, @@ -243,7 +250,7 @@ func createTestInput( ms.MountStoreWithDB(v, storetypes.StoreTypeMemory, db) } - require.NoError(t, ms.LoadLatestVersion()) + require.NoError(tb, ms.LoadLatestVersion()) ctx := sdk.NewContext(ms, tmproto.Header{ Height: 1234567, @@ -251,8 +258,8 @@ func createTestInput( }, isCheckTx, log.NewNopLogger()) ctx = types.WithTXCounter(ctx, 0) - encodingConfig := MakeEncodingConfig(t) - appCodec, legacyAmino := encodingConfig.Marshaler, encodingConfig.Amino + encodingConfig := MakeEncodingConfig(tb) + appCodec, legacyAmino := encodingConfig.Codec, encodingConfig.Amino paramsKeeper := paramskeeper.NewKeeper( appCodec, @@ -278,7 +285,7 @@ func createTestInput( } subspace := func(m string) paramstypes.Subspace { r, ok := paramsKeeper.GetSubspace(m) - require.True(t, ok) + require.True(tb, ok) var keyTable paramstypes.KeyTable switch r.Name() { @@ -340,7 +347,7 @@ func createTestInput( blockedAddrs[authtypes.NewModuleAddress(acc).String()] = true } - require.NoError(t, accountKeeper.SetParams(ctx, authtypes.DefaultParams())) + require.NoError(tb, accountKeeper.SetParams(ctx, authtypes.DefaultParams())) bankKeeper := bankkeeper.NewBaseKeeper( appCodec, @@ -349,7 +356,7 @@ func createTestInput( blockedAddrs, authtypes.NewModuleAddress(banktypes.ModuleName).String(), ) - require.NoError(t, bankKeeper.SetParams(ctx, banktypes.DefaultParams())) + require.NoError(tb, bankKeeper.SetParams(ctx, banktypes.DefaultParams())) stakingKeeper := stakingkeeper.NewKeeper( appCodec, @@ -359,7 +366,7 @@ func createTestInput( authtypes.NewModuleAddress(stakingtypes.ModuleName).String(), ) stakingtypes.DefaultParams() - require.NoError(t, stakingKeeper.SetParams(ctx, TestingStakeParams)) + require.NoError(tb, stakingKeeper.SetParams(ctx, TestingStakeParams)) distKeeper := distributionkeeper.NewKeeper( appCodec, @@ -370,7 +377,7 @@ func createTestInput( authtypes.FeeCollectorName, authtypes.NewModuleAddress(distributiontypes.ModuleName).String(), ) - require.NoError(t, distKeeper.SetParams(ctx, distributiontypes.DefaultParams())) + require.NoError(tb, distKeeper.SetParams(ctx, distributiontypes.DefaultParams())) stakingKeeper.SetHooks(distKeeper.Hooks()) // set genesis items required for distribution @@ -385,7 +392,7 @@ func createTestInput( authtypes.NewModuleAddress(upgradetypes.ModuleName).String(), ) - faucet := NewTestFaucet(t, ctx, bankKeeper, minttypes.ModuleName, sdk.NewCoin("stake", sdk.NewInt(100_000_000_000))) + faucet := NewTestFaucet(tb, ctx, bankKeeper, minttypes.ModuleName, sdk.NewCoin("stake", sdk.NewInt(100_000_000_000))) // set some funds ot pay out validatores, based on code from: // https://github.com/cosmos/cosmos-sdk/blob/fea231556aee4d549d7551a6190389c4328194eb/x/distribution/keeper/keeper_test.go#L50-L57 @@ -438,16 +445,11 @@ func createTestInput( authtypes.NewModuleAddress(govtypes.ModuleName).String(), opts..., ) - require.NoError(t, keeper.SetParams(ctx, types.DefaultParams())) + require.NoError(tb, keeper.SetParams(ctx, types.DefaultParams())) // add wasm handler so we can loop-back (contracts calling contracts) contractKeeper := NewDefaultPermissionKeeper(&keeper) - govRouter := govv1beta1.NewRouter(). - AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). - AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(paramsKeeper)). - AddRoute(types.RouterKey, NewWasmProposalHandler(&keeper, types.EnableAllProposals)) - govKeeper := govkeeper.NewKeeper( appCodec, keys[govtypes.StoreKey], @@ -458,8 +460,7 @@ func createTestInput( govtypes.DefaultConfig(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - require.NoError(t, govKeeper.SetParams(ctx, govv1.DefaultParams())) - govKeeper.SetLegacyRouter(govRouter) + require.NoError(tb, govKeeper.SetParams(ctx, govv1.DefaultParams())) govKeeper.SetProposalID(ctx, 1) am := module.NewManager( // minimal module set that we use for message/ query tests @@ -586,8 +587,10 @@ func DeterministicAccountAddress(_ testing.TB, v byte) sdk.AccAddress { return bytes.Repeat([]byte{v}, address.Len) } -func RandomBech32AccountAddress(t testing.TB) string { - return RandomAccountAddress(t).String() +func RandomBech32AccountAddress(tb testing.TB) string { + tb.Helper() + + return RandomAccountAddress(tb).String() } type ExampleContract struct { @@ -598,35 +601,47 @@ type ExampleContract struct { Checksum []byte } -func StoreHackatomExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { - return StoreExampleContractWasm(t, ctx, keepers, testdata.HackatomContractWasm()) +func StoreHackatomExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { + tb.Helper() + + return StoreExampleContractWasm(tb, ctx, keepers, testdata.HackatomContractWasm()) } -func StoreBurnerExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { - return StoreExampleContractWasm(t, ctx, keepers, testdata.BurnerContractWasm()) +func StoreBurnerExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { + tb.Helper() + + return StoreExampleContractWasm(tb, ctx, keepers, testdata.BurnerContractWasm()) } -func StoreIBCReflectContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { - return StoreExampleContractWasm(t, ctx, keepers, testdata.IBCReflectContractWasm()) +func StoreIBCReflectContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { + tb.Helper() + + return StoreExampleContractWasm(tb, ctx, keepers, testdata.IBCReflectContractWasm()) } -func StoreReflectContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { - return StoreExampleContractWasm(t, ctx, keepers, testdata.ReflectContractWasm()) +func StoreReflectContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleContract { + tb.Helper() + + return StoreExampleContractWasm(tb, ctx, keepers, testdata.ReflectContractWasm()) } -func StoreExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers, wasmFile string) ExampleContract { +func StoreExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers, wasmFile string) ExampleContract { + tb.Helper() + wasmCode, err := os.ReadFile(wasmFile) - require.NoError(t, err) - return StoreExampleContractWasm(t, ctx, keepers, wasmCode) + require.NoError(tb, err) + return StoreExampleContractWasm(tb, ctx, keepers, wasmCode) } -func StoreExampleContractWasm(t testing.TB, ctx sdk.Context, keepers TestKeepers, wasmCode []byte) ExampleContract { +func StoreExampleContractWasm(tb testing.TB, ctx sdk.Context, keepers TestKeepers, wasmCode []byte) ExampleContract { + tb.Helper() + anyAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 1000)) creator, creatorAddr := keyPubAddr() - fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) + fundAccounts(tb, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) codeID, _, err := keepers.ContractKeeper.Create(ctx, creatorAddr, wasmCode, nil) - require.NoError(t, err) + require.NoError(tb, err) hash := keepers.WasmKeeper.GetCodeInfo(ctx, codeID).CodeHash return ExampleContract{anyAmount, creator, creatorAddr, codeID, hash} } @@ -638,37 +653,39 @@ type ExampleContractInstance struct { Contract sdk.AccAddress } -// SeedNewContractInstance sets the mock wasmerEngine in keeper and calls store + instantiate to init the contract's metadata -func SeedNewContractInstance(t testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContractInstance { - t.Helper() - exampleContract := StoreRandomContract(t, ctx, keepers, mock) +// SeedNewContractInstance sets the mock WasmEngine in keeper and calls store + instantiate to init the contract's metadata +func SeedNewContractInstance(tb testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmEngine) ExampleContractInstance { + tb.Helper() + exampleContract := StoreRandomContract(tb, ctx, keepers, mock) contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, exampleContract.CodeID, exampleContract.CreatorAddr, exampleContract.CreatorAddr, []byte(`{}`), "", nil) - require.NoError(t, err) + require.NoError(tb, err) return ExampleContractInstance{ ExampleContract: exampleContract, Contract: contractAddr, } } -// StoreRandomContract sets the mock wasmerEngine in keeper and calls store -func StoreRandomContract(t testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContract { - return StoreRandomContractWithAccessConfig(t, ctx, keepers, mock, nil) +// StoreRandomContract sets the mock WasmEngine in keeper and calls store +func StoreRandomContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers, mock types.WasmEngine) ExampleContract { + tb.Helper() + + return StoreRandomContractWithAccessConfig(tb, ctx, keepers, mock, nil) } func StoreRandomContractWithAccessConfig( - t testing.TB, ctx sdk.Context, + tb testing.TB, ctx sdk.Context, keepers TestKeepers, - mock types.WasmerEngine, + mock types.WasmEngine, cfg *types.AccessConfig, ) ExampleContract { - t.Helper() + tb.Helper() anyAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 1000)) creator, creatorAddr := keyPubAddr() - fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) + fundAccounts(tb, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) keepers.WasmKeeper.wasmVM = mock - wasmCode := append(wasmIdent, rand.Bytes(10)...) //nolint:gocritic + wasmCode := append(wasmIdent, rand.Bytes(10)...) codeID, checksum, err := keepers.ContractKeeper.Create(ctx, creatorAddr, wasmCode, cfg) - require.NoError(t, err) + require.NoError(tb, err) exampleContract := ExampleContract{InitialAmount: anyAmount, Creator: creator, CreatorAddr: creatorAddr, CodeID: codeID, Checksum: checksum} return exampleContract } @@ -685,23 +702,25 @@ type HackatomExampleInstance struct { } // InstantiateHackatomExampleContract load and instantiate the "./testdata/hackatom.wasm" contract -func InstantiateHackatomExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) HackatomExampleInstance { - contract := StoreHackatomExampleContract(t, ctx, keepers) +func InstantiateHackatomExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) HackatomExampleInstance { + tb.Helper() + + contract := StoreHackatomExampleContract(tb, ctx, keepers) verifier, verifierAddr := keyPubAddr() - fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, verifierAddr, contract.InitialAmount) + fundAccounts(tb, ctx, keepers.AccountKeeper, keepers.BankKeeper, verifierAddr, contract.InitialAmount) beneficiary, beneficiaryAddr := keyPubAddr() initMsgBz := HackatomExampleInitMsg{ Verifier: verifierAddr, Beneficiary: beneficiaryAddr, - }.GetBytes(t) + }.GetBytes(tb) initialAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 100)) adminAddr := contract.CreatorAddr label := "demo contract to query" contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, contract.CodeID, contract.CreatorAddr, adminAddr, initMsgBz, label, initialAmount) - require.NoError(t, err) + require.NoError(tb, err) return HackatomExampleInstance{ ExampleContract: contract, Contract: contractAddr, @@ -722,13 +741,15 @@ type ExampleInstance struct { } // InstantiateReflectExampleContract load and instantiate the "./testdata/reflect.wasm" contract -func InstantiateReflectExampleContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleInstance { - example := StoreReflectContract(t, ctx, keepers) +func InstantiateReflectExampleContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) ExampleInstance { + tb.Helper() + + example := StoreReflectContract(tb, ctx, keepers) initialAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 100)) label := "demo contract to query" contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, example.CodeID, example.CreatorAddr, example.CreatorAddr, []byte("{}"), label, initialAmount) - require.NoError(t, err) + require.NoError(tb, err) return ExampleInstance{ ExampleContract: example, Contract: contractAddr, @@ -742,9 +763,11 @@ type HackatomExampleInitMsg struct { Beneficiary sdk.AccAddress `json:"beneficiary"` } -func (m HackatomExampleInitMsg) GetBytes(t testing.TB) []byte { +func (m HackatomExampleInitMsg) GetBytes(tb testing.TB) []byte { + tb.Helper() + initMsgBz, err := json.Marshal(m) - require.NoError(t, err) + require.NoError(tb, err) return initMsgBz } @@ -756,17 +779,19 @@ type IBCReflectExampleInstance struct { } // InstantiateIBCReflectContract load and instantiate the "./testdata/ibc_reflect.wasm" contract -func InstantiateIBCReflectContract(t testing.TB, ctx sdk.Context, keepers TestKeepers) IBCReflectExampleInstance { - reflectID := StoreReflectContract(t, ctx, keepers).CodeID - ibcReflectID := StoreIBCReflectContract(t, ctx, keepers).CodeID +func InstantiateIBCReflectContract(tb testing.TB, ctx sdk.Context, keepers TestKeepers) IBCReflectExampleInstance { + tb.Helper() + + reflectID := StoreReflectContract(tb, ctx, keepers).CodeID + ibcReflectID := StoreIBCReflectContract(tb, ctx, keepers).CodeID initMsgBz := IBCReflectInitMsg{ ReflectCodeID: reflectID, - }.GetBytes(t) - adminAddr := RandomAccountAddress(t) + }.GetBytes(tb) + adminAddr := RandomAccountAddress(tb) contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, ibcReflectID, adminAddr, adminAddr, initMsgBz, "ibc-reflect-factory", nil) - require.NoError(t, err) + require.NoError(tb, err) return IBCReflectExampleInstance{ Admin: adminAddr, Contract: contractAddr, @@ -779,26 +804,31 @@ type IBCReflectInitMsg struct { ReflectCodeID uint64 `json:"reflect_code_id"` } -func (m IBCReflectInitMsg) GetBytes(t testing.TB) []byte { +func (m IBCReflectInitMsg) GetBytes(tb testing.TB) []byte { + tb.Helper() + initMsgBz, err := json.Marshal(m) - require.NoError(t, err) + require.NoError(tb, err) return initMsgBz } type BurnerExampleInitMsg struct { Payout sdk.AccAddress `json:"payout"` + Delete uint32 `json:"delete"` } -func (m BurnerExampleInitMsg) GetBytes(t testing.TB) []byte { +func (m BurnerExampleInitMsg) GetBytes(tb testing.TB) []byte { + tb.Helper() initMsgBz, err := json.Marshal(m) - require.NoError(t, err) + require.NoError(tb, err) return initMsgBz } -func fundAccounts(t testing.TB, ctx sdk.Context, am authkeeper.AccountKeeper, bank bankkeeper.Keeper, addr sdk.AccAddress, coins sdk.Coins) { +func fundAccounts(tb testing.TB, ctx sdk.Context, am authkeeper.AccountKeeper, bank bankkeeper.Keeper, addr sdk.AccAddress, coins sdk.Coins) { + tb.Helper() acc := am.NewAccountWithAddress(ctx, addr) am.SetAccount(ctx, acc) - NewTestFaucet(t, ctx, bank, minttypes.ModuleName, coins...).Fund(ctx, addr, coins...) + NewTestFaucet(tb, ctx, bank, minttypes.ModuleName, coins...).Fund(ctx, addr, coins...) } var keyCounter uint64 diff --git a/x/wasm/keeper/test_fuzz.go b/x/wasm/keeper/test_fuzz.go index 2b15a26be7..7bd3e9bbd5 100644 --- a/x/wasm/keeper/test_fuzz.go +++ b/x/wasm/keeper/test_fuzz.go @@ -4,9 +4,10 @@ import ( "encoding/json" tmBytes "github.com/cometbft/cometbft/libs/bytes" - sdk "github.com/cosmos/cosmos-sdk/types" fuzz "github.com/google/gofuzz" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/keeper/testdata/burner.wasm b/x/wasm/keeper/testdata/burner.wasm index 6639075611..dbfd0aa521 100644 Binary files a/x/wasm/keeper/testdata/burner.wasm and b/x/wasm/keeper/testdata/burner.wasm differ diff --git a/x/wasm/keeper/testdata/contracts.go b/x/wasm/keeper/testdata/contracts.go index 6073e4d530..dc81aa23d5 100644 --- a/x/wasm/keeper/testdata/contracts.go +++ b/x/wasm/keeper/testdata/contracts.go @@ -7,6 +7,10 @@ import ( "github.com/cosmos/cosmos-sdk/types" ) +const ( + ChecksumHackatom = "3f4cd47c39c57fe1733fb41ed176eebd9d5c67baf5df8a1eeda1455e758f8514" +) + var ( //go:embed reflect.wasm reflectContract []byte diff --git a/x/wasm/keeper/testdata/cyberpunk.wasm b/x/wasm/keeper/testdata/cyberpunk.wasm index 7f81df52e1..809224e5fa 100644 Binary files a/x/wasm/keeper/testdata/cyberpunk.wasm and b/x/wasm/keeper/testdata/cyberpunk.wasm differ diff --git a/x/wasm/keeper/testdata/hackatom.wasm b/x/wasm/keeper/testdata/hackatom.wasm index d7ae04051c..5333788263 100644 Binary files a/x/wasm/keeper/testdata/hackatom.wasm and b/x/wasm/keeper/testdata/hackatom.wasm differ diff --git a/x/wasm/keeper/testdata/hackatom.wasm.gzip b/x/wasm/keeper/testdata/hackatom.wasm.gzip index 58da39db0b..70425704bf 100644 Binary files a/x/wasm/keeper/testdata/hackatom.wasm.gzip and b/x/wasm/keeper/testdata/hackatom.wasm.gzip differ diff --git a/x/wasm/keeper/testdata/ibc_reflect.wasm b/x/wasm/keeper/testdata/ibc_reflect.wasm index c51a0ba473..051be2a56f 100644 Binary files a/x/wasm/keeper/testdata/ibc_reflect.wasm and b/x/wasm/keeper/testdata/ibc_reflect.wasm differ diff --git a/x/wasm/keeper/testdata/ibc_reflect_send.wasm b/x/wasm/keeper/testdata/ibc_reflect_send.wasm index a6a2b7ff4a..1d361d8837 100644 Binary files a/x/wasm/keeper/testdata/ibc_reflect_send.wasm and b/x/wasm/keeper/testdata/ibc_reflect_send.wasm differ diff --git a/x/wasm/keeper/testdata/reflect.wasm b/x/wasm/keeper/testdata/reflect.wasm index 23fcff5533..28a64acbf8 100644 Binary files a/x/wasm/keeper/testdata/reflect.wasm and b/x/wasm/keeper/testdata/reflect.wasm differ diff --git a/x/wasm/keeper/testdata/staking.wasm b/x/wasm/keeper/testdata/staking.wasm index 635b04ec15..4749d77505 100644 Binary files a/x/wasm/keeper/testdata/staking.wasm and b/x/wasm/keeper/testdata/staking.wasm differ diff --git a/x/wasm/keeper/testdata/version.txt b/x/wasm/keeper/testdata/version.txt index f5ca6914e9..0d0c52f84d 100644 --- a/x/wasm/keeper/testdata/version.txt +++ b/x/wasm/keeper/testdata/version.txt @@ -1,3 +1 @@ -v1.3.0 -burner.wasm: v1.2.0 -ibc-reflect.wasm: custom build, see: https://github.com/CosmWasm/cosmwasm/pull/1690 +v1.4.0 diff --git a/x/wasm/keeper/wasmtesting/extension_mocks.go b/x/wasm/keeper/wasmtesting/extension_mocks.go index 562d9e74b0..3ab14c9a1c 100644 --- a/x/wasm/keeper/wasmtesting/extension_mocks.go +++ b/x/wasm/keeper/wasmtesting/extension_mocks.go @@ -6,10 +6,10 @@ import ( ) type MockCoinTransferrer struct { - TransferCoinsFn func(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + TransferCoinsFn func(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error } -func (m *MockCoinTransferrer) TransferCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error { +func (m *MockCoinTransferrer) TransferCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error { if m.TransferCoinsFn == nil { panic("not expected to be called") } diff --git a/x/wasm/keeper/wasmtesting/gas_register.go b/x/wasm/keeper/wasmtesting/gas_register.go index 516cd5fb4a..d0f718af3a 100644 --- a/x/wasm/keeper/wasmtesting/gas_register.go +++ b/x/wasm/keeper/wasmtesting/gas_register.go @@ -2,6 +2,7 @@ package wasmtesting import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/keeper/wasmtesting/messenger.go b/x/wasm/keeper/wasmtesting/messenger.go index dbafda3886..8f613cf667 100644 --- a/x/wasm/keeper/wasmtesting/messenger.go +++ b/x/wasm/keeper/wasmtesting/messenger.go @@ -4,6 +4,7 @@ import ( "errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/keeper/wasmtesting/mock_engine.go b/x/wasm/keeper/wasmtesting/mock_engine.go index af10d40b7a..b1c7b11d04 100644 --- a/x/wasm/keeper/wasmtesting/mock_engine.go +++ b/x/wasm/keeper/wasmtesting/mock_engine.go @@ -3,20 +3,20 @@ package wasmtesting import ( "bytes" - errorsmod "cosmossdk.io/errors" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/rand" + errorsmod "cosmossdk.io/errors" + "github.com/CosmWasm/wasmd/x/wasm/types" ) -var _ types.WasmerEngine = &MockWasmer{} +var _ types.WasmEngine = &MockWasmEngine{} -// MockWasmer implements types.WasmerEngine for testing purpose. One or multiple messages can be stubbed. +// MockWasmEngine implements types.WasmEngine for testing purpose. One or multiple messages can be stubbed. // Without a stub function a panic is thrown. -type MockWasmer struct { +type MockWasmEngine struct { StoreCodeFn func(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) StoreCodeUncheckedFn func(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) AnalyzeCodeFn func(codeID wasmvm.Checksum) (*wasmvmtypes.AnalysisReport, error) @@ -39,42 +39,42 @@ type MockWasmer struct { GetMetricsFn func() (*wasmvmtypes.Metrics, error) } -func (m *MockWasmer) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) { +func (m *MockWasmEngine) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) { if m.IBCChannelOpenFn == nil { panic("not supposed to be called!") } return m.IBCChannelOpenFn(codeID, env, msg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) IBCChannelConnect(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelConnectMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { +func (m *MockWasmEngine) IBCChannelConnect(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelConnectMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { if m.IBCChannelConnectFn == nil { panic("not supposed to be called!") } return m.IBCChannelConnectFn(codeID, env, msg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) IBCChannelClose(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelCloseMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { +func (m *MockWasmEngine) IBCChannelClose(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelCloseMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { if m.IBCChannelCloseFn == nil { panic("not supposed to be called!") } return m.IBCChannelCloseFn(codeID, env, msg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) IBCPacketReceive(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketReceiveMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCReceiveResult, uint64, error) { +func (m *MockWasmEngine) IBCPacketReceive(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketReceiveMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCReceiveResult, uint64, error) { if m.IBCPacketReceiveFn == nil { panic("not supposed to be called!") } return m.IBCPacketReceiveFn(codeID, env, msg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) IBCPacketAck(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketAckMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { +func (m *MockWasmEngine) IBCPacketAck(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketAckMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { if m.IBCPacketAckFn == nil { panic("not supposed to be called!") } return m.IBCPacketAckFn(codeID, env, msg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) IBCPacketTimeout(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketTimeoutMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { +func (m *MockWasmEngine) IBCPacketTimeout(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketTimeoutMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) { if m.IBCPacketTimeoutFn == nil { panic("not supposed to be called!") } @@ -82,113 +82,113 @@ func (m *MockWasmer) IBCPacketTimeout(codeID wasmvm.Checksum, env wasmvmtypes.En } // Deprecated: use StoreCode instead. -func (m *MockWasmer) Create(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) { +func (m *MockWasmEngine) Create(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) { panic("Deprecated: use StoreCode instead") } -func (m *MockWasmer) StoreCode(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) { +func (m *MockWasmEngine) StoreCode(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) { if m.StoreCodeFn == nil { panic("not supposed to be called!") } return m.StoreCodeFn(codeID) } -func (m *MockWasmer) StoreCodeUnchecked(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) { +func (m *MockWasmEngine) StoreCodeUnchecked(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) { if m.StoreCodeUncheckedFn == nil { panic("not supposed to be called!") } return m.StoreCodeUncheckedFn(codeID) } -func (m *MockWasmer) AnalyzeCode(codeID wasmvm.Checksum) (*wasmvmtypes.AnalysisReport, error) { +func (m *MockWasmEngine) AnalyzeCode(codeID wasmvm.Checksum) (*wasmvmtypes.AnalysisReport, error) { if m.AnalyzeCodeFn == nil { panic("not supposed to be called!") } return m.AnalyzeCodeFn(codeID) } -func (m *MockWasmer) Instantiate(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { +func (m *MockWasmEngine) Instantiate(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { if m.InstantiateFn == nil { panic("not supposed to be called!") } return m.InstantiateFn(codeID, env, info, initMsg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) Execute(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { +func (m *MockWasmEngine) Execute(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, executeMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { if m.ExecuteFn == nil { panic("not supposed to be called!") } return m.ExecuteFn(codeID, env, info, executeMsg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) Query(codeID wasmvm.Checksum, env wasmvmtypes.Env, queryMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) ([]byte, uint64, error) { +func (m *MockWasmEngine) Query(codeID wasmvm.Checksum, env wasmvmtypes.Env, queryMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) ([]byte, uint64, error) { if m.QueryFn == nil { panic("not supposed to be called!") } return m.QueryFn(codeID, env, queryMsg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) Migrate(codeID wasmvm.Checksum, env wasmvmtypes.Env, migrateMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { +func (m *MockWasmEngine) Migrate(codeID wasmvm.Checksum, env wasmvmtypes.Env, migrateMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { if m.MigrateFn == nil { panic("not supposed to be called!") } return m.MigrateFn(codeID, env, migrateMsg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) Sudo(codeID wasmvm.Checksum, env wasmvmtypes.Env, sudoMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { +func (m *MockWasmEngine) Sudo(codeID wasmvm.Checksum, env wasmvmtypes.Env, sudoMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { if m.SudoFn == nil { panic("not supposed to be called!") } return m.SudoFn(codeID, env, sudoMsg, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) Reply(codeID wasmvm.Checksum, env wasmvmtypes.Env, reply wasmvmtypes.Reply, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { +func (m *MockWasmEngine) Reply(codeID wasmvm.Checksum, env wasmvmtypes.Env, reply wasmvmtypes.Reply, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { if m.ReplyFn == nil { panic("not supposed to be called!") } return m.ReplyFn(codeID, env, reply, store, goapi, querier, gasMeter, gasLimit, deserCost) } -func (m *MockWasmer) GetCode(codeID wasmvm.Checksum) (wasmvm.WasmCode, error) { +func (m *MockWasmEngine) GetCode(codeID wasmvm.Checksum) (wasmvm.WasmCode, error) { if m.GetCodeFn == nil { panic("not supposed to be called!") } return m.GetCodeFn(codeID) } -func (m *MockWasmer) Cleanup() { +func (m *MockWasmEngine) Cleanup() { if m.CleanupFn == nil { panic("not supposed to be called!") } m.CleanupFn() } -func (m *MockWasmer) Pin(checksum wasmvm.Checksum) error { +func (m *MockWasmEngine) Pin(checksum wasmvm.Checksum) error { if m.PinFn == nil { panic("not supposed to be called!") } return m.PinFn(checksum) } -func (m *MockWasmer) Unpin(checksum wasmvm.Checksum) error { +func (m *MockWasmEngine) Unpin(checksum wasmvm.Checksum) error { if m.UnpinFn == nil { panic("not supposed to be called!") } return m.UnpinFn(checksum) } -func (m *MockWasmer) GetMetrics() (*wasmvmtypes.Metrics, error) { +func (m *MockWasmEngine) GetMetrics() (*wasmvmtypes.Metrics, error) { if m.GetMetricsFn == nil { panic("not expected to be called") } return m.GetMetricsFn() } -var AlwaysPanicMockWasmer = &MockWasmer{} +var AlwaysPanicMockWasmEngine = &MockWasmEngine{} -// SelfCallingInstMockWasmer prepares a Wasmer mock that calls itself on instantiation. -func SelfCallingInstMockWasmer(executeCalled *bool) *MockWasmer { - return &MockWasmer{ +// SelfCallingInstMockWasmEngine prepares a WasmEngine mock that calls itself on instantiation. +func SelfCallingInstMockWasmEngine(executeCalled *bool) *MockWasmEngine { + return &MockWasmEngine{ StoreCodeFn: func(code wasmvm.WasmCode) (wasmvm.Checksum, error) { anyCodeID := bytes.Repeat([]byte{0x1}, 32) return anyCodeID, nil @@ -211,7 +211,7 @@ func SelfCallingInstMockWasmer(executeCalled *bool) *MockWasmer { } // IBCContractCallbacks defines the methods from wasmvm to interact with the wasm contract. -// A mock contract would implement the interface to fully simulate a wasm contract's behaviour. +// A mock contract would implement the interface to fully simulate a wasm contract's behavior. type IBCContractCallbacks interface { IBCChannelOpen( codeID wasmvm.Checksum, @@ -302,24 +302,24 @@ type contractExecutable interface { } // MakeInstantiable adds some noop functions to not fail when contract is used for instantiation -func MakeInstantiable(m *MockWasmer) { +func MakeInstantiable(m *MockWasmEngine) { m.StoreCodeFn = HashOnlyStoreCodeFn m.InstantiateFn = NoOpInstantiateFn m.AnalyzeCodeFn = WithoutIBCAnalyzeFn } // MakeIBCInstantiable adds some noop functions to not fail when contract is used for instantiation -func MakeIBCInstantiable(m *MockWasmer) { +func MakeIBCInstantiable(m *MockWasmEngine) { MakeInstantiable(m) m.AnalyzeCodeFn = HasIBCAnalyzeFn } -// NewIBCContractMockWasmer prepares a mocked wasm_engine for testing with an IBC contract test type. +// NewIBCContractMockWasmEngine prepares a mocked wasm_engine for testing with an IBC contract test type. // It is safe to use the mock with store code and instantiate functions in keeper as is also prepared // with stubs. Execute is optional. When implemented by the Go test contract then it can be used with // the mock. -func NewIBCContractMockWasmer(c IBCContractCallbacks) *MockWasmer { - m := &MockWasmer{ +func NewIBCContractMockWasmEngine(c IBCContractCallbacks) *MockWasmEngine { + m := &MockWasmEngine{ IBCChannelOpenFn: c.IBCChannelOpen, IBCChannelConnectFn: c.IBCChannelConnect, IBCChannelCloseFn: c.IBCChannelClose, diff --git a/x/wasm/keeper/wasmtesting/mock_keepers.go b/x/wasm/keeper/wasmtesting/mock_keepers.go index b5e688691b..8cae741855 100644 --- a/x/wasm/keeper/wasmtesting/mock_keepers.go +++ b/x/wasm/keeper/wasmtesting/mock_keepers.go @@ -1,21 +1,22 @@ package wasmtesting import ( - sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/CosmWasm/wasmd/x/wasm/types" ) type MockChannelKeeper struct { - GetChannelFn func(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) - GetNextSequenceSendFn func(ctx sdk.Context, portID, channelID string) (uint64, bool) - ChanCloseInitFn func(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error - GetAllChannelsFn func(ctx sdk.Context) []channeltypes.IdentifiedChannel - IterateChannelsFn func(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) - SetChannelFn func(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel) + GetChannelFn func(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetNextSequenceSendFn func(ctx sdk.Context, portID, channelID string) (uint64, bool) + ChanCloseInitFn func(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error + GetAllChannelsFn func(ctx sdk.Context) []channeltypes.IdentifiedChannel + SetChannelFn func(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel) + GetAllChannelsWithPortPrefixFn func(ctx sdk.Context, portPrefix string) []channeltypes.IdentifiedChannel } func (m *MockChannelKeeper) GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) { @@ -46,11 +47,11 @@ func (m *MockChannelKeeper) ChanCloseInit(ctx sdk.Context, portID, channelID str return m.ChanCloseInitFn(ctx, portID, channelID, chanCap) } -func (m *MockChannelKeeper) IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) { - if m.IterateChannelsFn == nil { +func (m *MockChannelKeeper) GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []channeltypes.IdentifiedChannel { + if m.GetAllChannelsWithPortPrefixFn == nil { panic("not expected to be called") } - m.IterateChannelsFn(ctx, cb) + return m.GetAllChannelsWithPortPrefixFn(ctx, portPrefix) } func (m *MockChannelKeeper) SetChannel(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel) { @@ -61,10 +62,10 @@ func (m *MockChannelKeeper) SetChannel(ctx sdk.Context, portID, channelID string } type MockIBCPacketSender struct { - SendPacketFn func(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) + SendPacketFn func(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) } -func (m *MockIBCPacketSender) SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) { +func (m *MockIBCPacketSender) SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) (uint64, error) { if m.SendPacketFn == nil { panic("not supposed to be called!") } diff --git a/x/wasm/keeper/wasmtesting/msg_dispatcher.go b/x/wasm/keeper/wasmtesting/msg_dispatcher.go index a6600941a5..4d016f4741 100644 --- a/x/wasm/keeper/wasmtesting/msg_dispatcher.go +++ b/x/wasm/keeper/wasmtesting/msg_dispatcher.go @@ -2,6 +2,7 @@ package wasmtesting import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/keeper/wasmtesting/query_handler.go b/x/wasm/keeper/wasmtesting/query_handler.go index 52cf97d31f..e70495b52f 100644 --- a/x/wasm/keeper/wasmtesting/query_handler.go +++ b/x/wasm/keeper/wasmtesting/query_handler.go @@ -2,6 +2,7 @@ package wasmtesting import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/wasm/migrations/v1/store_test.go b/x/wasm/migrations/v1/store_test.go index 857d0810a6..7afec80b59 100644 --- a/x/wasm/migrations/v1/store_test.go +++ b/x/wasm/migrations/v1/store_test.go @@ -5,12 +5,12 @@ import ( "encoding/json" "testing" - "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" - "github.com/stretchr/testify/require" + "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/types" ) diff --git a/x/wasm/migrations/v3/store_test.go b/x/wasm/migrations/v3/store_test.go index 17fe5b2425..0bd217d299 100644 --- a/x/wasm/migrations/v3/store_test.go +++ b/x/wasm/migrations/v3/store_test.go @@ -4,17 +4,17 @@ import ( "bytes" "testing" - "github.com/CosmWasm/wasmd/x/wasm" - "github.com/CosmWasm/wasmd/x/wasm/keeper" - "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" - v3 "github.com/CosmWasm/wasmd/x/wasm/migrations/v3" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/CosmWasm/wasmd/x/wasm" + "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" + v3 "github.com/CosmWasm/wasmd/x/wasm/migrations/v3" "github.com/CosmWasm/wasmd/x/wasm/types" ) @@ -29,7 +29,7 @@ func TestMigrate3To4(t *testing.T) { creator := sdk.AccAddress(bytes.Repeat([]byte{1}, address.Len)) keepers.Faucet.Fund(ctx, creator, deposit...) - var mock wasmtesting.MockWasmer + var mock wasmtesting.MockWasmEngine wasmtesting.MakeInstantiable(&mock) // contract with only address permission diff --git a/x/wasm/module.go b/x/wasm/module.go index e1f6421226..d209899f67 100644 --- a/x/wasm/module.go +++ b/x/wasm/module.go @@ -7,12 +7,15 @@ import ( "runtime/debug" "strings" + wasmvm "github.com/CosmWasm/wasmvm" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/baseapp" - - wasmvm "github.com/CosmWasm/wasmvm" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -21,9 +24,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cast" - "github.com/spf13/cobra" "github.com/CosmWasm/wasmd/x/wasm/client/cli" "github.com/CosmWasm/wasmd/x/wasm/exported" @@ -42,7 +42,7 @@ const ( flagWasmMemoryCacheSize = "wasm.memory_cache_size" flagWasmQueryGasLimit = "wasm.query_gas_limit" flagWasmSimulationGasLimit = "wasm.simulation_gas_limit" - flagWasmSkipWasmVMVersionCheck = "wasm.skip_wasmvm_version_check" //nolint:gosec + flagWasmSkipWasmVMVersionCheck = "wasm.skip_wasmvm_version_check" ) // AppModuleBasic defines the basic application module used by the wasm module. diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index f0d5ada32a..b91137daf2 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -7,21 +7,21 @@ import ( "strings" "testing" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/spf13/viper" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cometbft/cometbft/crypto/ed25519" + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/module" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/CosmWasm/wasmd/app/params" "github.com/CosmWasm/wasmd/x/wasm/exported" @@ -56,14 +56,15 @@ type testData struct { } func setupTest(t *testing.T) testData { - ctx, keepers := keeper.CreateTestInput(t, false, "iterator,staking,stargate,cosmwasm_1_1") + t.Helper() + ctx, keepers := keeper.CreateTestInput(t, false, "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4") encConf := keeper.MakeEncodingConfig(t) queryRouter := baseapp.NewGRPCQueryRouter() serviceRouter := baseapp.NewMsgServiceRouter() queryRouter.SetInterfaceRegistry(encConf.InterfaceRegistry) serviceRouter.SetInterfaceRegistry(encConf.InterfaceRegistry) data := testData{ - module: NewAppModule(encConf.Marshaler, keepers.WasmKeeper, keepers.AccountKeeper, keepers.BankKeeper, nil, newMockSubspace(types.DefaultParams())), + module: NewAppModule(encConf.Codec, keepers.WasmKeeper, keepers.AccountKeeper, keepers.BankKeeper, nil, newMockSubspace(types.DefaultParams())), ctx: ctx, acctKeeper: keepers.AccountKeeper, keeper: *keepers.WasmKeeper, @@ -74,7 +75,7 @@ func setupTest(t *testing.T) testData { msgServiceRouter: serviceRouter, encConf: encConf, } - data.module.RegisterServices(module.NewConfigurator(encConf.Marshaler, serviceRouter, queryRouter)) + data.module.RegisterServices(module.NewConfigurator(encConf.Codec, serviceRouter, queryRouter)) return data } @@ -152,12 +153,12 @@ func TestHandleCreate(t *testing.T) { res, err := h(data.ctx, tc.msg) if !tc.isValid { require.Error(t, err, "%#v", res) - assertCodeList(t, q, data.ctx, 0, data.encConf.Marshaler) - assertCodeBytes(t, q, data.ctx, 1, nil, data.encConf.Marshaler) + assertCodeList(t, q, data.ctx, 0, data.encConf.Codec) + assertCodeBytes(t, q, data.ctx, 1, nil, data.encConf.Codec) return } require.NoError(t, err) - assertCodeList(t, q, data.ctx, 1, data.encConf.Marshaler) + assertCodeList(t, q, data.ctx, 1, data.encConf.Codec) }) } } @@ -219,16 +220,16 @@ func TestHandleInstantiate(t *testing.T) { require.Equal(t, "wasm", res.Events[1].Type) assertAttribute(t, "_contract_address", contractBech32Addr, res.Events[1].Attributes[0]) - assertCodeList(t, q, data.ctx, 1, data.encConf.Marshaler) - assertCodeBytes(t, q, data.ctx, 1, testContract, data.encConf.Marshaler) + assertCodeList(t, q, data.ctx, 1, data.encConf.Codec) + assertCodeBytes(t, q, data.ctx, 1, testContract, data.encConf.Codec) - assertContractList(t, q, data.ctx, 1, []string{contractBech32Addr}, data.encConf.Marshaler) - assertContractInfo(t, q, data.ctx, contractBech32Addr, 1, creator, data.encConf.Marshaler) + assertContractList(t, q, data.ctx, 1, []string{contractBech32Addr}, data.encConf.Codec) + assertContractInfo(t, q, data.ctx, contractBech32Addr, 1, creator, data.encConf.Codec) assertContractState(t, q, data.ctx, contractBech32Addr, state{ Verifier: fred.String(), Beneficiary: bob.String(), Funder: creator.String(), - }, data.encConf.Marshaler) + }, data.encConf.Codec) } func TestHandleExecute(t *testing.T) { @@ -353,16 +354,16 @@ func TestHandleExecute(t *testing.T) { assert.Equal(t, sdk.Coins{}, data.bankKeeper.GetAllBalances(data.ctx, contractAcct.GetAddress())) // ensure all contract state is as after init - assertCodeList(t, q, data.ctx, 1, data.encConf.Marshaler) - assertCodeBytes(t, q, data.ctx, 1, testContract, data.encConf.Marshaler) + assertCodeList(t, q, data.ctx, 1, data.encConf.Codec) + assertCodeBytes(t, q, data.ctx, 1, testContract, data.encConf.Codec) - assertContractList(t, q, data.ctx, 1, []string{contractBech32Addr}, data.encConf.Marshaler) - assertContractInfo(t, q, data.ctx, contractBech32Addr, 1, creator, data.encConf.Marshaler) + assertContractList(t, q, data.ctx, 1, []string{contractBech32Addr}, data.encConf.Codec) + assertContractInfo(t, q, data.ctx, contractBech32Addr, 1, creator, data.encConf.Codec) assertContractState(t, q, data.ctx, contractBech32Addr, state{ Verifier: fred.String(), Beneficiary: bob.String(), Funder: creator.String(), - }, data.encConf.Marshaler) + }, data.encConf.Codec) } func TestHandleExecuteEscrow(t *testing.T) { @@ -546,7 +547,7 @@ func prettyAttr(attr abci.EventAttribute) sdk.Attribute { return sdk.NewAttribute(attr.Key, attr.Value) } -func assertAttribute(t *testing.T, key string, value string, attr abci.EventAttribute) { +func assertAttribute(t *testing.T, key, value string, attr abci.EventAttribute) { t.Helper() assert.Equal(t, key, attr.Key, prettyAttr(attr)) assert.Equal(t, value, attr.Value, prettyAttr(attr)) diff --git a/x/wasm/relay_pingpong_test.go b/x/wasm/relay_pingpong_test.go index 4ae022b17e..a9eadc7f90 100644 --- a/x/wasm/relay_pingpong_test.go +++ b/x/wasm/relay_pingpong_test.go @@ -5,19 +5,18 @@ import ( "fmt" "testing" - app2 "github.com/CosmWasm/wasmd/app" - - ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - ibctesting "github.com/cosmos/ibc-go/v7/testing" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + + app2 "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" @@ -44,10 +43,10 @@ func TestPinPong(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(pingContract)), + wasmtesting.NewIBCContractMockWasmEngine(pingContract)), } chainBOpts = []wasmkeeper.Option{wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(pongContract), + wasmtesting.NewIBCContractMockWasmEngine(pongContract), )} coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts, chainBOpts) chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) diff --git a/x/wasm/relay_test.go b/x/wasm/relay_test.go index 81698f5a4a..91a6a37d15 100644 --- a/x/wasm/relay_test.go +++ b/x/wasm/relay_test.go @@ -6,13 +6,8 @@ import ( "testing" "time" - "github.com/CosmWasm/wasmd/app" - - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/math" wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -20,6 +15,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/CosmWasm/wasmd/app" wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" @@ -45,6 +46,7 @@ func TestFromIBCTransferToContract(t *testing.T) { "ack": { contract: &ackReceiverContract{}, setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + t.Helper() c := contract.(*ackReceiverContract) c.t = t c.chain = chain @@ -57,6 +59,7 @@ func TestFromIBCTransferToContract(t *testing.T) { "nack": { contract: &nackReceiverContract{}, setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + t.Helper() c := contract.(*nackReceiverContract) c.t = t }, @@ -68,6 +71,7 @@ func TestFromIBCTransferToContract(t *testing.T) { "error": { contract: &errorReceiverContract{}, setupContract: func(t *testing.T, contract wasmtesting.IBCContractCallbacks, chain *wasmibctesting.TestChain) { + t.Helper() c := contract.(*errorReceiverContract) c.t = t }, @@ -82,7 +86,7 @@ func TestFromIBCTransferToContract(t *testing.T) { t.Run(name, func(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(spec.contract), + wasmtesting.NewIBCContractMockWasmEngine(spec.contract), )} coordinator = wasmibctesting.NewCoordinator(t, 2, []wasmkeeper.Option{}, chainAOpts) chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) @@ -158,7 +162,7 @@ func TestContractCanInitiateIBCTransferMsg(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContract)), + wasmtesting.NewIBCContractMockWasmEngine(myContract)), } coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) chainA = coordinator.GetChain(wasmibctesting.GetChainID(1)) @@ -229,7 +233,7 @@ func TestContractCanEmulateIBCTransferMessage(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContract)), + wasmtesting.NewIBCContractMockWasmEngine(myContract)), } coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) @@ -304,7 +308,7 @@ func TestContractCanEmulateIBCTransferMessageWithTimeout(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContract)), + wasmtesting.NewIBCContractMockWasmEngine(myContract)), } coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts) @@ -385,10 +389,10 @@ func TestContractEmulateIBCTransferMessageOnDiffContractIBCChannel(t *testing.T) var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContractA1), + wasmtesting.NewIBCContractMockWasmEngine(myContractA1), ), wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContractA2), + wasmtesting.NewIBCContractMockWasmEngine(myContractA2), ), } @@ -448,11 +452,11 @@ func TestContractHandlesChannelClose(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContractA)), + wasmtesting.NewIBCContractMockWasmEngine(myContractA)), } chainBOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContractB)), + wasmtesting.NewIBCContractMockWasmEngine(myContractB)), } coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts, chainBOpts) @@ -494,13 +498,13 @@ func TestContractHandlesChannelCloseNotOwned(t *testing.T) { var ( chainAOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContractA1)), + wasmtesting.NewIBCContractMockWasmEngine(myContractA1)), wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContractA2)), + wasmtesting.NewIBCContractMockWasmEngine(myContractA2)), } chainBOpts = []wasmkeeper.Option{ wasmkeeper.WithWasmEngine( - wasmtesting.NewIBCContractMockWasmer(myContractB)), + wasmtesting.NewIBCContractMockWasmEngine(myContractB)), } coordinator = wasmibctesting.NewCoordinator(t, 2, chainAOpts, chainBOpts) diff --git a/x/wasm/simulation/genesis.go b/x/wasm/simulation/genesis.go index 5271bd2365..ce6916db0a 100644 --- a/x/wasm/simulation/genesis.go +++ b/x/wasm/simulation/genesis.go @@ -14,7 +14,7 @@ func RandomizedGenState(simstate *module.SimulationState) { Codes: nil, Contracts: nil, Sequences: []types.Sequence{ - {IDKey: types.KeyLastCodeID, Value: simstate.Rand.Uint64()}, + {IDKey: types.KeySequenceCodeID, Value: simstate.Rand.Uint64()}, }, GenMsgs: nil, } diff --git a/x/wasm/simulation/operations.go b/x/wasm/simulation/operations.go index ea5860b369..6e937badb4 100644 --- a/x/wasm/simulation/operations.go +++ b/x/wasm/simulation/operations.go @@ -5,9 +5,10 @@ import ( "math/rand" "os" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" + errorsmod "cosmossdk.io/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -25,7 +26,7 @@ import ( // Simulation operation weights constants // -//nolint:gosec + const ( OpWeightMsgStoreCode = "op_weight_msg_store_code" OpWeightMsgInstantiateContract = "op_weight_msg_instantiate_contract" diff --git a/x/wasm/types/authz.go b/x/wasm/types/authz.go index 9692088710..7a55dda860 100644 --- a/x/wasm/types/authz.go +++ b/x/wasm/types/authz.go @@ -1,25 +1,142 @@ package types import ( + "bytes" "strings" + wasmvm "github.com/CosmWasm/wasmvm" + "github.com/cosmos/gogoproto/proto" + errorsmod "cosmossdk.io/errors" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authztypes "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/cosmos/gogoproto/proto" + + "github.com/CosmWasm/wasmd/x/wasm/ioutils" ) -const gasDeserializationCostPerByte = uint64(1) +const ( + gasDeserializationCostPerByte = uint64(1) + // CodehashWildcard matches any code hash + CodehashWildcard = "*" +) var ( + _ authztypes.Authorization = &StoreCodeAuthorization{} _ authztypes.Authorization = &ContractExecutionAuthorization{} _ authztypes.Authorization = &ContractMigrationAuthorization{} _ cdctypes.UnpackInterfacesMessage = &ContractExecutionAuthorization{} _ cdctypes.UnpackInterfacesMessage = &ContractMigrationAuthorization{} ) +// NewStoreCodeAuthorization constructor +func NewStoreCodeAuthorization(grants ...CodeGrant) *StoreCodeAuthorization { + return &StoreCodeAuthorization{ + Grants: grants, + } +} + +// MsgTypeURL implements Authorization.MsgTypeURL. +func (a StoreCodeAuthorization) MsgTypeURL() string { + return sdk.MsgTypeURL(&MsgStoreCode{}) +} + +// Accept implements Authorization.Accept. +func (a *StoreCodeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authztypes.AcceptResponse, error) { + storeMsg, ok := msg.(*MsgStoreCode) + if !ok { + return authztypes.AcceptResponse{}, sdkerrors.ErrInvalidRequest.Wrap("unknown msg type") + } + + code := storeMsg.WASMByteCode + permission := storeMsg.InstantiatePermission + + if ioutils.IsGzip(code) { + gasRegister, ok := GasRegisterFromContext(ctx) + if !ok { + return authztypes.AcceptResponse{}, sdkerrors.ErrNotFound.Wrap("gas register") + } + ctx.GasMeter().ConsumeGas(gasRegister.UncompressCosts(len(code)), "Uncompress gzip bytecode") + wasmCode, err := ioutils.Uncompress(code, int64(MaxWasmSize)) + if err != nil { + return authztypes.AcceptResponse{}, sdkerrors.ErrInvalidRequest.Wrap("uncompress wasm archive") + } + code = wasmCode + } + + checksum, err := wasmvm.CreateChecksum(code) + if err != nil { + return authztypes.AcceptResponse{}, sdkerrors.ErrInvalidRequest.Wrap("checksum") + } + + for _, grant := range a.Grants { + if grant.Accept(checksum, permission) { + return authztypes.AcceptResponse{Accept: true}, nil + } + } + return authztypes.AcceptResponse{Accept: false}, nil +} + +// ValidateBasic implements Authorization.ValidateBasic. +func (a StoreCodeAuthorization) ValidateBasic() error { + numberOfGrants := len(a.Grants) + switch numberOfGrants { + case 0: + return ErrEmpty.Wrap("grants") + case 1: + if err := a.Grants[0].ValidateBasic(); err != nil { + return errorsmod.Wrapf(err, "position %d", 0) + } + default: + uniqueGrants := make(map[string]struct{}, numberOfGrants) + for i, grant := range a.Grants { + if strings.EqualFold(string(grant.CodeHash), CodehashWildcard) { + return sdkerrors.ErrInvalidRequest.Wrap("cannot have multiple grants when wildcard grant is one of them") + } + if err := grant.ValidateBasic(); err != nil { + return errorsmod.Wrapf(err, "position %d", i) + } + uniqueGrants[strings.ToLower(string(grant.CodeHash))] = struct{}{} + } + if len(uniqueGrants) != numberOfGrants { + return sdkerrors.ErrInvalidRequest.Wrap("cannot have multiple grants with same code hash") + } + } + return nil +} + +// NewCodeGrant constructor +func NewCodeGrant(codeHash []byte, instantiatePermission *AccessConfig) (*CodeGrant, error) { + return &CodeGrant{ + CodeHash: codeHash, + InstantiatePermission: instantiatePermission, + }, nil +} + +// ValidateBasic validates the grant +func (g CodeGrant) ValidateBasic() error { + if len(g.CodeHash) == 0 { + return ErrEmpty.Wrap("code hash") + } + if g.InstantiatePermission != nil { + return g.InstantiatePermission.ValidateBasic() + } + return nil +} + +// Accept checks if checksum and permission match the grant +func (g CodeGrant) Accept(checksum []byte, permission *AccessConfig) bool { + if !strings.EqualFold(string(g.CodeHash), CodehashWildcard) && !bytes.EqualFold(g.CodeHash, checksum) { + return false + } + if g.InstantiatePermission == nil { + return true + } + return permission.IsSubset(*g.InstantiatePermission) +} + // AuthzableWasmMsg is abstract wasm tx message that is supported in authz type AuthzableWasmMsg interface { GetFunds() sdk.Coins @@ -166,8 +283,8 @@ func AcceptGrantedMessage[T AuthzableWasmMsg](ctx sdk.Context, grants []Contract // finally do limit state updates in result switch { case result.DeleteLimit: - updatedGrants := append(grants[0:i], grants[i+1:]...) //nolint:gocritic - if len(updatedGrants) == 0 { // remove when empty + updatedGrants := append(grants[0:i], grants[i+1:]...) + if len(updatedGrants) == 0 { // remove when empty return authztypes.AcceptResponse{Accept: true, Delete: true}, nil } newAuthz := factory.NewAuthz(updatedGrants) diff --git a/x/wasm/types/authz.pb.go b/x/wasm/types/authz.pb.go index 26e28de48c..150758ce8f 100644 --- a/x/wasm/types/authz.pb.go +++ b/x/wasm/types/authz.pb.go @@ -28,6 +28,46 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// StoreCodeAuthorization defines authorization for wasm code upload. +// Since: wasmd 0.42 +type StoreCodeAuthorization struct { + // Grants for code upload + Grants []CodeGrant `protobuf:"bytes,1,rep,name=grants,proto3" json:"grants"` +} + +func (m *StoreCodeAuthorization) Reset() { *m = StoreCodeAuthorization{} } +func (m *StoreCodeAuthorization) String() string { return proto.CompactTextString(m) } +func (*StoreCodeAuthorization) ProtoMessage() {} +func (*StoreCodeAuthorization) Descriptor() ([]byte, []int) { + return fileDescriptor_36ff3a20cf32b258, []int{0} +} +func (m *StoreCodeAuthorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StoreCodeAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StoreCodeAuthorization.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StoreCodeAuthorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_StoreCodeAuthorization.Merge(m, src) +} +func (m *StoreCodeAuthorization) XXX_Size() int { + return m.Size() +} +func (m *StoreCodeAuthorization) XXX_DiscardUnknown() { + xxx_messageInfo_StoreCodeAuthorization.DiscardUnknown(m) +} + +var xxx_messageInfo_StoreCodeAuthorization proto.InternalMessageInfo + // ContractExecutionAuthorization defines authorization for wasm execute. // Since: wasmd 0.30 type ContractExecutionAuthorization struct { @@ -39,7 +79,7 @@ func (m *ContractExecutionAuthorization) Reset() { *m = ContractExecutio func (m *ContractExecutionAuthorization) String() string { return proto.CompactTextString(m) } func (*ContractExecutionAuthorization) ProtoMessage() {} func (*ContractExecutionAuthorization) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{0} + return fileDescriptor_36ff3a20cf32b258, []int{1} } func (m *ContractExecutionAuthorization) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,7 +119,7 @@ func (m *ContractMigrationAuthorization) Reset() { *m = ContractMigratio func (m *ContractMigrationAuthorization) String() string { return proto.CompactTextString(m) } func (*ContractMigrationAuthorization) ProtoMessage() {} func (*ContractMigrationAuthorization) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{1} + return fileDescriptor_36ff3a20cf32b258, []int{2} } func (m *ContractMigrationAuthorization) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -108,6 +148,50 @@ func (m *ContractMigrationAuthorization) XXX_DiscardUnknown() { var xxx_messageInfo_ContractMigrationAuthorization proto.InternalMessageInfo +// CodeGrant a granted permission for a single code +type CodeGrant struct { + // CodeHash is the unique identifier created by wasmvm + // Wildcard "*" is used to specify any kind of grant. + CodeHash []byte `protobuf:"bytes,1,opt,name=code_hash,json=codeHash,proto3" json:"code_hash,omitempty"` + // InstantiatePermission is the superset access control to apply + // on contract creation. + // Optional + InstantiatePermission *AccessConfig `protobuf:"bytes,2,opt,name=instantiate_permission,json=instantiatePermission,proto3" json:"instantiate_permission,omitempty"` +} + +func (m *CodeGrant) Reset() { *m = CodeGrant{} } +func (m *CodeGrant) String() string { return proto.CompactTextString(m) } +func (*CodeGrant) ProtoMessage() {} +func (*CodeGrant) Descriptor() ([]byte, []int) { + return fileDescriptor_36ff3a20cf32b258, []int{3} +} +func (m *CodeGrant) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CodeGrant) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CodeGrant.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CodeGrant) XXX_Merge(src proto.Message) { + xxx_messageInfo_CodeGrant.Merge(m, src) +} +func (m *CodeGrant) XXX_Size() int { + return m.Size() +} +func (m *CodeGrant) XXX_DiscardUnknown() { + xxx_messageInfo_CodeGrant.DiscardUnknown(m) +} + +var xxx_messageInfo_CodeGrant proto.InternalMessageInfo + // ContractGrant a granted permission for a single contract // Since: wasmd 0.30 type ContractGrant struct { @@ -126,7 +210,7 @@ func (m *ContractGrant) Reset() { *m = ContractGrant{} } func (m *ContractGrant) String() string { return proto.CompactTextString(m) } func (*ContractGrant) ProtoMessage() {} func (*ContractGrant) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{2} + return fileDescriptor_36ff3a20cf32b258, []int{4} } func (m *ContractGrant) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -166,7 +250,7 @@ func (m *MaxCallsLimit) Reset() { *m = MaxCallsLimit{} } func (m *MaxCallsLimit) String() string { return proto.CompactTextString(m) } func (*MaxCallsLimit) ProtoMessage() {} func (*MaxCallsLimit) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{3} + return fileDescriptor_36ff3a20cf32b258, []int{5} } func (m *MaxCallsLimit) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -206,7 +290,7 @@ func (m *MaxFundsLimit) Reset() { *m = MaxFundsLimit{} } func (m *MaxFundsLimit) String() string { return proto.CompactTextString(m) } func (*MaxFundsLimit) ProtoMessage() {} func (*MaxFundsLimit) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{4} + return fileDescriptor_36ff3a20cf32b258, []int{6} } func (m *MaxFundsLimit) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -249,7 +333,7 @@ func (m *CombinedLimit) Reset() { *m = CombinedLimit{} } func (m *CombinedLimit) String() string { return proto.CompactTextString(m) } func (*CombinedLimit) ProtoMessage() {} func (*CombinedLimit) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{5} + return fileDescriptor_36ff3a20cf32b258, []int{7} } func (m *CombinedLimit) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -288,7 +372,7 @@ func (m *AllowAllMessagesFilter) Reset() { *m = AllowAllMessagesFilter{} func (m *AllowAllMessagesFilter) String() string { return proto.CompactTextString(m) } func (*AllowAllMessagesFilter) ProtoMessage() {} func (*AllowAllMessagesFilter) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{6} + return fileDescriptor_36ff3a20cf32b258, []int{8} } func (m *AllowAllMessagesFilter) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -329,7 +413,7 @@ func (m *AcceptedMessageKeysFilter) Reset() { *m = AcceptedMessageKeysFi func (m *AcceptedMessageKeysFilter) String() string { return proto.CompactTextString(m) } func (*AcceptedMessageKeysFilter) ProtoMessage() {} func (*AcceptedMessageKeysFilter) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{7} + return fileDescriptor_36ff3a20cf32b258, []int{9} } func (m *AcceptedMessageKeysFilter) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -370,7 +454,7 @@ func (m *AcceptedMessagesFilter) Reset() { *m = AcceptedMessagesFilter{} func (m *AcceptedMessagesFilter) String() string { return proto.CompactTextString(m) } func (*AcceptedMessagesFilter) ProtoMessage() {} func (*AcceptedMessagesFilter) Descriptor() ([]byte, []int) { - return fileDescriptor_36ff3a20cf32b258, []int{8} + return fileDescriptor_36ff3a20cf32b258, []int{10} } func (m *AcceptedMessagesFilter) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -400,8 +484,10 @@ func (m *AcceptedMessagesFilter) XXX_DiscardUnknown() { var xxx_messageInfo_AcceptedMessagesFilter proto.InternalMessageInfo func init() { + proto.RegisterType((*StoreCodeAuthorization)(nil), "cosmwasm.wasm.v1.StoreCodeAuthorization") proto.RegisterType((*ContractExecutionAuthorization)(nil), "cosmwasm.wasm.v1.ContractExecutionAuthorization") proto.RegisterType((*ContractMigrationAuthorization)(nil), "cosmwasm.wasm.v1.ContractMigrationAuthorization") + proto.RegisterType((*CodeGrant)(nil), "cosmwasm.wasm.v1.CodeGrant") proto.RegisterType((*ContractGrant)(nil), "cosmwasm.wasm.v1.ContractGrant") proto.RegisterType((*MaxCallsLimit)(nil), "cosmwasm.wasm.v1.MaxCallsLimit") proto.RegisterType((*MaxFundsLimit)(nil), "cosmwasm.wasm.v1.MaxFundsLimit") @@ -414,49 +500,93 @@ func init() { func init() { proto.RegisterFile("cosmwasm/wasm/v1/authz.proto", fileDescriptor_36ff3a20cf32b258) } var fileDescriptor_36ff3a20cf32b258 = []byte{ - // 665 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0x4d, 0x4f, 0xd4, 0x40, - 0x18, 0xde, 0x01, 0x44, 0x76, 0x10, 0x3f, 0x1a, 0x42, 0x16, 0x24, 0x5d, 0x52, 0xbf, 0x56, 0x92, - 0x6d, 0xb3, 0x18, 0x2f, 0x7b, 0x31, 0xbb, 0xab, 0x18, 0x23, 0x78, 0x68, 0x4c, 0x20, 0x5e, 0xc8, - 0xb4, 0x3b, 0x94, 0x91, 0x76, 0x86, 0x74, 0xa6, 0xc0, 0x92, 0xf8, 0x07, 0x3c, 0x79, 0xf3, 0x2f, - 0x18, 0x4f, 0x1c, 0xf6, 0xe8, 0x0f, 0x20, 0x9c, 0x38, 0x1a, 0x0f, 0xa8, 0x10, 0xc3, 0x7f, 0xf0, - 0x64, 0x3a, 0x33, 0x5d, 0x58, 0x02, 0x1b, 0xe4, 0xc4, 0x65, 0xda, 0xf7, 0x7d, 0x67, 0x9e, 0xe7, - 0x79, 0x3f, 0xda, 0x81, 0x93, 0x3e, 0xe3, 0xd1, 0x06, 0xe2, 0x91, 0x23, 0x97, 0xf5, 0x8a, 0x83, - 0x12, 0xb1, 0xb2, 0x65, 0xaf, 0xc5, 0x4c, 0x30, 0xe3, 0x76, 0x16, 0xb5, 0xe5, 0xb2, 0x5e, 0x99, - 0x18, 0x0d, 0x58, 0xc0, 0x64, 0xd0, 0x49, 0xdf, 0xd4, 0xbe, 0x89, 0xf1, 0x74, 0x1f, 0xe3, 0x4b, - 0x2a, 0xa0, 0x0c, 0x1d, 0x32, 0x95, 0xe5, 0x78, 0x88, 0x63, 0x67, 0xbd, 0xe2, 0x61, 0x81, 0x2a, - 0x8e, 0xcf, 0x08, 0xcd, 0x8e, 0x06, 0x8c, 0x05, 0x21, 0x76, 0xa4, 0xe5, 0x25, 0xcb, 0x0e, 0xa2, - 0x2d, 0x1d, 0xba, 0x83, 0x22, 0x42, 0x99, 0x23, 0x57, 0xe5, 0xb2, 0xda, 0x00, 0x9a, 0x0d, 0x46, - 0x45, 0x8c, 0x7c, 0xf1, 0x62, 0x13, 0xfb, 0x89, 0x20, 0x8c, 0xd6, 0x12, 0xb1, 0xc2, 0x62, 0xb2, - 0x85, 0x52, 0xc3, 0xa8, 0xc3, 0xc1, 0x20, 0x46, 0x54, 0xf0, 0x02, 0x98, 0xea, 0x2f, 0x0d, 0xcf, - 0x14, 0xed, 0xd3, 0x49, 0xd8, 0x19, 0xc2, 0xcb, 0x74, 0x5f, 0x3d, 0xbf, 0xb3, 0x5f, 0xcc, 0x7d, - 0x39, 0xda, 0x9e, 0x06, 0xae, 0x3e, 0x59, 0x7d, 0xb3, 0xdb, 0x2e, 0x5b, 0x3a, 0x0d, 0x55, 0x0f, - 0xad, 0xdc, 0xee, 0xe2, 0xfa, 0x78, 0xb4, 0x3d, 0x7d, 0x4f, 0xd6, 0xad, 0xb7, 0xa6, 0x2e, 0xd9, - 0xf3, 0x24, 0x88, 0xd1, 0x15, 0x93, 0x7d, 0xb6, 0x26, 0xeb, 0x07, 0x80, 0x23, 0x5d, 0xa4, 0xc6, - 0x04, 0x1c, 0xf2, 0xb5, 0xa3, 0x00, 0xa6, 0x40, 0x29, 0xef, 0x76, 0x6c, 0xe3, 0x2d, 0xbc, 0x16, - 0x92, 0x88, 0x88, 0x42, 0xdf, 0x14, 0x28, 0x0d, 0xcf, 0x8c, 0xda, 0xaa, 0xb3, 0x76, 0xd6, 0x59, - 0xbb, 0x46, 0x5b, 0xf5, 0xd2, 0x6e, 0xbb, 0x7c, 0xff, 0xdc, 0xcc, 0x52, 0xfa, 0xad, 0xb9, 0x14, - 0x64, 0xd1, 0x55, 0x60, 0xc6, 0x02, 0x1c, 0x5c, 0x26, 0xa1, 0xc0, 0x71, 0xa1, 0xbf, 0x07, 0xec, - 0xe3, 0xdd, 0x76, 0xf9, 0x41, 0x6f, 0xd8, 0x59, 0x89, 0xb2, 0xe8, 0x6a, 0x38, 0x8b, 0xc2, 0x91, - 0x79, 0xb4, 0xd9, 0x40, 0x61, 0xc8, 0x25, 0xa3, 0x31, 0x09, 0xf3, 0x31, 0x8e, 0x10, 0xa1, 0x84, - 0x06, 0x32, 0xb9, 0x01, 0xf7, 0xd8, 0x51, 0x7d, 0x76, 0x51, 0xe1, 0x69, 0x75, 0x0d, 0x59, 0xdd, - 0x2e, 0x78, 0xeb, 0x1b, 0x90, 0x84, 0xb3, 0x09, 0x6d, 0x6a, 0xc2, 0xf7, 0xf0, 0x3a, 0x8a, 0x58, - 0x72, 0xdc, 0xf3, 0x71, 0x5b, 0x37, 0x2f, 0xfd, 0x58, 0x3a, 0xbd, 0x6b, 0x30, 0x42, 0xeb, 0x4f, - 0xd3, 0x6e, 0x7f, 0xfd, 0x59, 0x2c, 0x05, 0x44, 0xac, 0x24, 0x9e, 0xed, 0xb3, 0x48, 0x7f, 0x67, - 0xfa, 0x51, 0xe6, 0xcd, 0x55, 0x47, 0xb4, 0xd6, 0x30, 0x97, 0x07, 0xb8, 0x9a, 0x8c, 0x8c, 0xe0, - 0x92, 0xf2, 0x8f, 0xc5, 0x5a, 0x7f, 0xe4, 0x2c, 0x44, 0x1e, 0xa1, 0xb8, 0xa9, 0xe4, 0x3f, 0x82, - 0xb7, 0xfc, 0x34, 0xbd, 0xa5, 0xd3, 0x55, 0xbb, 0x29, 0xdd, 0x6e, 0xe6, 0x3d, 0x99, 0x67, 0xdf, - 0x15, 0xcc, 0xb3, 0x2b, 0x2b, 0xcb, 0x87, 0x63, 0xb5, 0x30, 0x64, 0x1b, 0xb5, 0x30, 0x9c, 0xc7, - 0x9c, 0xa3, 0x00, 0x73, 0x35, 0x39, 0xd5, 0x57, 0x17, 0x9e, 0xb1, 0x14, 0xfb, 0xae, 0xc4, 0x3e, - 0x1b, 0xca, 0xfa, 0x00, 0xc7, 0x6b, 0xbe, 0x8f, 0xd7, 0x04, 0x6e, 0xea, 0xc8, 0x6b, 0xdc, 0xd2, - 0x41, 0xc3, 0x80, 0x03, 0xab, 0xb8, 0xa5, 0x66, 0x22, 0xef, 0xca, 0xf7, 0xea, 0xdc, 0x7f, 0x71, - 0x9b, 0x8a, 0xfb, 0x3c, 0x06, 0xeb, 0x33, 0x80, 0x63, 0xa7, 0xa2, 0x19, 0xf9, 0x0c, 0x1c, 0x8a, - 0xb4, 0x47, 0x0a, 0xb8, 0x51, 0x1f, 0xfb, 0xbb, 0x5f, 0x34, 0x5c, 0xb4, 0xd1, 0xf9, 0x57, 0xa8, - 0xb0, 0xdb, 0xd9, 0x77, 0xb9, 0xc2, 0x9c, 0x49, 0x5f, 0x7f, 0xbe, 0xf3, 0xdb, 0xcc, 0xed, 0x1c, - 0x98, 0x60, 0xef, 0xc0, 0x04, 0xbf, 0x0e, 0x4c, 0xf0, 0xe9, 0xd0, 0xcc, 0xed, 0x1d, 0x9a, 0xb9, - 0xef, 0x87, 0x66, 0xee, 0xdd, 0xc3, 0x13, 0x43, 0xd1, 0x60, 0x3c, 0x5a, 0xc8, 0xee, 0xad, 0xa6, - 0xb3, 0xa9, 0xee, 0x2f, 0x39, 0x18, 0xde, 0xa0, 0xfc, 0x37, 0x3c, 0xf9, 0x17, 0x00, 0x00, 0xff, - 0xff, 0x84, 0xc4, 0x51, 0x3d, 0xdd, 0x06, 0x00, 0x00, + // 772 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0xcf, 0x4f, 0x13, 0x4d, + 0x18, 0xee, 0x02, 0x1f, 0x1f, 0x1d, 0xe0, 0xfb, 0xb1, 0xe1, 0x6b, 0x5a, 0x20, 0x5b, 0xb2, 0xdf, + 0xaf, 0x4a, 0xd2, 0xdd, 0x14, 0xe3, 0xa5, 0x07, 0x4d, 0x5b, 0x45, 0x8d, 0x60, 0xcc, 0xaa, 0x81, + 0x78, 0x69, 0xa6, 0xdb, 0x61, 0x3b, 0xb2, 0x3b, 0xd3, 0xec, 0x4c, 0x81, 0x92, 0x18, 0xef, 0x9e, + 0xbc, 0x79, 0xf5, 0x68, 0x3c, 0x71, 0xe8, 0xd1, 0x3f, 0x80, 0x70, 0xe2, 0x68, 0x3c, 0xa0, 0x42, + 0x0c, 0xff, 0x83, 0x27, 0xb3, 0x33, 0xd3, 0x96, 0x96, 0x42, 0x90, 0x13, 0x97, 0xed, 0xce, 0xfb, + 0xce, 0xfb, 0x3e, 0xcf, 0x33, 0xf3, 0xf4, 0x5d, 0x30, 0xeb, 0x52, 0x16, 0x6c, 0x42, 0x16, 0xd8, + 0xe2, 0xb1, 0x91, 0xb3, 0x61, 0x83, 0xd7, 0xb6, 0xad, 0x7a, 0x48, 0x39, 0xd5, 0xff, 0x68, 0x67, + 0x2d, 0xf1, 0xd8, 0xc8, 0x4d, 0x4f, 0x79, 0xd4, 0xa3, 0x22, 0x69, 0x47, 0x6f, 0x72, 0xdf, 0x74, + 0x2a, 0xda, 0x47, 0x59, 0x59, 0x26, 0xe4, 0x42, 0xa5, 0x0c, 0xb9, 0xb2, 0x2b, 0x90, 0x21, 0x7b, + 0x23, 0x57, 0x41, 0x1c, 0xe6, 0x6c, 0x97, 0x62, 0xa2, 0xf2, 0xa7, 0x09, 0xf0, 0x66, 0x1d, 0xb5, + 0xab, 0x53, 0x1e, 0xa5, 0x9e, 0x8f, 0x6c, 0xb1, 0xaa, 0x34, 0xd6, 0x6c, 0x48, 0x9a, 0x2a, 0xf5, + 0x27, 0x0c, 0x30, 0xa1, 0xb6, 0x78, 0xca, 0x90, 0xf9, 0x56, 0x03, 0x89, 0xc7, 0x9c, 0x86, 0xa8, + 0x44, 0xab, 0xa8, 0xd0, 0xe0, 0x35, 0x1a, 0xe2, 0x6d, 0xc8, 0x31, 0x25, 0xfa, 0x4d, 0x30, 0xea, + 0x85, 0x90, 0x70, 0x96, 0xd4, 0xe6, 0x86, 0x33, 0xe3, 0x0b, 0x33, 0x56, 0xbf, 0x34, 0x2b, 0x2a, + 0xba, 0x1b, 0xed, 0x29, 0xc6, 0x77, 0x0f, 0xd2, 0xb1, 0x77, 0xc7, 0x3b, 0xf3, 0x9a, 0xa3, 0xaa, + 0xf2, 0x8b, 0x7b, 0xad, 0xac, 0xa9, 0x84, 0xc9, 0x13, 0x52, 0x5a, 0xac, 0x1e, 0x9c, 0x57, 0xc7, + 0x3b, 0xf3, 0x33, 0x42, 0xc8, 0x60, 0x1e, 0x66, 0x4b, 0x03, 0x46, 0x89, 0x12, 0x1e, 0x42, 0x97, + 0xdf, 0xd9, 0x42, 0x6e, 0x23, 0x8a, 0xf6, 0x52, 0x2d, 0xf6, 0x51, 0x4d, 0x0f, 0xa2, 0x2a, 0x3b, + 0x9c, 0x49, 0xf7, 0xe1, 0xc5, 0xe9, 0xfe, 0x2d, 0xe8, 0x9e, 0xcf, 0xa9, 0x87, 0xf6, 0x32, 0xf6, + 0x42, 0x78, 0xc5, 0x68, 0x0f, 0xe6, 0x64, 0xbe, 0x04, 0xf1, 0xce, 0xad, 0xea, 0x33, 0x20, 0xee, + 0xd2, 0x2a, 0x2a, 0xd7, 0x20, 0xab, 0x25, 0xb5, 0x39, 0x2d, 0x33, 0xe1, 0x8c, 0x45, 0x81, 0x7b, + 0x90, 0xd5, 0xf4, 0xa7, 0x20, 0x81, 0x09, 0xe3, 0x90, 0x70, 0x0c, 0x39, 0x2a, 0xd7, 0x51, 0x18, + 0x60, 0xc6, 0x30, 0x25, 0xc9, 0xa1, 0x39, 0x2d, 0x33, 0xbe, 0x60, 0x9c, 0x56, 0x53, 0x70, 0x5d, + 0xc4, 0x58, 0x89, 0x92, 0x35, 0xec, 0x39, 0x7f, 0x9d, 0xa8, 0x7e, 0xd4, 0x29, 0x36, 0x3f, 0x69, + 0x60, 0xb2, 0x47, 0xb5, 0x3e, 0x0d, 0xc6, 0x5c, 0x15, 0x10, 0x24, 0xe2, 0x4e, 0x67, 0xad, 0x3f, + 0x01, 0xbf, 0xf8, 0x38, 0xc0, 0x5c, 0x61, 0x4e, 0x59, 0xd2, 0xfd, 0x56, 0xdb, 0xfd, 0x56, 0x81, + 0x34, 0x8b, 0x99, 0xbd, 0x56, 0xf6, 0x9f, 0x33, 0x8f, 0x36, 0xd2, 0xbf, 0xbd, 0x14, 0x35, 0x59, + 0x75, 0x64, 0x33, 0x7d, 0x05, 0x8c, 0xae, 0x61, 0x9f, 0xa3, 0x30, 0x39, 0x7c, 0x4e, 0xdb, 0x6b, + 0x7b, 0xad, 0xec, 0xbf, 0xe7, 0xb7, 0x5d, 0x14, 0x5d, 0x56, 0x1d, 0xd5, 0xce, 0x24, 0x60, 0x72, + 0x19, 0x6e, 0x95, 0xa0, 0xef, 0x33, 0x81, 0xa8, 0xcf, 0x82, 0x78, 0x88, 0x02, 0x88, 0x09, 0x26, + 0x9e, 0x10, 0x37, 0xe2, 0x74, 0x03, 0xf9, 0x5b, 0x17, 0x25, 0x1e, 0x5d, 0xaf, 0x2e, 0xae, 0xb7, + 0xa7, 0xbd, 0xf9, 0x41, 0x13, 0x80, 0x8b, 0x0d, 0x52, 0x55, 0x80, 0xcf, 0xc1, 0xaf, 0x30, 0xa0, + 0x8d, 0xae, 0xe9, 0x52, 0x96, 0x72, 0x4f, 0x34, 0x6e, 0x3a, 0xe6, 0x29, 0x51, 0x4c, 0x8a, 0x37, + 0x22, 0xbb, 0xbd, 0xff, 0x9c, 0xce, 0x78, 0x98, 0xd7, 0x1a, 0x15, 0xcb, 0xa5, 0x81, 0x9a, 0x54, + 0xea, 0x27, 0xcb, 0xaa, 0xeb, 0x6a, 0xf8, 0x44, 0x05, 0x4c, 0x5a, 0xb3, 0x0d, 0x70, 0x49, 0xfa, + 0x5d, 0xb2, 0xe6, 0x37, 0xe1, 0x85, 0xa0, 0x82, 0x09, 0xaa, 0x4a, 0xfa, 0xff, 0x83, 0xdf, 0xdd, + 0x48, 0x5e, 0xb9, 0xff, 0xd4, 0x7e, 0x13, 0x61, 0xa7, 0x1d, 0x3d, 0xa9, 0x73, 0xe8, 0x0a, 0xea, + 0xec, 0x51, 0x65, 0xba, 0x20, 0x51, 0xf0, 0x7d, 0xba, 0x59, 0xf0, 0xfd, 0x65, 0xc4, 0x18, 0xf4, + 0x10, 0x93, 0xce, 0xc9, 0xdf, 0xbf, 0xb0, 0xc7, 0xba, 0x73, 0x74, 0x70, 0x2b, 0xf3, 0x05, 0x48, + 0x45, 0xff, 0xbf, 0x3a, 0x47, 0x55, 0x95, 0x79, 0x80, 0x9a, 0x2a, 0xa9, 0xeb, 0x60, 0x64, 0x1d, + 0x35, 0xa5, 0x27, 0xe2, 0x8e, 0x78, 0xcf, 0x2f, 0xfd, 0x14, 0xb6, 0x21, 0xb1, 0xcf, 0x42, 0x30, + 0xdf, 0x68, 0x20, 0xd1, 0x97, 0x6d, 0x83, 0x2f, 0x80, 0xb1, 0x40, 0x45, 0x04, 0x81, 0x89, 0x62, + 0xe2, 0xfb, 0x41, 0x5a, 0x77, 0xe0, 0x66, 0x67, 0x58, 0xc9, 0xb4, 0xd3, 0xd9, 0x77, 0xb9, 0x83, + 0x19, 0x08, 0x5f, 0xbc, 0xbd, 0xfb, 0xd5, 0x88, 0xed, 0x1e, 0x1a, 0xda, 0xfe, 0xa1, 0xa1, 0x7d, + 0x39, 0x34, 0xb4, 0xd7, 0x47, 0x46, 0x6c, 0xff, 0xc8, 0x88, 0x7d, 0x3c, 0x32, 0x62, 0xcf, 0xfe, + 0x3b, 0x61, 0x8a, 0x12, 0x65, 0xc1, 0x4a, 0xfb, 0xc3, 0x5b, 0xb5, 0xb7, 0xe4, 0x07, 0x58, 0x18, + 0xa3, 0x32, 0x2a, 0x66, 0xc3, 0xf5, 0x1f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x55, 0xf8, 0x5e, 0x18, + 0x1f, 0x08, 0x00, 0x00, +} + +func (m *StoreCodeAuthorization) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *StoreCodeAuthorization) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StoreCodeAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Grants) > 0 { + for iNdEx := len(m.Grants) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Grants[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAuthz(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil } func (m *ContractExecutionAuthorization) Marshal() (dAtA []byte, err error) { @@ -533,6 +663,48 @@ func (m *ContractMigrationAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, return len(dAtA) - i, nil } +func (m *CodeGrant) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CodeGrant) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CodeGrant) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.InstantiatePermission != nil { + { + size, err := m.InstantiatePermission.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAuthz(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.CodeHash) > 0 { + i -= len(m.CodeHash) + copy(dAtA[i:], m.CodeHash) + i = encodeVarintAuthz(dAtA, i, uint64(len(m.CodeHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *ContractGrant) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -792,6 +964,21 @@ func encodeVarintAuthz(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *StoreCodeAuthorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Grants) > 0 { + for _, e := range m.Grants { + l = e.Size() + n += 1 + l + sovAuthz(uint64(l)) + } + } + return n +} + func (m *ContractExecutionAuthorization) Size() (n int) { if m == nil { return 0 @@ -822,6 +1009,23 @@ func (m *ContractMigrationAuthorization) Size() (n int) { return n } +func (m *CodeGrant) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CodeHash) + if l > 0 { + n += 1 + l + sovAuthz(uint64(l)) + } + if m.InstantiatePermission != nil { + l = m.InstantiatePermission.Size() + n += 1 + l + sovAuthz(uint64(l)) + } + return n +} + func (m *ContractGrant) Size() (n int) { if m == nil { return 0 @@ -933,6 +1137,90 @@ func sovAuthz(x uint64) (n int) { func sozAuthz(x uint64) (n int) { return sovAuthz(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *StoreCodeAuthorization) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: StoreCodeAuthorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StoreCodeAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Grants", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAuthz + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Grants = append(m.Grants, CodeGrant{}) + if err := m.Grants[len(m.Grants)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAuthz(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAuthz + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *ContractExecutionAuthorization) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1101,6 +1389,126 @@ func (m *ContractMigrationAuthorization) Unmarshal(dAtA []byte) error { } return nil } +func (m *CodeGrant) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CodeGrant: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CodeGrant: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CodeHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAuthz + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CodeHash = append(m.CodeHash[:0], dAtA[iNdEx:postIndex]...) + if m.CodeHash == nil { + m.CodeHash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InstantiatePermission", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAuthz + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.InstantiatePermission == nil { + m.InstantiatePermission = &AccessConfig{} + } + if err := m.InstantiatePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAuthz(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAuthz + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *ContractGrant) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/wasm/types/authz_policy.go b/x/wasm/types/authz_policy.go index 8e812f2b93..335f315d03 100644 --- a/x/wasm/types/authz_policy.go +++ b/x/wasm/types/authz_policy.go @@ -11,7 +11,7 @@ type ChainAccessConfigs struct { } // NewChainAccessConfigs constructor -func NewChainAccessConfigs(upload AccessConfig, instantiate AccessConfig) ChainAccessConfigs { +func NewChainAccessConfigs(upload, instantiate AccessConfig) ChainAccessConfigs { return ChainAccessConfigs{Upload: upload, Instantiate: instantiate} } diff --git a/x/wasm/types/authz_test.go b/x/wasm/types/authz_test.go index 79d279b258..65667218b9 100644 --- a/x/wasm/types/authz_test.go +++ b/x/wasm/types/authz_test.go @@ -2,15 +2,18 @@ package types import ( "math" + "strings" "testing" + wasmvm "github.com/CosmWasm/wasmvm" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + errorsmod "cosmossdk.io/errors" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authztypes "github.com/cosmos/cosmos-sdk/x/authz" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authztypes "github.com/cosmos/cosmos-sdk/x/authz" ) func TestContractAuthzFilterValidate(t *testing.T) { @@ -478,23 +481,23 @@ func TestValidateContractAuthorization(t *testing.T) { }{ "contract execution": { setup: func(t *testing.T) validatable { - return NewContractMigrationAuthorization(*validGrant) + return NewContractExecutionAuthorization(*validGrant) }, }, "contract execution - duplicate grants": { setup: func(t *testing.T) validatable { - return NewContractMigrationAuthorization(*validGrant, *validGrant) + return NewContractExecutionAuthorization(*validGrant, *validGrant) }, }, "contract execution - invalid grant": { setup: func(t *testing.T) validatable { - return NewContractMigrationAuthorization(*validGrant, *invalidGrant) + return NewContractExecutionAuthorization(*validGrant, *invalidGrant) }, expErr: true, }, "contract execution - empty grants": { setup: func(t *testing.T) validatable { - return NewContractMigrationAuthorization() + return NewContractExecutionAuthorization() }, expErr: true, }, @@ -727,3 +730,243 @@ func mustGrant(contract sdk.AccAddress, limit ContractAuthzLimitX, filter Contra } return *g } + +func TestValidateCodeGrant(t *testing.T) { + specs := map[string]struct { + codeHash []byte + instantiatePermission *AccessConfig + expErr bool + }{ + "all good": { + codeHash: []byte("any_valid_checksum"), + instantiatePermission: &AllowEverybody, + }, + "empty permission": { + codeHash: []byte("any_valid_checksum"), + expErr: false, + }, + "empty code hash": { + codeHash: []byte{}, + instantiatePermission: &AllowEverybody, + expErr: true, + }, + "nil code hash": { + codeHash: nil, + instantiatePermission: &AllowEverybody, + expErr: true, + }, + "invalid permission": { + codeHash: []byte("any_valid_checksum"), + instantiatePermission: &AccessConfig{Permission: AccessTypeUnspecified}, + expErr: true, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + grant, err := NewCodeGrant(spec.codeHash, spec.instantiatePermission) + require.NoError(t, err) + + gotErr := grant.ValidateBasic() + if spec.expErr { + require.Error(t, gotErr) + return + } + require.NoError(t, gotErr) + }) + } +} + +func TestValidateStoreCodeAuthorization(t *testing.T) { + validGrant, err := NewCodeGrant([]byte("any_valid_checksum"), &AllowEverybody) + require.NoError(t, err) + validGrantUpperCase, err := NewCodeGrant([]byte("ANY_VALID_CHECKSUM"), &AllowEverybody) + require.NoError(t, err) + invalidGrant, err := NewCodeGrant(nil, &AllowEverybody) + require.NoError(t, err) + wildcardGrant, err := NewCodeGrant([]byte("*"), &AllowEverybody) + require.NoError(t, err) + emptyPermissionGrant, err := NewCodeGrant([]byte("any_valid_checksum"), nil) + require.NoError(t, err) + + specs := map[string]struct { + setup func(t *testing.T) []CodeGrant + expErr bool + }{ + "all good": { + setup: func(t *testing.T) []CodeGrant { + return []CodeGrant{*validGrant} + }, + }, + "wildcard grant": { + setup: func(t *testing.T) []CodeGrant { + return []CodeGrant{*wildcardGrant} + }, + }, + "empty permission grant": { + setup: func(t *testing.T) []CodeGrant { + return []CodeGrant{*emptyPermissionGrant} + }, + }, + "duplicate grants - wildcard": { + setup: func(t *testing.T) []CodeGrant { + return []CodeGrant{*wildcardGrant, *validGrant} + }, + expErr: true, + }, + "duplicate grants - same case code hash": { + setup: func(t *testing.T) []CodeGrant { + return []CodeGrant{*validGrant, *validGrant} + }, + expErr: true, + }, + "duplicate grants - different case code hash": { + setup: func(t *testing.T) []CodeGrant { + return []CodeGrant{*validGrant, *validGrantUpperCase} + }, + expErr: true, + }, + "invalid grant": { + setup: func(t *testing.T) []CodeGrant { + return []CodeGrant{*validGrant, *invalidGrant} + }, + expErr: true, + }, + "empty grants": { + setup: func(t *testing.T) []CodeGrant { + return []CodeGrant{} + }, + expErr: true, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + gotErr := NewStoreCodeAuthorization(spec.setup(t)...).ValidateBasic() + if spec.expErr { + require.Error(t, gotErr) + return + } + require.NoError(t, gotErr) + }) + } +} + +func TestStoreCodeAuthorizationAccept(t *testing.T) { + reflectCodeHash, err := wasmvm.CreateChecksum(reflectWasmCode) + require.NoError(t, err) + + reflectCodeHashUpperCase := strings.ToUpper(string(reflectCodeHash)) + + grantWildcard, err := NewCodeGrant([]byte("*"), &AllowEverybody) + require.NoError(t, err) + + grantReflectCode, err := NewCodeGrant(reflectCodeHash, &AllowNobody) + require.NoError(t, err) + + grantReflectCodeUpperCase, err := NewCodeGrant([]byte(reflectCodeHashUpperCase), &AllowNobody) + require.NoError(t, err) + + grantOtherCode, err := NewCodeGrant([]byte("any_valid_checksum"), &AllowEverybody) + require.NoError(t, err) + + emptyPermissionReflectCodeGrant, err := NewCodeGrant(reflectCodeHash, nil) + require.NoError(t, err) + + specs := map[string]struct { + auth authztypes.Authorization + msg sdk.Msg + expResult authztypes.AcceptResponse + expErr *errorsmod.Error + }{ + "accepted wildcard": { + auth: NewStoreCodeAuthorization(*grantWildcard), + msg: &MsgStoreCode{ + Sender: sdk.AccAddress(randBytes(SDKAddrLen)).String(), + WASMByteCode: reflectWasmCode, + InstantiatePermission: &AllowEverybody, + }, + expResult: authztypes.AcceptResponse{ + Accept: true, + }, + }, + "accepted reflect code": { + auth: NewStoreCodeAuthorization(*grantReflectCode), + msg: &MsgStoreCode{ + Sender: sdk.AccAddress(randBytes(SDKAddrLen)).String(), + WASMByteCode: reflectWasmCode, + InstantiatePermission: &AllowNobody, + }, + expResult: authztypes.AcceptResponse{ + Accept: true, + }, + }, + "accepted reflect code - empty permission": { + auth: NewStoreCodeAuthorization(*emptyPermissionReflectCodeGrant), + msg: &MsgStoreCode{ + Sender: sdk.AccAddress(randBytes(SDKAddrLen)).String(), + WASMByteCode: reflectWasmCode, + InstantiatePermission: &AllowNobody, + }, + expResult: authztypes.AcceptResponse{ + Accept: true, + }, + }, + "accepted reflect code - different case": { + auth: NewStoreCodeAuthorization(*grantReflectCodeUpperCase), + msg: &MsgStoreCode{ + Sender: sdk.AccAddress(randBytes(SDKAddrLen)).String(), + WASMByteCode: reflectWasmCode, + InstantiatePermission: &AllowNobody, + }, + expResult: authztypes.AcceptResponse{ + Accept: true, + }, + }, + "not accepted - no matching code": { + auth: NewStoreCodeAuthorization(*grantOtherCode), + msg: &MsgStoreCode{ + Sender: sdk.AccAddress(randBytes(SDKAddrLen)).String(), + WASMByteCode: reflectWasmCode, + InstantiatePermission: &AllowEverybody, + }, + expResult: authztypes.AcceptResponse{ + Accept: false, + }, + }, + "not accepted - no matching permission": { + auth: NewStoreCodeAuthorization(*grantReflectCode), + msg: &MsgStoreCode{ + Sender: sdk.AccAddress(randBytes(SDKAddrLen)).String(), + WASMByteCode: reflectWasmCode, + InstantiatePermission: &AllowEverybody, + }, + expResult: authztypes.AcceptResponse{ + Accept: false, + }, + }, + "invalid msg type": { + auth: NewStoreCodeAuthorization(*grantWildcard), + msg: &MsgMigrateContract{ + Sender: sdk.AccAddress(randBytes(SDKAddrLen)).String(), + Contract: sdk.AccAddress(randBytes(SDKAddrLen)).String(), + CodeID: 1, + Msg: []byte(`{"foo":"bar"}`), + }, + expResult: authztypes.AcceptResponse{ + Accept: false, + }, + expErr: sdkerrors.ErrInvalidRequest, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + ctx := sdk.Context{}.WithGasMeter(sdk.NewInfiniteGasMeter()) + gotResult, gotErr := spec.auth.Accept(ctx, spec.msg) + if spec.expErr != nil { + require.ErrorIs(t, gotErr, spec.expErr) + return + } + require.NoError(t, gotErr) + assert.Equal(t, spec.expResult, gotResult) + }) + } +} diff --git a/x/wasm/types/codec.go b/x/wasm/types/codec.go index aafa435fb9..c1fcfb9972 100644 --- a/x/wasm/types/codec.go +++ b/x/wasm/types/codec.go @@ -30,19 +30,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgStoreAndInstantiateContract{}, "wasm/MsgStoreAndInstantiateContract", nil) cdc.RegisterConcrete(&MsgAddCodeUploadParamsAddresses{}, "wasm/MsgAddCodeUploadParamsAddresses", nil) cdc.RegisterConcrete(&MsgRemoveCodeUploadParamsAddresses{}, "wasm/MsgRemoveCodeUploadParamsAddresses", nil) - - cdc.RegisterConcrete(&PinCodesProposal{}, "wasm/PinCodesProposal", nil) - cdc.RegisterConcrete(&UnpinCodesProposal{}, "wasm/UnpinCodesProposal", nil) - cdc.RegisterConcrete(&StoreCodeProposal{}, "wasm/StoreCodeProposal", nil) - cdc.RegisterConcrete(&InstantiateContractProposal{}, "wasm/InstantiateContractProposal", nil) - cdc.RegisterConcrete(&InstantiateContract2Proposal{}, "wasm/InstantiateContract2Proposal", nil) - cdc.RegisterConcrete(&MigrateContractProposal{}, "wasm/MigrateContractProposal", nil) - cdc.RegisterConcrete(&SudoContractProposal{}, "wasm/SudoContractProposal", nil) - cdc.RegisterConcrete(&ExecuteContractProposal{}, "wasm/ExecuteContractProposal", nil) - cdc.RegisterConcrete(&UpdateAdminProposal{}, "wasm/UpdateAdminProposal", nil) - cdc.RegisterConcrete(&ClearAdminProposal{}, "wasm/ClearAdminProposal", nil) - cdc.RegisterConcrete(&UpdateInstantiateConfigProposal{}, "wasm/UpdateInstantiateConfigProposal", nil) - cdc.RegisterConcrete(&StoreAndInstantiateContractProposal{}, "wasm/StoreAndInstantiateContractProposal", nil) + cdc.RegisterConcrete(&MsgStoreAndMigrateContract{}, "wasm/MsgStoreAndMigrateContract", nil) + cdc.RegisterConcrete(&MsgUpdateContractLabel{}, "wasm/MsgUpdateContractLabel", nil) cdc.RegisterInterface((*ContractInfoExtension)(nil), nil) @@ -56,6 +45,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MaxFundsLimit{}, "wasm/MaxFundsLimit", nil) cdc.RegisterConcrete(&CombinedLimit{}, "wasm/CombinedLimit", nil) + cdc.RegisterConcrete(&StoreCodeAuthorization{}, "wasm/StoreCodeAuthorization", nil) cdc.RegisterConcrete(&ContractExecutionAuthorization{}, "wasm/ContractExecutionAuthorization", nil) cdc.RegisterConcrete(&ContractMigrationAuthorization{}, "wasm/ContractMigrationAuthorization", nil) } @@ -80,21 +70,11 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { &MsgStoreAndInstantiateContract{}, &MsgAddCodeUploadParamsAddresses{}, &MsgRemoveCodeUploadParamsAddresses{}, + &MsgStoreAndMigrateContract{}, + &MsgUpdateContractLabel{}, ) registry.RegisterImplementations( (*v1beta1.Content)(nil), - &StoreCodeProposal{}, - &InstantiateContractProposal{}, - &InstantiateContract2Proposal{}, - &MigrateContractProposal{}, - &SudoContractProposal{}, - &ExecuteContractProposal{}, - &UpdateAdminProposal{}, - &ClearAdminProposal{}, - &PinCodesProposal{}, - &UnpinCodesProposal{}, - &UpdateInstantiateConfigProposal{}, - &StoreAndInstantiateContractProposal{}, ) registry.RegisterInterface("cosmwasm.wasm.v1.ContractInfoExtension", (*ContractInfoExtension)(nil)) @@ -117,6 +97,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations( (*authz.Authorization)(nil), + &StoreCodeAuthorization{}, &ContractExecutionAuthorization{}, &ContractMigrationAuthorization{}, ) diff --git a/x/wasm/types/context.go b/x/wasm/types/context.go index 0463e3ae1a..006e397624 100644 --- a/x/wasm/types/context.go +++ b/x/wasm/types/context.go @@ -14,6 +14,8 @@ const ( contextKeyQueryStackSize contextKey = iota // authorization policy for sub-messages contextKeySubMsgAuthzPolicy = iota + // gas register + contextKeyGasRegister = iota ) // WithTXCounter stores a transaction counter value in the context @@ -52,3 +54,17 @@ func SubMsgAuthzPolicy(ctx sdk.Context) (AuthorizationPolicy, bool) { val, ok := ctx.Value(contextKeySubMsgAuthzPolicy).(AuthorizationPolicy) return val, ok } + +// WithGasRegister stores the gas register into the context returned +func WithGasRegister(ctx sdk.Context, gr GasRegister) sdk.Context { + if gr == nil { + panic("gas register must not be nil") + } + return ctx.WithValue(contextKeyGasRegister, gr) +} + +// GasRegisterFromContext reads the gas register from the context +func GasRegisterFromContext(ctx sdk.Context) (GasRegister, bool) { + val, ok := ctx.Value(contextKeyGasRegister).(GasRegister) + return val, ok +} diff --git a/x/wasm/types/errors.go b/x/wasm/types/errors.go index 378c25d67b..58aa5caf1a 100644 --- a/x/wasm/types/errors.go +++ b/x/wasm/types/errors.go @@ -1,8 +1,9 @@ package types import ( - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + + errorsmod "cosmossdk.io/errors" ) // Codes for wasm contract errors diff --git a/x/wasm/types/errors_test.go b/x/wasm/types/errors_test.go index 495f5e828b..5e1034f628 100644 --- a/x/wasm/types/errors_test.go +++ b/x/wasm/types/errors_test.go @@ -4,10 +4,11 @@ import ( "errors" "testing" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + errorsmod "cosmossdk.io/errors" ) func TestWasmVMFlavouredError(t *testing.T) { @@ -17,22 +18,26 @@ func TestWasmVMFlavouredError(t *testing.T) { }{ "IsOf": { exec: func(t *testing.T) { + t.Helper() assert.True(t, errorsmod.IsOf(myErr, myErr.sdkErr)) assert.Equal(t, myErr.sdkErr, myErr.Unwrap()) }, }, "unwrapped": { exec: func(t *testing.T) { + t.Helper() assert.Equal(t, myErr.sdkErr, myErr.Unwrap()) }, }, "caused": { exec: func(t *testing.T) { + t.Helper() assert.Equal(t, myErr.sdkErr, myErr.Cause()) }, }, "wrapped supports WasmVMErrorable": { exec: func(t *testing.T) { + t.Helper() var wasmvmErr WasmVMErrorable require.True(t, errors.As(myErr.Wrap("my description"), &wasmvmErr)) gotErr := wasmvmErr.ToWasmVMError() @@ -41,6 +46,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "wrappedf supports WasmVMErrorable": { exec: func(t *testing.T) { + t.Helper() var wasmvmErr WasmVMErrorable require.True(t, errors.As(myErr.Wrapf("my description: %d", 1), &wasmvmErr)) gotErr := wasmvmErr.ToWasmVMError() @@ -49,6 +55,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "supports WasmVMErrorable": { exec: func(t *testing.T) { + t.Helper() var wasmvmErr WasmVMErrorable require.True(t, errors.As(myErr, &wasmvmErr)) gotErr := wasmvmErr.ToWasmVMError() @@ -57,6 +64,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "fallback to sdk error when wasmvm error unset": { exec: func(t *testing.T) { + t.Helper() var wasmvmErr WasmVMErrorable require.True(t, errors.As(WasmVMFlavouredError{sdkErr: ErrEmpty}, &wasmvmErr)) gotErr := wasmvmErr.ToWasmVMError() @@ -65,6 +73,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "abci info": { exec: func(t *testing.T) { + t.Helper() codespace, code, log := errorsmod.ABCIInfo(myErr, false) assert.Equal(t, DefaultCodespace, codespace) assert.Equal(t, uint32(28), code) @@ -73,6 +82,7 @@ func TestWasmVMFlavouredError(t *testing.T) { }, "abci info - wrapped": { exec: func(t *testing.T) { + t.Helper() codespace, code, log := errorsmod.ABCIInfo(myErr.Wrap("my description"), false) assert.Equal(t, DefaultCodespace, codespace) assert.Equal(t, uint32(28), code) diff --git a/x/wasm/types/events.go b/x/wasm/types/events.go index 7034b37b76..5abe563a34 100644 --- a/x/wasm/types/events.go +++ b/x/wasm/types/events.go @@ -3,8 +3,9 @@ package types import ( "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" + + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( @@ -23,12 +24,13 @@ const ( EventTypeReply = "reply" EventTypeGovContractResult = "gov_contract_result" EventTypeUpdateContractAdmin = "update_contract_admin" + EventTypeUpdateContractLabel = "update_contract_label" EventTypeUpdateCodeAccessConfig = "update_code_access_config" EventTypePacketRecv = "ibc_packet_received" // add new types to IsAcceptedEventOnRecvPacketErrorAck ) -// EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error +// EmitAcknowledgementEvent emits an event signaling a successful or failed acknowledgement and including the error // details if any. func EmitAcknowledgementEvent(ctx sdk.Context, contractAddr sdk.AccAddress, ack exported.Acknowledgement, err error) { success := err == nil && (ack == nil || ack.Success()) @@ -60,6 +62,7 @@ const ( AttributeKeyResultDataHex = "result" AttributeKeyRequiredCapability = "required_capability" AttributeKeyNewAdmin = "new_admin_address" + AttributeKeyNewLabel = "new_label" AttributeKeyCodePermission = "code_permission" AttributeKeyAuthorizedAddresses = "authorized_addresses" AttributeKeyAckSuccess = "success" diff --git a/x/wasm/types/expected_keepers.go b/x/wasm/types/expected_keepers.go index 19e5f50aa5..720baaaaf4 100644 --- a/x/wasm/types/expected_keepers.go +++ b/x/wasm/types/expected_keepers.go @@ -4,6 +4,9 @@ import ( "context" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -11,9 +14,6 @@ import ( capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // BankViewKeeper defines a subset of methods implemented by the cosmos-sdk bank keeper @@ -37,7 +37,7 @@ type BankKeeper interface { Burner IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error BlockedAddr(addr sdk.AccAddress) bool - SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error } // AccountKeeper defines a subset of methods implemented by the cosmos-sdk account keeper @@ -52,8 +52,10 @@ type AccountKeeper interface { // DistributionKeeper defines a subset of methods implemented by the cosmos-sdk distribution keeper type DistributionKeeper interface { - DelegationRewards(ctx context.Context, req *distrtypes.QueryDelegationRewardsRequest) (*distrtypes.QueryDelegationRewardsResponse, error) - GetDelegatorWithdrawAddr(ctx sdk.Context, delAddr sdk.AccAddress) sdk.AccAddress + DelegatorWithdrawAddress(c context.Context, req *distrtypes.QueryDelegatorWithdrawAddressRequest) (*distrtypes.QueryDelegatorWithdrawAddressResponse, error) + DelegationRewards(c context.Context, req *distrtypes.QueryDelegationRewardsRequest) (*distrtypes.QueryDelegationRewardsResponse, error) + DelegationTotalRewards(c context.Context, req *distrtypes.QueryDelegationTotalRewardsRequest) (*distrtypes.QueryDelegationTotalRewardsResponse, error) + DelegatorValidators(c context.Context, req *distrtypes.QueryDelegatorValidatorsRequest) (*distrtypes.QueryDelegatorValidatorsResponse, error) } // StakingKeeper defines a subset of methods implemented by the cosmos-sdk staking keeper @@ -80,8 +82,8 @@ type ChannelKeeper interface { GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error GetAllChannels(ctx sdk.Context) (channels []channeltypes.IdentifiedChannel) - IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) SetChannel(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel) + GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []channeltypes.IdentifiedChannel } // ICS4Wrapper defines the method for an IBC data package to be submitted. diff --git a/x/wasm/types/exported_keepers.go b/x/wasm/types/exported_keepers.go index 4fa5c6ac59..a77d823a3b 100644 --- a/x/wasm/types/exported_keepers.go +++ b/x/wasm/types/exported_keepers.go @@ -2,9 +2,10 @@ package types import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // ViewKeeper provides read only operations @@ -53,19 +54,19 @@ type ContractOpsKeeper interface { ) (sdk.AccAddress, []byte, error) // Execute executes the contract instance - Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) + Execute(ctx sdk.Context, contractAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) // Migrate allows to upgrade a contract to a new code with data migration. - Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) + Migrate(ctx sdk.Context, contractAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) // Sudo allows to call privileged entry point of a contract. Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) // UpdateContractAdmin sets the admin value on the ContractInfo. It must be a valid address (use ClearContractAdmin to remove it) - UpdateContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newAdmin sdk.AccAddress) error + UpdateContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress) error // ClearContractAdmin sets the admin value on the ContractInfo to nil, to disable further migrations/ updates. - ClearContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress) error + ClearContractAdmin(ctx sdk.Context, contractAddress, caller sdk.AccAddress) error // PinCode pins the wasm contract in wasmvm cache PinCode(ctx sdk.Context, codeID uint64) error diff --git a/x/wasm/keeper/gas_register.go b/x/wasm/types/gas_register.go similarity index 91% rename from x/wasm/keeper/gas_register.go rename to x/wasm/types/gas_register.go index ad97b30c56..da5e989149 100644 --- a/x/wasm/keeper/gas_register.go +++ b/x/wasm/types/gas_register.go @@ -1,13 +1,13 @@ -package keeper +package types import ( - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + + errorsmod "cosmossdk.io/errors" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/CosmWasm/wasmd/x/wasm/types" ) const ( @@ -81,9 +81,13 @@ type GasRegister interface { ReplyCosts(pinned bool, reply wasmvmtypes.Reply) sdk.Gas // EventCosts costs to persist an event EventCosts(attrs []wasmvmtypes.EventAttribute, events wasmvmtypes.Events) sdk.Gas - // ToWasmVMGas converts from sdk gas to wasmvm gas + // ToWasmVMGas converts from Cosmos SDK gas units to [CosmWasm gas] (aka. wasmvm gas) + // + // [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md ToWasmVMGas(source sdk.Gas) uint64 - // FromWasmVMGas converts from wasmvm gas to sdk gas + // FromWasmVMGas converts from [CosmWasm gas] (aka. wasmvm gas) to Cosmos SDK gas units + // + // [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md FromWasmVMGas(source uint64) sdk.Gas } @@ -156,7 +160,7 @@ func (g WasmGasRegister) NewContractInstanceCosts(pinned bool, msgLen int) store // CompileCosts costs to persist and "compile" a new wasm contract func (g WasmGasRegister) CompileCosts(byteLength int) storetypes.Gas { if byteLength < 0 { - panic(errorsmod.Wrap(types.ErrInvalid, "negative length")) + panic(errorsmod.Wrap(ErrInvalid, "negative length")) } return g.c.CompileCost * uint64(byteLength) } @@ -164,7 +168,7 @@ func (g WasmGasRegister) CompileCosts(byteLength int) storetypes.Gas { // UncompressCosts costs to unpack a new wasm contract func (g WasmGasRegister) UncompressCosts(byteLength int) sdk.Gas { if byteLength < 0 { - panic(errorsmod.Wrap(types.ErrInvalid, "negative length")) + panic(errorsmod.Wrap(ErrInvalid, "negative length")) } return g.c.UncompressCost.Mul(uint64(byteLength)).Floor() } @@ -172,7 +176,7 @@ func (g WasmGasRegister) UncompressCosts(byteLength int) sdk.Gas { // InstantiateContractCosts costs when interacting with a wasm contract func (g WasmGasRegister) InstantiateContractCosts(pinned bool, msgLen int) sdk.Gas { if msgLen < 0 { - panic(errorsmod.Wrap(types.ErrInvalid, "negative length")) + panic(errorsmod.Wrap(ErrInvalid, "negative length")) } dataCosts := sdk.Gas(msgLen) * g.c.ContractMessageDataCost if pinned { @@ -230,7 +234,7 @@ func (g WasmGasRegister) eventAttributeCosts(attrs []wasmvmtypes.EventAttribute, } // apply free tier -func calcWithFreeTier(storedBytes uint64, freeTier uint64) (uint64, uint64) { +func calcWithFreeTier(storedBytes, freeTier uint64) (uint64, uint64) { if storedBytes <= freeTier { return 0, freeTier - storedBytes } @@ -238,7 +242,9 @@ func calcWithFreeTier(storedBytes uint64, freeTier uint64) (uint64, uint64) { return storedBytes, 0 } -// ToWasmVMGas convert to wasmVM contract runtime gas unit +// ToWasmVMGas converts from Cosmos SDK gas units to [CosmWasm gas] (aka. wasmvm gas) +// +// [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md func (g WasmGasRegister) ToWasmVMGas(source storetypes.Gas) uint64 { x := source * g.c.GasMultiplier if x < source { @@ -247,7 +253,9 @@ func (g WasmGasRegister) ToWasmVMGas(source storetypes.Gas) uint64 { return x } -// FromWasmVMGas converts to SDK gas unit +// FromWasmVMGas converts from [CosmWasm gas] (aka. wasmvm gas) to Cosmos SDK gas units +// +// [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md func (g WasmGasRegister) FromWasmVMGas(source uint64) sdk.Gas { return source / g.c.GasMultiplier } diff --git a/x/wasm/keeper/gas_register_test.go b/x/wasm/types/gas_register_test.go similarity index 99% rename from x/wasm/keeper/gas_register_test.go rename to x/wasm/types/gas_register_test.go index bf8dcd773d..34155d4784 100644 --- a/x/wasm/keeper/gas_register_test.go +++ b/x/wasm/types/gas_register_test.go @@ -1,16 +1,15 @@ -package keeper +package types import ( "math" "strings" "testing" - "github.com/CosmWasm/wasmd/x/wasm/types" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/stretchr/testify/assert" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" ) func TestCompileCosts(t *testing.T) { @@ -451,7 +450,7 @@ func TestUncompressCosts(t *testing.T) { exp: 2, }, "max len": { - lenIn: types.MaxWasmSize, + lenIn: MaxWasmSize, exp: 122880, }, "invalid len": { diff --git a/x/wasm/types/genesis.go b/x/wasm/types/genesis.go index 50cd9b2595..4dd85e03fc 100644 --- a/x/wasm/types/genesis.go +++ b/x/wasm/types/genesis.go @@ -2,6 +2,7 @@ package types import ( errorsmod "cosmossdk.io/errors" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/wasm/types/genesis_test.go b/x/wasm/types/genesis_test.go index 5c80f5318b..5686624820 100644 --- a/x/wasm/types/genesis_test.go +++ b/x/wasm/types/genesis_test.go @@ -6,12 +6,13 @@ import ( "time" "github.com/cometbft/cometbft/libs/rand" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const invalidAddress = "invalid address" diff --git a/x/wasm/types/iavl_range_test.go b/x/wasm/types/iavl_range_test.go index fd3297b467..85607dab23 100644 --- a/x/wasm/types/iavl_range_test.go +++ b/x/wasm/types/iavl_range_test.go @@ -4,10 +4,11 @@ import ( "testing" dbm "github.com/cometbft/cometbft-db" - "github.com/cosmos/cosmos-sdk/store" - "github.com/cosmos/cosmos-sdk/store/iavl" iavl2 "github.com/cosmos/iavl" "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/iavl" ) // This is modeled close to diff --git a/x/wasm/types/json_matching_test.go b/x/wasm/types/json_matching_test.go index 286fde3969..18bb40b019 100644 --- a/x/wasm/types/json_matching_test.go +++ b/x/wasm/types/json_matching_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - // sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" ) diff --git a/x/wasm/types/keys.go b/x/wasm/types/keys.go index 4f605872d6..468d9865ed 100644 --- a/x/wasm/types/keys.go +++ b/x/wasm/types/keys.go @@ -34,8 +34,8 @@ var ( ContractsByCreatorPrefix = []byte{0x09} ParamsKey = []byte{0x10} - KeyLastCodeID = append(SequenceKeyPrefix, []byte("lastCodeId")...) - KeyLastInstanceID = append(SequenceKeyPrefix, []byte("lastContractId")...) + KeySequenceCodeID = append(SequenceKeyPrefix, []byte("lastCodeId")...) + KeySequenceInstanceID = append(SequenceKeyPrefix, []byte("lastContractId")...) ) // GetCodeKey constructs the key for retreiving the ID for the WASM code @@ -84,7 +84,7 @@ func GetContractByCodeIDSecondaryIndexPrefix(codeID uint64) []byte { } // GetContractByCreatorSecondaryIndexKey returns the key for the second index: `` -func GetContractByCreatorSecondaryIndexKey(bz []byte, position []byte, contractAddr sdk.AccAddress) []byte { +func GetContractByCreatorSecondaryIndexKey(bz, position []byte, contractAddr sdk.AccAddress) []byte { prefixBytes := GetContractsByCreatorPrefix(bz) lenPrefixBytes := len(prefixBytes) r := make([]byte, lenPrefixBytes+AbsoluteTxPositionLen+len(contractAddr)) diff --git a/x/wasm/types/params.go b/x/wasm/types/params.go index c653142a14..9793ee68a0 100644 --- a/x/wasm/types/params.go +++ b/x/wasm/types/params.go @@ -4,11 +4,13 @@ import ( "encoding/json" "fmt" - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/jsonpb" "github.com/pkg/errors" "gopkg.in/yaml.v2" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" ) var AllAccessTypes = []AccessType{ diff --git a/x/wasm/types/params_test.go b/x/wasm/types/params_test.go index 7534e5d646..2a275000aa 100644 --- a/x/wasm/types/params_test.go +++ b/x/wasm/types/params_test.go @@ -5,11 +5,12 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestValidateParams(t *testing.T) { diff --git a/x/wasm/types/proposal.go b/x/wasm/types/proposal.go deleted file mode 100644 index 468f45b177..0000000000 --- a/x/wasm/types/proposal.go +++ /dev/null @@ -1,986 +0,0 @@ -package types - -import ( - "encoding/base64" - "encoding/hex" - "fmt" - "strings" - - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -type ProposalType string - -const ( - ProposalTypeStoreCode ProposalType = "StoreCode" - ProposalTypeInstantiateContract ProposalType = "InstantiateContract" - ProposalTypeInstantiateContract2 ProposalType = "InstantiateContract2" - ProposalTypeMigrateContract ProposalType = "MigrateContract" - ProposalTypeSudoContract ProposalType = "SudoContract" - ProposalTypeExecuteContract ProposalType = "ExecuteContract" - ProposalTypeUpdateAdmin ProposalType = "UpdateAdmin" - ProposalTypeClearAdmin ProposalType = "ClearAdmin" - ProposalTypePinCodes ProposalType = "PinCodes" - ProposalTypeUnpinCodes ProposalType = "UnpinCodes" - ProposalTypeUpdateInstantiateConfig ProposalType = "UpdateInstantiateConfig" - ProposalTypeStoreAndInstantiateContractProposal ProposalType = "StoreAndInstantiateContract" -) - -// DisableAllProposals contains no wasm gov types. -var DisableAllProposals []ProposalType - -// EnableAllProposals contains all wasm gov types as keys. -var EnableAllProposals = []ProposalType{ - ProposalTypeStoreCode, - ProposalTypeInstantiateContract, - ProposalTypeInstantiateContract2, - ProposalTypeMigrateContract, - ProposalTypeSudoContract, - ProposalTypeExecuteContract, - ProposalTypeUpdateAdmin, - ProposalTypeClearAdmin, - ProposalTypePinCodes, - ProposalTypeUnpinCodes, - ProposalTypeUpdateInstantiateConfig, - ProposalTypeStoreAndInstantiateContractProposal, -} - -// ConvertToProposals maps each key to a ProposalType and returns a typed list. -// If any string is not a valid type (in this file), then return an error -func ConvertToProposals(keys []string) ([]ProposalType, error) { - valid := make(map[string]bool, len(EnableAllProposals)) - for _, key := range EnableAllProposals { - valid[string(key)] = true - } - - proposals := make([]ProposalType, len(keys)) - for i, key := range keys { - if _, ok := valid[key]; !ok { - return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "'%s' is not a valid ProposalType", key) - } - proposals[i] = ProposalType(key) - } - return proposals, nil -} - -func init() { // register new content types with the sdk - v1beta1.RegisterProposalType(string(ProposalTypeStoreCode)) - v1beta1.RegisterProposalType(string(ProposalTypeInstantiateContract)) - v1beta1.RegisterProposalType(string(ProposalTypeInstantiateContract2)) - v1beta1.RegisterProposalType(string(ProposalTypeMigrateContract)) - v1beta1.RegisterProposalType(string(ProposalTypeSudoContract)) - v1beta1.RegisterProposalType(string(ProposalTypeExecuteContract)) - v1beta1.RegisterProposalType(string(ProposalTypeUpdateAdmin)) - v1beta1.RegisterProposalType(string(ProposalTypeClearAdmin)) - v1beta1.RegisterProposalType(string(ProposalTypePinCodes)) - v1beta1.RegisterProposalType(string(ProposalTypeUnpinCodes)) - v1beta1.RegisterProposalType(string(ProposalTypeUpdateInstantiateConfig)) - v1beta1.RegisterProposalType(string(ProposalTypeStoreAndInstantiateContractProposal)) -} - -func NewStoreCodeProposal( - title string, - description string, - runAs string, - wasmBz []byte, - permission *AccessConfig, - unpinCode bool, - source string, - builder string, - codeHash []byte, -) *StoreCodeProposal { - return &StoreCodeProposal{title, description, runAs, wasmBz, permission, unpinCode, source, builder, codeHash} -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p StoreCodeProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *StoreCodeProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p StoreCodeProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p StoreCodeProposal) ProposalType() string { return string(ProposalTypeStoreCode) } - -// ValidateBasic validates the proposal -func (p StoreCodeProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return errorsmod.Wrap(err, "run as") - } - - if err := validateWasmCode(p.WASMByteCode, MaxProposalWasmSize); err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) - } - - if p.InstantiatePermission != nil { - if err := p.InstantiatePermission.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "instantiate permission") - } - } - - if err := ValidateVerificationInfo(p.Source, p.Builder, p.CodeHash); err != nil { - return errorsmod.Wrapf(err, "code verification info") - } - return nil -} - -// String implements the Stringer interface. -func (p StoreCodeProposal) String() string { - return fmt.Sprintf(`Store Code Proposal: - Title: %s - Description: %s - Run as: %s - WasmCode: %X - Source: %s - Builder: %s - Code Hash: %X -`, p.Title, p.Description, p.RunAs, p.WASMByteCode, p.Source, p.Builder, p.CodeHash) -} - -// MarshalYAML pretty prints the wasm byte code -func (p StoreCodeProposal) MarshalYAML() (interface{}, error) { - return struct { - Title string `yaml:"title"` - Description string `yaml:"description"` - RunAs string `yaml:"run_as"` - WASMByteCode string `yaml:"wasm_byte_code"` - InstantiatePermission *AccessConfig `yaml:"instantiate_permission"` - Source string `yaml:"source"` - Builder string `yaml:"builder"` - CodeHash string `yaml:"code_hash"` - }{ - Title: p.Title, - Description: p.Description, - RunAs: p.RunAs, - WASMByteCode: base64.StdEncoding.EncodeToString(p.WASMByteCode), - InstantiatePermission: p.InstantiatePermission, - Source: p.Source, - Builder: p.Builder, - CodeHash: hex.EncodeToString(p.CodeHash), - }, nil -} - -func NewInstantiateContractProposal( - title string, - description string, - runAs string, - admin string, - codeID uint64, - label string, - msg RawContractMessage, - funds sdk.Coins, -) *InstantiateContractProposal { - return &InstantiateContractProposal{title, description, runAs, admin, codeID, label, msg, funds} -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p InstantiateContractProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *InstantiateContractProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p InstantiateContractProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p InstantiateContractProposal) ProposalType() string { - return string(ProposalTypeInstantiateContract) -} - -// ValidateBasic validates the proposal -func (p InstantiateContractProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "run as") - } - - if p.CodeID == 0 { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") - } - - if err := ValidateLabel(p.Label); err != nil { - return err - } - - if !p.Funds.IsValid() { - return sdkerrors.ErrInvalidCoins - } - - if len(p.Admin) != 0 { - if _, err := sdk.AccAddressFromBech32(p.Admin); err != nil { - return err - } - } - if err := p.Msg.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "payload msg") - } - return nil -} - -// String implements the Stringer interface. -func (p InstantiateContractProposal) String() string { - return fmt.Sprintf(`Instantiate Code Proposal: - Title: %s - Description: %s - Run as: %s - Admin: %s - Code id: %d - Label: %s - Msg: %q - Funds: %s -`, p.Title, p.Description, p.RunAs, p.Admin, p.CodeID, p.Label, p.Msg, p.Funds) -} - -// MarshalYAML pretty prints the init message -func (p InstantiateContractProposal) MarshalYAML() (interface{}, error) { - return struct { - Title string `yaml:"title"` - Description string `yaml:"description"` - RunAs string `yaml:"run_as"` - Admin string `yaml:"admin"` - CodeID uint64 `yaml:"code_id"` - Label string `yaml:"label"` - Msg string `yaml:"msg"` - Funds sdk.Coins `yaml:"funds"` - }{ - Title: p.Title, - Description: p.Description, - RunAs: p.RunAs, - Admin: p.Admin, - CodeID: p.CodeID, - Label: p.Label, - Msg: string(p.Msg), - Funds: p.Funds, - }, nil -} - -func NewInstantiateContract2Proposal( - title string, - description string, - runAs string, - admin string, - codeID uint64, - label string, - msg RawContractMessage, - funds sdk.Coins, - salt []byte, - fixMsg bool, -) *InstantiateContract2Proposal { - return &InstantiateContract2Proposal{title, description, runAs, admin, codeID, label, msg, funds, salt, fixMsg} -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p InstantiateContract2Proposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *InstantiateContract2Proposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p InstantiateContract2Proposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p InstantiateContract2Proposal) ProposalType() string { - return string(ProposalTypeInstantiateContract2) -} - -// ValidateBasic validates the proposal -func (p InstantiateContract2Proposal) ValidateBasic() error { - // Validate title and description - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - // Validate run as - if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "run as") - } - // Validate admin - if len(p.Admin) != 0 { - if _, err := sdk.AccAddressFromBech32(p.Admin); err != nil { - return err - } - } - // Validate codeid - if p.CodeID == 0 { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") - } - // Validate label - if err := ValidateLabel(p.Label); err != nil { - return err - } - // Validate msg - if err := p.Msg.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "payload msg") - } - // Validate funds - if !p.Funds.IsValid() { - return sdkerrors.ErrInvalidCoins - } - // Validate salt - if len(p.Salt) == 0 { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "salt is required") - } - return nil -} - -// String implements the Stringer interface. -func (p InstantiateContract2Proposal) String() string { - return fmt.Sprintf(`Instantiate Code Proposal: - Title: %s - Description: %s - Run as: %s - Admin: %s - Code id: %d - Label: %s - Msg: %q - Funds: %s - Salt: %X -`, p.Title, p.Description, p.RunAs, p.Admin, p.CodeID, p.Label, p.Msg, p.Funds, p.Salt) -} - -// MarshalYAML pretty prints the init message -func (p InstantiateContract2Proposal) MarshalYAML() (interface{}, error) { - return struct { - Title string `yaml:"title"` - Description string `yaml:"description"` - RunAs string `yaml:"run_as"` - Admin string `yaml:"admin"` - CodeID uint64 `yaml:"code_id"` - Label string `yaml:"label"` - Msg string `yaml:"msg"` - Funds sdk.Coins `yaml:"funds"` - Salt string `yaml:"salt"` - }{ - Title: p.Title, - Description: p.Description, - RunAs: p.RunAs, - Admin: p.Admin, - CodeID: p.CodeID, - Label: p.Label, - Msg: string(p.Msg), - Funds: p.Funds, - Salt: base64.StdEncoding.EncodeToString(p.Salt), - }, nil -} - -func NewStoreAndInstantiateContractProposal( - title string, - description string, - runAs string, - wasmBz []byte, - source string, - builder string, - codeHash []byte, - permission *AccessConfig, - unpinCode bool, - admin string, - label string, - msg RawContractMessage, - funds sdk.Coins, -) *StoreAndInstantiateContractProposal { - return &StoreAndInstantiateContractProposal{ - Title: title, - Description: description, - RunAs: runAs, - WASMByteCode: wasmBz, - Source: source, - Builder: builder, - CodeHash: codeHash, - InstantiatePermission: permission, - UnpinCode: unpinCode, - Admin: admin, - Label: label, - Msg: msg, - Funds: funds, - } -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p StoreAndInstantiateContractProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *StoreAndInstantiateContractProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p StoreAndInstantiateContractProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p StoreAndInstantiateContractProposal) ProposalType() string { - return string(ProposalTypeStoreAndInstantiateContractProposal) -} - -// ValidateBasic validates the proposal -func (p StoreAndInstantiateContractProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return errorsmod.Wrap(err, "run as") - } - - if err := validateWasmCode(p.WASMByteCode, MaxProposalWasmSize); err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) - } - - if err := ValidateVerificationInfo(p.Source, p.Builder, p.CodeHash); err != nil { - return errorsmod.Wrap(err, "code info") - } - - if p.InstantiatePermission != nil { - if err := p.InstantiatePermission.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "instantiate permission") - } - } - - if err := ValidateLabel(p.Label); err != nil { - return err - } - - if !p.Funds.IsValid() { - return sdkerrors.ErrInvalidCoins - } - - if len(p.Admin) != 0 { - if _, err := sdk.AccAddressFromBech32(p.Admin); err != nil { - return err - } - } - if err := p.Msg.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "payload msg") - } - return nil -} - -// String implements the Stringer interface. -func (p StoreAndInstantiateContractProposal) String() string { - return fmt.Sprintf(`Store And Instantiate Coontract Proposal: - Title: %s - Description: %s - Run as: %s - WasmCode: %X - Source: %s - Builder: %s - Code Hash: %X - Instantiate permission: %s - Unpin code: %t - Admin: %s - Label: %s - Msg: %q - Funds: %s -`, p.Title, p.Description, p.RunAs, p.WASMByteCode, p.Source, p.Builder, p.CodeHash, p.InstantiatePermission, p.UnpinCode, p.Admin, p.Label, p.Msg, p.Funds) -} - -// MarshalYAML pretty prints the wasm byte code and the init message -func (p StoreAndInstantiateContractProposal) MarshalYAML() (interface{}, error) { - return struct { - Title string `yaml:"title"` - Description string `yaml:"description"` - RunAs string `yaml:"run_as"` - WASMByteCode string `yaml:"wasm_byte_code"` - Source string `yaml:"source"` - Builder string `yaml:"builder"` - CodeHash string `yaml:"code_hash"` - InstantiatePermission *AccessConfig `yaml:"instantiate_permission"` - UnpinCode bool `yaml:"unpin_code"` - Admin string `yaml:"admin"` - Label string `yaml:"label"` - Msg string `yaml:"msg"` - Funds sdk.Coins `yaml:"funds"` - }{ - Title: p.Title, - Description: p.Description, - RunAs: p.RunAs, - WASMByteCode: base64.StdEncoding.EncodeToString(p.WASMByteCode), - InstantiatePermission: p.InstantiatePermission, - UnpinCode: p.UnpinCode, - Admin: p.Admin, - Label: p.Label, - Source: p.Source, - Builder: p.Builder, - CodeHash: hex.EncodeToString(p.CodeHash), - Msg: string(p.Msg), - Funds: p.Funds, - }, nil -} - -func NewMigrateContractProposal( - title string, - description string, - contract string, - codeID uint64, - msg RawContractMessage, -) *MigrateContractProposal { - return &MigrateContractProposal{ - Title: title, - Description: description, - Contract: contract, - CodeID: codeID, - Msg: msg, - } -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p MigrateContractProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *MigrateContractProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p MigrateContractProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p MigrateContractProposal) ProposalType() string { return string(ProposalTypeMigrateContract) } - -// ValidateBasic validates the proposal -func (p MigrateContractProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if p.CodeID == 0 { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required") - } - if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return errorsmod.Wrap(err, "contract") - } - if err := p.Msg.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "payload msg") - } - return nil -} - -// String implements the Stringer interface. -func (p MigrateContractProposal) String() string { - return fmt.Sprintf(`Migrate Contract Proposal: - Title: %s - Description: %s - Contract: %s - Code id: %d - Msg: %q -`, p.Title, p.Description, p.Contract, p.CodeID, p.Msg) -} - -// MarshalYAML pretty prints the migrate message -func (p MigrateContractProposal) MarshalYAML() (interface{}, error) { - return struct { - Title string `yaml:"title"` - Description string `yaml:"description"` - Contract string `yaml:"contract"` - CodeID uint64 `yaml:"code_id"` - Msg string `yaml:"msg"` - }{ - Title: p.Title, - Description: p.Description, - Contract: p.Contract, - CodeID: p.CodeID, - Msg: string(p.Msg), - }, nil -} - -func NewSudoContractProposal( - title string, - description string, - contract string, - msg RawContractMessage, -) *SudoContractProposal { - return &SudoContractProposal{ - Title: title, - Description: description, - Contract: contract, - Msg: msg, - } -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p SudoContractProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *SudoContractProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p SudoContractProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p SudoContractProposal) ProposalType() string { return string(ProposalTypeSudoContract) } - -// ValidateBasic validates the proposal -func (p SudoContractProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return errorsmod.Wrap(err, "contract") - } - if err := p.Msg.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "payload msg") - } - return nil -} - -// String implements the Stringer interface. -func (p SudoContractProposal) String() string { - return fmt.Sprintf(`Migrate Contract Proposal: - Title: %s - Description: %s - Contract: %s - Msg: %q -`, p.Title, p.Description, p.Contract, p.Msg) -} - -// MarshalYAML pretty prints the migrate message -func (p SudoContractProposal) MarshalYAML() (interface{}, error) { - return struct { - Title string `yaml:"title"` - Description string `yaml:"description"` - Contract string `yaml:"contract"` - Msg string `yaml:"msg"` - }{ - Title: p.Title, - Description: p.Description, - Contract: p.Contract, - Msg: string(p.Msg), - }, nil -} - -func NewExecuteContractProposal( - title string, - description string, - runAs string, - contract string, - msg RawContractMessage, - funds sdk.Coins, -) *ExecuteContractProposal { - return &ExecuteContractProposal{title, description, runAs, contract, msg, funds} -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p ExecuteContractProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *ExecuteContractProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p ExecuteContractProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p ExecuteContractProposal) ProposalType() string { return string(ProposalTypeExecuteContract) } - -// ValidateBasic validates the proposal -func (p ExecuteContractProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return errorsmod.Wrap(err, "contract") - } - if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return errorsmod.Wrap(err, "run as") - } - if !p.Funds.IsValid() { - return sdkerrors.ErrInvalidCoins - } - if err := p.Msg.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "payload msg") - } - return nil -} - -// String implements the Stringer interface. -func (p ExecuteContractProposal) String() string { - return fmt.Sprintf(`Migrate Contract Proposal: - Title: %s - Description: %s - Contract: %s - Run as: %s - Msg: %q - Funds: %s -`, p.Title, p.Description, p.Contract, p.RunAs, p.Msg, p.Funds) -} - -// MarshalYAML pretty prints the migrate message -func (p ExecuteContractProposal) MarshalYAML() (interface{}, error) { - return struct { - Title string `yaml:"title"` - Description string `yaml:"description"` - Contract string `yaml:"contract"` - Msg string `yaml:"msg"` - RunAs string `yaml:"run_as"` - Funds sdk.Coins `yaml:"funds"` - }{ - Title: p.Title, - Description: p.Description, - Contract: p.Contract, - Msg: string(p.Msg), - RunAs: p.RunAs, - Funds: p.Funds, - }, nil -} - -func NewUpdateAdminProposal( - title string, - description string, - newAdmin string, - contract string, -) *UpdateAdminProposal { - return &UpdateAdminProposal{title, description, newAdmin, contract} -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p UpdateAdminProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *UpdateAdminProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p UpdateAdminProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p UpdateAdminProposal) ProposalType() string { return string(ProposalTypeUpdateAdmin) } - -// ValidateBasic validates the proposal -func (p UpdateAdminProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return errorsmod.Wrap(err, "contract") - } - if _, err := sdk.AccAddressFromBech32(p.NewAdmin); err != nil { - return errorsmod.Wrap(err, "new admin") - } - return nil -} - -// String implements the Stringer interface. -func (p UpdateAdminProposal) String() string { - return fmt.Sprintf(`Update Contract Admin Proposal: - Title: %s - Description: %s - Contract: %s - New Admin: %s -`, p.Title, p.Description, p.Contract, p.NewAdmin) -} - -func NewClearAdminProposal( - title string, - description string, - contract string, -) *ClearAdminProposal { - return &ClearAdminProposal{title, description, contract} -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p ClearAdminProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *ClearAdminProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p ClearAdminProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p ClearAdminProposal) ProposalType() string { return string(ProposalTypeClearAdmin) } - -// ValidateBasic validates the proposal -func (p ClearAdminProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { - return errorsmod.Wrap(err, "contract") - } - return nil -} - -// String implements the Stringer interface. -func (p ClearAdminProposal) String() string { - return fmt.Sprintf(`Clear Contract Admin Proposal: - Title: %s - Description: %s - Contract: %s -`, p.Title, p.Description, p.Contract) -} - -func NewPinCodesProposal( - title string, - description string, - codeIDs []uint64, -) *PinCodesProposal { - return &PinCodesProposal{ - Title: title, - Description: description, - CodeIDs: codeIDs, - } -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p PinCodesProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *PinCodesProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p PinCodesProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p PinCodesProposal) ProposalType() string { return string(ProposalTypePinCodes) } - -// ValidateBasic validates the proposal -func (p PinCodesProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if len(p.CodeIDs) == 0 { - return errorsmod.Wrap(ErrEmpty, "code ids") - } - return nil -} - -// String implements the Stringer interface. -func (p PinCodesProposal) String() string { - return fmt.Sprintf(`Pin Wasm Codes Proposal: - Title: %s - Description: %s - Codes: %v -`, p.Title, p.Description, p.CodeIDs) -} - -func NewUnpinCodesProposal( - title string, - description string, - codeIDs []uint64, -) *UnpinCodesProposal { - return &UnpinCodesProposal{ - Title: title, - Description: description, - CodeIDs: codeIDs, - } -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p UnpinCodesProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *UnpinCodesProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p UnpinCodesProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p UnpinCodesProposal) ProposalType() string { return string(ProposalTypeUnpinCodes) } - -// ValidateBasic validates the proposal -func (p UnpinCodesProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if len(p.CodeIDs) == 0 { - return errorsmod.Wrap(ErrEmpty, "code ids") - } - return nil -} - -// String implements the Stringer interface. -func (p UnpinCodesProposal) String() string { - return fmt.Sprintf(`Unpin Wasm Codes Proposal: - Title: %s - Description: %s - Codes: %v -`, p.Title, p.Description, p.CodeIDs) -} - -func validateProposalCommons(title, description string) error { - if strings.TrimSpace(title) != title { - return errorsmod.Wrap(govtypes.ErrInvalidProposalContent, "proposal title must not start/end with white spaces") - } - if len(title) == 0 { - return errorsmod.Wrap(govtypes.ErrInvalidProposalContent, "proposal title cannot be blank") - } - if len(title) > v1beta1.MaxTitleLength { - return errorsmod.Wrapf(govtypes.ErrInvalidProposalContent, "proposal title is longer than max length of %d", v1beta1.MaxTitleLength) - } - if strings.TrimSpace(description) != description { - return errorsmod.Wrap(govtypes.ErrInvalidProposalContent, "proposal description must not start/end with white spaces") - } - if len(description) == 0 { - return errorsmod.Wrap(govtypes.ErrInvalidProposalContent, "proposal description cannot be blank") - } - if len(description) > v1beta1.MaxDescriptionLength { - return errorsmod.Wrapf(govtypes.ErrInvalidProposalContent, "proposal description is longer than max length of %d", v1beta1.MaxDescriptionLength) - } - return nil -} - -func NewUpdateInstantiateConfigProposal( - title string, - description string, - accessConfigUpdates ...AccessConfigUpdate, -) *UpdateInstantiateConfigProposal { - return &UpdateInstantiateConfigProposal{ - Title: title, - Description: description, - AccessConfigUpdates: accessConfigUpdates, - } -} - -// ProposalRoute returns the routing key of a parameter change proposal. -func (p UpdateInstantiateConfigProposal) ProposalRoute() string { return RouterKey } - -// GetTitle returns the title of the proposal -func (p *UpdateInstantiateConfigProposal) GetTitle() string { return p.Title } - -// GetDescription returns the human readable description of the proposal -func (p UpdateInstantiateConfigProposal) GetDescription() string { return p.Description } - -// ProposalType returns the type -func (p UpdateInstantiateConfigProposal) ProposalType() string { - return string(ProposalTypeUpdateInstantiateConfig) -} - -// ValidateBasic validates the proposal -func (p UpdateInstantiateConfigProposal) ValidateBasic() error { - if err := validateProposalCommons(p.Title, p.Description); err != nil { - return err - } - if len(p.AccessConfigUpdates) == 0 { - return errorsmod.Wrap(ErrEmpty, "code updates") - } - dedup := make(map[uint64]bool) - for _, codeUpdate := range p.AccessConfigUpdates { - _, found := dedup[codeUpdate.CodeID] - if found { - return errorsmod.Wrapf(ErrDuplicate, "duplicate code: %d", codeUpdate.CodeID) - } - if err := codeUpdate.InstantiatePermission.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "instantiate permission") - } - dedup[codeUpdate.CodeID] = true - } - return nil -} - -// String implements the Stringer interface. -func (p UpdateInstantiateConfigProposal) String() string { - return fmt.Sprintf(`Update Instantiate Config Proposal: - Title: %s - Description: %s - AccessConfigUpdates: %v -`, p.Title, p.Description, p.AccessConfigUpdates) -} - -// String implements the Stringer interface. -func (c AccessConfigUpdate) String() string { - return fmt.Sprintf(`AccessConfigUpdate: - CodeID: %d - AccessConfig: %v -`, c.CodeID, c.InstantiatePermission) -} diff --git a/x/wasm/types/proposal.pb.go b/x/wasm/types/proposal.pb.go deleted file mode 100644 index aecf2aec5f..0000000000 --- a/x/wasm/types/proposal.pb.go +++ /dev/null @@ -1,5758 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: cosmwasm/wasm/v1/proposal.proto - -package types - -import ( - bytes "bytes" - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit StoreCodeProposal. To submit WASM code to the system, -// a simple MsgStoreCode can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type StoreCodeProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // RunAs is the address that is passed to the contract's environment as sender - RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` - // WASMByteCode can be raw or gzip compressed - WASMByteCode []byte `protobuf:"bytes,4,opt,name=wasm_byte_code,json=wasmByteCode,proto3" json:"wasm_byte_code,omitempty"` - // InstantiatePermission to apply on contract creation, optional - InstantiatePermission *AccessConfig `protobuf:"bytes,7,opt,name=instantiate_permission,json=instantiatePermission,proto3" json:"instantiate_permission,omitempty"` - // UnpinCode code on upload, optional - UnpinCode bool `protobuf:"varint,8,opt,name=unpin_code,json=unpinCode,proto3" json:"unpin_code,omitempty"` - // Source is the URL where the code is hosted - Source string `protobuf:"bytes,9,opt,name=source,proto3" json:"source,omitempty"` - // Builder is the docker image used to build the code deterministically, used - // for smart contract verification - Builder string `protobuf:"bytes,10,opt,name=builder,proto3" json:"builder,omitempty"` - // CodeHash is the SHA256 sum of the code outputted by builder, used for smart - // contract verification - CodeHash []byte `protobuf:"bytes,11,opt,name=code_hash,json=codeHash,proto3" json:"code_hash,omitempty"` -} - -func (m *StoreCodeProposal) Reset() { *m = StoreCodeProposal{} } -func (*StoreCodeProposal) ProtoMessage() {} -func (*StoreCodeProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{0} -} -func (m *StoreCodeProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *StoreCodeProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_StoreCodeProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *StoreCodeProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_StoreCodeProposal.Merge(m, src) -} -func (m *StoreCodeProposal) XXX_Size() int { - return m.Size() -} -func (m *StoreCodeProposal) XXX_DiscardUnknown() { - xxx_messageInfo_StoreCodeProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_StoreCodeProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit InstantiateContractProposal. To instantiate a contract, -// a simple MsgInstantiateContract can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type InstantiateContractProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // RunAs is the address that is passed to the contract's environment as sender - RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` - // Admin is an optional address that can execute migrations - Admin string `protobuf:"bytes,4,opt,name=admin,proto3" json:"admin,omitempty"` - // CodeID is the reference to the stored WASM code - CodeID uint64 `protobuf:"varint,5,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` - // Label is optional metadata to be stored with a constract instance. - Label string `protobuf:"bytes,6,opt,name=label,proto3" json:"label,omitempty"` - // Msg json encoded message to be passed to the contract on instantiation - Msg RawContractMessage `protobuf:"bytes,7,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` - // Funds coins that are transferred to the contract on instantiation - Funds github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,8,rep,name=funds,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"funds"` -} - -func (m *InstantiateContractProposal) Reset() { *m = InstantiateContractProposal{} } -func (*InstantiateContractProposal) ProtoMessage() {} -func (*InstantiateContractProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{1} -} -func (m *InstantiateContractProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *InstantiateContractProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_InstantiateContractProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *InstantiateContractProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_InstantiateContractProposal.Merge(m, src) -} -func (m *InstantiateContractProposal) XXX_Size() int { - return m.Size() -} -func (m *InstantiateContractProposal) XXX_DiscardUnknown() { - xxx_messageInfo_InstantiateContractProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_InstantiateContractProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit InstantiateContract2Proposal. To instantiate contract 2, -// a simple MsgInstantiateContract2 can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type InstantiateContract2Proposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // RunAs is the address that is passed to the contract's enviroment as sender - RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` - // Admin is an optional address that can execute migrations - Admin string `protobuf:"bytes,4,opt,name=admin,proto3" json:"admin,omitempty"` - // CodeID is the reference to the stored WASM code - CodeID uint64 `protobuf:"varint,5,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` - // Label is optional metadata to be stored with a constract instance. - Label string `protobuf:"bytes,6,opt,name=label,proto3" json:"label,omitempty"` - // Msg json encode message to be passed to the contract on instantiation - Msg RawContractMessage `protobuf:"bytes,7,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` - // Funds coins that are transferred to the contract on instantiation - Funds github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,8,rep,name=funds,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"funds"` - // Salt is an arbitrary value provided by the sender. Size can be 1 to 64. - Salt []byte `protobuf:"bytes,9,opt,name=salt,proto3" json:"salt,omitempty"` - // FixMsg include the msg value into the hash for the predictable address. - // Default is false - FixMsg bool `protobuf:"varint,10,opt,name=fix_msg,json=fixMsg,proto3" json:"fix_msg,omitempty"` -} - -func (m *InstantiateContract2Proposal) Reset() { *m = InstantiateContract2Proposal{} } -func (*InstantiateContract2Proposal) ProtoMessage() {} -func (*InstantiateContract2Proposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{2} -} -func (m *InstantiateContract2Proposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *InstantiateContract2Proposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_InstantiateContract2Proposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *InstantiateContract2Proposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_InstantiateContract2Proposal.Merge(m, src) -} -func (m *InstantiateContract2Proposal) XXX_Size() int { - return m.Size() -} -func (m *InstantiateContract2Proposal) XXX_DiscardUnknown() { - xxx_messageInfo_InstantiateContract2Proposal.DiscardUnknown(m) -} - -var xxx_messageInfo_InstantiateContract2Proposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit MigrateContractProposal. To migrate a contract, -// a simple MsgMigrateContract can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type MigrateContractProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // Contract is the address of the smart contract - Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` - // CodeID references the new WASM code - CodeID uint64 `protobuf:"varint,5,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` - // Msg json encoded message to be passed to the contract on migration - Msg RawContractMessage `protobuf:"bytes,6,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` -} - -func (m *MigrateContractProposal) Reset() { *m = MigrateContractProposal{} } -func (*MigrateContractProposal) ProtoMessage() {} -func (*MigrateContractProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{3} -} -func (m *MigrateContractProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MigrateContractProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MigrateContractProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MigrateContractProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_MigrateContractProposal.Merge(m, src) -} -func (m *MigrateContractProposal) XXX_Size() int { - return m.Size() -} -func (m *MigrateContractProposal) XXX_DiscardUnknown() { - xxx_messageInfo_MigrateContractProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_MigrateContractProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit SudoContractProposal. To call sudo on a contract, -// a simple MsgSudoContract can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type SudoContractProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // Contract is the address of the smart contract - Contract string `protobuf:"bytes,3,opt,name=contract,proto3" json:"contract,omitempty"` - // Msg json encoded message to be passed to the contract as sudo - Msg RawContractMessage `protobuf:"bytes,4,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` -} - -func (m *SudoContractProposal) Reset() { *m = SudoContractProposal{} } -func (*SudoContractProposal) ProtoMessage() {} -func (*SudoContractProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{4} -} -func (m *SudoContractProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SudoContractProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SudoContractProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *SudoContractProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_SudoContractProposal.Merge(m, src) -} -func (m *SudoContractProposal) XXX_Size() int { - return m.Size() -} -func (m *SudoContractProposal) XXX_DiscardUnknown() { - xxx_messageInfo_SudoContractProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_SudoContractProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit ExecuteContractProposal. To call execute on a contract, -// a simple MsgExecuteContract can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type ExecuteContractProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // RunAs is the address that is passed to the contract's environment as sender - RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` - // Contract is the address of the smart contract - Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` - // Msg json encoded message to be passed to the contract as execute - Msg RawContractMessage `protobuf:"bytes,5,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` - // Funds coins that are transferred to the contract on instantiation - Funds github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=funds,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"funds"` -} - -func (m *ExecuteContractProposal) Reset() { *m = ExecuteContractProposal{} } -func (*ExecuteContractProposal) ProtoMessage() {} -func (*ExecuteContractProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{5} -} -func (m *ExecuteContractProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ExecuteContractProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ExecuteContractProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ExecuteContractProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_ExecuteContractProposal.Merge(m, src) -} -func (m *ExecuteContractProposal) XXX_Size() int { - return m.Size() -} -func (m *ExecuteContractProposal) XXX_DiscardUnknown() { - xxx_messageInfo_ExecuteContractProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_ExecuteContractProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit UpdateAdminProposal. To set an admin for a contract, -// a simple MsgUpdateAdmin can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type UpdateAdminProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // NewAdmin address to be set - NewAdmin string `protobuf:"bytes,3,opt,name=new_admin,json=newAdmin,proto3" json:"new_admin,omitempty" yaml:"new_admin"` - // Contract is the address of the smart contract - Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` -} - -func (m *UpdateAdminProposal) Reset() { *m = UpdateAdminProposal{} } -func (*UpdateAdminProposal) ProtoMessage() {} -func (*UpdateAdminProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{6} -} -func (m *UpdateAdminProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UpdateAdminProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UpdateAdminProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UpdateAdminProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateAdminProposal.Merge(m, src) -} -func (m *UpdateAdminProposal) XXX_Size() int { - return m.Size() -} -func (m *UpdateAdminProposal) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateAdminProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateAdminProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit ClearAdminProposal. To clear the admin of a contract, -// a simple MsgClearAdmin can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type ClearAdminProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // Contract is the address of the smart contract - Contract string `protobuf:"bytes,3,opt,name=contract,proto3" json:"contract,omitempty"` -} - -func (m *ClearAdminProposal) Reset() { *m = ClearAdminProposal{} } -func (*ClearAdminProposal) ProtoMessage() {} -func (*ClearAdminProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{7} -} -func (m *ClearAdminProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ClearAdminProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ClearAdminProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ClearAdminProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_ClearAdminProposal.Merge(m, src) -} -func (m *ClearAdminProposal) XXX_Size() int { - return m.Size() -} -func (m *ClearAdminProposal) XXX_DiscardUnknown() { - xxx_messageInfo_ClearAdminProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_ClearAdminProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit PinCodesProposal. To pin a set of code ids in the wasmvm -// cache, a simple MsgPinCodes can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type PinCodesProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty" yaml:"title"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" yaml:"description"` - // CodeIDs references the new WASM codes - CodeIDs []uint64 `protobuf:"varint,3,rep,packed,name=code_ids,json=codeIds,proto3" json:"code_ids,omitempty" yaml:"code_ids"` -} - -func (m *PinCodesProposal) Reset() { *m = PinCodesProposal{} } -func (*PinCodesProposal) ProtoMessage() {} -func (*PinCodesProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{8} -} -func (m *PinCodesProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *PinCodesProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_PinCodesProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *PinCodesProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_PinCodesProposal.Merge(m, src) -} -func (m *PinCodesProposal) XXX_Size() int { - return m.Size() -} -func (m *PinCodesProposal) XXX_DiscardUnknown() { - xxx_messageInfo_PinCodesProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_PinCodesProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit UnpinCodesProposal. To unpin a set of code ids in the wasmvm -// cache, a simple MsgUnpinCodes can be invoked from the x/gov module via -// a v1 governance proposal. -// -// Deprecated: Do not use. -type UnpinCodesProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty" yaml:"title"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" yaml:"description"` - // CodeIDs references the WASM codes - CodeIDs []uint64 `protobuf:"varint,3,rep,packed,name=code_ids,json=codeIds,proto3" json:"code_ids,omitempty" yaml:"code_ids"` -} - -func (m *UnpinCodesProposal) Reset() { *m = UnpinCodesProposal{} } -func (*UnpinCodesProposal) ProtoMessage() {} -func (*UnpinCodesProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{9} -} -func (m *UnpinCodesProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UnpinCodesProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UnpinCodesProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UnpinCodesProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_UnpinCodesProposal.Merge(m, src) -} -func (m *UnpinCodesProposal) XXX_Size() int { - return m.Size() -} -func (m *UnpinCodesProposal) XXX_DiscardUnknown() { - xxx_messageInfo_UnpinCodesProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_UnpinCodesProposal proto.InternalMessageInfo - -// AccessConfigUpdate contains the code id and the access config to be -// applied. -type AccessConfigUpdate struct { - // CodeID is the reference to the stored WASM code to be updated - CodeID uint64 `protobuf:"varint,1,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` - // InstantiatePermission to apply to the set of code ids - InstantiatePermission AccessConfig `protobuf:"bytes,2,opt,name=instantiate_permission,json=instantiatePermission,proto3" json:"instantiate_permission"` -} - -func (m *AccessConfigUpdate) Reset() { *m = AccessConfigUpdate{} } -func (*AccessConfigUpdate) ProtoMessage() {} -func (*AccessConfigUpdate) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{10} -} -func (m *AccessConfigUpdate) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *AccessConfigUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_AccessConfigUpdate.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *AccessConfigUpdate) XXX_Merge(src proto.Message) { - xxx_messageInfo_AccessConfigUpdate.Merge(m, src) -} -func (m *AccessConfigUpdate) XXX_Size() int { - return m.Size() -} -func (m *AccessConfigUpdate) XXX_DiscardUnknown() { - xxx_messageInfo_AccessConfigUpdate.DiscardUnknown(m) -} - -var xxx_messageInfo_AccessConfigUpdate proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit UpdateInstantiateConfigProposal. To update instantiate config -// to a set of code ids, a simple MsgUpdateInstantiateConfig can be invoked from -// the x/gov module via a v1 governance proposal. -// -// Deprecated: Do not use. -type UpdateInstantiateConfigProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty" yaml:"title"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" yaml:"description"` - // AccessConfigUpdate contains the list of code ids and the access config - // to be applied. - AccessConfigUpdates []AccessConfigUpdate `protobuf:"bytes,3,rep,name=access_config_updates,json=accessConfigUpdates,proto3" json:"access_config_updates"` -} - -func (m *UpdateInstantiateConfigProposal) Reset() { *m = UpdateInstantiateConfigProposal{} } -func (*UpdateInstantiateConfigProposal) ProtoMessage() {} -func (*UpdateInstantiateConfigProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{11} -} -func (m *UpdateInstantiateConfigProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UpdateInstantiateConfigProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UpdateInstantiateConfigProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UpdateInstantiateConfigProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateInstantiateConfigProposal.Merge(m, src) -} -func (m *UpdateInstantiateConfigProposal) XXX_Size() int { - return m.Size() -} -func (m *UpdateInstantiateConfigProposal) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateInstantiateConfigProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateInstantiateConfigProposal proto.InternalMessageInfo - -// Deprecated: Do not use. Since wasmd v0.40, there is no longer a need for -// an explicit StoreAndInstantiateContractProposal. To store and instantiate -// the contract, a simple MsgStoreAndInstantiateContract can be invoked from -// the x/gov module via a v1 governance proposal. -// -// Deprecated: Do not use. -type StoreAndInstantiateContractProposal struct { - // Title is a short summary - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // Description is a human readable text - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // RunAs is the address that is passed to the contract's environment as sender - RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` - // WASMByteCode can be raw or gzip compressed - WASMByteCode []byte `protobuf:"bytes,4,opt,name=wasm_byte_code,json=wasmByteCode,proto3" json:"wasm_byte_code,omitempty"` - // InstantiatePermission to apply on contract creation, optional - InstantiatePermission *AccessConfig `protobuf:"bytes,5,opt,name=instantiate_permission,json=instantiatePermission,proto3" json:"instantiate_permission,omitempty"` - // UnpinCode code on upload, optional - UnpinCode bool `protobuf:"varint,6,opt,name=unpin_code,json=unpinCode,proto3" json:"unpin_code,omitempty"` - // Admin is an optional address that can execute migrations - Admin string `protobuf:"bytes,7,opt,name=admin,proto3" json:"admin,omitempty"` - // Label is optional metadata to be stored with a constract instance. - Label string `protobuf:"bytes,8,opt,name=label,proto3" json:"label,omitempty"` - // Msg json encoded message to be passed to the contract on instantiation - Msg RawContractMessage `protobuf:"bytes,9,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` - // Funds coins that are transferred to the contract on instantiation - Funds github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,10,rep,name=funds,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"funds"` - // Source is the URL where the code is hosted - Source string `protobuf:"bytes,11,opt,name=source,proto3" json:"source,omitempty"` - // Builder is the docker image used to build the code deterministically, used - // for smart contract verification - Builder string `protobuf:"bytes,12,opt,name=builder,proto3" json:"builder,omitempty"` - // CodeHash is the SHA256 sum of the code outputted by builder, used for smart - // contract verification - CodeHash []byte `protobuf:"bytes,13,opt,name=code_hash,json=codeHash,proto3" json:"code_hash,omitempty"` -} - -func (m *StoreAndInstantiateContractProposal) Reset() { *m = StoreAndInstantiateContractProposal{} } -func (*StoreAndInstantiateContractProposal) ProtoMessage() {} -func (*StoreAndInstantiateContractProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{12} -} -func (m *StoreAndInstantiateContractProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *StoreAndInstantiateContractProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_StoreAndInstantiateContractProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *StoreAndInstantiateContractProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_StoreAndInstantiateContractProposal.Merge(m, src) -} -func (m *StoreAndInstantiateContractProposal) XXX_Size() int { - return m.Size() -} -func (m *StoreAndInstantiateContractProposal) XXX_DiscardUnknown() { - xxx_messageInfo_StoreAndInstantiateContractProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_StoreAndInstantiateContractProposal proto.InternalMessageInfo - -func init() { - proto.RegisterType((*StoreCodeProposal)(nil), "cosmwasm.wasm.v1.StoreCodeProposal") - proto.RegisterType((*InstantiateContractProposal)(nil), "cosmwasm.wasm.v1.InstantiateContractProposal") - proto.RegisterType((*InstantiateContract2Proposal)(nil), "cosmwasm.wasm.v1.InstantiateContract2Proposal") - proto.RegisterType((*MigrateContractProposal)(nil), "cosmwasm.wasm.v1.MigrateContractProposal") - proto.RegisterType((*SudoContractProposal)(nil), "cosmwasm.wasm.v1.SudoContractProposal") - proto.RegisterType((*ExecuteContractProposal)(nil), "cosmwasm.wasm.v1.ExecuteContractProposal") - proto.RegisterType((*UpdateAdminProposal)(nil), "cosmwasm.wasm.v1.UpdateAdminProposal") - proto.RegisterType((*ClearAdminProposal)(nil), "cosmwasm.wasm.v1.ClearAdminProposal") - proto.RegisterType((*PinCodesProposal)(nil), "cosmwasm.wasm.v1.PinCodesProposal") - proto.RegisterType((*UnpinCodesProposal)(nil), "cosmwasm.wasm.v1.UnpinCodesProposal") - proto.RegisterType((*AccessConfigUpdate)(nil), "cosmwasm.wasm.v1.AccessConfigUpdate") - proto.RegisterType((*UpdateInstantiateConfigProposal)(nil), "cosmwasm.wasm.v1.UpdateInstantiateConfigProposal") - proto.RegisterType((*StoreAndInstantiateContractProposal)(nil), "cosmwasm.wasm.v1.StoreAndInstantiateContractProposal") -} - -func init() { proto.RegisterFile("cosmwasm/wasm/v1/proposal.proto", fileDescriptor_be6422d717c730cb) } - -var fileDescriptor_be6422d717c730cb = []byte{ - // 1163 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x58, 0xcd, 0x6f, 0xe3, 0x44, - 0x14, 0xcf, 0x34, 0x89, 0x93, 0x4c, 0x02, 0x64, 0xbd, 0xfd, 0x98, 0xed, 0x16, 0x3b, 0x78, 0x57, - 0xab, 0x68, 0xa5, 0x4d, 0xd4, 0x22, 0x10, 0x84, 0x0f, 0x29, 0x2e, 0x8b, 0xe8, 0x8a, 0x4a, 0x95, - 0xab, 0x6a, 0x25, 0x2e, 0x61, 0x62, 0x4f, 0x52, 0x8b, 0xc4, 0x13, 0x79, 0xec, 0x7e, 0xfc, 0x0b, - 0x9c, 0x38, 0x71, 0xe1, 0x8e, 0x2a, 0x4e, 0x2b, 0xc1, 0xbf, 0x80, 0x54, 0x71, 0xda, 0x03, 0x87, - 0x45, 0x48, 0x81, 0x4d, 0x0f, 0x7b, 0xe0, 0x80, 0xd4, 0x23, 0x07, 0x40, 0x9e, 0x71, 0x52, 0xb7, - 0x4d, 0xe2, 0x2e, 0xb4, 0x2b, 0x21, 0x71, 0x71, 0xf2, 0xe6, 0xcd, 0xd8, 0xbf, 0xdf, 0xfb, 0xcd, - 0x3c, 0xbf, 0x67, 0xa8, 0x9a, 0x94, 0x75, 0x77, 0x31, 0xeb, 0x56, 0xf9, 0x65, 0x67, 0xb9, 0xda, - 0x73, 0x69, 0x8f, 0x32, 0xdc, 0xa9, 0xf4, 0x5c, 0xea, 0x51, 0xb9, 0x38, 0x9c, 0x50, 0xe1, 0x97, - 0x9d, 0xe5, 0xc5, 0xd9, 0x36, 0x6d, 0x53, 0xee, 0xac, 0x06, 0xff, 0xc4, 0xbc, 0xc5, 0x1b, 0xc1, - 0x3c, 0xca, 0x1a, 0xc2, 0x21, 0x8c, 0xd0, 0xa5, 0x08, 0xab, 0xda, 0xc4, 0x8c, 0x54, 0x77, 0x96, - 0x9b, 0xc4, 0xc3, 0xcb, 0x55, 0x93, 0xda, 0x4e, 0xe8, 0x5f, 0x3a, 0x87, 0xc1, 0xdb, 0xef, 0x91, - 0xe1, 0xea, 0x6b, 0xb8, 0x6b, 0x3b, 0xb4, 0xca, 0xaf, 0x62, 0x48, 0x3b, 0x48, 0xc2, 0x6b, 0x9b, - 0x1e, 0x75, 0xc9, 0x2a, 0xb5, 0xc8, 0x46, 0x88, 0x57, 0x9e, 0x85, 0x69, 0xcf, 0xf6, 0x3a, 0x04, - 0x81, 0x12, 0x28, 0xe7, 0x0c, 0x61, 0xc8, 0x25, 0x98, 0xb7, 0x08, 0x33, 0x5d, 0xbb, 0xe7, 0xd9, - 0xd4, 0x41, 0x33, 0xdc, 0x17, 0x1d, 0x92, 0xe7, 0xa0, 0xe4, 0xfa, 0x4e, 0x03, 0x33, 0x94, 0x14, - 0x0b, 0x5d, 0xdf, 0xa9, 0x33, 0xf9, 0x4d, 0xf8, 0x72, 0x00, 0xa7, 0xd1, 0xdc, 0xf7, 0x48, 0xc3, - 0xa4, 0x16, 0x41, 0xa9, 0x12, 0x28, 0x17, 0xf4, 0xe2, 0xa0, 0xaf, 0x16, 0x1e, 0xd6, 0x37, 0xd7, - 0xf5, 0x7d, 0x8f, 0x03, 0x30, 0x0a, 0xc1, 0xbc, 0xa1, 0x25, 0x6f, 0xc1, 0x79, 0xdb, 0x61, 0x1e, - 0x76, 0x3c, 0x1b, 0x7b, 0xa4, 0xd1, 0x23, 0x6e, 0xd7, 0x66, 0x2c, 0x78, 0x76, 0xa6, 0x04, 0xca, - 0xf9, 0x15, 0xa5, 0x72, 0x36, 0xa2, 0x95, 0xba, 0x69, 0x12, 0xc6, 0x56, 0xa9, 0xd3, 0xb2, 0xdb, - 0xc6, 0x5c, 0x64, 0xf5, 0xc6, 0x68, 0xb1, 0xfc, 0x2a, 0x84, 0xbe, 0xd3, 0xb3, 0x1d, 0x01, 0x25, - 0x5b, 0x02, 0xe5, 0xac, 0x91, 0xe3, 0x23, 0xfc, 0xa9, 0xf3, 0x50, 0x62, 0xd4, 0x77, 0x4d, 0x82, - 0x72, 0x9c, 0x44, 0x68, 0xc9, 0x08, 0x66, 0x9a, 0xbe, 0xdd, 0xb1, 0x88, 0x8b, 0x20, 0x77, 0x0c, - 0x4d, 0xf9, 0x26, 0xcc, 0x05, 0xb7, 0x6a, 0x6c, 0x63, 0xb6, 0x8d, 0xf2, 0x01, 0x35, 0x23, 0x1b, - 0x0c, 0x7c, 0x84, 0xd9, 0x76, 0xed, 0x9d, 0x1f, 0xbe, 0xbb, 0xb7, 0x18, 0x8a, 0xd8, 0xa6, 0x3b, - 0x95, 0x50, 0xb5, 0xca, 0x2a, 0x75, 0x3c, 0xe2, 0x78, 0x9f, 0x3f, 0x7b, 0x74, 0x77, 0x9e, 0x8b, - 0x75, 0x4e, 0x06, 0x04, 0x1e, 0xa4, 0xb2, 0xe9, 0xa2, 0xf4, 0x20, 0x95, 0x95, 0x8a, 0x19, 0xed, - 0xcb, 0x24, 0xbc, 0xb9, 0x76, 0x42, 0x28, 0x58, 0xef, 0x62, 0xd3, 0xbb, 0x2a, 0xd1, 0x66, 0x61, - 0x1a, 0x5b, 0x5d, 0xdb, 0xe1, 0x5a, 0xe5, 0x0c, 0x61, 0xc8, 0xb7, 0x60, 0x86, 0x53, 0xb5, 0x2d, - 0x94, 0x2e, 0x81, 0x72, 0x4a, 0x87, 0x83, 0xbe, 0x2a, 0x05, 0xa8, 0xd7, 0x3e, 0x30, 0xa4, 0xc0, - 0xb5, 0x66, 0x05, 0x4b, 0x3b, 0xb8, 0x49, 0x3a, 0x48, 0x12, 0x4b, 0xb9, 0x21, 0x97, 0x61, 0xb2, - 0xcb, 0xda, 0x5c, 0xba, 0x82, 0x3e, 0xff, 0x47, 0x5f, 0x95, 0x0d, 0xbc, 0x3b, 0x64, 0xb1, 0x4e, - 0x18, 0xc3, 0x6d, 0x62, 0x04, 0x53, 0xe4, 0x16, 0x4c, 0xb7, 0x7c, 0xc7, 0x62, 0x28, 0x5b, 0x4a, - 0x96, 0xf3, 0x2b, 0x37, 0x2a, 0x61, 0xf8, 0x82, 0x5d, 0x1f, 0x89, 0x9f, 0xed, 0xe8, 0x6f, 0x1c, - 0xf6, 0xd5, 0xc4, 0x37, 0xbf, 0xa8, 0xe5, 0xb6, 0xed, 0x6d, 0xfb, 0xcd, 0x8a, 0x49, 0xbb, 0xe1, - 0x81, 0x09, 0x7f, 0xee, 0x31, 0xeb, 0xb3, 0xf0, 0x0c, 0x04, 0x0b, 0xd8, 0xc1, 0xb3, 0x47, 0x77, - 0x81, 0x21, 0x6e, 0x5f, 0xbb, 0x1f, 0x2f, 0x4d, 0x89, 0x4b, 0x33, 0x25, 0xec, 0x08, 0x68, 0xdf, - 0x27, 0xe1, 0xd2, 0x98, 0x19, 0x2b, 0xff, 0x2b, 0xf3, 0x4f, 0x95, 0x91, 0x65, 0x98, 0x62, 0xb8, - 0xe3, 0xf1, 0x13, 0x58, 0x30, 0xf8, 0x7f, 0x79, 0x01, 0x66, 0x5a, 0xf6, 0x5e, 0x23, 0x40, 0x0a, - 0xf9, 0x99, 0x95, 0x5a, 0xf6, 0xde, 0x3a, 0x6b, 0xd7, 0x3e, 0x8c, 0x97, 0xf1, 0xb5, 0x49, 0x32, - 0xae, 0x44, 0x74, 0xfc, 0x0b, 0xc0, 0x85, 0x75, 0xbb, 0xed, 0x5e, 0xe6, 0xe1, 0x5a, 0x84, 0x59, - 0x33, 0xbc, 0x57, 0x28, 0xd7, 0xc8, 0xbe, 0x98, 0x62, 0xa1, 0x36, 0x52, 0xac, 0x36, 0xb5, 0x7a, - 0x7c, 0x18, 0x96, 0x78, 0x18, 0x26, 0x70, 0x44, 0x40, 0xfb, 0x11, 0xc0, 0xd9, 0x4d, 0xdf, 0xa2, - 0x57, 0x42, 0x3f, 0x79, 0x86, 0x7e, 0xc8, 0x2c, 0x15, 0xcf, 0xec, 0xfd, 0x78, 0x66, 0x37, 0x44, - 0x0a, 0x1d, 0x83, 0x1d, 0x01, 0xed, 0xa7, 0x19, 0xb8, 0x70, 0x7f, 0x8f, 0x98, 0xfe, 0xd5, 0x67, - 0xcd, 0x69, 0x7a, 0x87, 0x84, 0xd3, 0xcf, 0x71, 0xcc, 0xa4, 0xab, 0x4d, 0x80, 0x17, 0xde, 0x32, - 0x13, 0xa2, 0x87, 0x80, 0xf6, 0x33, 0x80, 0xd7, 0xb7, 0x7a, 0x16, 0xf6, 0x48, 0x3d, 0x48, 0x43, - 0xff, 0x3a, 0xae, 0xcb, 0x30, 0xe7, 0x90, 0xdd, 0x86, 0x48, 0x70, 0x3c, 0xb4, 0xfa, 0xec, 0x71, - 0x5f, 0x2d, 0xee, 0xe3, 0x6e, 0xa7, 0xa6, 0x8d, 0x5c, 0x9a, 0x91, 0x75, 0xc8, 0x2e, 0x7f, 0xe4, - 0xb4, 0x98, 0xd7, 0xde, 0x8b, 0x67, 0x88, 0x38, 0xc3, 0x31, 0x1c, 0x10, 0xd0, 0xbe, 0x06, 0x50, - 0x5e, 0xed, 0x10, 0xec, 0x5e, 0x0e, 0xb9, 0x29, 0xc7, 0xa1, 0xf6, 0x6e, 0x3c, 0xd2, 0x05, 0x8e, - 0xf4, 0x3c, 0x1e, 0x04, 0xb4, 0xdf, 0x00, 0x2c, 0x6e, 0x88, 0x02, 0x86, 0x8d, 0x60, 0xde, 0x39, - 0x05, 0x53, 0x2f, 0x1e, 0xf7, 0xd5, 0x82, 0x88, 0x23, 0x1f, 0xd6, 0x86, 0xc0, 0xdf, 0x1a, 0x03, - 0x5c, 0x9f, 0x3f, 0xee, 0xab, 0xb2, 0x98, 0x1d, 0x71, 0x6a, 0xa7, 0x09, 0xbd, 0x0d, 0xb3, 0x61, - 0x0a, 0x0b, 0xce, 0x41, 0xb2, 0x9c, 0xd2, 0x95, 0x41, 0x5f, 0xcd, 0x88, 0x1c, 0xc6, 0x8e, 0xfb, - 0xea, 0x2b, 0xe2, 0x0e, 0xc3, 0x49, 0x9a, 0x91, 0x11, 0x79, 0x8d, 0xd5, 0x6a, 0xf1, 0x7c, 0xe7, - 0x38, 0xdf, 0xb3, 0xb4, 0x10, 0xd0, 0x7e, 0x07, 0x50, 0xde, 0x1a, 0x16, 0x6c, 0xff, 0x11, 0xbe, - 0x17, 0xd6, 0xf7, 0x3c, 0x31, 0x04, 0xb4, 0xaf, 0x00, 0x94, 0xa3, 0xb5, 0xad, 0xd8, 0xae, 0xd1, - 0x57, 0x08, 0x98, 0xf8, 0x0a, 0xf9, 0x74, 0x62, 0x19, 0x3d, 0x73, 0x91, 0x32, 0x5a, 0xcf, 0x05, - 0x39, 0x46, 0xe4, 0x8d, 0xf1, 0x15, 0xb5, 0xf6, 0xed, 0x0c, 0x54, 0x05, 0xa2, 0xd3, 0xaf, 0xd8, - 0x96, 0xdd, 0x7e, 0x81, 0xe2, 0x98, 0x70, 0x0e, 0x73, 0xdc, 0x0d, 0x93, 0x3f, 0xba, 0xe1, 0x73, - 0x48, 0x42, 0xa9, 0xfc, 0xca, 0xed, 0xe9, 0x34, 0x05, 0xfe, 0x28, 0xd9, 0xeb, 0xf8, 0x9c, 0x9b, - 0xd5, 0xd6, 0xe2, 0x65, 0xbc, 0x1d, 0x49, 0x28, 0x13, 0xe3, 0x81, 0x80, 0xf6, 0x67, 0x0a, 0xde, - 0xe2, 0x45, 0x7f, 0xdd, 0xb1, 0x5e, 0x60, 0x61, 0x7f, 0xf9, 0xdd, 0x58, 0xfa, 0xf2, 0xba, 0x31, - 0xe9, 0x6c, 0x37, 0x36, 0x2a, 0x76, 0x33, 0xd1, 0x62, 0x77, 0x54, 0xc7, 0x66, 0xc7, 0xd4, 0xb1, - 0xb9, 0xe7, 0x78, 0xc1, 0xc2, 0xab, 0xad, 0x63, 0x4f, 0x7a, 0xc9, 0xfc, 0xa4, 0x5e, 0xb2, 0x30, - 0xa5, 0x97, 0x7c, 0xe9, 0x4c, 0x2f, 0xb9, 0x1e, 0xbf, 0xf9, 0xca, 0x27, 0xbd, 0xe4, 0xf4, 0x6d, - 0x85, 0x80, 0xfe, 0xf1, 0xe1, 0x53, 0x25, 0xf1, 0xe4, 0xa9, 0x92, 0x38, 0x18, 0x28, 0xe0, 0x70, - 0xa0, 0x80, 0xc7, 0x03, 0x05, 0xfc, 0x3a, 0x50, 0xc0, 0x17, 0x47, 0x4a, 0xe2, 0xf1, 0x91, 0x92, - 0x78, 0x72, 0xa4, 0x24, 0x3e, 0xb9, 0x13, 0x61, 0xbe, 0x4a, 0x59, 0xf7, 0xe1, 0xf0, 0xf3, 0x82, - 0x55, 0xdd, 0x13, 0x9f, 0x19, 0x38, 0xfb, 0xa6, 0xc4, 0xbf, 0x28, 0xbc, 0xfe, 0x77, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x0f, 0x40, 0x90, 0x22, 0x08, 0x11, 0x00, 0x00, -} - -func (this *StoreCodeProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*StoreCodeProposal) - if !ok { - that2, ok := that.(StoreCodeProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.RunAs != that1.RunAs { - return false - } - if !bytes.Equal(this.WASMByteCode, that1.WASMByteCode) { - return false - } - if !this.InstantiatePermission.Equal(that1.InstantiatePermission) { - return false - } - if this.UnpinCode != that1.UnpinCode { - return false - } - if this.Source != that1.Source { - return false - } - if this.Builder != that1.Builder { - return false - } - if !bytes.Equal(this.CodeHash, that1.CodeHash) { - return false - } - return true -} -func (this *InstantiateContractProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*InstantiateContractProposal) - if !ok { - that2, ok := that.(InstantiateContractProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.RunAs != that1.RunAs { - return false - } - if this.Admin != that1.Admin { - return false - } - if this.CodeID != that1.CodeID { - return false - } - if this.Label != that1.Label { - return false - } - if !bytes.Equal(this.Msg, that1.Msg) { - return false - } - if len(this.Funds) != len(that1.Funds) { - return false - } - for i := range this.Funds { - if !this.Funds[i].Equal(&that1.Funds[i]) { - return false - } - } - return true -} -func (this *InstantiateContract2Proposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*InstantiateContract2Proposal) - if !ok { - that2, ok := that.(InstantiateContract2Proposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.RunAs != that1.RunAs { - return false - } - if this.Admin != that1.Admin { - return false - } - if this.CodeID != that1.CodeID { - return false - } - if this.Label != that1.Label { - return false - } - if !bytes.Equal(this.Msg, that1.Msg) { - return false - } - if len(this.Funds) != len(that1.Funds) { - return false - } - for i := range this.Funds { - if !this.Funds[i].Equal(&that1.Funds[i]) { - return false - } - } - if !bytes.Equal(this.Salt, that1.Salt) { - return false - } - if this.FixMsg != that1.FixMsg { - return false - } - return true -} -func (this *MigrateContractProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*MigrateContractProposal) - if !ok { - that2, ok := that.(MigrateContractProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.Contract != that1.Contract { - return false - } - if this.CodeID != that1.CodeID { - return false - } - if !bytes.Equal(this.Msg, that1.Msg) { - return false - } - return true -} -func (this *SudoContractProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*SudoContractProposal) - if !ok { - that2, ok := that.(SudoContractProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.Contract != that1.Contract { - return false - } - if !bytes.Equal(this.Msg, that1.Msg) { - return false - } - return true -} -func (this *ExecuteContractProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ExecuteContractProposal) - if !ok { - that2, ok := that.(ExecuteContractProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.RunAs != that1.RunAs { - return false - } - if this.Contract != that1.Contract { - return false - } - if !bytes.Equal(this.Msg, that1.Msg) { - return false - } - if len(this.Funds) != len(that1.Funds) { - return false - } - for i := range this.Funds { - if !this.Funds[i].Equal(&that1.Funds[i]) { - return false - } - } - return true -} -func (this *UpdateAdminProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*UpdateAdminProposal) - if !ok { - that2, ok := that.(UpdateAdminProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.NewAdmin != that1.NewAdmin { - return false - } - if this.Contract != that1.Contract { - return false - } - return true -} -func (this *ClearAdminProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ClearAdminProposal) - if !ok { - that2, ok := that.(ClearAdminProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.Contract != that1.Contract { - return false - } - return true -} -func (this *PinCodesProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*PinCodesProposal) - if !ok { - that2, ok := that.(PinCodesProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if len(this.CodeIDs) != len(that1.CodeIDs) { - return false - } - for i := range this.CodeIDs { - if this.CodeIDs[i] != that1.CodeIDs[i] { - return false - } - } - return true -} -func (this *UnpinCodesProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*UnpinCodesProposal) - if !ok { - that2, ok := that.(UnpinCodesProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if len(this.CodeIDs) != len(that1.CodeIDs) { - return false - } - for i := range this.CodeIDs { - if this.CodeIDs[i] != that1.CodeIDs[i] { - return false - } - } - return true -} -func (this *AccessConfigUpdate) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*AccessConfigUpdate) - if !ok { - that2, ok := that.(AccessConfigUpdate) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.CodeID != that1.CodeID { - return false - } - if !this.InstantiatePermission.Equal(&that1.InstantiatePermission) { - return false - } - return true -} -func (this *UpdateInstantiateConfigProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*UpdateInstantiateConfigProposal) - if !ok { - that2, ok := that.(UpdateInstantiateConfigProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if len(this.AccessConfigUpdates) != len(that1.AccessConfigUpdates) { - return false - } - for i := range this.AccessConfigUpdates { - if !this.AccessConfigUpdates[i].Equal(&that1.AccessConfigUpdates[i]) { - return false - } - } - return true -} -func (this *StoreAndInstantiateContractProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*StoreAndInstantiateContractProposal) - if !ok { - that2, ok := that.(StoreAndInstantiateContractProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if this.RunAs != that1.RunAs { - return false - } - if !bytes.Equal(this.WASMByteCode, that1.WASMByteCode) { - return false - } - if !this.InstantiatePermission.Equal(that1.InstantiatePermission) { - return false - } - if this.UnpinCode != that1.UnpinCode { - return false - } - if this.Admin != that1.Admin { - return false - } - if this.Label != that1.Label { - return false - } - if !bytes.Equal(this.Msg, that1.Msg) { - return false - } - if len(this.Funds) != len(that1.Funds) { - return false - } - for i := range this.Funds { - if !this.Funds[i].Equal(&that1.Funds[i]) { - return false - } - } - if this.Source != that1.Source { - return false - } - if this.Builder != that1.Builder { - return false - } - if !bytes.Equal(this.CodeHash, that1.CodeHash) { - return false - } - return true -} -func (m *StoreCodeProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StoreCodeProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *StoreCodeProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CodeHash) > 0 { - i -= len(m.CodeHash) - copy(dAtA[i:], m.CodeHash) - i = encodeVarintProposal(dAtA, i, uint64(len(m.CodeHash))) - i-- - dAtA[i] = 0x5a - } - if len(m.Builder) > 0 { - i -= len(m.Builder) - copy(dAtA[i:], m.Builder) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Builder))) - i-- - dAtA[i] = 0x52 - } - if len(m.Source) > 0 { - i -= len(m.Source) - copy(dAtA[i:], m.Source) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Source))) - i-- - dAtA[i] = 0x4a - } - if m.UnpinCode { - i-- - if m.UnpinCode { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x40 - } - if m.InstantiatePermission != nil { - { - size, err := m.InstantiatePermission.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintProposal(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x3a - } - if len(m.WASMByteCode) > 0 { - i -= len(m.WASMByteCode) - copy(dAtA[i:], m.WASMByteCode) - i = encodeVarintProposal(dAtA, i, uint64(len(m.WASMByteCode))) - i-- - dAtA[i] = 0x22 - } - if len(m.RunAs) > 0 { - i -= len(m.RunAs) - copy(dAtA[i:], m.RunAs) - i = encodeVarintProposal(dAtA, i, uint64(len(m.RunAs))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *InstantiateContractProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *InstantiateContractProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *InstantiateContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Funds) > 0 { - for iNdEx := len(m.Funds) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Funds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintProposal(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x42 - } - } - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Msg))) - i-- - dAtA[i] = 0x3a - } - if len(m.Label) > 0 { - i -= len(m.Label) - copy(dAtA[i:], m.Label) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Label))) - i-- - dAtA[i] = 0x32 - } - if m.CodeID != 0 { - i = encodeVarintProposal(dAtA, i, uint64(m.CodeID)) - i-- - dAtA[i] = 0x28 - } - if len(m.Admin) > 0 { - i -= len(m.Admin) - copy(dAtA[i:], m.Admin) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Admin))) - i-- - dAtA[i] = 0x22 - } - if len(m.RunAs) > 0 { - i -= len(m.RunAs) - copy(dAtA[i:], m.RunAs) - i = encodeVarintProposal(dAtA, i, uint64(len(m.RunAs))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *InstantiateContract2Proposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *InstantiateContract2Proposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *InstantiateContract2Proposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.FixMsg { - i-- - if m.FixMsg { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x50 - } - if len(m.Salt) > 0 { - i -= len(m.Salt) - copy(dAtA[i:], m.Salt) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Salt))) - i-- - dAtA[i] = 0x4a - } - if len(m.Funds) > 0 { - for iNdEx := len(m.Funds) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Funds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintProposal(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x42 - } - } - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Msg))) - i-- - dAtA[i] = 0x3a - } - if len(m.Label) > 0 { - i -= len(m.Label) - copy(dAtA[i:], m.Label) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Label))) - i-- - dAtA[i] = 0x32 - } - if m.CodeID != 0 { - i = encodeVarintProposal(dAtA, i, uint64(m.CodeID)) - i-- - dAtA[i] = 0x28 - } - if len(m.Admin) > 0 { - i -= len(m.Admin) - copy(dAtA[i:], m.Admin) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Admin))) - i-- - dAtA[i] = 0x22 - } - if len(m.RunAs) > 0 { - i -= len(m.RunAs) - copy(dAtA[i:], m.RunAs) - i = encodeVarintProposal(dAtA, i, uint64(len(m.RunAs))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MigrateContractProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MigrateContractProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MigrateContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Msg))) - i-- - dAtA[i] = 0x32 - } - if m.CodeID != 0 { - i = encodeVarintProposal(dAtA, i, uint64(m.CodeID)) - i-- - dAtA[i] = 0x28 - } - if len(m.Contract) > 0 { - i -= len(m.Contract) - copy(dAtA[i:], m.Contract) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Contract))) - i-- - dAtA[i] = 0x22 - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *SudoContractProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SudoContractProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SudoContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Msg))) - i-- - dAtA[i] = 0x22 - } - if len(m.Contract) > 0 { - i -= len(m.Contract) - copy(dAtA[i:], m.Contract) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Contract))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *ExecuteContractProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ExecuteContractProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ExecuteContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Funds) > 0 { - for iNdEx := len(m.Funds) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Funds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintProposal(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x32 - } - } - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Msg))) - i-- - dAtA[i] = 0x2a - } - if len(m.Contract) > 0 { - i -= len(m.Contract) - copy(dAtA[i:], m.Contract) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Contract))) - i-- - dAtA[i] = 0x22 - } - if len(m.RunAs) > 0 { - i -= len(m.RunAs) - copy(dAtA[i:], m.RunAs) - i = encodeVarintProposal(dAtA, i, uint64(len(m.RunAs))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *UpdateAdminProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UpdateAdminProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UpdateAdminProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Contract) > 0 { - i -= len(m.Contract) - copy(dAtA[i:], m.Contract) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Contract))) - i-- - dAtA[i] = 0x22 - } - if len(m.NewAdmin) > 0 { - i -= len(m.NewAdmin) - copy(dAtA[i:], m.NewAdmin) - i = encodeVarintProposal(dAtA, i, uint64(len(m.NewAdmin))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *ClearAdminProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ClearAdminProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ClearAdminProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Contract) > 0 { - i -= len(m.Contract) - copy(dAtA[i:], m.Contract) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Contract))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *PinCodesProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *PinCodesProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *PinCodesProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CodeIDs) > 0 { - dAtA3 := make([]byte, len(m.CodeIDs)*10) - var j2 int - for _, num := range m.CodeIDs { - for num >= 1<<7 { - dAtA3[j2] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j2++ - } - dAtA3[j2] = uint8(num) - j2++ - } - i -= j2 - copy(dAtA[i:], dAtA3[:j2]) - i = encodeVarintProposal(dAtA, i, uint64(j2)) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *UnpinCodesProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnpinCodesProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UnpinCodesProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CodeIDs) > 0 { - dAtA5 := make([]byte, len(m.CodeIDs)*10) - var j4 int - for _, num := range m.CodeIDs { - for num >= 1<<7 { - dAtA5[j4] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j4++ - } - dAtA5[j4] = uint8(num) - j4++ - } - i -= j4 - copy(dAtA[i:], dAtA5[:j4]) - i = encodeVarintProposal(dAtA, i, uint64(j4)) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *AccessConfigUpdate) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *AccessConfigUpdate) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *AccessConfigUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.InstantiatePermission.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintProposal(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if m.CodeID != 0 { - i = encodeVarintProposal(dAtA, i, uint64(m.CodeID)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *UpdateInstantiateConfigProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UpdateInstantiateConfigProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UpdateInstantiateConfigProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.AccessConfigUpdates) > 0 { - for iNdEx := len(m.AccessConfigUpdates) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.AccessConfigUpdates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintProposal(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *StoreAndInstantiateContractProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StoreAndInstantiateContractProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *StoreAndInstantiateContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CodeHash) > 0 { - i -= len(m.CodeHash) - copy(dAtA[i:], m.CodeHash) - i = encodeVarintProposal(dAtA, i, uint64(len(m.CodeHash))) - i-- - dAtA[i] = 0x6a - } - if len(m.Builder) > 0 { - i -= len(m.Builder) - copy(dAtA[i:], m.Builder) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Builder))) - i-- - dAtA[i] = 0x62 - } - if len(m.Source) > 0 { - i -= len(m.Source) - copy(dAtA[i:], m.Source) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Source))) - i-- - dAtA[i] = 0x5a - } - if len(m.Funds) > 0 { - for iNdEx := len(m.Funds) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Funds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintProposal(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x52 - } - } - if len(m.Msg) > 0 { - i -= len(m.Msg) - copy(dAtA[i:], m.Msg) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Msg))) - i-- - dAtA[i] = 0x4a - } - if len(m.Label) > 0 { - i -= len(m.Label) - copy(dAtA[i:], m.Label) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Label))) - i-- - dAtA[i] = 0x42 - } - if len(m.Admin) > 0 { - i -= len(m.Admin) - copy(dAtA[i:], m.Admin) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Admin))) - i-- - dAtA[i] = 0x3a - } - if m.UnpinCode { - i-- - if m.UnpinCode { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x30 - } - if m.InstantiatePermission != nil { - { - size, err := m.InstantiatePermission.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintProposal(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - if len(m.WASMByteCode) > 0 { - i -= len(m.WASMByteCode) - copy(dAtA[i:], m.WASMByteCode) - i = encodeVarintProposal(dAtA, i, uint64(len(m.WASMByteCode))) - i-- - dAtA[i] = 0x22 - } - if len(m.RunAs) > 0 { - i -= len(m.RunAs) - copy(dAtA[i:], m.RunAs) - i = encodeVarintProposal(dAtA, i, uint64(len(m.RunAs))) - i-- - dAtA[i] = 0x1a - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { - offset -= sovProposal(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *StoreCodeProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.RunAs) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.WASMByteCode) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if m.InstantiatePermission != nil { - l = m.InstantiatePermission.Size() - n += 1 + l + sovProposal(uint64(l)) - } - if m.UnpinCode { - n += 2 - } - l = len(m.Source) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Builder) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.CodeHash) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - return n -} - -func (m *InstantiateContractProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.RunAs) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Admin) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if m.CodeID != 0 { - n += 1 + sovProposal(uint64(m.CodeID)) - } - l = len(m.Label) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Msg) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if len(m.Funds) > 0 { - for _, e := range m.Funds { - l = e.Size() - n += 1 + l + sovProposal(uint64(l)) - } - } - return n -} - -func (m *InstantiateContract2Proposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.RunAs) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Admin) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if m.CodeID != 0 { - n += 1 + sovProposal(uint64(m.CodeID)) - } - l = len(m.Label) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Msg) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if len(m.Funds) > 0 { - for _, e := range m.Funds { - l = e.Size() - n += 1 + l + sovProposal(uint64(l)) - } - } - l = len(m.Salt) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if m.FixMsg { - n += 2 - } - return n -} - -func (m *MigrateContractProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Contract) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if m.CodeID != 0 { - n += 1 + sovProposal(uint64(m.CodeID)) - } - l = len(m.Msg) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - return n -} - -func (m *SudoContractProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Contract) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Msg) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - return n -} - -func (m *ExecuteContractProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.RunAs) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Contract) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Msg) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if len(m.Funds) > 0 { - for _, e := range m.Funds { - l = e.Size() - n += 1 + l + sovProposal(uint64(l)) - } - } - return n -} - -func (m *UpdateAdminProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.NewAdmin) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Contract) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - return n -} - -func (m *ClearAdminProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Contract) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - return n -} - -func (m *PinCodesProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if len(m.CodeIDs) > 0 { - l = 0 - for _, e := range m.CodeIDs { - l += sovProposal(uint64(e)) - } - n += 1 + sovProposal(uint64(l)) + l - } - return n -} - -func (m *UnpinCodesProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if len(m.CodeIDs) > 0 { - l = 0 - for _, e := range m.CodeIDs { - l += sovProposal(uint64(e)) - } - n += 1 + sovProposal(uint64(l)) + l - } - return n -} - -func (m *AccessConfigUpdate) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.CodeID != 0 { - n += 1 + sovProposal(uint64(m.CodeID)) - } - l = m.InstantiatePermission.Size() - n += 1 + l + sovProposal(uint64(l)) - return n -} - -func (m *UpdateInstantiateConfigProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if len(m.AccessConfigUpdates) > 0 { - for _, e := range m.AccessConfigUpdates { - l = e.Size() - n += 1 + l + sovProposal(uint64(l)) - } - } - return n -} - -func (m *StoreAndInstantiateContractProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.RunAs) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.WASMByteCode) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if m.InstantiatePermission != nil { - l = m.InstantiatePermission.Size() - n += 1 + l + sovProposal(uint64(l)) - } - if m.UnpinCode { - n += 2 - } - l = len(m.Admin) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Label) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Msg) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - if len(m.Funds) > 0 { - for _, e := range m.Funds { - l = e.Size() - n += 1 + l + sovProposal(uint64(l)) - } - } - l = len(m.Source) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.Builder) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - l = len(m.CodeHash) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } - return n -} - -func sovProposal(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozProposal(x uint64) (n int) { - return sovProposal(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *StoreCodeProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StoreCodeProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StoreCodeProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RunAs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RunAs = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field WASMByteCode", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.WASMByteCode = append(m.WASMByteCode[:0], dAtA[iNdEx:postIndex]...) - if m.WASMByteCode == nil { - m.WASMByteCode = []byte{} - } - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InstantiatePermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.InstantiatePermission == nil { - m.InstantiatePermission = &AccessConfig{} - } - if err := m.InstantiatePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field UnpinCode", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.UnpinCode = bool(v != 0) - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Source", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Source = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 10: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Builder", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Builder = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CodeHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CodeHash = append(m.CodeHash[:0], dAtA[iNdEx:postIndex]...) - if m.CodeHash == nil { - m.CodeHash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *InstantiateContractProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: InstantiateContractProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: InstantiateContractProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RunAs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RunAs = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Admin = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) - } - m.CodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CodeID |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Label", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Label = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) - if m.Msg == nil { - m.Msg = []byte{} - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Funds = append(m.Funds, types.Coin{}) - if err := m.Funds[len(m.Funds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *InstantiateContract2Proposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: InstantiateContract2Proposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: InstantiateContract2Proposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RunAs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RunAs = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Admin = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) - } - m.CodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CodeID |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Label", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Label = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) - if m.Msg == nil { - m.Msg = []byte{} - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Funds = append(m.Funds, types.Coin{}) - if err := m.Funds[len(m.Funds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Salt", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Salt = append(m.Salt[:0], dAtA[iNdEx:postIndex]...) - if m.Salt == nil { - m.Salt = []byte{} - } - iNdEx = postIndex - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field FixMsg", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.FixMsg = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MigrateContractProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MigrateContractProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MigrateContractProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Contract = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) - } - m.CodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CodeID |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) - if m.Msg == nil { - m.Msg = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SudoContractProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SudoContractProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SudoContractProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Contract = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) - if m.Msg == nil { - m.Msg = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ExecuteContractProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ExecuteContractProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ExecuteContractProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RunAs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RunAs = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Contract = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) - if m.Msg == nil { - m.Msg = []byte{} - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Funds = append(m.Funds, types.Coin{}) - if err := m.Funds[len(m.Funds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UpdateAdminProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UpdateAdminProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UpdateAdminProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NewAdmin", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.NewAdmin = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Contract = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ClearAdminProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ClearAdminProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ClearAdminProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Contract = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *PinCodesProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: PinCodesProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: PinCodesProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.CodeIDs = append(m.CodeIDs, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.CodeIDs) == 0 { - m.CodeIDs = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.CodeIDs = append(m.CodeIDs, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field CodeIDs", wireType) - } - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UnpinCodesProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnpinCodesProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnpinCodesProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.CodeIDs = append(m.CodeIDs, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.CodeIDs) == 0 { - m.CodeIDs = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.CodeIDs = append(m.CodeIDs, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field CodeIDs", wireType) - } - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AccessConfigUpdate) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: AccessConfigUpdate: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AccessConfigUpdate: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) - } - m.CodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.CodeID |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InstantiatePermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.InstantiatePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UpdateInstantiateConfigProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UpdateInstantiateConfigProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UpdateInstantiateConfigProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AccessConfigUpdates", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AccessConfigUpdates = append(m.AccessConfigUpdates, AccessConfigUpdate{}) - if err := m.AccessConfigUpdates[len(m.AccessConfigUpdates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StoreAndInstantiateContractProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StoreAndInstantiateContractProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StoreAndInstantiateContractProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RunAs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RunAs = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field WASMByteCode", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.WASMByteCode = append(m.WASMByteCode[:0], dAtA[iNdEx:postIndex]...) - if m.WASMByteCode == nil { - m.WASMByteCode = []byte{} - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InstantiatePermission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.InstantiatePermission == nil { - m.InstantiatePermission = &AccessConfig{} - } - if err := m.InstantiatePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field UnpinCode", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.UnpinCode = bool(v != 0) - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Admin = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Label", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Label = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) - if m.Msg == nil { - m.Msg = []byte{} - } - iNdEx = postIndex - case 10: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Funds = append(m.Funds, types.Coin{}) - if err := m.Funds[len(m.Funds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Source", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Source = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 12: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Builder", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Builder = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 13: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CodeHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CodeHash = append(m.CodeHash[:0], dAtA[iNdEx:postIndex]...) - if m.CodeHash == nil { - m.CodeHash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipProposal(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthProposal - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipProposal(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowProposal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowProposal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowProposal - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthProposal - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupProposal - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthProposal - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthProposal = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowProposal = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupProposal = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/wasm/types/proposal_test.go b/x/wasm/types/proposal_test.go deleted file mode 100644 index a139d47816..0000000000 --- a/x/wasm/types/proposal_test.go +++ /dev/null @@ -1,1129 +0,0 @@ -package types - -import ( - "bytes" - "encoding/json" - "strings" - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" -) - -func TestValidateProposalCommons(t *testing.T) { - type commonProposal struct { - Title, Description string - } - - specs := map[string]struct { - src commonProposal - expErr bool - }{ - "all good": {src: commonProposal{ - Title: "Foo", - Description: "Bar", - }}, - "prevent empty title": { - src: commonProposal{ - Description: "Bar", - }, - expErr: true, - }, - "prevent white space only title": { - src: commonProposal{ - Title: " ", - Description: "Bar", - }, - expErr: true, - }, - "prevent leading white spaces in title": { - src: commonProposal{ - Title: " Foo", - Description: "Bar", - }, - expErr: true, - }, - "prevent title exceeds max length ": { - src: commonProposal{ - Title: strings.Repeat("a", v1beta1.MaxTitleLength+1), - Description: "Bar", - }, - expErr: true, - }, - "prevent empty description": { - src: commonProposal{ - Title: "Foo", - }, - expErr: true, - }, - "prevent leading white spaces in description": { - src: commonProposal{ - Title: "Foo", - Description: " Bar", - }, - expErr: true, - }, - "prevent white space only description": { - src: commonProposal{ - Title: "Foo", - Description: " ", - }, - expErr: true, - }, - "prevent descr exceeds max length ": { - src: commonProposal{ - Title: "Foo", - Description: strings.Repeat("a", v1beta1.MaxDescriptionLength+1), - }, - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := validateProposalCommons(spec.src.Title, spec.src.Description) - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateStoreCodeProposal(t *testing.T) { - var anyAddress sdk.AccAddress = bytes.Repeat([]byte{0x0}, ContractAddrLen) - - specs := map[string]struct { - src *StoreCodeProposal - expErr bool - }{ - "all good": { - src: StoreCodeProposalFixture(), - }, - "all good no code verification info": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.Source = "" - p.Builder = "" - p.CodeHash = nil - }), - }, - "source missing": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.Source = "" - }), - expErr: true, - }, - "builder missing": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.Builder = "" - }), - expErr: true, - }, - "code hash missing": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.CodeHash = nil - }), - expErr: true, - }, - "with instantiate permission": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - accessConfig := AccessTypeAnyOfAddresses.With(anyAddress) - p.InstantiatePermission = &accessConfig - }), - }, - "base data missing": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.Title = "" - }), - expErr: true, - }, - "run_as missing": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.RunAs = "" - }), - expErr: true, - }, - "run_as invalid": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.RunAs = invalidAddress - }), - expErr: true, - }, - "wasm code missing": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.WASMByteCode = nil - }), - expErr: true, - }, - "wasm code invalid": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxProposalWasmSize+1) - }), - expErr: true, - }, - "with invalid instantiate permission": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.InstantiatePermission = &AccessConfig{} - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateInstantiateContractProposal(t *testing.T) { - specs := map[string]struct { - src *InstantiateContractProposal - expErr bool - }{ - "all good": { - src: InstantiateContractProposalFixture(), - }, - "without admin": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Admin = "" - }), - }, - "without init msg": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Msg = nil - }), - expErr: true, - }, - "with invalid init msg": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Msg = []byte("not a json string") - }), - expErr: true, - }, - "without init funds": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Funds = nil - }), - }, - "base data missing": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Title = "" - }), - expErr: true, - }, - "run_as missing": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.RunAs = "" - }), - expErr: true, - }, - "run_as invalid": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.RunAs = invalidAddress - }), - expErr: true, - }, - "admin invalid": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Admin = invalidAddress - }), - expErr: true, - }, - "code id empty": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.CodeID = 0 - }), - expErr: true, - }, - "label empty": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Label = "" - }), - expErr: true, - }, - "init funds negative": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(-1)}} - }), - expErr: true, - }, - "init funds with duplicates": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(1)}, {Denom: "foo", Amount: sdk.NewInt(2)}} - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateInstantiateContract2Proposal(t *testing.T) { - specs := map[string]struct { - src *InstantiateContract2Proposal - expErr bool - }{ - "all good": { - src: InstantiateContract2ProposalFixture(), - }, - "without admin": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Admin = "" - }), - }, - "without init msg": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Msg = nil - }), - expErr: true, - }, - "with invalid init msg": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Msg = []byte("not a json string") - }), - expErr: true, - }, - "without init funds": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Funds = nil - }), - }, - "base data missing": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Title = "" - }), - expErr: true, - }, - "run_as missing": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.RunAs = "" - }), - expErr: true, - }, - "run_as invalid": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.RunAs = invalidAddress - }), - expErr: true, - }, - "admin invalid": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Admin = invalidAddress - }), - expErr: true, - }, - "code id empty": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.CodeID = 0 - }), - expErr: true, - }, - "label empty": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Label = "" - }), - expErr: true, - }, - "untrimmed label ": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Label = " label " - }), - expErr: true, - }, - "init funds negative": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(-1)}} - }), - expErr: true, - }, - "init funds with duplicates": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(1)}, {Denom: "foo", Amount: sdk.NewInt(2)}} - }), - expErr: true, - }, - "init with empty salt": { - src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { - p.Salt = nil - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateStoreAndInstantiateContractProposal(t *testing.T) { - var anyAddress sdk.AccAddress = bytes.Repeat([]byte{0x0}, ContractAddrLen) - - specs := map[string]struct { - src *StoreAndInstantiateContractProposal - expErr bool - }{ - "all good": { - src: StoreAndInstantiateContractProposalFixture(), - }, - "all good no code verification info": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Source = "" - p.Builder = "" - p.CodeHash = nil - }), - }, - "source missing": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Source = "" - }), - expErr: true, - }, - "builder missing": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Builder = "" - }), - expErr: true, - }, - "code hash missing": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.CodeHash = nil - }), - expErr: true, - }, - "with instantiate permission": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - accessConfig := AccessTypeAnyOfAddresses.With(anyAddress) - p.InstantiatePermission = &accessConfig - }), - }, - "base data missing": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Title = "" - }), - expErr: true, - }, - "run_as missing": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.RunAs = "" - }), - expErr: true, - }, - "run_as invalid": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.RunAs = invalidAddress - }), - expErr: true, - }, - "wasm code missing": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.WASMByteCode = nil - }), - expErr: true, - }, - "wasm code invalid": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxProposalWasmSize+1) - }), - expErr: true, - }, - "with invalid instantiate permission": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.InstantiatePermission = &AccessConfig{} - }), - expErr: true, - }, - "without admin": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Admin = "" - }), - }, - "without init msg": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Msg = nil - }), - expErr: true, - }, - "with invalid init msg": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Msg = []byte("not a json string") - }), - expErr: true, - }, - "without init funds": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Funds = nil - }), - }, - "admin invalid": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Admin = invalidAddress - }), - expErr: true, - }, - "label empty": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Label = "" - }), - expErr: true, - }, - "init funds negative": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(-1)}} - }), - expErr: true, - }, - "init funds with duplicates": { - src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) { - p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(1)}, {Denom: "foo", Amount: sdk.NewInt(2)}} - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateMigrateContractProposal(t *testing.T) { - invalidAddress := "invalid address2" - - specs := map[string]struct { - src *MigrateContractProposal - expErr bool - }{ - "all good": { - src: MigrateContractProposalFixture(), - }, - "without migrate msg": { - src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.Msg = nil - }), - expErr: true, - }, - "migrate msg with invalid json": { - src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.Msg = []byte("not a json message") - }), - expErr: true, - }, - "base data missing": { - src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.Title = "" - }), - expErr: true, - }, - "contract missing": { - src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.Contract = "" - }), - expErr: true, - }, - "contract invalid": { - src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.Contract = invalidAddress - }), - expErr: true, - }, - "code id empty": { - src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.CodeID = 0 - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateSudoContractProposal(t *testing.T) { - specs := map[string]struct { - src *SudoContractProposal - expErr bool - }{ - "all good": { - src: SudoContractProposalFixture(), - }, - "msg is nil": { - src: SudoContractProposalFixture(func(p *SudoContractProposal) { - p.Msg = nil - }), - expErr: true, - }, - "msg with invalid json": { - src: SudoContractProposalFixture(func(p *SudoContractProposal) { - p.Msg = []byte("not a json message") - }), - expErr: true, - }, - "base data missing": { - src: SudoContractProposalFixture(func(p *SudoContractProposal) { - p.Title = "" - }), - expErr: true, - }, - "contract missing": { - src: SudoContractProposalFixture(func(p *SudoContractProposal) { - p.Contract = "" - }), - expErr: true, - }, - "contract invalid": { - src: SudoContractProposalFixture(func(p *SudoContractProposal) { - p.Contract = invalidAddress - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateExecuteContractProposal(t *testing.T) { - specs := map[string]struct { - src *ExecuteContractProposal - expErr bool - }{ - "all good": { - src: ExecuteContractProposalFixture(), - }, - "msg is nil": { - src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { - p.Msg = nil - }), - expErr: true, - }, - "msg with invalid json": { - src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { - p.Msg = []byte("not a valid json message") - }), - expErr: true, - }, - "base data missing": { - src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { - p.Title = "" - }), - expErr: true, - }, - "contract missing": { - src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { - p.Contract = "" - }), - expErr: true, - }, - "contract invalid": { - src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { - p.Contract = invalidAddress - }), - expErr: true, - }, - "run as is invalid": { - src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { - p.RunAs = invalidAddress - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateUpdateAdminProposal(t *testing.T) { - specs := map[string]struct { - src *UpdateAdminProposal - expErr bool - }{ - "all good": { - src: UpdateAdminProposalFixture(), - }, - "base data missing": { - src: UpdateAdminProposalFixture(func(p *UpdateAdminProposal) { - p.Title = "" - }), - expErr: true, - }, - "contract missing": { - src: UpdateAdminProposalFixture(func(p *UpdateAdminProposal) { - p.Contract = "" - }), - expErr: true, - }, - "contract invalid": { - src: UpdateAdminProposalFixture(func(p *UpdateAdminProposal) { - p.Contract = invalidAddress - }), - expErr: true, - }, - "admin missing": { - src: UpdateAdminProposalFixture(func(p *UpdateAdminProposal) { - p.NewAdmin = "" - }), - expErr: true, - }, - "admin invalid": { - src: UpdateAdminProposalFixture(func(p *UpdateAdminProposal) { - p.NewAdmin = invalidAddress - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestValidateClearAdminProposal(t *testing.T) { - specs := map[string]struct { - src *ClearAdminProposal - expErr bool - }{ - "all good": { - src: ClearAdminProposalFixture(), - }, - "base data missing": { - src: ClearAdminProposalFixture(func(p *ClearAdminProposal) { - p.Title = "" - }), - expErr: true, - }, - "contract missing": { - src: ClearAdminProposalFixture(func(p *ClearAdminProposal) { - p.Contract = "" - }), - expErr: true, - }, - "contract invalid": { - src: ClearAdminProposalFixture(func(p *ClearAdminProposal) { - p.Contract = invalidAddress - }), - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestProposalStrings(t *testing.T) { - specs := map[string]struct { - src v1beta1.Content - exp string - }{ - "store code": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.WASMByteCode = []byte{0o1, 0o2, 0o3, 0o4, 0o5, 0o6, 0o7, 0x08, 0x09, 0x0a} - }), - exp: `Store Code Proposal: - Title: Foo - Description: Bar - Run as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 - WasmCode: 0102030405060708090A - Source: https://example.com/ - Builder: cosmwasm/workspace-optimizer:v0.12.8 - Code Hash: 6E340B9CFFB37A989CA544E6BB780A2C78901D3FB33738768511A30617AFA01D -`, - }, - "instantiate contract": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(1)}, {Denom: "bar", Amount: sdk.NewInt(2)}} - }), - exp: `Instantiate Code Proposal: - Title: Foo - Description: Bar - Run as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 - Admin: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 - Code id: 1 - Label: testing - Msg: "{\"verifier\":\"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4\",\"beneficiary\":\"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4\"}" - Funds: 1foo,2bar -`, - }, - "instantiate contract without funds": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { p.Funds = nil }), - exp: `Instantiate Code Proposal: - Title: Foo - Description: Bar - Run as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 - Admin: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 - Code id: 1 - Label: testing - Msg: "{\"verifier\":\"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4\",\"beneficiary\":\"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4\"}" - Funds: -`, - }, - "instantiate contract without admin": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { p.Admin = "" }), - exp: `Instantiate Code Proposal: - Title: Foo - Description: Bar - Run as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 - Admin: - Code id: 1 - Label: testing - Msg: "{\"verifier\":\"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4\",\"beneficiary\":\"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4\"}" - Funds: -`, - }, - "migrate contract": { - src: MigrateContractProposalFixture(), - exp: `Migrate Contract Proposal: - Title: Foo - Description: Bar - Contract: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr - Code id: 1 - Msg: "{\"verifier\":\"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4\"}" -`, - }, - "update admin": { - src: UpdateAdminProposalFixture(), - exp: `Update Contract Admin Proposal: - Title: Foo - Description: Bar - Contract: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr - New Admin: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 -`, - }, - "clear admin": { - src: ClearAdminProposalFixture(), - exp: `Clear Contract Admin Proposal: - Title: Foo - Description: Bar - Contract: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr -`, - }, - "pin codes": { - src: &PinCodesProposal{ - Title: "Foo", - Description: "Bar", - CodeIDs: []uint64{1, 2, 3}, - }, - exp: `Pin Wasm Codes Proposal: - Title: Foo - Description: Bar - Codes: [1 2 3] -`, - }, - "unpin codes": { - src: &UnpinCodesProposal{ - Title: "Foo", - Description: "Bar", - CodeIDs: []uint64{3, 2, 1}, - }, - exp: `Unpin Wasm Codes Proposal: - Title: Foo - Description: Bar - Codes: [3 2 1] -`, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - assert.Equal(t, spec.exp, spec.src.String()) - }) - } -} - -func TestProposalYaml(t *testing.T) { - specs := map[string]struct { - src v1beta1.Content - exp string - }{ - "store code": { - src: StoreCodeProposalFixture(func(p *StoreCodeProposal) { - p.WASMByteCode = []byte{0o1, 0o2, 0o3, 0o4, 0o5, 0o6, 0o7, 0x08, 0x09, 0x0a} - }), - exp: `title: Foo -description: Bar -run_as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 -wasm_byte_code: AQIDBAUGBwgJCg== -instantiate_permission: null -source: https://example.com/ -builder: cosmwasm/workspace-optimizer:v0.12.8 -code_hash: 6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d -`, - }, - "instantiate contract": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(1)}, {Denom: "bar", Amount: sdk.NewInt(2)}} - }), - exp: `title: Foo -description: Bar -run_as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 -admin: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 -code_id: 1 -label: testing -msg: '{"verifier":"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4","beneficiary":"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4"}' -funds: -- denom: foo - amount: "1" -- denom: bar - amount: "2" -`, - }, - "instantiate contract without funds": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { p.Funds = nil }), - exp: `title: Foo -description: Bar -run_as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 -admin: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 -code_id: 1 -label: testing -msg: '{"verifier":"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4","beneficiary":"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4"}' -funds: [] -`, - }, - "instantiate contract without admin": { - src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { p.Admin = "" }), - exp: `title: Foo -description: Bar -run_as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 -admin: "" -code_id: 1 -label: testing -msg: '{"verifier":"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4","beneficiary":"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4"}' -funds: [] -`, - }, - "migrate contract": { - src: MigrateContractProposalFixture(), - exp: `title: Foo -description: Bar -contract: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr -code_id: 1 -msg: '{"verifier":"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4"}' -`, - }, - "update admin": { - src: UpdateAdminProposalFixture(), - exp: `title: Foo -description: Bar -new_admin: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 -contract: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr -`, - }, - "clear admin": { - src: ClearAdminProposalFixture(), - exp: `title: Foo -description: Bar -contract: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr -`, - }, - "pin codes": { - src: &PinCodesProposal{ - Title: "Foo", - Description: "Bar", - CodeIDs: []uint64{1, 2, 3}, - }, - exp: `title: Foo -description: Bar -code_ids: -- 1 -- 2 -- 3 -`, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - v, err := yaml.Marshal(&spec.src) - require.NoError(t, err) - assert.Equal(t, spec.exp, string(v)) - }) - } -} - -func TestConvertToProposals(t *testing.T) { - cases := map[string]struct { - input string - isError bool - proposals []ProposalType - }{ - "one proper item": { - input: "UpdateAdmin", - proposals: []ProposalType{ProposalTypeUpdateAdmin}, - }, - "multiple proper items": { - input: "StoreCode,InstantiateContract,MigrateContract", - proposals: []ProposalType{ProposalTypeStoreCode, ProposalTypeInstantiateContract, ProposalTypeMigrateContract}, - }, - "empty trailing item": { - input: "StoreCode,", - isError: true, - }, - "invalid item": { - input: "StoreCode,InvalidProposalType", - isError: true, - }, - } - - for name, tc := range cases { - t.Run(name, func(t *testing.T) { - chunks := strings.Split(tc.input, ",") - proposals, err := ConvertToProposals(chunks) - if tc.isError { - require.Error(t, err) - } else { - require.NoError(t, err) - require.Equal(t, proposals, tc.proposals) - } - }) - } -} - -func TestUnmarshalContentFromJson(t *testing.T) { - specs := map[string]struct { - src string - got v1beta1.Content - exp v1beta1.Content - }{ - "instantiate ": { - src: ` -{ - "title": "foo", - "description": "bar", - "admin": "myAdminAddress", - "code_id": 1, - "funds": [{"denom": "ALX", "amount": "2"},{"denom": "BLX","amount": "3"}], - "msg": {}, - "label": "testing", - "run_as": "myRunAsAddress" -}`, - got: &InstantiateContractProposal{}, - exp: &InstantiateContractProposal{ - Title: "foo", - Description: "bar", - RunAs: "myRunAsAddress", - Admin: "myAdminAddress", - CodeID: 1, - Label: "testing", - Msg: []byte("{}"), - Funds: sdk.NewCoins(sdk.NewCoin("ALX", sdk.NewInt(2)), sdk.NewCoin("BLX", sdk.NewInt(3))), - }, - }, - "migrate ": { - src: ` -{ - "title": "foo", - "description": "bar", - "code_id": 1, - "contract": "myContractAddr", - "msg": {}, - "run_as": "myRunAsAddress" -}`, - got: &MigrateContractProposal{}, - exp: &MigrateContractProposal{ - Title: "foo", - Description: "bar", - Contract: "myContractAddr", - CodeID: 1, - Msg: []byte("{}"), - }, - }, - } - for name, spec := range specs { - t.Run(name, func(t *testing.T) { - require.NoError(t, json.Unmarshal([]byte(spec.src), spec.got)) - assert.Equal(t, spec.exp, spec.got) - }) - } -} - -func TestProposalJsonSignBytes(t *testing.T) { - const myInnerMsg = `{"foo":"bar"}` - specs := map[string]struct { - src v1beta1.Content - exp string - }{ - "instantiate contract": { - src: &InstantiateContractProposal{Msg: RawContractMessage(myInnerMsg)}, - exp: ` -{ - "type":"cosmos-sdk/MsgSubmitProposal", - "value":{"content":{"type":"wasm/InstantiateContractProposal","value":{"funds":[],"msg":{"foo":"bar"}}},"initial_deposit":[]} -}`, - }, - "migrate contract": { - src: &MigrateContractProposal{Msg: RawContractMessage(myInnerMsg)}, - exp: ` -{ - "type":"cosmos-sdk/MsgSubmitProposal", - "value":{"content":{"type":"wasm/MigrateContractProposal","value":{"msg":{"foo":"bar"}}},"initial_deposit":[]} -}`, - }, - } - for name, spec := range specs { - t.Run(name, func(t *testing.T) { - msg, err := v1beta1.NewMsgSubmitProposal(spec.src, sdk.NewCoins(), []byte{}) - require.NoError(t, err) - - bz := msg.GetSignBytes() - assert.JSONEq(t, spec.exp, string(bz), "exp %s\n got: %s\n", spec.exp, string(bz)) - }) - } -} diff --git a/x/wasm/types/test_fixtures.go b/x/wasm/types/test_fixtures.go index 8d573984c2..be4c5725e5 100644 --- a/x/wasm/types/test_fixtures.go +++ b/x/wasm/types/test_fixtures.go @@ -1,13 +1,11 @@ package types import ( - "bytes" _ "embed" - "encoding/hex" - "encoding/json" "math/rand" wasmvm "github.com/CosmWasm/wasmvm" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -205,250 +203,3 @@ func MsgExecuteContractFixture(mutators ...func(*MsgExecuteContract)) *MsgExecut } return r } - -func StoreCodeProposalFixture(mutators ...func(*StoreCodeProposal)) *StoreCodeProposal { - const anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4" - wasm := []byte{0x0} - // got the value from shell sha256sum - codeHash, err := hex.DecodeString("6E340B9CFFB37A989CA544E6BB780A2C78901D3FB33738768511A30617AFA01D") - if err != nil { - panic(err) - } - - p := &StoreCodeProposal{ - Title: "Foo", - Description: "Bar", - RunAs: anyAddress, - WASMByteCode: wasm, - Source: "https://example.com/", - Builder: "cosmwasm/workspace-optimizer:v0.12.8", - CodeHash: codeHash, - } - for _, m := range mutators { - m(p) - } - return p -} - -func InstantiateContractProposalFixture(mutators ...func(p *InstantiateContractProposal)) *InstantiateContractProposal { - var ( - anyValidAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, ContractAddrLen) - - initMsg = struct { - Verifier sdk.AccAddress `json:"verifier"` - Beneficiary sdk.AccAddress `json:"beneficiary"` - }{ - Verifier: anyValidAddress, - Beneficiary: anyValidAddress, - } - ) - const anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4" - - initMsgBz, err := json.Marshal(initMsg) - if err != nil { - panic(err) - } - p := &InstantiateContractProposal{ - Title: "Foo", - Description: "Bar", - RunAs: anyAddress, - Admin: anyAddress, - CodeID: 1, - Label: "testing", - Msg: initMsgBz, - Funds: nil, - } - - for _, m := range mutators { - m(p) - } - return p -} - -func InstantiateContract2ProposalFixture(mutators ...func(p *InstantiateContract2Proposal)) *InstantiateContract2Proposal { - var ( - anyValidAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, ContractAddrLen) - - initMsg = struct { - Verifier sdk.AccAddress `json:"verifier"` - Beneficiary sdk.AccAddress `json:"beneficiary"` - }{ - Verifier: anyValidAddress, - Beneficiary: anyValidAddress, - } - ) - const ( - anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4" - mySalt = "myDefaultSalt" - ) - - initMsgBz, err := json.Marshal(initMsg) - if err != nil { - panic(err) - } - p := &InstantiateContract2Proposal{ - Title: "Foo", - Description: "Bar", - RunAs: anyAddress, - Admin: anyAddress, - CodeID: 1, - Label: "testing", - Msg: initMsgBz, - Funds: nil, - Salt: []byte(mySalt), - FixMsg: false, - } - - for _, m := range mutators { - m(p) - } - return p -} - -func StoreAndInstantiateContractProposalFixture(mutators ...func(p *StoreAndInstantiateContractProposal)) *StoreAndInstantiateContractProposal { - var ( - anyValidAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, ContractAddrLen) - - initMsg = struct { - Verifier sdk.AccAddress `json:"verifier"` - Beneficiary sdk.AccAddress `json:"beneficiary"` - }{ - Verifier: anyValidAddress, - Beneficiary: anyValidAddress, - } - ) - const anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4" - wasm := []byte{0x0} - // got the value from shell sha256sum - codeHash, err := hex.DecodeString("6E340B9CFFB37A989CA544E6BB780A2C78901D3FB33738768511A30617AFA01D") - if err != nil { - panic(err) - } - - initMsgBz, err := json.Marshal(initMsg) - if err != nil { - panic(err) - } - p := &StoreAndInstantiateContractProposal{ - Title: "Foo", - Description: "Bar", - RunAs: anyAddress, - WASMByteCode: wasm, - Source: "https://example.com/", - Builder: "cosmwasm/workspace-optimizer:v0.12.9", - CodeHash: codeHash, - Admin: anyAddress, - Label: "testing", - Msg: initMsgBz, - Funds: nil, - } - - for _, m := range mutators { - m(p) - } - return p -} - -func MigrateContractProposalFixture(mutators ...func(p *MigrateContractProposal)) *MigrateContractProposal { - var ( - anyValidAddress sdk.AccAddress = bytes.Repeat([]byte{0x1}, ContractAddrLen) - - migMsg = struct { - Verifier sdk.AccAddress `json:"verifier"` - }{Verifier: anyValidAddress} - ) - - migMsgBz, err := json.Marshal(migMsg) - if err != nil { - panic(err) - } - const ( - contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" - anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4" - ) - p := &MigrateContractProposal{ - Title: "Foo", - Description: "Bar", - Contract: contractAddr, - CodeID: 1, - Msg: migMsgBz, - } - - for _, m := range mutators { - m(p) - } - return p -} - -func SudoContractProposalFixture(mutators ...func(p *SudoContractProposal)) *SudoContractProposal { - const ( - contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" - ) - - p := &SudoContractProposal{ - Title: "Foo", - Description: "Bar", - Contract: contractAddr, - Msg: []byte(`{"do":"something"}`), - } - - for _, m := range mutators { - m(p) - } - return p -} - -func ExecuteContractProposalFixture(mutators ...func(p *ExecuteContractProposal)) *ExecuteContractProposal { - const ( - contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" - anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4" - ) - - p := &ExecuteContractProposal{ - Title: "Foo", - Description: "Bar", - Contract: contractAddr, - RunAs: anyAddress, - Msg: []byte(`{"do":"something"}`), - Funds: sdk.Coins{{ - Denom: "stake", - Amount: sdk.NewInt(1), - }}, - } - - for _, m := range mutators { - m(p) - } - return p -} - -func UpdateAdminProposalFixture(mutators ...func(p *UpdateAdminProposal)) *UpdateAdminProposal { - const ( - contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" - anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4" - ) - - p := &UpdateAdminProposal{ - Title: "Foo", - Description: "Bar", - NewAdmin: anyAddress, - Contract: contractAddr, - } - for _, m := range mutators { - m(p) - } - return p -} - -func ClearAdminProposalFixture(mutators ...func(p *ClearAdminProposal)) *ClearAdminProposal { - const contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" - p := &ClearAdminProposal{ - Title: "Foo", - Description: "Bar", - Contract: contractAddr, - } - for _, m := range mutators { - m(p) - } - return p -} diff --git a/x/wasm/types/tx.go b/x/wasm/types/tx.go index ba8acce15d..d739cb49aa 100644 --- a/x/wasm/types/tx.go +++ b/x/wasm/types/tx.go @@ -7,6 +7,7 @@ import ( "strings" errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -103,7 +104,7 @@ func (msg MsgInstantiateContract) ValidateBasic() error { } if err := ValidateLabel(msg.Label); err != nil { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "label is required") + return errorsmod.Wrap(err, "label") } if !msg.Funds.IsValid() { @@ -364,7 +365,7 @@ func (msg MsgInstantiateContract2) ValidateBasic() error { } if err := ValidateLabel(msg.Label); err != nil { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "label is required") + return errorsmod.Wrap(err, "label") } if !msg.Funds.IsValid() { @@ -484,12 +485,25 @@ func (msg MsgPinCodes) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } +const maxCodeIDTotal = 50 + func (msg MsgPinCodes) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return errorsmod.Wrap(err, "authority") } - if len(msg.CodeIDs) == 0 { + return validateCodeIDs(msg.CodeIDs) +} + +// ensure not empty, not duplicates and not exceeding max number +func validateCodeIDs(codeIDs []uint64) error { + switch n := len(codeIDs); { + case n == 0: return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty code ids") + case n > maxCodeIDTotal: + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "total number of code ids is greater than %d", maxCodeIDTotal) + } + if hasDuplicates(codeIDs) { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "duplicate code ids") } return nil } @@ -518,10 +532,7 @@ func (msg MsgUnpinCodes) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return errorsmod.Wrap(err, "authority") } - if len(msg.CodeIDs) == 0 { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty code ids") - } - return nil + return validateCodeIDs(msg.CodeIDs) } func (msg MsgSudoContract) Route() string { @@ -583,7 +594,7 @@ func (msg MsgStoreAndInstantiateContract) ValidateBasic() error { } if err := ValidateLabel(msg.Label); err != nil { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "label is required") + return errorsmod.Wrap(err, "label") } if !msg.Funds.IsValid() { @@ -683,6 +694,7 @@ func (msg MsgRemoveCodeUploadParamsAddresses) ValidateBasic() error { func checkDuplicatedAddresses(addresses []string) error { index := map[string]struct{}{} for _, addr := range addresses { + addr = strings.ToUpper(addr) if _, err := sdk.AccAddressFromBech32(addr); err != nil { return errorsmod.Wrap(err, "addresses") } @@ -693,3 +705,89 @@ func checkDuplicatedAddresses(addresses []string) error { } return nil } + +func (msg MsgStoreAndMigrateContract) Route() string { + return RouterKey +} + +func (msg MsgStoreAndMigrateContract) Type() string { + return "store-and-migrate-contract" +} + +func (msg MsgStoreAndMigrateContract) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg MsgStoreAndMigrateContract) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +func (msg MsgStoreAndMigrateContract) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errorsmod.Wrap(err, "authority") + } + + if _, err := sdk.AccAddressFromBech32(msg.Contract); err != nil { + return errorsmod.Wrap(err, "contract") + } + + if err := msg.Msg.ValidateBasic(); err != nil { + return errorsmod.Wrap(err, "payload msg") + } + + if err := validateWasmCode(msg.WASMByteCode, MaxWasmSize); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error()) + } + + if msg.InstantiatePermission != nil { + if err := msg.InstantiatePermission.ValidateBasic(); err != nil { + return errorsmod.Wrap(err, "instantiate permission") + } + } + return nil +} + +// returns true when slice contains any duplicates +func hasDuplicates[T comparable](s []T) bool { + index := make(map[T]struct{}, len(s)) + for _, v := range s { + if _, exists := index[v]; exists { + return true + } + index[v] = struct{}{} + } + return false +} + +func (msg MsgUpdateContractLabel) Route() string { + return RouterKey +} + +func (msg MsgUpdateContractLabel) Type() string { + return "update-contract-label" +} + +func (msg MsgUpdateContractLabel) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { + return errorsmod.Wrap(err, "sender") + } + if err := ValidateLabel(msg.NewLabel); err != nil { + return errorsmod.Wrap(err, "label") + } + if _, err := sdk.AccAddressFromBech32(msg.Contract); err != nil { + return errorsmod.Wrap(err, "contract") + } + return nil +} + +func (msg MsgUpdateContractLabel) GetSigners() []sdk.AccAddress { + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{senderAddr} +} diff --git a/x/wasm/types/tx.pb.go b/x/wasm/types/tx.pb.go index 76a0bafe02..40ae2a613c 100644 --- a/x/wasm/types/tx.pb.go +++ b/x/wasm/types/tx.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + _ "github.com/cosmos/cosmos-proto" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" @@ -17,15 +21,14 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +var ( + _ = proto.Marshal + _ = fmt.Errorf + _ = math.Inf +) // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -50,9 +53,11 @@ func (*MsgStoreCode) ProtoMessage() {} func (*MsgStoreCode) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{0} } + func (m *MsgStoreCode) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgStoreCode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgStoreCode.Marshal(b, m, deterministic) @@ -65,12 +70,15 @@ func (m *MsgStoreCode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } + func (m *MsgStoreCode) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgStoreCode.Merge(m, src) } + func (m *MsgStoreCode) XXX_Size() int { return m.Size() } + func (m *MsgStoreCode) XXX_DiscardUnknown() { xxx_messageInfo_MsgStoreCode.DiscardUnknown(m) } @@ -91,9 +99,11 @@ func (*MsgStoreCodeResponse) ProtoMessage() {} func (*MsgStoreCodeResponse) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{1} } + func (m *MsgStoreCodeResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgStoreCodeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgStoreCodeResponse.Marshal(b, m, deterministic) @@ -106,12 +116,15 @@ func (m *MsgStoreCodeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte return b[:n], nil } } + func (m *MsgStoreCodeResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgStoreCodeResponse.Merge(m, src) } + func (m *MsgStoreCodeResponse) XXX_Size() int { return m.Size() } + func (m *MsgStoreCodeResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgStoreCodeResponse.DiscardUnknown(m) } @@ -141,9 +154,11 @@ func (*MsgInstantiateContract) ProtoMessage() {} func (*MsgInstantiateContract) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{2} } + func (m *MsgInstantiateContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgInstantiateContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgInstantiateContract.Marshal(b, m, deterministic) @@ -156,12 +171,15 @@ func (m *MsgInstantiateContract) XXX_Marshal(b []byte, deterministic bool) ([]by return b[:n], nil } } + func (m *MsgInstantiateContract) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgInstantiateContract.Merge(m, src) } + func (m *MsgInstantiateContract) XXX_Size() int { return m.Size() } + func (m *MsgInstantiateContract) XXX_DiscardUnknown() { xxx_messageInfo_MsgInstantiateContract.DiscardUnknown(m) } @@ -182,9 +200,11 @@ func (*MsgInstantiateContractResponse) ProtoMessage() {} func (*MsgInstantiateContractResponse) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{3} } + func (m *MsgInstantiateContractResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgInstantiateContractResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgInstantiateContractResponse.Marshal(b, m, deterministic) @@ -197,12 +217,15 @@ func (m *MsgInstantiateContractResponse) XXX_Marshal(b []byte, deterministic boo return b[:n], nil } } + func (m *MsgInstantiateContractResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgInstantiateContractResponse.Merge(m, src) } + func (m *MsgInstantiateContractResponse) XXX_Size() int { return m.Size() } + func (m *MsgInstantiateContractResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgInstantiateContractResponse.DiscardUnknown(m) } @@ -237,9 +260,11 @@ func (*MsgInstantiateContract2) ProtoMessage() {} func (*MsgInstantiateContract2) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{4} } + func (m *MsgInstantiateContract2) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgInstantiateContract2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgInstantiateContract2.Marshal(b, m, deterministic) @@ -252,12 +277,15 @@ func (m *MsgInstantiateContract2) XXX_Marshal(b []byte, deterministic bool) ([]b return b[:n], nil } } + func (m *MsgInstantiateContract2) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgInstantiateContract2.Merge(m, src) } + func (m *MsgInstantiateContract2) XXX_Size() int { return m.Size() } + func (m *MsgInstantiateContract2) XXX_DiscardUnknown() { xxx_messageInfo_MsgInstantiateContract2.DiscardUnknown(m) } @@ -278,9 +306,11 @@ func (*MsgInstantiateContract2Response) ProtoMessage() {} func (*MsgInstantiateContract2Response) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{5} } + func (m *MsgInstantiateContract2Response) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgInstantiateContract2Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgInstantiateContract2Response.Marshal(b, m, deterministic) @@ -293,12 +323,15 @@ func (m *MsgInstantiateContract2Response) XXX_Marshal(b []byte, deterministic bo return b[:n], nil } } + func (m *MsgInstantiateContract2Response) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgInstantiateContract2Response.Merge(m, src) } + func (m *MsgInstantiateContract2Response) XXX_Size() int { return m.Size() } + func (m *MsgInstantiateContract2Response) XXX_DiscardUnknown() { xxx_messageInfo_MsgInstantiateContract2Response.DiscardUnknown(m) } @@ -323,9 +356,11 @@ func (*MsgExecuteContract) ProtoMessage() {} func (*MsgExecuteContract) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{6} } + func (m *MsgExecuteContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgExecuteContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgExecuteContract.Marshal(b, m, deterministic) @@ -338,12 +373,15 @@ func (m *MsgExecuteContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } + func (m *MsgExecuteContract) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgExecuteContract.Merge(m, src) } + func (m *MsgExecuteContract) XXX_Size() int { return m.Size() } + func (m *MsgExecuteContract) XXX_DiscardUnknown() { xxx_messageInfo_MsgExecuteContract.DiscardUnknown(m) } @@ -362,9 +400,11 @@ func (*MsgExecuteContractResponse) ProtoMessage() {} func (*MsgExecuteContractResponse) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{7} } + func (m *MsgExecuteContractResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgExecuteContractResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgExecuteContractResponse.Marshal(b, m, deterministic) @@ -377,12 +417,15 @@ func (m *MsgExecuteContractResponse) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } + func (m *MsgExecuteContractResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgExecuteContractResponse.Merge(m, src) } + func (m *MsgExecuteContractResponse) XXX_Size() int { return m.Size() } + func (m *MsgExecuteContractResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgExecuteContractResponse.DiscardUnknown(m) } @@ -407,9 +450,11 @@ func (*MsgMigrateContract) ProtoMessage() {} func (*MsgMigrateContract) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{8} } + func (m *MsgMigrateContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgMigrateContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgMigrateContract.Marshal(b, m, deterministic) @@ -422,12 +467,15 @@ func (m *MsgMigrateContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } + func (m *MsgMigrateContract) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgMigrateContract.Merge(m, src) } + func (m *MsgMigrateContract) XXX_Size() int { return m.Size() } + func (m *MsgMigrateContract) XXX_DiscardUnknown() { xxx_messageInfo_MsgMigrateContract.DiscardUnknown(m) } @@ -447,9 +495,11 @@ func (*MsgMigrateContractResponse) ProtoMessage() {} func (*MsgMigrateContractResponse) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{9} } + func (m *MsgMigrateContractResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgMigrateContractResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgMigrateContractResponse.Marshal(b, m, deterministic) @@ -462,12 +512,15 @@ func (m *MsgMigrateContractResponse) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } + func (m *MsgMigrateContractResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgMigrateContractResponse.Merge(m, src) } + func (m *MsgMigrateContractResponse) XXX_Size() int { return m.Size() } + func (m *MsgMigrateContractResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgMigrateContractResponse.DiscardUnknown(m) } @@ -490,9 +543,11 @@ func (*MsgUpdateAdmin) ProtoMessage() {} func (*MsgUpdateAdmin) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{10} } + func (m *MsgUpdateAdmin) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgUpdateAdmin) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgUpdateAdmin.Marshal(b, m, deterministic) @@ -505,12 +560,15 @@ func (m *MsgUpdateAdmin) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro return b[:n], nil } } + func (m *MsgUpdateAdmin) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUpdateAdmin.Merge(m, src) } + func (m *MsgUpdateAdmin) XXX_Size() int { return m.Size() } + func (m *MsgUpdateAdmin) XXX_DiscardUnknown() { xxx_messageInfo_MsgUpdateAdmin.DiscardUnknown(m) } @@ -518,8 +576,7 @@ func (m *MsgUpdateAdmin) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateAdmin proto.InternalMessageInfo // MsgUpdateAdminResponse returns empty data -type MsgUpdateAdminResponse struct { -} +type MsgUpdateAdminResponse struct{} func (m *MsgUpdateAdminResponse) Reset() { *m = MsgUpdateAdminResponse{} } func (m *MsgUpdateAdminResponse) String() string { return proto.CompactTextString(m) } @@ -527,9 +584,11 @@ func (*MsgUpdateAdminResponse) ProtoMessage() {} func (*MsgUpdateAdminResponse) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{11} } + func (m *MsgUpdateAdminResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgUpdateAdminResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgUpdateAdminResponse.Marshal(b, m, deterministic) @@ -542,12 +601,15 @@ func (m *MsgUpdateAdminResponse) XXX_Marshal(b []byte, deterministic bool) ([]by return b[:n], nil } } + func (m *MsgUpdateAdminResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUpdateAdminResponse.Merge(m, src) } + func (m *MsgUpdateAdminResponse) XXX_Size() int { return m.Size() } + func (m *MsgUpdateAdminResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgUpdateAdminResponse.DiscardUnknown(m) } @@ -568,9 +630,11 @@ func (*MsgClearAdmin) ProtoMessage() {} func (*MsgClearAdmin) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{12} } + func (m *MsgClearAdmin) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgClearAdmin) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgClearAdmin.Marshal(b, m, deterministic) @@ -583,12 +647,15 @@ func (m *MsgClearAdmin) XXX_Marshal(b []byte, deterministic bool) ([]byte, error return b[:n], nil } } + func (m *MsgClearAdmin) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgClearAdmin.Merge(m, src) } + func (m *MsgClearAdmin) XXX_Size() int { return m.Size() } + func (m *MsgClearAdmin) XXX_DiscardUnknown() { xxx_messageInfo_MsgClearAdmin.DiscardUnknown(m) } @@ -596,8 +663,7 @@ func (m *MsgClearAdmin) XXX_DiscardUnknown() { var xxx_messageInfo_MsgClearAdmin proto.InternalMessageInfo // MsgClearAdminResponse returns empty data -type MsgClearAdminResponse struct { -} +type MsgClearAdminResponse struct{} func (m *MsgClearAdminResponse) Reset() { *m = MsgClearAdminResponse{} } func (m *MsgClearAdminResponse) String() string { return proto.CompactTextString(m) } @@ -605,9 +671,11 @@ func (*MsgClearAdminResponse) ProtoMessage() {} func (*MsgClearAdminResponse) Descriptor() ([]byte, []int) { return fileDescriptor_4f74d82755520264, []int{13} } + func (m *MsgClearAdminResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgClearAdminResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgClearAdminResponse.Marshal(b, m, deterministic) @@ -620,18 +688,68 @@ func (m *MsgClearAdminResponse) XXX_Marshal(b []byte, deterministic bool) ([]byt return b[:n], nil } } + func (m *MsgClearAdminResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgClearAdminResponse.Merge(m, src) } + func (m *MsgClearAdminResponse) XXX_Size() int { return m.Size() } + func (m *MsgClearAdminResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgClearAdminResponse.DiscardUnknown(m) } var xxx_messageInfo_MsgClearAdminResponse proto.InternalMessageInfo +// AccessConfigUpdate contains the code id and the access config to be +// applied. +type AccessConfigUpdate struct { + // CodeID is the reference to the stored WASM code to be updated + CodeID uint64 `protobuf:"varint,1,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` + // InstantiatePermission to apply to the set of code ids + InstantiatePermission AccessConfig `protobuf:"bytes,2,opt,name=instantiate_permission,json=instantiatePermission,proto3" json:"instantiate_permission"` +} + +func (m *AccessConfigUpdate) Reset() { *m = AccessConfigUpdate{} } +func (m *AccessConfigUpdate) String() string { return proto.CompactTextString(m) } +func (*AccessConfigUpdate) ProtoMessage() {} +func (*AccessConfigUpdate) Descriptor() ([]byte, []int) { + return fileDescriptor_4f74d82755520264, []int{14} +} + +func (m *AccessConfigUpdate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *AccessConfigUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AccessConfigUpdate.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *AccessConfigUpdate) XXX_Merge(src proto.Message) { + xxx_messageInfo_AccessConfigUpdate.Merge(m, src) +} + +func (m *AccessConfigUpdate) XXX_Size() int { + return m.Size() +} + +func (m *AccessConfigUpdate) XXX_DiscardUnknown() { + xxx_messageInfo_AccessConfigUpdate.DiscardUnknown(m) +} + +var xxx_messageInfo_AccessConfigUpdate proto.InternalMessageInfo + // MsgUpdateInstantiateConfig updates instantiate config for a smart contract type MsgUpdateInstantiateConfig struct { // Sender is the that actor that signed the messages @@ -646,11 +764,13 @@ func (m *MsgUpdateInstantiateConfig) Reset() { *m = MsgUpdateInstantiate func (m *MsgUpdateInstantiateConfig) String() string { return proto.CompactTextString(m) } func (*MsgUpdateInstantiateConfig) ProtoMessage() {} func (*MsgUpdateInstantiateConfig) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{14} + return fileDescriptor_4f74d82755520264, []int{15} } + func (m *MsgUpdateInstantiateConfig) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgUpdateInstantiateConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgUpdateInstantiateConfig.Marshal(b, m, deterministic) @@ -663,12 +783,15 @@ func (m *MsgUpdateInstantiateConfig) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } + func (m *MsgUpdateInstantiateConfig) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUpdateInstantiateConfig.Merge(m, src) } + func (m *MsgUpdateInstantiateConfig) XXX_Size() int { return m.Size() } + func (m *MsgUpdateInstantiateConfig) XXX_DiscardUnknown() { xxx_messageInfo_MsgUpdateInstantiateConfig.DiscardUnknown(m) } @@ -676,18 +799,19 @@ func (m *MsgUpdateInstantiateConfig) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateInstantiateConfig proto.InternalMessageInfo // MsgUpdateInstantiateConfigResponse returns empty data -type MsgUpdateInstantiateConfigResponse struct { -} +type MsgUpdateInstantiateConfigResponse struct{} func (m *MsgUpdateInstantiateConfigResponse) Reset() { *m = MsgUpdateInstantiateConfigResponse{} } func (m *MsgUpdateInstantiateConfigResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateInstantiateConfigResponse) ProtoMessage() {} func (*MsgUpdateInstantiateConfigResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{15} + return fileDescriptor_4f74d82755520264, []int{16} } + func (m *MsgUpdateInstantiateConfigResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgUpdateInstantiateConfigResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgUpdateInstantiateConfigResponse.Marshal(b, m, deterministic) @@ -700,12 +824,15 @@ func (m *MsgUpdateInstantiateConfigResponse) XXX_Marshal(b []byte, deterministic return b[:n], nil } } + func (m *MsgUpdateInstantiateConfigResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUpdateInstantiateConfigResponse.Merge(m, src) } + func (m *MsgUpdateInstantiateConfigResponse) XXX_Size() int { return m.Size() } + func (m *MsgUpdateInstantiateConfigResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgUpdateInstantiateConfigResponse.DiscardUnknown(m) } @@ -728,11 +855,13 @@ func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParams) ProtoMessage() {} func (*MsgUpdateParams) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{16} + return fileDescriptor_4f74d82755520264, []int{17} } + func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) @@ -745,12 +874,15 @@ func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, err return b[:n], nil } } + func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUpdateParams.Merge(m, src) } + func (m *MsgUpdateParams) XXX_Size() int { return m.Size() } + func (m *MsgUpdateParams) XXX_DiscardUnknown() { xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) } @@ -761,18 +893,19 @@ var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo // MsgUpdateParams message. // // Since: 0.40 -type MsgUpdateParamsResponse struct { -} +type MsgUpdateParamsResponse struct{} func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParamsResponse) ProtoMessage() {} func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{17} + return fileDescriptor_4f74d82755520264, []int{18} } + func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) @@ -785,12 +918,15 @@ func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]b return b[:n], nil } } + func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) } + func (m *MsgUpdateParamsResponse) XXX_Size() int { return m.Size() } + func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) } @@ -813,11 +949,13 @@ func (m *MsgSudoContract) Reset() { *m = MsgSudoContract{} } func (m *MsgSudoContract) String() string { return proto.CompactTextString(m) } func (*MsgSudoContract) ProtoMessage() {} func (*MsgSudoContract) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{18} + return fileDescriptor_4f74d82755520264, []int{19} } + func (m *MsgSudoContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgSudoContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgSudoContract.Marshal(b, m, deterministic) @@ -830,12 +968,15 @@ func (m *MsgSudoContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, err return b[:n], nil } } + func (m *MsgSudoContract) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgSudoContract.Merge(m, src) } + func (m *MsgSudoContract) XXX_Size() int { return m.Size() } + func (m *MsgSudoContract) XXX_DiscardUnknown() { xxx_messageInfo_MsgSudoContract.DiscardUnknown(m) } @@ -855,11 +996,13 @@ func (m *MsgSudoContractResponse) Reset() { *m = MsgSudoContractResponse func (m *MsgSudoContractResponse) String() string { return proto.CompactTextString(m) } func (*MsgSudoContractResponse) ProtoMessage() {} func (*MsgSudoContractResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{19} + return fileDescriptor_4f74d82755520264, []int{20} } + func (m *MsgSudoContractResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgSudoContractResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgSudoContractResponse.Marshal(b, m, deterministic) @@ -872,12 +1015,15 @@ func (m *MsgSudoContractResponse) XXX_Marshal(b []byte, deterministic bool) ([]b return b[:n], nil } } + func (m *MsgSudoContractResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgSudoContractResponse.Merge(m, src) } + func (m *MsgSudoContractResponse) XXX_Size() int { return m.Size() } + func (m *MsgSudoContractResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgSudoContractResponse.DiscardUnknown(m) } @@ -898,11 +1044,13 @@ func (m *MsgPinCodes) Reset() { *m = MsgPinCodes{} } func (m *MsgPinCodes) String() string { return proto.CompactTextString(m) } func (*MsgPinCodes) ProtoMessage() {} func (*MsgPinCodes) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{20} + return fileDescriptor_4f74d82755520264, []int{21} } + func (m *MsgPinCodes) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgPinCodes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgPinCodes.Marshal(b, m, deterministic) @@ -915,12 +1063,15 @@ func (m *MsgPinCodes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } + func (m *MsgPinCodes) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgPinCodes.Merge(m, src) } + func (m *MsgPinCodes) XXX_Size() int { return m.Size() } + func (m *MsgPinCodes) XXX_DiscardUnknown() { xxx_messageInfo_MsgPinCodes.DiscardUnknown(m) } @@ -931,18 +1082,19 @@ var xxx_messageInfo_MsgPinCodes proto.InternalMessageInfo // MsgPinCodes message. // // Since: 0.40 -type MsgPinCodesResponse struct { -} +type MsgPinCodesResponse struct{} func (m *MsgPinCodesResponse) Reset() { *m = MsgPinCodesResponse{} } func (m *MsgPinCodesResponse) String() string { return proto.CompactTextString(m) } func (*MsgPinCodesResponse) ProtoMessage() {} func (*MsgPinCodesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{21} + return fileDescriptor_4f74d82755520264, []int{22} } + func (m *MsgPinCodesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgPinCodesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgPinCodesResponse.Marshal(b, m, deterministic) @@ -955,12 +1107,15 @@ func (m *MsgPinCodesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } + func (m *MsgPinCodesResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgPinCodesResponse.Merge(m, src) } + func (m *MsgPinCodesResponse) XXX_Size() int { return m.Size() } + func (m *MsgPinCodesResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgPinCodesResponse.DiscardUnknown(m) } @@ -981,11 +1136,13 @@ func (m *MsgUnpinCodes) Reset() { *m = MsgUnpinCodes{} } func (m *MsgUnpinCodes) String() string { return proto.CompactTextString(m) } func (*MsgUnpinCodes) ProtoMessage() {} func (*MsgUnpinCodes) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{22} + return fileDescriptor_4f74d82755520264, []int{23} } + func (m *MsgUnpinCodes) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgUnpinCodes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgUnpinCodes.Marshal(b, m, deterministic) @@ -998,12 +1155,15 @@ func (m *MsgUnpinCodes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error return b[:n], nil } } + func (m *MsgUnpinCodes) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUnpinCodes.Merge(m, src) } + func (m *MsgUnpinCodes) XXX_Size() int { return m.Size() } + func (m *MsgUnpinCodes) XXX_DiscardUnknown() { xxx_messageInfo_MsgUnpinCodes.DiscardUnknown(m) } @@ -1014,18 +1174,19 @@ var xxx_messageInfo_MsgUnpinCodes proto.InternalMessageInfo // MsgUnpinCodes message. // // Since: 0.40 -type MsgUnpinCodesResponse struct { -} +type MsgUnpinCodesResponse struct{} func (m *MsgUnpinCodesResponse) Reset() { *m = MsgUnpinCodesResponse{} } func (m *MsgUnpinCodesResponse) String() string { return proto.CompactTextString(m) } func (*MsgUnpinCodesResponse) ProtoMessage() {} func (*MsgUnpinCodesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{23} + return fileDescriptor_4f74d82755520264, []int{24} } + func (m *MsgUnpinCodesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgUnpinCodesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgUnpinCodesResponse.Marshal(b, m, deterministic) @@ -1038,12 +1199,15 @@ func (m *MsgUnpinCodesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byt return b[:n], nil } } + func (m *MsgUnpinCodesResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUnpinCodesResponse.Merge(m, src) } + func (m *MsgUnpinCodesResponse) XXX_Size() int { return m.Size() } + func (m *MsgUnpinCodesResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgUnpinCodesResponse.DiscardUnknown(m) } @@ -1087,11 +1251,13 @@ func (m *MsgStoreAndInstantiateContract) Reset() { *m = MsgStoreAndInsta func (m *MsgStoreAndInstantiateContract) String() string { return proto.CompactTextString(m) } func (*MsgStoreAndInstantiateContract) ProtoMessage() {} func (*MsgStoreAndInstantiateContract) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{24} + return fileDescriptor_4f74d82755520264, []int{25} } + func (m *MsgStoreAndInstantiateContract) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgStoreAndInstantiateContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgStoreAndInstantiateContract.Marshal(b, m, deterministic) @@ -1104,12 +1270,15 @@ func (m *MsgStoreAndInstantiateContract) XXX_Marshal(b []byte, deterministic boo return b[:n], nil } } + func (m *MsgStoreAndInstantiateContract) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgStoreAndInstantiateContract.Merge(m, src) } + func (m *MsgStoreAndInstantiateContract) XXX_Size() int { return m.Size() } + func (m *MsgStoreAndInstantiateContract) XXX_DiscardUnknown() { xxx_messageInfo_MsgStoreAndInstantiateContract.DiscardUnknown(m) } @@ -1133,11 +1302,13 @@ func (m *MsgStoreAndInstantiateContractResponse) Reset() { func (m *MsgStoreAndInstantiateContractResponse) String() string { return proto.CompactTextString(m) } func (*MsgStoreAndInstantiateContractResponse) ProtoMessage() {} func (*MsgStoreAndInstantiateContractResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{25} + return fileDescriptor_4f74d82755520264, []int{26} } + func (m *MsgStoreAndInstantiateContractResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *MsgStoreAndInstantiateContractResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgStoreAndInstantiateContractResponse.Marshal(b, m, deterministic) @@ -1150,12 +1321,15 @@ func (m *MsgStoreAndInstantiateContractResponse) XXX_Marshal(b []byte, determini return b[:n], nil } } + func (m *MsgStoreAndInstantiateContractResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgStoreAndInstantiateContractResponse.Merge(m, src) } + func (m *MsgStoreAndInstantiateContractResponse) XXX_Size() int { return m.Size() } + func (m *MsgStoreAndInstantiateContractResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgStoreAndInstantiateContractResponse.DiscardUnknown(m) } @@ -1174,7 +1348,7 @@ func (m *MsgAddCodeUploadParamsAddresses) Reset() { *m = MsgAddCodeUploa func (m *MsgAddCodeUploadParamsAddresses) String() string { return proto.CompactTextString(m) } func (*MsgAddCodeUploadParamsAddresses) ProtoMessage() {} func (*MsgAddCodeUploadParamsAddresses) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{26} + return fileDescriptor_4f74d82755520264, []int{27} } func (m *MsgAddCodeUploadParamsAddresses) XXX_Unmarshal(b []byte) error { @@ -1218,7 +1392,7 @@ func (m *MsgAddCodeUploadParamsAddressesResponse) Reset() { func (m *MsgAddCodeUploadParamsAddressesResponse) String() string { return proto.CompactTextString(m) } func (*MsgAddCodeUploadParamsAddressesResponse) ProtoMessage() {} func (*MsgAddCodeUploadParamsAddressesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{27} + return fileDescriptor_4f74d82755520264, []int{28} } func (m *MsgAddCodeUploadParamsAddressesResponse) XXX_Unmarshal(b []byte) error { @@ -1264,7 +1438,7 @@ func (m *MsgRemoveCodeUploadParamsAddresses) Reset() { *m = MsgRemoveCod func (m *MsgRemoveCodeUploadParamsAddresses) String() string { return proto.CompactTextString(m) } func (*MsgRemoveCodeUploadParamsAddresses) ProtoMessage() {} func (*MsgRemoveCodeUploadParamsAddresses) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{28} + return fileDescriptor_4f74d82755520264, []int{29} } func (m *MsgRemoveCodeUploadParamsAddresses) XXX_Unmarshal(b []byte) error { @@ -1311,7 +1485,7 @@ func (m *MsgRemoveCodeUploadParamsAddressesResponse) String() string { } func (*MsgRemoveCodeUploadParamsAddressesResponse) ProtoMessage() {} func (*MsgRemoveCodeUploadParamsAddressesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4f74d82755520264, []int{29} + return fileDescriptor_4f74d82755520264, []int{30} } func (m *MsgRemoveCodeUploadParamsAddressesResponse) XXX_Unmarshal(b []byte) error { @@ -1345,153 +1519,364 @@ func (m *MsgRemoveCodeUploadParamsAddressesResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRemoveCodeUploadParamsAddressesResponse proto.InternalMessageInfo -func init() { - proto.RegisterType((*MsgStoreCode)(nil), "cosmwasm.wasm.v1.MsgStoreCode") - proto.RegisterType((*MsgStoreCodeResponse)(nil), "cosmwasm.wasm.v1.MsgStoreCodeResponse") - proto.RegisterType((*MsgInstantiateContract)(nil), "cosmwasm.wasm.v1.MsgInstantiateContract") - proto.RegisterType((*MsgInstantiateContractResponse)(nil), "cosmwasm.wasm.v1.MsgInstantiateContractResponse") - proto.RegisterType((*MsgInstantiateContract2)(nil), "cosmwasm.wasm.v1.MsgInstantiateContract2") - proto.RegisterType((*MsgInstantiateContract2Response)(nil), "cosmwasm.wasm.v1.MsgInstantiateContract2Response") - proto.RegisterType((*MsgExecuteContract)(nil), "cosmwasm.wasm.v1.MsgExecuteContract") - proto.RegisterType((*MsgExecuteContractResponse)(nil), "cosmwasm.wasm.v1.MsgExecuteContractResponse") - proto.RegisterType((*MsgMigrateContract)(nil), "cosmwasm.wasm.v1.MsgMigrateContract") - proto.RegisterType((*MsgMigrateContractResponse)(nil), "cosmwasm.wasm.v1.MsgMigrateContractResponse") - proto.RegisterType((*MsgUpdateAdmin)(nil), "cosmwasm.wasm.v1.MsgUpdateAdmin") - proto.RegisterType((*MsgUpdateAdminResponse)(nil), "cosmwasm.wasm.v1.MsgUpdateAdminResponse") - proto.RegisterType((*MsgClearAdmin)(nil), "cosmwasm.wasm.v1.MsgClearAdmin") - proto.RegisterType((*MsgClearAdminResponse)(nil), "cosmwasm.wasm.v1.MsgClearAdminResponse") - proto.RegisterType((*MsgUpdateInstantiateConfig)(nil), "cosmwasm.wasm.v1.MsgUpdateInstantiateConfig") - proto.RegisterType((*MsgUpdateInstantiateConfigResponse)(nil), "cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse") - proto.RegisterType((*MsgUpdateParams)(nil), "cosmwasm.wasm.v1.MsgUpdateParams") - proto.RegisterType((*MsgUpdateParamsResponse)(nil), "cosmwasm.wasm.v1.MsgUpdateParamsResponse") - proto.RegisterType((*MsgSudoContract)(nil), "cosmwasm.wasm.v1.MsgSudoContract") - proto.RegisterType((*MsgSudoContractResponse)(nil), "cosmwasm.wasm.v1.MsgSudoContractResponse") - proto.RegisterType((*MsgPinCodes)(nil), "cosmwasm.wasm.v1.MsgPinCodes") - proto.RegisterType((*MsgPinCodesResponse)(nil), "cosmwasm.wasm.v1.MsgPinCodesResponse") - proto.RegisterType((*MsgUnpinCodes)(nil), "cosmwasm.wasm.v1.MsgUnpinCodes") - proto.RegisterType((*MsgUnpinCodesResponse)(nil), "cosmwasm.wasm.v1.MsgUnpinCodesResponse") - proto.RegisterType((*MsgStoreAndInstantiateContract)(nil), "cosmwasm.wasm.v1.MsgStoreAndInstantiateContract") - proto.RegisterType((*MsgStoreAndInstantiateContractResponse)(nil), "cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse") - proto.RegisterType((*MsgAddCodeUploadParamsAddresses)(nil), "cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses") - proto.RegisterType((*MsgAddCodeUploadParamsAddressesResponse)(nil), "cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddressesResponse") - proto.RegisterType((*MsgRemoveCodeUploadParamsAddresses)(nil), "cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddresses") - proto.RegisterType((*MsgRemoveCodeUploadParamsAddressesResponse)(nil), "cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddressesResponse") +// MsgStoreAndMigrateContract is the MsgStoreAndMigrateContract +// request type. +// +// Since: 0.42 +type MsgStoreAndMigrateContract struct { + // Authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // WASMByteCode can be raw or gzip compressed + WASMByteCode []byte `protobuf:"bytes,2,opt,name=wasm_byte_code,json=wasmByteCode,proto3" json:"wasm_byte_code,omitempty"` + // InstantiatePermission to apply on contract creation, optional + InstantiatePermission *AccessConfig `protobuf:"bytes,3,opt,name=instantiate_permission,json=instantiatePermission,proto3" json:"instantiate_permission,omitempty"` + // Contract is the address of the smart contract + Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` + // Msg json encoded message to be passed to the contract on migration + Msg RawContractMessage `protobuf:"bytes,5,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` } -func init() { proto.RegisterFile("cosmwasm/wasm/v1/tx.proto", fileDescriptor_4f74d82755520264) } - -var fileDescriptor_4f74d82755520264 = []byte{ - // 1574 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x58, 0xcf, 0x6f, 0x1b, 0xc5, - 0x17, 0xcf, 0xc6, 0xbf, 0x5f, 0xfc, 0x6d, 0xd3, 0xad, 0x9b, 0x38, 0xdb, 0xd6, 0x4e, 0xb7, 0x3f, - 0xe2, 0xe6, 0x9b, 0xda, 0x8d, 0xbf, 0x5f, 0x0a, 0x35, 0x5c, 0xe2, 0x14, 0x89, 0x54, 0x32, 0x44, - 0x1b, 0xa5, 0x15, 0xa8, 0x92, 0xb5, 0xf6, 0x4e, 0x36, 0xab, 0x7a, 0x77, 0x8d, 0x67, 0x9d, 0x1f, - 0x07, 0x2e, 0x20, 0x21, 0x81, 0x38, 0x70, 0xe1, 0x4f, 0x40, 0x02, 0x2e, 0xf4, 0xc0, 0x81, 0x63, - 0x4f, 0xa8, 0x12, 0x1c, 0x2a, 0x4e, 0x1c, 0x90, 0x81, 0x14, 0xa9, 0xdc, 0x90, 0x7a, 0xe4, 0x84, - 0x76, 0x66, 0x77, 0xbd, 0x5e, 0xef, 0xae, 0x9d, 0x84, 0x0a, 0x24, 0x2e, 0x89, 0x67, 0xe6, 0xbd, - 0x37, 0xef, 0xf3, 0x79, 0x6f, 0xde, 0xbc, 0x59, 0x98, 0x6b, 0xea, 0x58, 0xdd, 0x15, 0xb1, 0x5a, - 0x22, 0x7f, 0x76, 0x96, 0x4b, 0xc6, 0x5e, 0xb1, 0xdd, 0xd1, 0x0d, 0x9d, 0x9d, 0xb6, 0x97, 0x8a, - 0xe4, 0xcf, 0xce, 0x32, 0x97, 0x33, 0x67, 0x74, 0x5c, 0x6a, 0x88, 0x18, 0x95, 0x76, 0x96, 0x1b, - 0xc8, 0x10, 0x97, 0x4b, 0x4d, 0x5d, 0xd1, 0xa8, 0x06, 0x37, 0x6b, 0xad, 0xab, 0x58, 0x36, 0x2d, - 0xa9, 0x58, 0xb6, 0x16, 0x32, 0xb2, 0x2e, 0xeb, 0xe4, 0x67, 0xc9, 0xfc, 0x65, 0xcd, 0x9e, 0x1b, - 0xde, 0x7b, 0xbf, 0x8d, 0xb0, 0xb5, 0x3a, 0x47, 0x8d, 0xd5, 0xa9, 0x1a, 0x1d, 0x58, 0x4b, 0xa7, - 0x44, 0x55, 0xd1, 0xf4, 0x12, 0xf9, 0x4b, 0xa7, 0xf8, 0x5f, 0x19, 0x48, 0xd7, 0xb0, 0xbc, 0x61, - 0xe8, 0x1d, 0xb4, 0xaa, 0x4b, 0x88, 0x9d, 0x81, 0x38, 0x46, 0x9a, 0x84, 0x3a, 0x59, 0x66, 0x9e, - 0x29, 0xa4, 0x04, 0x6b, 0xc4, 0xde, 0x80, 0x13, 0xe6, 0x6e, 0xf5, 0xc6, 0xbe, 0x81, 0xea, 0x4d, - 0x5d, 0x42, 0xd9, 0xc9, 0x79, 0xa6, 0x90, 0xae, 0x4e, 0x1f, 0xf4, 0xf2, 0xe9, 0xbb, 0x2b, 0x1b, - 0xb5, 0xea, 0xbe, 0x41, 0x2c, 0x08, 0x69, 0x53, 0xce, 0x1e, 0xb1, 0x9b, 0x30, 0xa3, 0x68, 0xd8, - 0x10, 0x35, 0x43, 0x11, 0x0d, 0x54, 0x6f, 0xa3, 0x8e, 0xaa, 0x60, 0xac, 0xe8, 0x5a, 0x36, 0x36, - 0xcf, 0x14, 0xa6, 0xca, 0xb9, 0xa2, 0x97, 0xae, 0xe2, 0x4a, 0xb3, 0x89, 0x30, 0x5e, 0xd5, 0xb5, - 0x2d, 0x45, 0x16, 0xce, 0xb8, 0xb4, 0xd7, 0x1d, 0xe5, 0xca, 0x85, 0x77, 0x9f, 0x3e, 0x58, 0xb4, - 0x7c, 0xfb, 0xf0, 0xe9, 0x83, 0xc5, 0x53, 0x84, 0x0a, 0x37, 0x92, 0xdb, 0xd1, 0x64, 0x64, 0x3a, - 0x7a, 0x3b, 0x9a, 0x8c, 0x4e, 0xc7, 0xf8, 0xbb, 0x90, 0x71, 0xaf, 0x09, 0x08, 0xb7, 0x75, 0x0d, - 0x23, 0xf6, 0x22, 0x24, 0x4c, 0x2c, 0x75, 0x45, 0x22, 0x70, 0xa3, 0x55, 0x38, 0xe8, 0xe5, 0xe3, - 0xa6, 0xc8, 0xda, 0x2d, 0x21, 0x6e, 0x2e, 0xad, 0x49, 0x2c, 0x07, 0xc9, 0xe6, 0x36, 0x6a, 0xde, - 0xc7, 0x5d, 0x95, 0x82, 0x16, 0x9c, 0x31, 0xff, 0x70, 0x12, 0x66, 0x6a, 0x58, 0x5e, 0xeb, 0x3b, - 0xb9, 0xaa, 0x6b, 0x46, 0x47, 0x6c, 0x1a, 0x81, 0x4c, 0x66, 0x20, 0x26, 0x4a, 0xaa, 0xa2, 0x11, - 0x5b, 0x29, 0x81, 0x0e, 0xdc, 0x9e, 0x44, 0x02, 0x3d, 0xc9, 0x40, 0xac, 0x25, 0x36, 0x50, 0x2b, - 0x1b, 0xa5, 0xaa, 0x64, 0xc0, 0x16, 0x20, 0xa2, 0x62, 0x99, 0xf0, 0x99, 0xae, 0xce, 0xfc, 0xd1, - 0xcb, 0xb3, 0x82, 0xb8, 0x6b, 0xbb, 0x51, 0x43, 0x18, 0x8b, 0x32, 0x12, 0x4c, 0x11, 0x76, 0x0b, - 0x62, 0x5b, 0x5d, 0x4d, 0xc2, 0xd9, 0xf8, 0x7c, 0xa4, 0x30, 0x55, 0x9e, 0x2b, 0x5a, 0xe9, 0x61, - 0x26, 0x66, 0xd1, 0x4a, 0xcc, 0xe2, 0xaa, 0xae, 0x68, 0xd5, 0x17, 0x1e, 0xf5, 0xf2, 0x13, 0x5f, - 0xfc, 0x94, 0x2f, 0xc8, 0x8a, 0xb1, 0xdd, 0x6d, 0x14, 0x9b, 0xba, 0x6a, 0xe5, 0x92, 0xf5, 0xef, - 0x1a, 0x96, 0xee, 0x5b, 0x79, 0x67, 0x2a, 0xe0, 0xcf, 0x9e, 0x3e, 0x58, 0x64, 0x04, 0x6a, 0xbe, - 0xf2, 0x5f, 0x4f, 0x74, 0xce, 0xda, 0xd1, 0xf1, 0xe1, 0x89, 0x7f, 0x1d, 0x72, 0xfe, 0x2b, 0x4e, - 0x94, 0xb2, 0x90, 0x10, 0x25, 0xa9, 0x83, 0x30, 0xb6, 0xa8, 0xb4, 0x87, 0x2c, 0x0b, 0x51, 0x49, - 0x34, 0x44, 0x2b, 0x2c, 0xe4, 0x37, 0xff, 0xfb, 0x24, 0xcc, 0xfa, 0x1b, 0x2c, 0xff, 0x8b, 0x63, - 0x62, 0x52, 0x85, 0xc5, 0x96, 0x91, 0x4d, 0x50, 0xaa, 0xcc, 0xdf, 0xec, 0x2c, 0x24, 0xb6, 0x94, - 0xbd, 0xba, 0xe9, 0x69, 0x72, 0x9e, 0x29, 0x24, 0x85, 0xf8, 0x96, 0xb2, 0x57, 0xc3, 0x72, 0x65, - 0xc9, 0x13, 0xc0, 0x73, 0x21, 0x01, 0x2c, 0xf3, 0x6f, 0x40, 0x3e, 0x60, 0xe9, 0x88, 0x21, 0x7c, - 0x6f, 0x12, 0xd8, 0x1a, 0x96, 0x5f, 0xdd, 0x43, 0xcd, 0xee, 0x18, 0x27, 0xca, 0x3c, 0xa0, 0x96, - 0x8c, 0x15, 0x40, 0x67, 0x6c, 0x07, 0x22, 0x72, 0x88, 0x40, 0xc4, 0x9e, 0xef, 0xe1, 0x58, 0xf0, - 0x70, 0x3b, 0x6b, 0x73, 0xeb, 0x81, 0xcb, 0x5f, 0x07, 0x6e, 0x78, 0xd6, 0x61, 0xd4, 0xe6, 0x8d, - 0x71, 0xf1, 0xf6, 0x90, 0x21, 0xbc, 0xd5, 0x14, 0xb9, 0x23, 0x1e, 0x93, 0xb7, 0xb1, 0x72, 0xdf, - 0x22, 0x37, 0x3a, 0x92, 0xdc, 0x60, 0xd0, 0x1e, 0x5f, 0x2d, 0xd0, 0x9e, 0xd9, 0x50, 0xd0, 0xef, - 0x33, 0x70, 0xa2, 0x86, 0xe5, 0xcd, 0xb6, 0x24, 0x1a, 0x68, 0x85, 0x1c, 0xdc, 0x20, 0xc0, 0x67, - 0x21, 0xa5, 0xa1, 0xdd, 0xba, 0xfb, 0xa8, 0x27, 0x35, 0xb4, 0x4b, 0x95, 0xdc, 0x6c, 0x44, 0x06, - 0xd9, 0xa8, 0x5c, 0xf4, 0xb8, 0x7f, 0xda, 0x76, 0xdf, 0xb5, 0x2b, 0x9f, 0x25, 0x57, 0x81, 0x6b, - 0xc6, 0x76, 0x9b, 0x97, 0xe1, 0x3f, 0x35, 0x2c, 0xaf, 0xb6, 0x90, 0xd8, 0x09, 0x77, 0x30, 0xcc, - 0x07, 0xde, 0xe3, 0x03, 0x6b, 0xfb, 0xd0, 0xb7, 0xcb, 0xcf, 0xc2, 0x99, 0x81, 0x09, 0xc7, 0x83, - 0xdf, 0x18, 0xc2, 0x2b, 0x75, 0x6e, 0xf0, 0xa4, 0x6e, 0x29, 0x72, 0xa0, 0x3f, 0xae, 0x2c, 0x98, - 0x0c, 0xcc, 0x82, 0x7b, 0xc0, 0x99, 0xac, 0x06, 0x5c, 0xf3, 0x91, 0xb1, 0xae, 0xf9, 0xac, 0x86, - 0x76, 0xd7, 0x7c, 0x6f, 0xfa, 0x92, 0x07, 0x76, 0x7e, 0x90, 0xfa, 0x21, 0x2c, 0xfc, 0x25, 0xe0, - 0x83, 0x57, 0x1d, 0x42, 0xbe, 0x64, 0xe0, 0xa4, 0x23, 0xb6, 0x2e, 0x76, 0x44, 0x15, 0xb3, 0x37, - 0x20, 0x25, 0x76, 0x8d, 0x6d, 0xbd, 0xa3, 0x18, 0xfb, 0x94, 0x88, 0x6a, 0xf6, 0xfb, 0xaf, 0xae, - 0x65, 0xac, 0x42, 0xb0, 0x42, 0x2b, 0xd6, 0x86, 0xd1, 0x51, 0x34, 0x59, 0xe8, 0x8b, 0xb2, 0x2f, - 0x43, 0xbc, 0x4d, 0x2c, 0x10, 0x92, 0xa6, 0xca, 0xd9, 0x61, 0xb0, 0x74, 0x87, 0x6a, 0xca, 0xac, - 0x1c, 0xb4, 0x1a, 0x58, 0x2a, 0xf4, 0x64, 0xf4, 0x8d, 0x99, 0x10, 0x33, 0x83, 0x10, 0xa9, 0x2e, - 0x3f, 0x47, 0xae, 0x35, 0xf7, 0x94, 0x03, 0xe6, 0x6b, 0x0a, 0x66, 0xa3, 0x2b, 0xe9, 0xce, 0xa1, - 0x3f, 0x2a, 0x98, 0xbf, 0xa4, 0x98, 0x86, 0xa2, 0x72, 0xbb, 0xc9, 0x5f, 0x23, 0xa8, 0xdc, 0x53, - 0xa1, 0x87, 0xfd, 0x53, 0x06, 0xa6, 0x6a, 0x58, 0x5e, 0x57, 0x34, 0x33, 0x09, 0x8f, 0x1e, 0xb2, - 0x9b, 0x26, 0x4a, 0x92, 0xd8, 0x66, 0xd0, 0x22, 0x85, 0x68, 0x35, 0x77, 0xd0, 0xcb, 0x27, 0x68, - 0x66, 0xe3, 0x67, 0xbd, 0xfc, 0xc9, 0x7d, 0x51, 0x6d, 0x55, 0x78, 0x5b, 0x88, 0x17, 0x12, 0x34, - 0xdb, 0x31, 0xad, 0x05, 0x83, 0xd0, 0xa6, 0x6d, 0x68, 0xb6, 0x5f, 0xfc, 0x19, 0x38, 0xed, 0x1a, - 0x3a, 0x81, 0xfa, 0x9c, 0x21, 0x95, 0x60, 0x53, 0x6b, 0xff, 0x8d, 0x00, 0x2e, 0x0f, 0x03, 0x70, - 0x6a, 0x49, 0xdf, 0x33, 0xab, 0x96, 0xf4, 0x27, 0x1c, 0x10, 0xdf, 0x46, 0x49, 0xc7, 0x46, 0xba, - 0xe9, 0x15, 0x4d, 0xf2, 0xeb, 0x7d, 0x8f, 0x8a, 0x6a, 0xf8, 0x95, 0x11, 0x39, 0xe6, 0x2b, 0x23, - 0x7a, 0x8c, 0x57, 0x06, 0x7b, 0x1e, 0xa0, 0x6b, 0xe2, 0xa7, 0xae, 0xc4, 0x48, 0x8b, 0x94, 0xea, - 0xda, 0x8c, 0xf4, 0xbb, 0xc6, 0xb8, 0xbb, 0x6b, 0x74, 0x1a, 0xc2, 0x84, 0x4f, 0x43, 0x98, 0x3c, - 0x44, 0x1f, 0x92, 0x7a, 0xbe, 0x0d, 0xa1, 0x59, 0xf3, 0xf5, 0x6e, 0xa7, 0x89, 0xb2, 0x60, 0xd5, - 0x7c, 0x32, 0x32, 0x5b, 0xb5, 0x46, 0x57, 0x69, 0x99, 0x97, 0xc1, 0x14, 0x6d, 0xd5, 0xac, 0xa1, - 0x79, 0x7d, 0x92, 0x74, 0xda, 0x16, 0xf1, 0x76, 0x36, 0x6d, 0xbd, 0x84, 0x74, 0x09, 0xbd, 0x26, - 0xe2, 0xed, 0xca, 0x8d, 0xe1, 0xac, 0xba, 0x38, 0xf0, 0x28, 0xf3, 0x4f, 0x15, 0xfe, 0x0e, 0x5c, - 0x09, 0x97, 0x38, 0x62, 0x0f, 0xf9, 0x0d, 0x43, 0xba, 0xd2, 0x15, 0x49, 0x32, 0x63, 0xb5, 0xd9, - 0x6e, 0xe9, 0xa2, 0x44, 0xcb, 0xa6, 0x95, 0x7d, 0xc7, 0x38, 0x7c, 0x65, 0x48, 0x89, 0xb6, 0x11, - 0x72, 0xfa, 0x52, 0xd5, 0xcc, 0xb3, 0x5e, 0x7e, 0x9a, 0x1e, 0x39, 0x67, 0x89, 0x17, 0xfa, 0x62, - 0x95, 0x17, 0x87, 0xf9, 0xb9, 0x64, 0xf3, 0x13, 0xe6, 0x24, 0x7f, 0x15, 0x16, 0x46, 0x88, 0x38, - 0x27, 0xf3, 0x3b, 0x86, 0xdc, 0x7d, 0x02, 0x52, 0xf5, 0x1d, 0xf4, 0xcf, 0x80, 0x5d, 0x19, 0x86, - 0xbd, 0x60, 0xc3, 0x1e, 0xe1, 0x27, 0xbf, 0x04, 0x8b, 0xa3, 0xa5, 0x6c, 0xf0, 0xe5, 0x1f, 0xd3, - 0x10, 0xa9, 0x61, 0x99, 0xdd, 0x80, 0x54, 0xff, 0x73, 0x86, 0xcf, 0xc1, 0x77, 0x7f, 0x08, 0xe0, - 0xae, 0x84, 0xaf, 0x3b, 0xb9, 0xf7, 0x36, 0x9c, 0xf6, 0xab, 0x73, 0x05, 0x5f, 0x75, 0x1f, 0x49, - 0xee, 0xfa, 0xb8, 0x92, 0xce, 0x96, 0x06, 0x64, 0x7c, 0xdf, 0xb0, 0x57, 0xc7, 0xb5, 0x54, 0xe6, - 0x96, 0xc7, 0x16, 0x75, 0x76, 0x45, 0x70, 0xd2, 0xfb, 0xec, 0xba, 0xe4, 0x6b, 0xc5, 0x23, 0xc5, - 0x2d, 0x8d, 0x23, 0xe5, 0xde, 0xc6, 0xfb, 0x4a, 0xf1, 0xdf, 0xc6, 0x23, 0x15, 0xb0, 0x4d, 0xd0, - 0x7b, 0xe1, 0x4d, 0x98, 0x72, 0xbf, 0x0b, 0xe6, 0x7d, 0x95, 0x5d, 0x12, 0x5c, 0x61, 0x94, 0x84, - 0x63, 0xfa, 0x0e, 0x80, 0xab, 0xa1, 0xcf, 0xfb, 0xea, 0xf5, 0x05, 0xb8, 0x85, 0x11, 0x02, 0x8e, - 0xdd, 0x77, 0x60, 0x36, 0xa8, 0x4b, 0x5f, 0x0a, 0x71, 0x6e, 0x48, 0x9a, 0xfb, 0xff, 0x61, 0xa4, - 0x9d, 0xed, 0xef, 0x41, 0x7a, 0xa0, 0x27, 0xbe, 0x10, 0x62, 0x85, 0x8a, 0x70, 0x57, 0x47, 0x8a, - 0xb8, 0xad, 0x0f, 0x34, 0xa9, 0xfe, 0xd6, 0xdd, 0x22, 0x01, 0xd6, 0x7d, 0x1b, 0xc6, 0x75, 0x48, - 0x3a, 0x8d, 0xe1, 0x79, 0x5f, 0x35, 0x7b, 0x99, 0xbb, 0x1c, 0xba, 0xec, 0x0e, 0xb2, 0xab, 0x57, - 0xf3, 0x0f, 0x72, 0x5f, 0x20, 0x20, 0xc8, 0xc3, 0x2d, 0x14, 0xfb, 0x01, 0x03, 0x67, 0xc3, 0xfa, - 0xa7, 0xeb, 0xc1, 0x65, 0xc9, 0x5f, 0x83, 0x7b, 0xe9, 0xb0, 0x1a, 0x8e, 0x2f, 0x9f, 0x30, 0x90, - 0x1f, 0x75, 0x63, 0xf8, 0xe7, 0xd2, 0x08, 0x2d, 0xee, 0x95, 0xa3, 0x68, 0x39, 0x7e, 0x7d, 0xc4, - 0xc0, 0xb9, 0xd0, 0xdb, 0xdb, 0xbf, 0xba, 0x85, 0xa9, 0x70, 0x37, 0x0f, 0xad, 0x62, 0xbb, 0x53, - 0xbd, 0xf5, 0xe8, 0x97, 0xdc, 0xc4, 0xa3, 0x83, 0x1c, 0xf3, 0xf8, 0x20, 0xc7, 0xfc, 0x7c, 0x90, - 0x63, 0x3e, 0x7e, 0x92, 0x9b, 0x78, 0xfc, 0x24, 0x37, 0xf1, 0xc3, 0x93, 0xdc, 0xc4, 0x5b, 0x57, - 0x5c, 0x2d, 0xd8, 0xaa, 0x8e, 0xd5, 0xbb, 0xf6, 0xe7, 0x79, 0xa9, 0xb4, 0x47, 0x3f, 0xd3, 0x93, - 0x36, 0xac, 0x11, 0x27, 0x9f, 0xdd, 0xff, 0xf7, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9f, 0x81, - 0xf1, 0x23, 0x40, 0x18, 0x00, 0x00, +func (m *MsgStoreAndMigrateContract) Reset() { *m = MsgStoreAndMigrateContract{} } +func (m *MsgStoreAndMigrateContract) String() string { return proto.CompactTextString(m) } +func (*MsgStoreAndMigrateContract) ProtoMessage() {} +func (*MsgStoreAndMigrateContract) Descriptor() ([]byte, []int) { + return fileDescriptor_4f74d82755520264, []int{31} } -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +func (m *MsgStoreAndMigrateContract) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} -// MsgClient is the client API for Msg service. +func (m *MsgStoreAndMigrateContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgStoreAndMigrateContract.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *MsgStoreAndMigrateContract) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgStoreAndMigrateContract.Merge(m, src) +} + +func (m *MsgStoreAndMigrateContract) XXX_Size() int { + return m.Size() +} + +func (m *MsgStoreAndMigrateContract) XXX_DiscardUnknown() { + xxx_messageInfo_MsgStoreAndMigrateContract.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgStoreAndMigrateContract proto.InternalMessageInfo + +// MsgStoreAndMigrateContractResponse defines the response structure +// for executing a MsgStoreAndMigrateContract message. +// +// Since: 0.42 +type MsgStoreAndMigrateContractResponse struct { + // CodeID is the reference to the stored WASM code + CodeID uint64 `protobuf:"varint,1,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` + // Checksum is the sha256 hash of the stored code + Checksum []byte `protobuf:"bytes,2,opt,name=checksum,proto3" json:"checksum,omitempty"` + // Data contains bytes to returned from the contract + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *MsgStoreAndMigrateContractResponse) Reset() { *m = MsgStoreAndMigrateContractResponse{} } +func (m *MsgStoreAndMigrateContractResponse) String() string { return proto.CompactTextString(m) } +func (*MsgStoreAndMigrateContractResponse) ProtoMessage() {} +func (*MsgStoreAndMigrateContractResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4f74d82755520264, []int{32} +} + +func (m *MsgStoreAndMigrateContractResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *MsgStoreAndMigrateContractResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgStoreAndMigrateContractResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *MsgStoreAndMigrateContractResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgStoreAndMigrateContractResponse.Merge(m, src) +} + +func (m *MsgStoreAndMigrateContractResponse) XXX_Size() int { + return m.Size() +} + +func (m *MsgStoreAndMigrateContractResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgStoreAndMigrateContractResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgStoreAndMigrateContractResponse proto.InternalMessageInfo + +// MsgUpdateContractLabel sets a new label for a smart contract +type MsgUpdateContractLabel struct { + // Sender is the that actor that signed the messages + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + // NewLabel string to be set + NewLabel string `protobuf:"bytes,2,opt,name=new_label,json=newLabel,proto3" json:"new_label,omitempty"` + // Contract is the address of the smart contract + Contract string `protobuf:"bytes,3,opt,name=contract,proto3" json:"contract,omitempty"` +} + +func (m *MsgUpdateContractLabel) Reset() { *m = MsgUpdateContractLabel{} } +func (m *MsgUpdateContractLabel) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateContractLabel) ProtoMessage() {} +func (*MsgUpdateContractLabel) Descriptor() ([]byte, []int) { + return fileDescriptor_4f74d82755520264, []int{33} +} + +func (m *MsgUpdateContractLabel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *MsgUpdateContractLabel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateContractLabel.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *MsgUpdateContractLabel) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateContractLabel.Merge(m, src) +} + +func (m *MsgUpdateContractLabel) XXX_Size() int { + return m.Size() +} + +func (m *MsgUpdateContractLabel) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateContractLabel.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateContractLabel proto.InternalMessageInfo + +// MsgUpdateContractLabelResponse returns empty data +type MsgUpdateContractLabelResponse struct{} + +func (m *MsgUpdateContractLabelResponse) Reset() { *m = MsgUpdateContractLabelResponse{} } +func (m *MsgUpdateContractLabelResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateContractLabelResponse) ProtoMessage() {} +func (*MsgUpdateContractLabelResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4f74d82755520264, []int{34} +} + +func (m *MsgUpdateContractLabelResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *MsgUpdateContractLabelResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateContractLabelResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *MsgUpdateContractLabelResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateContractLabelResponse.Merge(m, src) +} + +func (m *MsgUpdateContractLabelResponse) XXX_Size() int { + return m.Size() +} + +func (m *MsgUpdateContractLabelResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateContractLabelResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateContractLabelResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgStoreCode)(nil), "cosmwasm.wasm.v1.MsgStoreCode") + proto.RegisterType((*MsgStoreCodeResponse)(nil), "cosmwasm.wasm.v1.MsgStoreCodeResponse") + proto.RegisterType((*MsgInstantiateContract)(nil), "cosmwasm.wasm.v1.MsgInstantiateContract") + proto.RegisterType((*MsgInstantiateContractResponse)(nil), "cosmwasm.wasm.v1.MsgInstantiateContractResponse") + proto.RegisterType((*MsgInstantiateContract2)(nil), "cosmwasm.wasm.v1.MsgInstantiateContract2") + proto.RegisterType((*MsgInstantiateContract2Response)(nil), "cosmwasm.wasm.v1.MsgInstantiateContract2Response") + proto.RegisterType((*MsgExecuteContract)(nil), "cosmwasm.wasm.v1.MsgExecuteContract") + proto.RegisterType((*MsgExecuteContractResponse)(nil), "cosmwasm.wasm.v1.MsgExecuteContractResponse") + proto.RegisterType((*MsgMigrateContract)(nil), "cosmwasm.wasm.v1.MsgMigrateContract") + proto.RegisterType((*MsgMigrateContractResponse)(nil), "cosmwasm.wasm.v1.MsgMigrateContractResponse") + proto.RegisterType((*MsgUpdateAdmin)(nil), "cosmwasm.wasm.v1.MsgUpdateAdmin") + proto.RegisterType((*MsgUpdateAdminResponse)(nil), "cosmwasm.wasm.v1.MsgUpdateAdminResponse") + proto.RegisterType((*MsgClearAdmin)(nil), "cosmwasm.wasm.v1.MsgClearAdmin") + proto.RegisterType((*MsgClearAdminResponse)(nil), "cosmwasm.wasm.v1.MsgClearAdminResponse") + proto.RegisterType((*AccessConfigUpdate)(nil), "cosmwasm.wasm.v1.AccessConfigUpdate") + proto.RegisterType((*MsgUpdateInstantiateConfig)(nil), "cosmwasm.wasm.v1.MsgUpdateInstantiateConfig") + proto.RegisterType((*MsgUpdateInstantiateConfigResponse)(nil), "cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "cosmwasm.wasm.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "cosmwasm.wasm.v1.MsgUpdateParamsResponse") + proto.RegisterType((*MsgSudoContract)(nil), "cosmwasm.wasm.v1.MsgSudoContract") + proto.RegisterType((*MsgSudoContractResponse)(nil), "cosmwasm.wasm.v1.MsgSudoContractResponse") + proto.RegisterType((*MsgPinCodes)(nil), "cosmwasm.wasm.v1.MsgPinCodes") + proto.RegisterType((*MsgPinCodesResponse)(nil), "cosmwasm.wasm.v1.MsgPinCodesResponse") + proto.RegisterType((*MsgUnpinCodes)(nil), "cosmwasm.wasm.v1.MsgUnpinCodes") + proto.RegisterType((*MsgUnpinCodesResponse)(nil), "cosmwasm.wasm.v1.MsgUnpinCodesResponse") + proto.RegisterType((*MsgStoreAndInstantiateContract)(nil), "cosmwasm.wasm.v1.MsgStoreAndInstantiateContract") + proto.RegisterType((*MsgStoreAndInstantiateContractResponse)(nil), "cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse") + proto.RegisterType((*MsgAddCodeUploadParamsAddresses)(nil), "cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses") + proto.RegisterType((*MsgAddCodeUploadParamsAddressesResponse)(nil), "cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddressesResponse") + proto.RegisterType((*MsgRemoveCodeUploadParamsAddresses)(nil), "cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddresses") + proto.RegisterType((*MsgRemoveCodeUploadParamsAddressesResponse)(nil), "cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddressesResponse") + proto.RegisterType((*MsgStoreAndMigrateContract)(nil), "cosmwasm.wasm.v1.MsgStoreAndMigrateContract") + proto.RegisterType((*MsgStoreAndMigrateContractResponse)(nil), "cosmwasm.wasm.v1.MsgStoreAndMigrateContractResponse") + proto.RegisterType((*MsgUpdateContractLabel)(nil), "cosmwasm.wasm.v1.MsgUpdateContractLabel") + proto.RegisterType((*MsgUpdateContractLabelResponse)(nil), "cosmwasm.wasm.v1.MsgUpdateContractLabelResponse") +} + +func init() { proto.RegisterFile("cosmwasm/wasm/v1/tx.proto", fileDescriptor_4f74d82755520264) } + +var fileDescriptor_4f74d82755520264 = []byte{ + // 1724 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x19, 0x4d, 0x6c, 0x1b, 0xc5, + 0x3a, 0x1b, 0x3b, 0x8e, 0x3d, 0xc9, 0x6b, 0xd3, 0xad, 0x9b, 0x38, 0xdb, 0xd6, 0x76, 0xb7, 0x3f, + 0x71, 0xf3, 0x52, 0x3b, 0xf1, 0xeb, 0xeb, 0x7b, 0x35, 0x5c, 0xe2, 0x14, 0x89, 0x54, 0x18, 0xa2, + 0x8d, 0xd2, 0x0a, 0x54, 0xc9, 0xac, 0xbd, 0x93, 0xcd, 0xaa, 0xde, 0x5d, 0xe3, 0x59, 0xe7, 0xe7, + 0xc0, 0x05, 0x24, 0x24, 0x10, 0x07, 0x2e, 0x9c, 0x38, 0x23, 0x01, 0x17, 0x7a, 0xe0, 0xc0, 0xb1, + 0x27, 0x54, 0x01, 0x42, 0x15, 0x27, 0x2e, 0x18, 0x48, 0x91, 0xca, 0x0d, 0xa9, 0x47, 0x4e, 0x68, + 0x67, 0x76, 0xd7, 0xe3, 0xf5, 0xec, 0xda, 0x49, 0x5a, 0x81, 0xc4, 0x25, 0xd9, 0x99, 0xf9, 0xbe, + 0x6f, 0xbe, 0xff, 0x9f, 0x31, 0x98, 0xad, 0x9b, 0x48, 0xdf, 0x91, 0x91, 0x5e, 0xc0, 0x7f, 0xb6, + 0x97, 0x0a, 0xd6, 0x6e, 0xbe, 0xd9, 0x32, 0x2d, 0x93, 0x9f, 0x72, 0x8f, 0xf2, 0xf8, 0xcf, 0xf6, + 0x92, 0x90, 0xb6, 0x77, 0x4c, 0x54, 0xa8, 0xc9, 0x08, 0x16, 0xb6, 0x97, 0x6a, 0xd0, 0x92, 0x97, + 0x0a, 0x75, 0x53, 0x33, 0x08, 0x86, 0x30, 0xe3, 0x9c, 0xeb, 0x48, 0xb5, 0x29, 0xe9, 0x48, 0x75, + 0x0e, 0x92, 0xaa, 0xa9, 0x9a, 0xf8, 0xb3, 0x60, 0x7f, 0x39, 0xbb, 0x67, 0xfa, 0xef, 0xde, 0x6b, + 0x42, 0xe4, 0x9c, 0xce, 0x12, 0x62, 0x55, 0x82, 0x46, 0x16, 0xce, 0xd1, 0x09, 0x59, 0xd7, 0x0c, + 0xb3, 0x80, 0xff, 0x92, 0x2d, 0xf1, 0x57, 0x0e, 0x4c, 0x56, 0x90, 0xba, 0x6e, 0x99, 0x2d, 0xb8, + 0x62, 0x2a, 0x90, 0x9f, 0x06, 0x31, 0x04, 0x0d, 0x05, 0xb6, 0x52, 0x5c, 0x96, 0xcb, 0x25, 0x24, + 0x67, 0xc5, 0x5f, 0x03, 0xc7, 0xec, 0xdb, 0xaa, 0xb5, 0x3d, 0x0b, 0x56, 0xeb, 0xa6, 0x02, 0x53, + 0xa3, 0x59, 0x2e, 0x37, 0x59, 0x9e, 0xda, 0xef, 0x64, 0x26, 0x6f, 0x2f, 0xaf, 0x57, 0xca, 0x7b, + 0x16, 0xa6, 0x20, 0x4d, 0xda, 0x70, 0xee, 0x8a, 0xdf, 0x00, 0xd3, 0x9a, 0x81, 0x2c, 0xd9, 0xb0, + 0x34, 0xd9, 0x82, 0xd5, 0x26, 0x6c, 0xe9, 0x1a, 0x42, 0x9a, 0x69, 0xa4, 0xc6, 0xb2, 0x5c, 0x6e, + 0xa2, 0x98, 0xce, 0xfb, 0xd5, 0x95, 0x5f, 0xae, 0xd7, 0x21, 0x42, 0x2b, 0xa6, 0xb1, 0xa9, 0xa9, + 0xd2, 0x29, 0x0a, 0x7b, 0xcd, 0x43, 0x2e, 0x9d, 0x7b, 0xeb, 0xf1, 0xbd, 0x79, 0x87, 0xb7, 0xf7, + 0x1e, 0xdf, 0x9b, 0x3f, 0x81, 0x55, 0x41, 0x4b, 0x72, 0x33, 0x1a, 0x8f, 0x4c, 0x45, 0x6f, 0x46, + 0xe3, 0xd1, 0xa9, 0x31, 0xf1, 0x36, 0x48, 0xd2, 0x67, 0x12, 0x44, 0x4d, 0xd3, 0x40, 0x90, 0x3f, + 0x0f, 0xc6, 0x6d, 0x59, 0xaa, 0x9a, 0x82, 0xc5, 0x8d, 0x96, 0xc1, 0x7e, 0x27, 0x13, 0xb3, 0x41, + 0x56, 0x6f, 0x48, 0x31, 0xfb, 0x68, 0x55, 0xe1, 0x05, 0x10, 0xaf, 0x6f, 0xc1, 0xfa, 0x5d, 0xd4, + 0xd6, 0x89, 0xd0, 0x92, 0xb7, 0x16, 0xef, 0x8f, 0x82, 0xe9, 0x0a, 0x52, 0x57, 0xbb, 0x4c, 0xae, + 0x98, 0x86, 0xd5, 0x92, 0xeb, 0x56, 0xa0, 0x26, 0x93, 0x60, 0x4c, 0x56, 0x74, 0xcd, 0xc0, 0xb4, + 0x12, 0x12, 0x59, 0xd0, 0x9c, 0x44, 0x02, 0x39, 0x49, 0x82, 0xb1, 0x86, 0x5c, 0x83, 0x8d, 0x54, + 0x94, 0xa0, 0xe2, 0x05, 0x9f, 0x03, 0x11, 0x1d, 0xa9, 0x58, 0x9f, 0x93, 0xe5, 0xe9, 0x3f, 0x3a, + 0x19, 0x5e, 0x92, 0x77, 0x5c, 0x36, 0x2a, 0x10, 0x21, 0x59, 0x85, 0x92, 0x0d, 0xc2, 0x6f, 0x82, + 0xb1, 0xcd, 0xb6, 0xa1, 0xa0, 0x54, 0x2c, 0x1b, 0xc9, 0x4d, 0x14, 0x67, 0xf3, 0x8e, 0x7b, 0xd8, + 0x8e, 0x99, 0x77, 0x1c, 0x33, 0xbf, 0x62, 0x6a, 0x46, 0xf9, 0xbf, 0x0f, 0x3a, 0x99, 0x91, 0xcf, + 0x7e, 0xca, 0xe4, 0x54, 0xcd, 0xda, 0x6a, 0xd7, 0xf2, 0x75, 0x53, 0x77, 0x7c, 0xc9, 0xf9, 0x77, + 0x05, 0x29, 0x77, 0x1d, 0xbf, 0xb3, 0x11, 0xd0, 0x27, 0x8f, 0xef, 0xcd, 0x73, 0x12, 0x21, 0x5f, + 0xfa, 0xb7, 0xcf, 0x3a, 0xa7, 0x5d, 0xeb, 0x30, 0xf4, 0x24, 0xbe, 0x0c, 0xd2, 0xec, 0x13, 0xcf, + 0x4a, 0x29, 0x30, 0x2e, 0x2b, 0x4a, 0x0b, 0x22, 0xe4, 0xa8, 0xd2, 0x5d, 0xf2, 0x3c, 0x88, 0x2a, + 0xb2, 0x25, 0x3b, 0x66, 0xc1, 0xdf, 0xe2, 0xef, 0xa3, 0x60, 0x86, 0x4d, 0xb0, 0xf8, 0x0f, 0xb6, + 0x89, 0xad, 0x2a, 0x24, 0x37, 0xac, 0xd4, 0x38, 0x51, 0x95, 0xfd, 0xcd, 0xcf, 0x80, 0xf1, 0x4d, + 0x6d, 0xb7, 0x6a, 0x73, 0x1a, 0xcf, 0x72, 0xb9, 0xb8, 0x14, 0xdb, 0xd4, 0x76, 0x2b, 0x48, 0x2d, + 0x2d, 0xf8, 0x0c, 0x78, 0x26, 0xc4, 0x80, 0x45, 0xf1, 0x15, 0x90, 0x09, 0x38, 0x3a, 0xa4, 0x09, + 0xdf, 0x1e, 0x05, 0x7c, 0x05, 0xa9, 0x2f, 0xec, 0xc2, 0x7a, 0x7b, 0x88, 0x88, 0xb2, 0x03, 0xd4, + 0x81, 0x71, 0x0c, 0xe8, 0xad, 0x5d, 0x43, 0x44, 0x0e, 0x60, 0x88, 0xb1, 0x67, 0x1b, 0x1c, 0x73, + 0x3e, 0xdd, 0xce, 0xb8, 0xba, 0xf5, 0x89, 0x2b, 0x2e, 0x02, 0xa1, 0x7f, 0xd7, 0xd3, 0xa8, 0xab, + 0x37, 0x8e, 0xd2, 0xdb, 0x7d, 0x0e, 0xeb, 0xad, 0xa2, 0xa9, 0x2d, 0xf9, 0x88, 0x7a, 0x1b, 0xca, + 0xf7, 0x1d, 0xe5, 0x46, 0x07, 0x2a, 0x37, 0x58, 0x68, 0x1f, 0xaf, 0x8e, 0xd0, 0xbe, 0xdd, 0x50, + 0xa1, 0xdf, 0xe1, 0xc0, 0xb1, 0x0a, 0x52, 0x37, 0x9a, 0x8a, 0x6c, 0xc1, 0x65, 0x1c, 0xb8, 0x41, + 0x02, 0x9f, 0x06, 0x09, 0x03, 0xee, 0x54, 0xe9, 0x50, 0x8f, 0x1b, 0x70, 0x87, 0x20, 0xd1, 0xda, + 0x88, 0xf4, 0x6a, 0xa3, 0x74, 0xde, 0xc7, 0xfe, 0x49, 0x97, 0x7d, 0xea, 0x56, 0x31, 0x85, 0x4b, + 0x01, 0xb5, 0xe3, 0xb2, 0x2d, 0xaa, 0xe0, 0x5f, 0x15, 0xa4, 0xae, 0x34, 0xa0, 0xdc, 0x0a, 0x67, + 0x30, 0x8c, 0x07, 0xd1, 0xc7, 0x03, 0xef, 0xf2, 0xd0, 0xa5, 0x2b, 0xce, 0x80, 0x53, 0x3d, 0x1b, + 0x1e, 0x07, 0x1f, 0x71, 0x80, 0xa7, 0xeb, 0x2a, 0xe1, 0x72, 0xb8, 0xfa, 0xf7, 0x7a, 0x60, 0x09, + 0x1f, 0x1d, 0xa6, 0x84, 0x97, 0x13, 0x76, 0xb8, 0x90, 0x10, 0x60, 0x57, 0x73, 0xf1, 0x37, 0x0e, + 0x5b, 0x9d, 0x30, 0xd5, 0x9b, 0x47, 0x36, 0x35, 0x35, 0x50, 0x5b, 0x14, 0xf7, 0xa3, 0x81, 0xdc, + 0xdf, 0x01, 0x82, 0x6d, 0xf3, 0x00, 0x09, 0x22, 0x43, 0x35, 0x21, 0x29, 0x03, 0xee, 0xac, 0x32, + 0xfb, 0x90, 0x82, 0xcf, 0x28, 0x99, 0x5e, 0xc7, 0xe8, 0x93, 0x45, 0xbc, 0x00, 0xc4, 0xe0, 0x53, + 0xcf, 0x5c, 0x9f, 0x73, 0xe0, 0xb8, 0x07, 0xb6, 0x26, 0xb7, 0x64, 0x1d, 0xf1, 0xd7, 0x40, 0x42, + 0x6e, 0x5b, 0x5b, 0x66, 0x4b, 0xb3, 0xf6, 0x88, 0x22, 0xca, 0xa9, 0xef, 0xbf, 0xb8, 0x92, 0x74, + 0xd2, 0xd4, 0x32, 0xc9, 0xa7, 0xeb, 0x56, 0x4b, 0x33, 0x54, 0xa9, 0x0b, 0xca, 0x3f, 0x07, 0x62, + 0x4d, 0x4c, 0xc1, 0x31, 0x57, 0xaa, 0x5f, 0x58, 0x72, 0x03, 0x6d, 0x28, 0x07, 0x85, 0xc4, 0x6d, + 0x97, 0x98, 0x2d, 0x62, 0xb2, 0x57, 0x44, 0x82, 0x2b, 0xce, 0xe2, 0xa2, 0x4b, 0x6f, 0x79, 0xc2, + 0x7c, 0x49, 0x84, 0x59, 0x6f, 0x2b, 0xa6, 0x97, 0x92, 0x0e, 0x2b, 0xcc, 0x53, 0x49, 0xf5, 0xa1, + 0x52, 0xd1, 0x6c, 0x8a, 0x57, 0xb0, 0x54, 0xf4, 0x56, 0x68, 0x2a, 0xfa, 0x98, 0x03, 0x13, 0x15, + 0xa4, 0xae, 0x69, 0x86, 0xed, 0x84, 0x87, 0x37, 0xd9, 0x75, 0x5b, 0x4a, 0xec, 0xd8, 0xb6, 0xd1, + 0x22, 0xb9, 0x68, 0x39, 0xbd, 0xdf, 0xc9, 0x8c, 0x13, 0xcf, 0x46, 0x4f, 0x3a, 0x99, 0xe3, 0x7b, + 0xb2, 0xde, 0x28, 0x89, 0x2e, 0x90, 0x28, 0x8d, 0x13, 0x6f, 0x47, 0x24, 0x53, 0xf5, 0x8a, 0x36, + 0xe5, 0x8a, 0xe6, 0xf2, 0x25, 0x9e, 0x02, 0x27, 0xa9, 0xa5, 0x67, 0xa8, 0x4f, 0x39, 0x9c, 0xa7, + 0x36, 0x8c, 0xe6, 0x5f, 0x28, 0xc0, 0xc5, 0x7e, 0x01, 0xbc, 0x4c, 0xd7, 0xe5, 0xcc, 0xc9, 0x74, + 0xdd, 0x0d, 0x4f, 0x88, 0x6f, 0xa2, 0xb8, 0x9f, 0xc4, 0xbd, 0xfe, 0xb2, 0xa1, 0xb0, 0x3a, 0xf3, + 0xc3, 0x4a, 0xd5, 0x3f, 0x03, 0x45, 0x8e, 0x38, 0x03, 0x45, 0x8f, 0x30, 0x03, 0xf1, 0x67, 0x01, + 0x68, 0xdb, 0xf2, 0x13, 0x56, 0xc6, 0x70, 0x03, 0x97, 0x68, 0xbb, 0x1a, 0xe9, 0xf6, 0xb4, 0x31, + 0xba, 0xa7, 0xf5, 0xda, 0xd5, 0x71, 0x46, 0xbb, 0x1a, 0x3f, 0x40, 0x97, 0x94, 0x78, 0xb6, 0xed, + 0xaa, 0x9d, 0xf3, 0xcd, 0x76, 0xab, 0x0e, 0x53, 0xc0, 0xc9, 0xf9, 0x78, 0x65, 0x37, 0x92, 0xb5, + 0xb6, 0xd6, 0xb0, 0x8b, 0xc1, 0x04, 0x69, 0x24, 0x9d, 0xa5, 0x5d, 0xdc, 0xb1, 0x3b, 0x6d, 0xc9, + 0x68, 0x2b, 0x35, 0xe9, 0xcc, 0x69, 0xa6, 0x02, 0x5f, 0x94, 0xd1, 0x56, 0xe9, 0x5a, 0xbf, 0x57, + 0x9d, 0xef, 0x19, 0x19, 0xd9, 0xae, 0x22, 0xde, 0x02, 0x97, 0xc2, 0x21, 0x0e, 0xd9, 0xe1, 0x7e, + 0xc5, 0xe1, 0x9e, 0x79, 0x59, 0x51, 0x6c, 0x5b, 0x6d, 0x34, 0x1b, 0xa6, 0xac, 0x90, 0xb4, 0xe9, + 0x78, 0xdf, 0x11, 0x82, 0xaf, 0x08, 0x12, 0xb2, 0x4b, 0x04, 0x47, 0x5f, 0xa2, 0x9c, 0x7c, 0xd2, + 0xc9, 0x4c, 0x91, 0x90, 0xf3, 0x8e, 0x44, 0xa9, 0x0b, 0x56, 0xfa, 0x5f, 0xbf, 0x7e, 0x2e, 0xb8, + 0xfa, 0x09, 0x63, 0x52, 0xbc, 0x0c, 0xe6, 0x06, 0x80, 0x78, 0x91, 0xf9, 0x2d, 0x87, 0x6b, 0x9f, + 0x04, 0x75, 0x73, 0x1b, 0xfe, 0x3d, 0xc4, 0x2e, 0xf5, 0x8b, 0x3d, 0xe7, 0x8a, 0x3d, 0x80, 0x4f, + 0x71, 0x01, 0xcc, 0x0f, 0x86, 0xf2, 0x84, 0xff, 0x71, 0x14, 0xb7, 0x38, 0xae, 0x27, 0xf9, 0x5b, + 0xf4, 0xa7, 0x97, 0x92, 0x8e, 0xfa, 0x2c, 0x13, 0x39, 0x4a, 0x4a, 0xa2, 0xcb, 0x73, 0x94, 0x5d, + 0x9e, 0x07, 0x8f, 0xc4, 0xa5, 0x62, 0xbf, 0x55, 0x32, 0xfe, 0x60, 0xf5, 0xcf, 0x0d, 0x7b, 0xd8, + 0xb7, 0x02, 0x4e, 0x9f, 0xda, 0x7b, 0x8f, 0x17, 0xcb, 0x11, 0x2a, 0x96, 0xbf, 0xe6, 0xa8, 0xc6, + 0xdf, 0xbd, 0xf2, 0x25, 0x9c, 0x57, 0x17, 0x7b, 0x3b, 0xd7, 0x10, 0x9b, 0xfa, 0x46, 0x14, 0x92, + 0xa3, 0xbb, 0x23, 0x0a, 0x21, 0x77, 0xd5, 0x3f, 0x1e, 0x84, 0x10, 0xec, 0x0e, 0x0e, 0x81, 0xaf, + 0x31, 0x0c, 0x8e, 0xc5, 0x2c, 0xae, 0x9e, 0x8c, 0x13, 0x57, 0x87, 0xc5, 0xef, 0x8e, 0x81, 0x48, + 0x05, 0xa9, 0xfc, 0x3a, 0x48, 0x74, 0x9f, 0x0d, 0x19, 0xfe, 0x42, 0x3f, 0xb8, 0x09, 0x97, 0xc2, + 0xcf, 0x3d, 0x03, 0xbd, 0x01, 0x4e, 0xb2, 0x2a, 0x76, 0x8e, 0x89, 0xce, 0x80, 0x14, 0x16, 0x87, + 0x85, 0xf4, 0xae, 0xb4, 0x40, 0x92, 0xf9, 0x56, 0x74, 0x79, 0x58, 0x4a, 0x45, 0x61, 0x69, 0x68, + 0x50, 0xef, 0x56, 0x08, 0x8e, 0xfb, 0x9f, 0x37, 0x2e, 0x30, 0xa9, 0xf8, 0xa0, 0x84, 0x85, 0x61, + 0xa0, 0xe8, 0x6b, 0xfc, 0xa9, 0x86, 0x7d, 0x8d, 0x0f, 0x2a, 0xe0, 0x9a, 0xa0, 0xb8, 0x7a, 0x15, + 0x4c, 0xd0, 0xf3, 0x77, 0x96, 0x89, 0x4c, 0x41, 0x08, 0xb9, 0x41, 0x10, 0x1e, 0xe9, 0x5b, 0x00, + 0x50, 0x83, 0x73, 0x86, 0x89, 0xd7, 0x05, 0x10, 0xe6, 0x06, 0x00, 0x78, 0x74, 0xdf, 0x04, 0x33, + 0x41, 0xf3, 0xe6, 0x42, 0x08, 0x73, 0x7d, 0xd0, 0xc2, 0xd5, 0x83, 0x40, 0x7b, 0xd7, 0xdf, 0x01, + 0x93, 0x3d, 0xd3, 0xdd, 0xb9, 0x10, 0x2a, 0x04, 0x44, 0xb8, 0x3c, 0x10, 0x84, 0xa6, 0xde, 0x33, + 0x6e, 0xb1, 0xa9, 0xd3, 0x20, 0x01, 0xd4, 0x99, 0xa3, 0xcf, 0x1a, 0x88, 0x7b, 0x23, 0xce, 0x59, + 0x26, 0x9a, 0x7b, 0x2c, 0x5c, 0x0c, 0x3d, 0xa6, 0x8d, 0x4c, 0x4d, 0x1d, 0x6c, 0x23, 0x77, 0x01, + 0x02, 0x8c, 0xdc, 0x3f, 0x0c, 0xf0, 0xef, 0x72, 0xe0, 0x74, 0xd8, 0x24, 0xb0, 0x18, 0x9c, 0x96, + 0xd8, 0x18, 0xc2, 0xff, 0x0f, 0x8a, 0xe1, 0xf1, 0xf2, 0x21, 0x07, 0x32, 0x83, 0x7a, 0x1f, 0xb6, + 0x2f, 0x0d, 0xc0, 0x12, 0x9e, 0x3f, 0x0c, 0x96, 0xc7, 0xd7, 0xfb, 0x1c, 0x38, 0x13, 0xda, 0x87, + 0xb2, 0xb3, 0x5b, 0x18, 0x8a, 0x70, 0xfd, 0xc0, 0x28, 0x74, 0x5c, 0x06, 0x35, 0x49, 0x0b, 0xa1, + 0xba, 0xf7, 0x67, 0xb0, 0xab, 0x07, 0x81, 0xa6, 0x0b, 0x10, 0xab, 0x90, 0x87, 0xe5, 0xab, 0x1e, + 0xc8, 0x80, 0x02, 0x14, 0x52, 0x50, 0xcb, 0x37, 0x1e, 0xfc, 0x92, 0x1e, 0x79, 0xb0, 0x9f, 0xe6, + 0x1e, 0xee, 0xa7, 0xb9, 0x9f, 0xf7, 0xd3, 0xdc, 0x07, 0x8f, 0xd2, 0x23, 0x0f, 0x1f, 0xa5, 0x47, + 0x7e, 0x78, 0x94, 0x1e, 0x79, 0xed, 0x12, 0x35, 0x3e, 0xad, 0x98, 0x48, 0xbf, 0xed, 0xfe, 0xf0, + 0xa7, 0x14, 0x76, 0xc9, 0x0f, 0x80, 0x78, 0x84, 0xaa, 0xc5, 0xf0, 0x0f, 0x7a, 0xff, 0xf9, 0x33, + 0x00, 0x00, 0xff, 0xff, 0x86, 0x50, 0x9c, 0xc9, 0x9a, 0x1c, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ context.Context + _ grpc.ClientConn +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { @@ -1507,7 +1892,7 @@ type MsgClient interface { ExecuteContract(ctx context.Context, in *MsgExecuteContract, opts ...grpc.CallOption) (*MsgExecuteContractResponse, error) // Migrate runs a code upgrade/ downgrade for a smart contract MigrateContract(ctx context.Context, in *MsgMigrateContract, opts ...grpc.CallOption) (*MsgMigrateContractResponse, error) - // UpdateAdmin sets a new admin for a smart contract + // UpdateAdmin sets a new admin for a smart contract UpdateAdmin(ctx context.Context, in *MsgUpdateAdmin, opts ...grpc.CallOption) (*MsgUpdateAdminResponse, error) // ClearAdmin removes any admin stored for a smart contract ClearAdmin(ctx context.Context, in *MsgClearAdmin, opts ...grpc.CallOption) (*MsgClearAdminResponse, error) @@ -1546,6 +1931,15 @@ type MsgClient interface { // adding addresses to code upload params. // The authority is defined in the keeper. AddCodeUploadParamsAddresses(ctx context.Context, in *MsgAddCodeUploadParamsAddresses, opts ...grpc.CallOption) (*MsgAddCodeUploadParamsAddressesResponse, error) + // StoreAndMigrateContract defines a governance operation for storing + // and migrating the contract. The authority is defined in the keeper. + // + // Since: 0.42 + StoreAndMigrateContract(ctx context.Context, in *MsgStoreAndMigrateContract, opts ...grpc.CallOption) (*MsgStoreAndMigrateContractResponse, error) + // UpdateContractLabel sets a new label for a smart contract + // + // Since: 0.43 + UpdateContractLabel(ctx context.Context, in *MsgUpdateContractLabel, opts ...grpc.CallOption) (*MsgUpdateContractLabelResponse, error) } type msgClient struct { @@ -1691,6 +2085,24 @@ func (c *msgClient) AddCodeUploadParamsAddresses(ctx context.Context, in *MsgAdd return out, nil } +func (c *msgClient) StoreAndMigrateContract(ctx context.Context, in *MsgStoreAndMigrateContract, opts ...grpc.CallOption) (*MsgStoreAndMigrateContractResponse, error) { + out := new(MsgStoreAndMigrateContractResponse) + err := c.cc.Invoke(ctx, "/cosmwasm.wasm.v1.Msg/StoreAndMigrateContract", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateContractLabel(ctx context.Context, in *MsgUpdateContractLabel, opts ...grpc.CallOption) (*MsgUpdateContractLabelResponse, error) { + out := new(MsgUpdateContractLabelResponse) + err := c.cc.Invoke(ctx, "/cosmwasm.wasm.v1.Msg/UpdateContractLabel", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // StoreCode to submit Wasm code to the system @@ -1705,7 +2117,7 @@ type MsgServer interface { ExecuteContract(context.Context, *MsgExecuteContract) (*MsgExecuteContractResponse, error) // Migrate runs a code upgrade/ downgrade for a smart contract MigrateContract(context.Context, *MsgMigrateContract) (*MsgMigrateContractResponse, error) - // UpdateAdmin sets a new admin for a smart contract + // UpdateAdmin sets a new admin for a smart contract UpdateAdmin(context.Context, *MsgUpdateAdmin) (*MsgUpdateAdminResponse, error) // ClearAdmin removes any admin stored for a smart contract ClearAdmin(context.Context, *MsgClearAdmin) (*MsgClearAdminResponse, error) @@ -1744,48 +2156,68 @@ type MsgServer interface { // adding addresses to code upload params. // The authority is defined in the keeper. AddCodeUploadParamsAddresses(context.Context, *MsgAddCodeUploadParamsAddresses) (*MsgAddCodeUploadParamsAddressesResponse, error) + // StoreAndMigrateContract defines a governance operation for storing + // and migrating the contract. The authority is defined in the keeper. + // + // Since: 0.42 + StoreAndMigrateContract(context.Context, *MsgStoreAndMigrateContract) (*MsgStoreAndMigrateContractResponse, error) + // UpdateContractLabel sets a new label for a smart contract + // + // Since: 0.43 + UpdateContractLabel(context.Context, *MsgUpdateContractLabel) (*MsgUpdateContractLabelResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. -type UnimplementedMsgServer struct { -} +type UnimplementedMsgServer struct{} func (*UnimplementedMsgServer) StoreCode(ctx context.Context, req *MsgStoreCode) (*MsgStoreCodeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method StoreCode not implemented") } + func (*UnimplementedMsgServer) InstantiateContract(ctx context.Context, req *MsgInstantiateContract) (*MsgInstantiateContractResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method InstantiateContract not implemented") } + func (*UnimplementedMsgServer) InstantiateContract2(ctx context.Context, req *MsgInstantiateContract2) (*MsgInstantiateContract2Response, error) { return nil, status.Errorf(codes.Unimplemented, "method InstantiateContract2 not implemented") } + func (*UnimplementedMsgServer) ExecuteContract(ctx context.Context, req *MsgExecuteContract) (*MsgExecuteContractResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ExecuteContract not implemented") } + func (*UnimplementedMsgServer) MigrateContract(ctx context.Context, req *MsgMigrateContract) (*MsgMigrateContractResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method MigrateContract not implemented") } + func (*UnimplementedMsgServer) UpdateAdmin(ctx context.Context, req *MsgUpdateAdmin) (*MsgUpdateAdminResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateAdmin not implemented") } + func (*UnimplementedMsgServer) ClearAdmin(ctx context.Context, req *MsgClearAdmin) (*MsgClearAdminResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ClearAdmin not implemented") } + func (*UnimplementedMsgServer) UpdateInstantiateConfig(ctx context.Context, req *MsgUpdateInstantiateConfig) (*MsgUpdateInstantiateConfigResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateInstantiateConfig not implemented") } + func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") } + func (*UnimplementedMsgServer) SudoContract(ctx context.Context, req *MsgSudoContract) (*MsgSudoContractResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SudoContract not implemented") } + func (*UnimplementedMsgServer) PinCodes(ctx context.Context, req *MsgPinCodes) (*MsgPinCodesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method PinCodes not implemented") } + func (*UnimplementedMsgServer) UnpinCodes(ctx context.Context, req *MsgUnpinCodes) (*MsgUnpinCodesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UnpinCodes not implemented") } + func (*UnimplementedMsgServer) StoreAndInstantiateContract(ctx context.Context, req *MsgStoreAndInstantiateContract) (*MsgStoreAndInstantiateContractResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method StoreAndInstantiateContract not implemented") } @@ -1798,6 +2230,14 @@ func (*UnimplementedMsgServer) AddCodeUploadParamsAddresses(ctx context.Context, return nil, status.Errorf(codes.Unimplemented, "method AddCodeUploadParamsAddresses not implemented") } +func (*UnimplementedMsgServer) StoreAndMigrateContract(ctx context.Context, req *MsgStoreAndMigrateContract) (*MsgStoreAndMigrateContractResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method StoreAndMigrateContract not implemented") +} + +func (*UnimplementedMsgServer) UpdateContractLabel(ctx context.Context, req *MsgUpdateContractLabel) (*MsgUpdateContractLabelResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateContractLabel not implemented") +} + func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } @@ -2072,6 +2512,42 @@ func _Msg_AddCodeUploadParamsAddresses_Handler(srv interface{}, ctx context.Cont return interceptor(ctx, in, info, handler) } +func _Msg_StoreAndMigrateContract_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgStoreAndMigrateContract) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).StoreAndMigrateContract(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmwasm.wasm.v1.Msg/StoreAndMigrateContract", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).StoreAndMigrateContract(ctx, req.(*MsgStoreAndMigrateContract)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateContractLabel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateContractLabel) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateContractLabel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmwasm.wasm.v1.Msg/UpdateContractLabel", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateContractLabel(ctx, req.(*MsgUpdateContractLabel)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmwasm.wasm.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -2136,6 +2612,14 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "AddCodeUploadParamsAddresses", Handler: _Msg_AddCodeUploadParamsAddresses_Handler, }, + { + MethodName: "StoreAndMigrateContract", + Handler: _Msg_StoreAndMigrateContract_Handler, + }, + { + MethodName: "UpdateContractLabel", + Handler: _Msg_UpdateContractLabel_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "cosmwasm/wasm/v1/tx.proto", @@ -2750,6 +3234,44 @@ func (m *MsgClearAdminResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *AccessConfigUpdate) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AccessConfigUpdate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AccessConfigUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.InstantiatePermission.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.CodeID != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.CodeID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func (m *MsgUpdateInstantiateConfig) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -2978,20 +3500,20 @@ func (m *MsgPinCodes) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.CodeIDs) > 0 { - dAtA5 := make([]byte, len(m.CodeIDs)*10) - var j4 int + dAtA6 := make([]byte, len(m.CodeIDs)*10) + var j5 int for _, num := range m.CodeIDs { for num >= 1<<7 { - dAtA5[j4] = uint8(uint64(num)&0x7f | 0x80) + dAtA6[j5] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j4++ + j5++ } - dAtA5[j4] = uint8(num) - j4++ + dAtA6[j5] = uint8(num) + j5++ } - i -= j4 - copy(dAtA[i:], dAtA5[:j4]) - i = encodeVarintTx(dAtA, i, uint64(j4)) + i -= j5 + copy(dAtA[i:], dAtA6[:j5]) + i = encodeVarintTx(dAtA, i, uint64(j5)) i-- dAtA[i] = 0x12 } @@ -3049,20 +3571,20 @@ func (m *MsgUnpinCodes) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.CodeIDs) > 0 { - dAtA7 := make([]byte, len(m.CodeIDs)*10) - var j6 int + dAtA8 := make([]byte, len(m.CodeIDs)*10) + var j7 int for _, num := range m.CodeIDs { for num >= 1<<7 { - dAtA7[j6] = uint8(uint64(num)&0x7f | 0x80) + dAtA8[j7] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j6++ + j7++ } - dAtA7[j6] = uint8(num) - j6++ + dAtA8[j7] = uint8(num) + j7++ } - i -= j6 - copy(dAtA[i:], dAtA7[:j6]) - i = encodeVarintTx(dAtA, i, uint64(j6)) + i -= j7 + copy(dAtA[i:], dAtA8[:j7]) + i = encodeVarintTx(dAtA, i, uint64(j7)) i-- dAtA[i] = 0x12 } @@ -3375,17 +3897,190 @@ func (m *MsgRemoveCodeUploadParamsAddressesResponse) MarshalToSizedBuffer(dAtA [ return len(dAtA) - i, nil } -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 +func (m *MsgStoreAndMigrateContract) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgStoreAndMigrateContract) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgStoreAndMigrateContract) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintTx(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x2a + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintTx(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0x22 + } + if m.InstantiatePermission != nil { + { + size, err := m.InstantiatePermission.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.WASMByteCode) > 0 { + i -= len(m.WASMByteCode) + copy(dAtA[i:], m.WASMByteCode) + i = encodeVarintTx(dAtA, i, uint64(len(m.WASMByteCode))) + i-- + dAtA[i] = 0x12 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgStoreAndMigrateContractResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgStoreAndMigrateContractResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgStoreAndMigrateContractResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintTx(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x1a + } + if len(m.Checksum) > 0 { + i -= len(m.Checksum) + copy(dAtA[i:], m.Checksum) + i = encodeVarintTx(dAtA, i, uint64(len(m.Checksum))) + i-- + dAtA[i] = 0x12 + } + if m.CodeID != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.CodeID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateContractLabel) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateContractLabel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateContractLabel) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintTx(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0x1a + } + if len(m.NewLabel) > 0 { + i -= len(m.NewLabel) + copy(dAtA[i:], m.NewLabel) + i = encodeVarintTx(dAtA, i, uint64(len(m.NewLabel))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateContractLabelResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateContractLabelResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateContractLabelResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 offset++ } dAtA[offset] = uint8(v) return base } + func (m *MsgStoreCode) Size() (n int) { if m == nil { return 0 @@ -3665,6 +4360,20 @@ func (m *MsgClearAdminResponse) Size() (n int) { return n } +func (m *AccessConfigUpdate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.CodeID != 0 { + n += 1 + sovTx(uint64(m.CodeID)) + } + l = m.InstantiatePermission.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + func (m *MsgUpdateInstantiateConfig) Size() (n int) { if m == nil { return 0 @@ -3937,12 +4646,93 @@ func (m *MsgRemoveCodeUploadParamsAddressesResponse) Size() (n int) { return n } +func (m *MsgStoreAndMigrateContract) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.WASMByteCode) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.InstantiatePermission != nil { + l = m.InstantiatePermission.Size() + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Msg) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgStoreAndMigrateContractResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.CodeID != 0 { + n += 1 + sovTx(uint64(m.CodeID)) + } + l = len(m.Checksum) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateContractLabel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.NewLabel) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateContractLabelResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } + func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } + func (m *MsgStoreCode) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -4095,6 +4885,7 @@ func (m *MsgStoreCode) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgStoreCodeResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -4198,6 +4989,7 @@ func (m *MsgStoreCodeResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -4431,6 +5223,7 @@ func (m *MsgInstantiateContract) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgInstantiateContractResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -4547,6 +5340,7 @@ func (m *MsgInstantiateContractResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgInstantiateContract2) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -4834,6 +5628,7 @@ func (m *MsgInstantiateContract2) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgInstantiateContract2Response) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -4950,6 +5745,7 @@ func (m *MsgInstantiateContract2Response) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgExecuteContract) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5132,6 +5928,7 @@ func (m *MsgExecuteContract) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgExecuteContractResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5216,6 +6013,7 @@ func (m *MsgExecuteContractResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgMigrateContract) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5383,6 +6181,7 @@ func (m *MsgMigrateContract) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgMigrateContractResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5467,6 +6266,7 @@ func (m *MsgMigrateContractResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgUpdateAdmin) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5613,6 +6413,7 @@ func (m *MsgUpdateAdmin) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgUpdateAdminResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5663,6 +6464,7 @@ func (m *MsgUpdateAdminResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgClearAdmin) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5777,6 +6579,7 @@ func (m *MsgClearAdmin) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgClearAdminResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5827,6 +6630,110 @@ func (m *MsgClearAdminResponse) Unmarshal(dAtA []byte) error { } return nil } + +func (m *AccessConfigUpdate) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AccessConfigUpdate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AccessConfigUpdate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) + } + m.CodeID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CodeID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InstantiatePermission", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.InstantiatePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + func (m *MsgUpdateInstantiateConfig) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5964,6 +6871,7 @@ func (m *MsgUpdateInstantiateConfig) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgUpdateInstantiateConfigResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6014,6 +6922,7 @@ func (m *MsgUpdateInstantiateConfigResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6129,6 +7038,7 @@ func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6179,6 +7089,7 @@ func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgSudoContract) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6327,6 +7238,7 @@ func (m *MsgSudoContract) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgSudoContractResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6411,6 +7323,7 @@ func (m *MsgSudoContractResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgPinCodes) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6569,6 +7482,7 @@ func (m *MsgPinCodes) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgPinCodesResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6619,6 +7533,7 @@ func (m *MsgPinCodesResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgUnpinCodes) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6777,6 +7692,7 @@ func (m *MsgUnpinCodes) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgUnpinCodesResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -6827,6 +7743,7 @@ func (m *MsgUnpinCodesResponse) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgStoreAndInstantiateContract) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -7229,6 +8146,7 @@ func (m *MsgStoreAndInstantiateContract) Unmarshal(dAtA []byte) error { } return nil } + func (m *MsgStoreAndInstantiateContractResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -7677,6 +8595,562 @@ func (m *MsgRemoveCodeUploadParamsAddressesResponse) Unmarshal(dAtA []byte) erro } return nil } + +func (m *MsgStoreAndMigrateContract) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgStoreAndMigrateContract: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgStoreAndMigrateContract: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WASMByteCode", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.WASMByteCode = append(m.WASMByteCode[:0], dAtA[iNdEx:postIndex]...) + if m.WASMByteCode == nil { + m.WASMByteCode = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InstantiatePermission", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.InstantiatePermission == nil { + m.InstantiatePermission = &AccessConfig{} + } + if err := m.InstantiatePermission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) + if m.Msg == nil { + m.Msg = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *MsgStoreAndMigrateContractResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgStoreAndMigrateContractResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgStoreAndMigrateContractResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CodeID", wireType) + } + m.CodeID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CodeID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Checksum", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Checksum = append(m.Checksum[:0], dAtA[iNdEx:postIndex]...) + if m.Checksum == nil { + m.Checksum = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *MsgUpdateContractLabel) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateContractLabel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateContractLabel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewLabel", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NewLabel = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *MsgUpdateContractLabelResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateContractLabelResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateContractLabelResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/wasm/types/tx_test.go b/x/wasm/types/tx_test.go index 6739510923..2e980fd795 100644 --- a/x/wasm/types/tx_test.go +++ b/x/wasm/types/tx_test.go @@ -5,10 +5,11 @@ import ( "strings" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) const ( @@ -884,7 +885,6 @@ func TestMsgRemoveCodeUploadParamsAddressesValidation(t *testing.T) { func TestMsgPinCodesValidation(t *testing.T) { // proper address size goodAddress := sdk.AccAddress(make([]byte, 20)).String() - specs := map[string]struct { src MsgPinCodes expErr bool @@ -914,6 +914,20 @@ func TestMsgPinCodesValidation(t *testing.T) { }, expErr: true, }, + "exceeds max code ids": { + src: MsgPinCodes{ + Authority: goodAddress, + CodeIDs: genCodeIDs(51), + }, + expErr: true, + }, + "duplicate code ids": { + src: MsgPinCodes{ + Authority: goodAddress, + CodeIDs: []uint64{1, 1}, + }, + expErr: true, + }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { @@ -960,6 +974,20 @@ func TestMsgUnpinCodesValidation(t *testing.T) { }, expErr: true, }, + "exceeds max code ids": { + src: MsgUnpinCodes{ + Authority: goodAddress, + CodeIDs: genCodeIDs(51), + }, + expErr: true, + }, + "duplicate code ids": { + src: MsgUnpinCodes{ + Authority: goodAddress, + CodeIDs: []uint64{1, 1}, + }, + expErr: true, + }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { @@ -973,6 +1001,14 @@ func TestMsgUnpinCodesValidation(t *testing.T) { } } +func genCodeIDs(max int) []uint64 { + r := make([]uint64, max) + for i := 0; i < max; i++ { + r[i] = uint64(i) + } + return r +} + func TestMsgSudoContractValidation(t *testing.T) { badAddress := "abcd" // proper address size @@ -1215,3 +1251,184 @@ func TestMsgStoreAndInstantiateContractValidation(t *testing.T) { }) } } + +func TestMsgStoreAndMigrateContractValidation(t *testing.T) { + // proper address size + goodAddress := sdk.AccAddress(make([]byte, 20)).String() + sdk.GetConfig().SetAddressVerifier(VerifyAddressLen()) + + cases := map[string]struct { + msg MsgStoreAndMigrateContract + valid bool + }{ + "all good": { + msg: MsgStoreAndMigrateContract{ + Authority: goodAddress, + Contract: goodAddress, + Msg: []byte("{}"), + WASMByteCode: []byte("foo"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: []string{goodAddress}}, + }, + valid: true, + }, + "empty InstantiatePermission": { + msg: MsgStoreAndMigrateContract{ + Authority: goodAddress, + Contract: goodAddress, + Msg: []byte("{}"), + WASMByteCode: []byte("foo"), + }, + valid: true, + }, + "empty": { + msg: MsgStoreAndMigrateContract{}, + valid: false, + }, + "missing byte code": { + msg: MsgStoreAndMigrateContract{ + Authority: goodAddress, + Contract: goodAddress, + Msg: []byte("{}"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: []string{goodAddress}}, + }, + valid: false, + }, + "missing contract": { + msg: MsgStoreAndMigrateContract{ + Authority: goodAddress, + Msg: []byte("{}"), + WASMByteCode: []byte("foo"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: []string{goodAddress}}, + }, + valid: false, + }, + "bad contract": { + msg: MsgStoreAndMigrateContract{ + Authority: goodAddress, + Contract: badAddress, + Msg: []byte("{}"), + WASMByteCode: []byte("foo"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: []string{goodAddress}}, + }, + valid: false, + }, + "bad authority": { + msg: MsgStoreAndMigrateContract{ + Authority: badAddress, + Contract: goodAddress, + Msg: []byte("{}"), + WASMByteCode: []byte("foo"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: []string{goodAddress}}, + }, + valid: false, + }, + "non json msg": { + msg: MsgStoreAndMigrateContract{ + Authority: goodAddress, + Contract: goodAddress, + Msg: []byte("invalid-json"), + WASMByteCode: []byte("foo"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: []string{goodAddress}}, + }, + valid: false, + }, + "empty msg": { + msg: MsgStoreAndMigrateContract{ + Authority: goodAddress, + Contract: goodAddress, + WASMByteCode: []byte("foo"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: []string{goodAddress}}, + }, + valid: false, + }, + "invalid InstantiatePermission": { + msg: MsgStoreAndMigrateContract{ + Authority: goodAddress, + Contract: goodAddress, + Msg: []byte("{}"), + WASMByteCode: []byte("foo"), + InstantiatePermission: &AccessConfig{Permission: AccessTypeAnyOfAddresses, Addresses: []string{badAddress}}, + }, + valid: false, + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + if tc.valid { + assert.NoError(t, err) + } else { + assert.Error(t, err) + } + }) + } +} + +func TestMsgUpdateContractLabel(t *testing.T) { + // proper address size + goodAddress := sdk.AccAddress(make([]byte, 20)).String() + otherGoodAddress := sdk.AccAddress(bytes.Repeat([]byte{0x1}, 20)).String() + + specs := map[string]struct { + src MsgUpdateContractLabel + expErr bool + }{ + "all good": { + src: MsgUpdateContractLabel{ + Sender: goodAddress, + NewLabel: "new label", + Contract: otherGoodAddress, + }, + }, + "new label required": { + src: MsgUpdateContractLabel{ + Sender: goodAddress, + Contract: otherGoodAddress, + }, + expErr: true, + }, + "bad sender": { + src: MsgUpdateContractLabel{ + Sender: badAddress, + NewLabel: "new label", + Contract: otherGoodAddress, + }, + expErr: true, + }, + "empty new label": { + src: MsgUpdateContractLabel{ + Sender: goodAddress, + NewLabel: "", + Contract: otherGoodAddress, + }, + expErr: true, + }, + "bad new label": { + src: MsgUpdateContractLabel{ + Sender: goodAddress, + NewLabel: " start with space ", + Contract: otherGoodAddress, + }, + expErr: true, + }, + "bad contract addr": { + src: MsgUpdateContractLabel{ + Sender: goodAddress, + NewLabel: "new label", + Contract: badAddress, + }, + expErr: true, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + err := spec.src.ValidateBasic() + if spec.expErr { + require.Error(t, err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/wasm/types/types.go b/x/wasm/types/types.go index 04300ff645..fdf390cf86 100644 --- a/x/wasm/types/types.go +++ b/x/wasm/types/types.go @@ -4,12 +4,14 @@ import ( "fmt" "reflect" - errorsmod "cosmossdk.io/errors" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + "github.com/cosmos/gogoproto/proto" + + errorsmod "cosmossdk.io/errors" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/gogoproto/proto" ) const ( diff --git a/x/wasm/types/types_test.go b/x/wasm/types/types_test.go index 45fd5df739..0734937eef 100644 --- a/x/wasm/types/types_test.go +++ b/x/wasm/types/types_test.go @@ -9,12 +9,13 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cometbft/cometbft/libs/rand" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestContractInfoValidateBasic(t *testing.T) { diff --git a/x/wasm/types/validation.go b/x/wasm/types/validation.go index b954c4f859..7282c01e1d 100644 --- a/x/wasm/types/validation.go +++ b/x/wasm/types/validation.go @@ -5,8 +5,9 @@ import ( "net/url" "strings" - errorsmod "cosmossdk.io/errors" "github.com/docker/distribution/reference" + + errorsmod "cosmossdk.io/errors" ) // MaxSaltSize is the longest salt that can be used when instantiating a contract diff --git a/x/wasm/types/wasmer_engine.go b/x/wasm/types/wasmer_engine.go index 18d4060a40..d3b465de77 100644 --- a/x/wasm/types/wasmer_engine.go +++ b/x/wasm/types/wasmer_engine.go @@ -3,14 +3,15 @@ package types import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) // DefaultMaxQueryStackSize maximum size of the stack of contract instances doing queries const DefaultMaxQueryStackSize uint32 = 10 -// WasmerEngine defines the WASM contract runtime engine. -type WasmerEngine interface { +// WasmEngine defines the WASM contract runtime engine. +type WasmEngine interface { // Create will compile the wasm code, and store the resulting pre-compile // as well as the original code. Both can be referenced later via CodeID // This must be done one time for given code, after which it can be