Remove genesis msgs (#1104)

* Remove genesis msgs

* Remove genesis msgs cli

* Refactor InitGenesis function
This commit is contained in:
pinosu
2022-12-09 13:20:49 +01:00
committed by GitHub
parent c5abd338e3
commit f3ebd929cc
19 changed files with 338 additions and 2382 deletions

View File

@@ -1,27 +0,0 @@
package main
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli"
)
func AddGenesisWasmMsgCmd(defaultNodeHome string) *cobra.Command {
txCmd := &cobra.Command{
Use: "add-wasm-genesis-message",
Short: "Wasm genesis subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
genesisIO := wasmcli.NewDefaultGenesisIO()
txCmd.AddCommand(
wasmcli.GenesisStoreCodeCmd(defaultNodeHome, genesisIO),
wasmcli.GenesisInstantiateContractCmd(defaultNodeHome, genesisIO),
wasmcli.GenesisExecuteContractCmd(defaultNodeHome, genesisIO),
wasmcli.GenesisListContractsCmd(defaultNodeHome, genesisIO),
wasmcli.GenesisListCodesCmd(defaultNodeHome, genesisIO),
)
return txCmd
}

View File

@@ -99,7 +99,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
AddGenesisWasmMsgCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
// testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),

View File

@@ -28,29 +28,10 @@
- [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)
- [MsgStoreCode](#cosmwasm.wasm.v1.MsgStoreCode)
- [MsgStoreCodeResponse](#cosmwasm.wasm.v1.MsgStoreCodeResponse)
- [MsgUpdateAdmin](#cosmwasm.wasm.v1.MsgUpdateAdmin)
- [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse)
- [Msg](#cosmwasm.wasm.v1.Msg)
- [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)
@@ -99,6 +80,24 @@
- [Query](#cosmwasm.wasm.v1.Query)
- [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)
- [MsgStoreCode](#cosmwasm.wasm.v1.MsgStoreCode)
- [MsgStoreCodeResponse](#cosmwasm.wasm.v1.MsgStoreCodeResponse)
- [MsgUpdateAdmin](#cosmwasm.wasm.v1.MsgUpdateAdmin)
- [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse)
- [Msg](#cosmwasm.wasm.v1.Msg)
- [Scalar Value Types](#scalar-value-types)
@@ -447,266 +446,6 @@ ContractCodeHistoryOperationType actions that caused a code change
<a name="cosmwasm/wasm/v1/tx.proto"></a>
<p align="right"><a href="#top">Top</a></p>
## cosmwasm/wasm/v1/tx.proto
<a name="cosmwasm.wasm.v1.MsgClearAdmin"></a>
### MsgClearAdmin
MsgClearAdmin removes any admin stored 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 |
<a name="cosmwasm.wasm.v1.MsgClearAdminResponse"></a>
### MsgClearAdminResponse
MsgClearAdminResponse returns empty data
<a name="cosmwasm.wasm.v1.MsgExecuteContract"></a>
### MsgExecuteContract
MsgExecuteContract submits the given message data to 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 |
| `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 |
<a name="cosmwasm.wasm.v1.MsgExecuteContractResponse"></a>
### MsgExecuteContractResponse
MsgExecuteContractResponse returns execution result data.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract |
<a name="cosmwasm.wasm.v1.MsgInstantiateContract"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgInstantiateContract2"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgInstantiateContract2Response"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgInstantiateContractResponse"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgMigrateContract"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgMigrateContractResponse"></a>
### 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) |
<a name="cosmwasm.wasm.v1.MsgStoreCode"></a>
### MsgStoreCode
MsgStoreCode submit Wasm code to the system
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | Sender is the that 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 |
<a name="cosmwasm.wasm.v1.MsgStoreCodeResponse"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgUpdateAdmin"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgUpdateAdminResponse"></a>
### MsgUpdateAdminResponse
MsgUpdateAdminResponse returns empty data
<!-- end messages -->
<!-- end enums -->
<!-- end HasExtensions -->
<a name="cosmwasm.wasm.v1.Msg"></a>
### 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 | |
<!-- end services -->
<a name="cosmwasm/wasm/v1/genesis.proto"></a>
<p align="right"><a href="#top">Top</a></p>
@@ -762,25 +501,6 @@ GenesisState - genesis state of x/wasm
| `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 | |
<a name="cosmwasm.wasm.v1.GenesisState.GenMsgs"></a>
### 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 |
@@ -927,7 +647,8 @@ contract.
<a name="cosmwasm.wasm.v1.InstantiateContract2Proposal"></a>
### InstantiateContract2Proposal
InstantiateContract2Proposal gov proposal content type to instantiate contract 2
InstantiateContract2Proposal gov proposal content type to instantiate
contract 2
| Field | Type | Label | Description |
@@ -1551,6 +1272,266 @@ Query provides defines the gRPC querier service
<a name="cosmwasm/wasm/v1/tx.proto"></a>
<p align="right"><a href="#top">Top</a></p>
## cosmwasm/wasm/v1/tx.proto
<a name="cosmwasm.wasm.v1.MsgClearAdmin"></a>
### MsgClearAdmin
MsgClearAdmin removes any admin stored 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 |
<a name="cosmwasm.wasm.v1.MsgClearAdminResponse"></a>
### MsgClearAdminResponse
MsgClearAdminResponse returns empty data
<a name="cosmwasm.wasm.v1.MsgExecuteContract"></a>
### MsgExecuteContract
MsgExecuteContract submits the given message data to 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 |
| `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 |
<a name="cosmwasm.wasm.v1.MsgExecuteContractResponse"></a>
### MsgExecuteContractResponse
MsgExecuteContractResponse returns execution result data.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract |
<a name="cosmwasm.wasm.v1.MsgInstantiateContract"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgInstantiateContract2"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgInstantiateContract2Response"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgInstantiateContractResponse"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgMigrateContract"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgMigrateContractResponse"></a>
### 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) |
<a name="cosmwasm.wasm.v1.MsgStoreCode"></a>
### MsgStoreCode
MsgStoreCode submit Wasm code to the system
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | Sender is the that 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 |
<a name="cosmwasm.wasm.v1.MsgStoreCodeResponse"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgUpdateAdmin"></a>
### 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 |
<a name="cosmwasm.wasm.v1.MsgUpdateAdminResponse"></a>
### MsgUpdateAdminResponse
MsgUpdateAdminResponse returns empty data
<!-- end messages -->
<!-- end enums -->
<!-- end HasExtensions -->
<a name="cosmwasm.wasm.v1.Msg"></a>
### 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 | |
<!-- end services -->
## Scalar Value Types
| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |

View File

@@ -3,7 +3,6 @@ package cosmwasm.wasm.v1;
import "gogoproto/gogo.proto";
import "cosmwasm/wasm/v1/types.proto";
import "cosmwasm/wasm/v1/tx.proto";
option go_package = "github.com/CosmWasm/wasmd/x/wasm/types";
@@ -20,23 +19,6 @@ message GenesisState {
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "sequences,omitempty"
];
repeated GenMsgs gen_msgs = 5 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "gen_msgs,omitempty"
];
// 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.
message GenMsgs {
// sum is a single message
oneof sum {
MsgStoreCode store_code = 1;
MsgInstantiateContract instantiate_contract = 2;
MsgExecuteContract execute_contract = 3;
// MsgInstantiateContract2 intentionally not supported
// see https://github.com/CosmWasm/wasmd/issues/987
}
}
}
// Code struct encompasses CodeInfo and CodeBytes

View File

@@ -60,14 +60,15 @@ message InstantiateContractProposal {
];
}
// InstantiateContract2Proposal gov proposal content type to instantiate contract 2
// InstantiateContract2Proposal gov proposal content type to instantiate
// contract 2
message InstantiateContract2Proposal {
// 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;
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

View File

@@ -28,5 +28,3 @@ cd ..
# move proto files to the right places
cp -r github.com/CosmWasm/wasmd/* ./
rm -rf github.com
go mod tidy

View File

@@ -1,531 +0,0 @@
package cli
import (
"bufio"
"bytes"
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
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"
"github.com/spf13/cobra"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/CosmWasm/wasmd/x/wasm/ioutils"
"github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/CosmWasm/wasmd/x/wasm/types"
)
// GenesisReader reads genesis data. Extension point for custom genesis state readers.
type GenesisReader interface {
ReadWasmGenesis(cmd *cobra.Command) (*GenesisData, error)
}
// GenesisMutator extension point to modify the wasm module genesis state.
// This gives flexibility to customize the data structure in the genesis file a bit.
type GenesisMutator interface {
// AlterWasmModuleState loads the genesis from the default or set home dir,
// unmarshalls the wasm module section into the object representation
// calls the callback function to modify it
// and marshals the modified state back into the genesis file
AlterWasmModuleState(cmd *cobra.Command, callback func(state *types.GenesisState, appState map[string]json.RawMessage) error) error
}
// GenesisStoreCodeCmd cli command to add a `MsgStoreCode` to the wasm section of the genesis
// that is executed on block 0.
func GenesisStoreCodeCmd(defaultNodeHome string, genesisMutator GenesisMutator) *cobra.Command {
cmd := &cobra.Command{
Use: "store [wasm file] --run-as [owner_address_or_key_name]\",",
Short: "Upload a wasm binary",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
senderAddr, err := getActorAddress(cmd)
if err != nil {
return err
}
msg, err := parseStoreCodeArgs(args[0], senderAddr, cmd.Flags())
if err != nil {
return err
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return genesisMutator.AlterWasmModuleState(cmd, func(state *types.GenesisState, _ map[string]json.RawMessage) error {
state.GenMsgs = append(state.GenMsgs, types.GenesisState_GenMsgs{
Sum: &types.GenesisState_GenMsgs_StoreCode{StoreCode: &msg},
})
return nil
})
},
SilenceUsage: true,
}
cmd.Flags().String(flagRunAs, "", "The address that is stored as code creator")
cmd.Flags().String(flagInstantiateByEverybody, "", "Everybody can instantiate a contract from the code, optional")
cmd.Flags().String(flagInstantiateNobody, "", "Nobody except the governance process can instantiate a contract from the code, optional")
cmd.Flags().String(flagInstantiateByAddress, "", "Only this address can instantiate a contract instance from the code, optional")
cmd.Flags().StringSlice(flagInstantiateByAnyOfAddress, []string{}, "Any of the addresses can instantiate a contract from the code, optional")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GenesisInstantiateContractCmd cli command to add a `MsgInstantiateContract` to the wasm section of the genesis
// that is executed on block 0.
func GenesisInstantiateContractCmd(defaultNodeHome string, genesisMutator GenesisMutator) *cobra.Command {
cmd := &cobra.Command{
Use: "instantiate-contract [code_id_int64] [json_encoded_init_args] --label [text] --run-as [address] --admin [address,optional] --amount [coins,optional]",
Short: "Instantiate a wasm contract",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
senderAddr, err := getActorAddress(cmd)
if err != nil {
return err
}
msg, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, senderAddr, cmd.Flags())
if err != nil {
return err
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return genesisMutator.AlterWasmModuleState(cmd, func(state *types.GenesisState, appState map[string]json.RawMessage) error {
// simple sanity check that sender has some balance, although it may be consumed by appState previous message already
switch ok, err := hasAccountBalance(cmd, appState, senderAddr, msg.Funds); {
case err != nil:
return err
case !ok:
return errors.New("sender has not enough account balance")
}
// does code id exists?
codeInfos := GetAllCodes(state)
if err != nil {
return err
}
var codeInfo *CodeMeta
for i := range codeInfos {
if codeInfos[i].CodeID == msg.CodeID {
codeInfo = &codeInfos[i]
break
}
}
if codeInfo == nil {
return fmt.Errorf("unknown code id: %d", msg.CodeID)
}
// permissions correct?
if !codeInfo.Info.InstantiateConfig.Allowed(senderAddr) {
return fmt.Errorf("permissions were not granted for %s", senderAddr)
}
state.GenMsgs = append(state.GenMsgs, types.GenesisState_GenMsgs{
Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: msg},
})
return nil
})
},
SilenceUsage: true,
}
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
cmd.Flags().String(flagLabel, "", "A human-readable name for this contract in lists")
cmd.Flags().String(flagAdmin, "", "Address or key name of an admin")
cmd.Flags().Bool(flagNoAdmin, false, "You must set this explicitly if you don't want an admin")
cmd.Flags().String(flagRunAs, "", "The address that pays the init funds. It is the creator of the contract.")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GenesisExecuteContractCmd cli command to add a `MsgExecuteContract` to the wasm section of the genesis
// that is executed on block 0.
func GenesisExecuteContractCmd(defaultNodeHome string, genesisMutator GenesisMutator) *cobra.Command {
cmd := &cobra.Command{
Use: "execute [contract_addr_bech32] [json_encoded_send_args] --run-as [address] --amount [coins,optional]",
Short: "Execute a command on a wasm contract",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
senderAddr, err := getActorAddress(cmd)
if err != nil {
return err
}
msg, err := parseExecuteArgs(args[0], args[1], senderAddr, cmd.Flags())
if err != nil {
return err
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return genesisMutator.AlterWasmModuleState(cmd, func(state *types.GenesisState, appState map[string]json.RawMessage) error {
// simple sanity check that sender has some balance, although it may be consumed by appState previous message already
switch ok, err := hasAccountBalance(cmd, appState, senderAddr, msg.Funds); {
case err != nil:
return err
case !ok:
return errors.New("sender has not enough account balance")
}
// - does contract address exists?
if !hasContract(state, msg.Contract) {
return fmt.Errorf("unknown contract: %s", msg.Contract)
}
state.GenMsgs = append(state.GenMsgs, types.GenesisState_GenMsgs{
Sum: &types.GenesisState_GenMsgs_ExecuteContract{ExecuteContract: &msg},
})
return nil
})
},
SilenceUsage: true,
}
cmd.Flags().String(flagAmount, "", "Coins to send to the contract along with command")
cmd.Flags().String(flagRunAs, "", "The address that pays the funds.")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GenesisListCodesCmd cli command to list all codes stored in the genesis wasm.code section
// as well as from messages that are queued in the wasm.genMsgs section.
func GenesisListCodesCmd(defaultNodeHome string, genReader GenesisReader) *cobra.Command {
cmd := &cobra.Command{
Use: "list-codes ",
Short: "Lists all codes from genesis code dump and queued messages",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
g, err := genReader.ReadWasmGenesis(cmd)
if err != nil {
return err
}
all := GetAllCodes(g.WasmModuleState)
if err != nil {
return err
}
return printJSONOutput(cmd, all)
},
SilenceUsage: true,
}
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GenesisListContractsCmd cli command to list all contracts stored in the genesis wasm.contract section
// as well as from messages that are queued in the wasm.genMsgs section.
func GenesisListContractsCmd(defaultNodeHome string, genReader GenesisReader) *cobra.Command {
cmd := &cobra.Command{
Use: "list-contracts ",
Short: "Lists all contracts from genesis contract dump and queued messages",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
g, err := genReader.ReadWasmGenesis(cmd)
if err != nil {
return err
}
state := g.WasmModuleState
all := GetAllContracts(state)
return printJSONOutput(cmd, all)
},
SilenceUsage: true,
}
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// clientCtx marshaller works only with proto or bytes, so we marshal the output ourselves
func printJSONOutput(cmd *cobra.Command, obj interface{}) error {
clientCtx := client.GetClientContextFromCmd(cmd)
bz, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return err
}
return clientCtx.PrintString(string(bz))
}
type CodeMeta struct {
CodeID uint64 `json:"code_id"`
Info types.CodeInfo `json:"info"`
}
func GetAllCodes(state *types.GenesisState) []CodeMeta {
all := make([]CodeMeta, len(state.Codes))
for i, c := range state.Codes {
all[i] = CodeMeta{
CodeID: c.CodeID,
Info: c.CodeInfo,
}
}
// add inflight
seq := codeSeqValue(state)
for _, m := range state.GenMsgs {
if msg := m.GetStoreCode(); msg != nil {
var accessConfig types.AccessConfig
if msg.InstantiatePermission != nil {
accessConfig = *msg.InstantiatePermission
} else {
// default
creator := sdk.MustAccAddressFromBech32(msg.Sender)
accessConfig = state.Params.InstantiateDefaultPermission.With(creator)
}
bz := msg.WASMByteCode
if ioutils.IsGzip(msg.WASMByteCode) {
var err error
bz, err = ioutils.Uncompress(msg.WASMByteCode, uint64(types.MaxWasmSize))
if err != nil {
panic(fmt.Sprintf("failed to unzip wasm binary: %s", err))
}
}
hash := sha256.Sum256(bz)
all = append(all, CodeMeta{
CodeID: seq,
Info: types.CodeInfo{
CodeHash: hash[:],
Creator: msg.Sender,
InstantiateConfig: accessConfig,
},
})
seq++
}
}
return all
}
type ContractMeta struct {
ContractAddress string `json:"contract_address"`
Info types.ContractInfo `json:"info"`
}
func GetAllContracts(state *types.GenesisState) []ContractMeta {
all := make([]ContractMeta, len(state.Contracts))
for i, c := range state.Contracts {
all[i] = ContractMeta{
ContractAddress: c.ContractAddress,
Info: c.ContractInfo,
}
}
// add inflight
seq := contractSeqValue(state)
for _, m := range state.GenMsgs {
if msg := m.GetInstantiateContract(); msg != nil {
all = append(all, ContractMeta{
ContractAddress: keeper.BuildContractAddressClassic(msg.CodeID, seq).String(),
Info: types.ContractInfo{
CodeID: msg.CodeID,
Creator: msg.Sender,
Admin: msg.Admin,
Label: msg.Label,
},
})
seq++
}
}
return all
}
func hasAccountBalance(cmd *cobra.Command, appState map[string]json.RawMessage, sender sdk.AccAddress, coins sdk.Coins) (bool, error) {
// no coins needed, no account needed
if coins.IsZero() {
return true, nil
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return false, err
}
cdc := clientCtx.Codec
var genBalIterator banktypes.GenesisBalancesIterator
err = genutil.ValidateAccountInGenesis(appState, genBalIterator, sender, coins, cdc)
if err != nil {
return false, err
}
return true, nil
}
func hasContract(state *types.GenesisState, contractAddr string) bool {
for _, c := range state.Contracts {
if c.ContractAddress == contractAddr {
return true
}
}
seq := contractSeqValue(state)
for _, m := range state.GenMsgs {
if msg := m.GetInstantiateContract(); msg != nil {
if keeper.BuildContractAddressClassic(msg.CodeID, seq).String() == contractAddr {
return true
}
seq++
}
}
return false
}
// GenesisData contains raw and unmarshalled data from the genesis file
type GenesisData struct {
GenesisFile string
GenDoc *tmtypes.GenesisDoc
AppState map[string]json.RawMessage
WasmModuleState *types.GenesisState
}
func NewGenesisData(genesisFile string, genDoc *tmtypes.GenesisDoc, appState map[string]json.RawMessage, wasmModuleState *types.GenesisState) *GenesisData {
return &GenesisData{GenesisFile: genesisFile, GenDoc: genDoc, AppState: appState, WasmModuleState: wasmModuleState}
}
type DefaultGenesisReader struct{}
func (d DefaultGenesisReader) ReadWasmGenesis(cmd *cobra.Command) (*GenesisData, error) {
clientCtx := client.GetClientContextFromCmd(cmd)
serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config
config.SetRoot(clientCtx.HomeDir)
genFile := config.GenesisFile()
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis state: %w", err)
}
var wasmGenesisState types.GenesisState
if appState[types.ModuleName] != nil {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx.Codec.MustUnmarshalJSON(appState[types.ModuleName], &wasmGenesisState)
}
return NewGenesisData(
genFile,
genDoc,
appState,
&wasmGenesisState,
), nil
}
var (
_ GenesisReader = DefaultGenesisIO{}
_ GenesisMutator = DefaultGenesisIO{}
)
// DefaultGenesisIO implements both interfaces to read and modify the genesis state for this module.
// This implementation uses the default data structure that is used by the module.go genesis import/ export.
type DefaultGenesisIO struct {
DefaultGenesisReader
}
// NewDefaultGenesisIO constructor to create a new instance
func NewDefaultGenesisIO() *DefaultGenesisIO {
return &DefaultGenesisIO{DefaultGenesisReader: DefaultGenesisReader{}}
}
// AlterWasmModuleState loads the genesis from the default or set home dir,
// unmarshalls the wasm module section into the object representation
// calls the callback function to modify it
// and marshals the modified state back into the genesis file
func (x DefaultGenesisIO) AlterWasmModuleState(cmd *cobra.Command, callback func(state *types.GenesisState, appState map[string]json.RawMessage) error) error {
g, err := x.ReadWasmGenesis(cmd)
if err != nil {
return err
}
if err := callback(g.WasmModuleState, g.AppState); err != nil {
return err
}
// and store update
if err := g.WasmModuleState.ValidateBasic(); err != nil {
return err
}
clientCtx := client.GetClientContextFromCmd(cmd)
wasmGenStateBz, err := clientCtx.Codec.MarshalJSON(g.WasmModuleState)
if err != nil {
return sdkerrors.Wrap(err, "marshal wasm genesis state")
}
g.AppState[types.ModuleName] = wasmGenStateBz
appStateJSON, err := json.Marshal(g.AppState)
if err != nil {
return sdkerrors.Wrap(err, "marshal application genesis state")
}
g.GenDoc.AppState = appStateJSON
return genutil.ExportGenesisFile(g.GenDoc, g.GenesisFile)
}
// contractSeqValue reads the contract sequence from the genesis or
// returns default start value used in the keeper
func contractSeqValue(state *types.GenesisState) uint64 {
var seq uint64 = 1
for _, s := range state.Sequences {
if bytes.Equal(s.IDKey, types.KeyLastInstanceID) {
seq = s.Value
break
}
}
return seq
}
// codeSeqValue reads the code sequence from the genesis or
// returns default start value used in the keeper
func codeSeqValue(state *types.GenesisState) uint64 {
var seq uint64 = 1
for _, s := range state.Sequences {
if bytes.Equal(s.IDKey, types.KeyLastCodeID) {
seq = s.Value
break
}
}
return seq
}
// getActorAddress returns the account address for the `--run-as` flag.
// The flag value can either be an address already or a key name where the
// address is read from the keyring instead.
func getActorAddress(cmd *cobra.Command) (sdk.AccAddress, error) {
actorArg, err := cmd.Flags().GetString(flagRunAs)
if err != nil {
return nil, fmt.Errorf("run-as: %s", err.Error())
}
if len(actorArg) == 0 {
return nil, errors.New("run-as address is required")
}
actorAddr, err := sdk.AccAddressFromBech32(actorArg)
if err == nil {
return actorAddr, nil
}
inBuf := bufio.NewReader(cmd.InOrStdin())
keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend)
if err != nil {
return nil, err
}
homeDir := client.GetClientContextFromCmd(cmd).HomeDir
// attempt to lookup address from Keybase if no address was provided
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, homeDir, inBuf)
if err != nil {
return nil, err
}
info, err := kb.Key(actorArg)
if err != nil {
return nil, fmt.Errorf("failed to get address from Keybase: %w", err)
}
return info.GetAddress(), nil
}

View File

@@ -1,748 +0,0 @@
package cli
import (
"context"
"encoding/json"
"os"
"path"
"testing"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/CosmWasm/wasmd/x/wasm/types"
)
var wasmIdent = []byte("\x00\x61\x73\x6D")
var myWellFundedAccount = keeper.RandomBech32AccountAddress(nil)
const defaultTestKeyName = "my-key-name"
func TestGenesisStoreCodeCmd(t *testing.T) {
minimalWasmGenesis := types.GenesisState{
Params: types.DefaultParams(),
}
anyValidWasmFile, err := os.CreateTemp(t.TempDir(), "wasm")
require.NoError(t, err)
anyValidWasmFile.Write(wasmIdent)
require.NoError(t, anyValidWasmFile.Close())
specs := map[string]struct {
srcGenesis types.GenesisState
mutator func(cmd *cobra.Command)
expError bool
}{
"all good with actor address": {
srcGenesis: minimalWasmGenesis,
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{anyValidWasmFile.Name()})
flagSet := cmd.Flags()
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
},
},
"all good with key name": {
srcGenesis: minimalWasmGenesis,
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{anyValidWasmFile.Name()})
flagSet := cmd.Flags()
flagSet.Set("run-as", defaultTestKeyName)
},
},
"with unknown actor key name should fail": {
srcGenesis: minimalWasmGenesis,
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{anyValidWasmFile.Name()})
flagSet := cmd.Flags()
flagSet.Set("run-as", "unknown key")
},
expError: true,
},
"without actor should fail": {
srcGenesis: minimalWasmGenesis,
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{anyValidWasmFile.Name()})
},
expError: true,
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
homeDir := setupGenesis(t, spec.srcGenesis)
// when
cmd := GenesisStoreCodeCmd(homeDir, NewDefaultGenesisIO())
spec.mutator(cmd)
err := executeCmdWithContext(t, homeDir, cmd)
if spec.expError {
require.Error(t, err)
return
}
require.NoError(t, err)
// then
moduleState := loadModuleState(t, homeDir)
assert.Len(t, moduleState.GenMsgs, 1)
})
}
}
func TestInstantiateContractCmd(t *testing.T) {
minimalWasmGenesis := types.GenesisState{
Params: types.DefaultParams(),
}
anyValidWasmFile, err := os.CreateTemp(t.TempDir(), "wasm")
require.NoError(t, err)
anyValidWasmFile.Write(wasmIdent)
require.NoError(t, anyValidWasmFile.Close())
specs := map[string]struct {
srcGenesis types.GenesisState
mutator func(cmd *cobra.Command)
expMsgCount int
expError bool
}{
"all good with code id in genesis codes": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
},
expMsgCount: 1,
},
"all good with code id from genesis store messages without initial sequence": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_StoreCode{StoreCode: types.MsgStoreCodeFixture()}},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("admin", myWellFundedAccount)
},
expMsgCount: 2,
},
"all good with code id from genesis store messages without initial sequence and key name admin": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_StoreCode{StoreCode: types.MsgStoreCodeFixture()}},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", defaultTestKeyName)
flagSet.Set("admin", defaultTestKeyName)
},
expMsgCount: 2,
},
"all good with code id from genesis store messages and sequence set": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_StoreCode{StoreCode: types.MsgStoreCodeFixture()}},
},
Sequences: []types.Sequence{
{IDKey: types.KeyLastCodeID, Value: 100},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"100", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
},
expMsgCount: 2,
},
"fails with codeID not existing in codes": {
srcGenesis: minimalWasmGenesis,
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"2", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
},
expError: true,
},
"fails when instantiation permissions not granted": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_StoreCode{StoreCode: types.MsgStoreCodeFixture(func(code *types.MsgStoreCode) {
code.InstantiatePermission = &types.AllowNobody
})}},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
},
expError: true,
},
"fails if no explicit --no-admin passed": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
},
expError: true,
},
"fails if both --admin and --no-admin passed": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
flagSet.Set("admin", myWellFundedAccount)
},
expError: true,
},
"succeeds with unknown account when no funds": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
flagSet.Set("no-admin", "true")
},
expMsgCount: 1,
},
"succeeds with funds from well funded account": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("amount", "100stake")
flagSet.Set("no-admin", "true")
},
expMsgCount: 1,
},
"fails without enough sender balance": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
flagSet.Set("amount", "10stake")
flagSet.Set("no-admin", "true")
},
expError: true,
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
homeDir := setupGenesis(t, spec.srcGenesis)
// when
cmd := GenesisInstantiateContractCmd(homeDir, NewDefaultGenesisIO())
spec.mutator(cmd)
err := executeCmdWithContext(t, homeDir, cmd)
if spec.expError {
require.Error(t, err)
return
}
require.NoError(t, err)
// then
moduleState := loadModuleState(t, homeDir)
assert.Len(t, moduleState.GenMsgs, spec.expMsgCount)
})
}
}
func TestExecuteContractCmd(t *testing.T) {
const firstContractAddress = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
minimalWasmGenesis := types.GenesisState{
Params: types.DefaultParams(),
}
anyValidWasmFile, err := os.CreateTemp(t.TempDir(), "wasm")
require.NoError(t, err)
anyValidWasmFile.Write(wasmIdent)
require.NoError(t, anyValidWasmFile.Close())
specs := map[string]struct {
srcGenesis types.GenesisState
mutator func(cmd *cobra.Command)
expMsgCount int
expError bool
}{
"all good with contract in genesis contracts": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfoFixture(),
CodeBytes: wasmIdent,
},
},
Contracts: []types.Contract{
{
ContractAddress: firstContractAddress,
ContractInfo: types.ContractInfoFixture(),
ContractState: []types.Model{},
ContractCodeHistory: []types.ContractCodeHistoryEntry{
types.ContractCodeHistoryEntryFixture(),
},
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{firstContractAddress, `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", myWellFundedAccount)
},
expMsgCount: 1,
},
"all good with contract from genesis store messages without initial sequence": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfoFixture(),
CodeBytes: wasmIdent,
},
},
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: types.MsgInstantiateContractFixture()}},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{firstContractAddress, `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", myWellFundedAccount)
},
expMsgCount: 2,
},
"all good with contract from genesis store messages and contract sequence set": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfoFixture(),
CodeBytes: wasmIdent,
},
},
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: types.MsgInstantiateContractFixture()}},
},
Sequences: []types.Sequence{
{IDKey: types.KeyLastInstanceID, Value: 100},
},
},
mutator: func(cmd *cobra.Command) {
// See TestBuildContractAddress in keeper_test.go
cmd.SetArgs([]string{"cosmos1mujpjkwhut9yjw4xueyugc02evfv46y0dtmnz4lh8xxkkdapym9stu5qm8", `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", myWellFundedAccount)
},
expMsgCount: 2,
},
"fails with unknown contract address": {
srcGenesis: minimalWasmGenesis,
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{keeper.RandomBech32AccountAddress(t), `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", myWellFundedAccount)
},
expError: true,
},
"succeeds with unknown account when no funds": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfoFixture(),
CodeBytes: wasmIdent,
},
},
Contracts: []types.Contract{
{
ContractAddress: firstContractAddress,
ContractInfo: types.ContractInfoFixture(),
ContractState: []types.Model{},
ContractCodeHistory: []types.ContractCodeHistoryEntry{
types.ContractCodeHistoryEntryFixture(),
},
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{firstContractAddress, `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
},
expMsgCount: 1,
},
"succeeds with funds from well funded account": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfoFixture(),
CodeBytes: wasmIdent,
},
},
Contracts: []types.Contract{
{
ContractAddress: firstContractAddress,
ContractInfo: types.ContractInfoFixture(),
ContractState: []types.Model{},
ContractCodeHistory: []types.ContractCodeHistoryEntry{
types.ContractCodeHistoryEntryFixture(),
},
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{firstContractAddress, `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("amount", "100stake")
},
expMsgCount: 1,
},
"fails without enough sender balance": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfoFixture(),
CodeBytes: wasmIdent,
},
},
Contracts: []types.Contract{
{
ContractAddress: firstContractAddress,
ContractInfo: types.ContractInfoFixture(),
ContractState: []types.Model{},
ContractCodeHistory: []types.ContractCodeHistoryEntry{
types.ContractCodeHistoryEntryFixture(),
},
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{firstContractAddress, `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
flagSet.Set("amount", "10stake")
},
expError: true,
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
homeDir := setupGenesis(t, spec.srcGenesis)
cmd := GenesisExecuteContractCmd(homeDir, NewDefaultGenesisIO())
spec.mutator(cmd)
// when
err := executeCmdWithContext(t, homeDir, cmd)
if spec.expError {
require.Error(t, err)
return
}
require.NoError(t, err)
// then
moduleState := loadModuleState(t, homeDir)
assert.Len(t, moduleState.GenMsgs, spec.expMsgCount)
})
}
}
func TestGetAllContracts(t *testing.T) {
specs := map[string]struct {
src types.GenesisState
exp []ContractMeta
}{
"read from contracts state": {
src: types.GenesisState{
Contracts: []types.Contract{
{
ContractAddress: "first-contract",
ContractInfo: types.ContractInfo{Label: "first"},
},
{
ContractAddress: "second-contract",
ContractInfo: types.ContractInfo{Label: "second"},
},
},
},
exp: []ContractMeta{
{
ContractAddress: "first-contract",
Info: types.ContractInfo{Label: "first"},
},
{
ContractAddress: "second-contract",
Info: types.ContractInfo{Label: "second"},
},
},
},
"read from message state": {
src: types.GenesisState{
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: &types.MsgInstantiateContract{Label: "first"}}},
{Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: &types.MsgInstantiateContract{Label: "second"}}},
},
},
exp: []ContractMeta{
{
ContractAddress: keeper.BuildContractAddressClassic(0, 1).String(),
Info: types.ContractInfo{Label: "first"},
},
{
ContractAddress: keeper.BuildContractAddressClassic(0, 2).String(),
Info: types.ContractInfo{Label: "second"},
},
},
},
"read from message state with contract sequence": {
src: types.GenesisState{
Sequences: []types.Sequence{
{IDKey: types.KeyLastInstanceID, Value: 100},
},
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: &types.MsgInstantiateContract{Label: "hundred"}}},
},
},
exp: []ContractMeta{
{
ContractAddress: keeper.BuildContractAddressClassic(0, 100).String(),
Info: types.ContractInfo{Label: "hundred"},
},
},
},
"read from contract and message state with contract sequence": {
src: types.GenesisState{
Contracts: []types.Contract{
{
ContractAddress: "first-contract",
ContractInfo: types.ContractInfo{Label: "first"},
},
},
Sequences: []types.Sequence{
{IDKey: types.KeyLastInstanceID, Value: 100},
},
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_InstantiateContract{InstantiateContract: &types.MsgInstantiateContract{Label: "hundred"}}},
},
},
exp: []ContractMeta{
{
ContractAddress: "first-contract",
Info: types.ContractInfo{Label: "first"},
},
{
ContractAddress: keeper.BuildContractAddressClassic(0, 100).String(),
Info: types.ContractInfo{Label: "hundred"},
},
},
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
got := GetAllContracts(&spec.src)
assert.Equal(t, spec.exp, got)
})
}
}
func setupGenesis(t *testing.T, wasmGenesis types.GenesisState) string {
appCodec := keeper.MakeEncodingConfig(t).Marshaler
homeDir := t.TempDir()
require.NoError(t, os.Mkdir(path.Join(homeDir, "config"), 0o700))
genFilename := path.Join(homeDir, "config", "genesis.json")
appState := make(map[string]json.RawMessage)
appState[types.ModuleName] = appCodec.MustMarshalJSON(&wasmGenesis)
bankGenesis := banktypes.DefaultGenesisState()
bankGenesis.Balances = append(bankGenesis.Balances, banktypes.Balance{
// add a balance for the default sender account
Address: myWellFundedAccount,
Coins: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000000000))),
})
appState[banktypes.ModuleName] = appCodec.MustMarshalJSON(bankGenesis)
appState[stakingtypes.ModuleName] = appCodec.MustMarshalJSON(stakingtypes.DefaultGenesisState())
appStateBz, err := json.Marshal(appState)
require.NoError(t, err)
genDoc := tmtypes.GenesisDoc{
ChainID: "testing",
AppState: appStateBz,
}
err = genutil.ExportGenesisFile(&genDoc, genFilename)
require.NoError(t, err)
return homeDir
}
func executeCmdWithContext(t *testing.T, homeDir string, cmd *cobra.Command) error {
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultTendermintConfig(homeDir)
require.NoError(t, err)
appCodec := keeper.MakeEncodingConfig(t).Marshaler
serverCtx := server.NewContext(viper.New(), cfg, logger)
clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(homeDir)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)
flagSet := cmd.Flags()
flagSet.Set("home", homeDir)
flagSet.Set(flags.FlagKeyringBackend, keyring.BackendTest)
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, homeDir, mockIn)
require.NoError(t, err)
_, err = kb.NewAccount(defaultTestKeyName, testdata.TestMnemonic, "", sdk.FullFundraiserPath, hd.Secp256k1)
require.NoError(t, err)
return cmd.ExecuteContext(ctx)
}
func loadModuleState(t *testing.T, homeDir string) types.GenesisState {
genFilename := path.Join(homeDir, "config", "genesis.json")
appState, _, err := genutiltypes.GenesisStateFromGenFile(genFilename)
require.NoError(t, err)
require.Contains(t, appState, types.ModuleName)
appCodec := keeper.MakeEncodingConfig(t).Marshaler
var moduleState types.GenesisState
require.NoError(t, appCodec.UnmarshalJSON(appState[types.ModuleName], &moduleState))
return moduleState
}

View File

@@ -212,7 +212,7 @@ func ProposalInstantiateContract2Cmd() *cobra.Command {
return err
}
src, err := parseInstantiateArgs(args[0], args[1], clientCtx.FromAddress, cmd.Flags())
src, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, clientCtx.FromAddress, cmd.Flags())
if err != nil {
return err
}

View File

@@ -80,7 +80,7 @@ func TestInitGenesis(t *testing.T) {
q2 := newData.module.LegacyQuerierHandler(nil)
// initialize new app with genstate
InitGenesis(newData.ctx, &newData.keeper, *genState, newData.stakingKeeper, newData.module.Route().Handler())
InitGenesis(newData.ctx, &newData.keeper, *genState)
// run same checks again on newdata, to make sure it was reinitialized correctly
assertCodeList(t, q2, newData.ctx, 1)

View File

@@ -16,7 +16,7 @@ type ValidatorSetSource interface {
// InitGenesis sets supply information for genesis.
//
// CONTRACT: all types of accounts must have been already initialized/created
func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, stakingKeeper ValidatorSetSource, msgHandler sdk.Handler) ([]abci.ValidatorUpdate, error) {
func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState) ([]abci.ValidatorUpdate, error) {
contractKeeper := NewGovPermissionKeeper(keeper)
keeper.SetParams(ctx, data.Params)
var maxCodeID uint64
@@ -64,21 +64,7 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, staki
if seqVal <= uint64(maxContractID) {
return nil, sdkerrors.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastInstanceID), seqVal, maxContractID)
}
if len(data.GenMsgs) == 0 {
return nil, nil
}
for _, genTx := range data.GenMsgs {
msg := genTx.AsMsg()
if msg == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "unknown message")
}
_, err := msgHandler(ctx, msg)
if err != nil {
return nil, sdkerrors.Wrap(err, "genesis")
}
}
return stakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
return nil, nil
}
// ExportGenesis returns a GenesisState for a given context and keeper.

View File

@@ -1,10 +1,8 @@
package keeper
import (
"bytes"
"crypto/sha256"
"encoding/base64"
"errors"
"fmt"
"math/rand"
"os"
@@ -23,9 +21,7 @@ import (
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proto/tendermint/crypto"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"
@@ -121,7 +117,7 @@ func TestGenesisExportImport(t *testing.T) {
var importState wasmTypes.GenesisState
err = dstKeeper.cdc.UnmarshalJSON(exportedGenesis, &importState)
require.NoError(t, err)
InitGenesis(dstCtx, dstKeeper, importState, &StakingKeeperMock{}, TestHandler(contractKeeper))
InitGenesis(dstCtx, dstKeeper, importState)
// compare whole DB
for j := range srcStoreKeys {
@@ -149,10 +145,8 @@ func TestGenesisInit(t *testing.T) {
myCodeInfo := wasmTypes.CodeInfoFixture(wasmTypes.WithSHA256CodeHash(wasmCode))
specs := map[string]struct {
src types.GenesisState
stakingMock StakingKeeperMock
msgHandlerMock MockMsgHandler
expSuccess bool
src types.GenesisState
expSuccess bool
}{
"happy path: code info correct": {
src: types.GenesisState{
@@ -457,53 +451,19 @@ func TestGenesisInit(t *testing.T) {
Params: types.DefaultParams(),
},
},
"validator set update called for any genesis messages": {
src: wasmTypes.GenesisState{
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_StoreCode{
StoreCode: types.MsgStoreCodeFixture(),
}},
},
Params: types.DefaultParams(),
},
stakingMock: StakingKeeperMock{expCalls: 1, validatorUpdate: []abci.ValidatorUpdate{
{
PubKey: crypto.PublicKey{Sum: &crypto.PublicKey_Ed25519{
Ed25519: []byte("a valid key"),
}},
Power: 100,
},
}},
msgHandlerMock: MockMsgHandler{expCalls: 1, expMsg: types.MsgStoreCodeFixture()},
expSuccess: true,
},
"validator set update not called on genesis msg handler errors": {
src: wasmTypes.GenesisState{
GenMsgs: []types.GenesisState_GenMsgs{
{Sum: &types.GenesisState_GenMsgs_StoreCode{
StoreCode: types.MsgStoreCodeFixture(),
}},
},
Params: types.DefaultParams(),
},
msgHandlerMock: MockMsgHandler{expCalls: 1, err: errors.New("test error response")},
stakingMock: StakingKeeperMock{expCalls: 0},
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
keeper, ctx, _ := setupKeeper(t)
require.NoError(t, types.ValidateGenesis(spec.src))
gotValidatorSet, gotErr := InitGenesis(ctx, keeper, spec.src, &spec.stakingMock, spec.msgHandlerMock.Handle)
_, gotErr := InitGenesis(ctx, keeper, spec.src)
if !spec.expSuccess {
require.Error(t, gotErr)
return
}
require.NoError(t, gotErr)
spec.msgHandlerMock.verifyCalls(t)
spec.stakingMock.verifyCalls(t)
assert.Equal(t, spec.stakingMock.validatorUpdate, gotValidatorSet)
for _, c := range spec.src.Codes {
assert.Equal(t, c.Pinned, keeper.IsPinnedCode(ctx, c.CodeID))
}
@@ -575,7 +535,6 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) {
]
}`
keeper, ctx, _ := setupKeeper(t)
contractKeeper := NewGovPermissionKeeper(keeper)
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
@@ -592,7 +551,7 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) {
ctx = ctx.WithBlockHeight(0).WithGasMeter(sdk.NewInfiniteGasMeter())
// when
_, err = InitGenesis(ctx, keeper, importState, &StakingKeeperMock{}, TestHandler(contractKeeper))
_, err = InitGenesis(ctx, keeper, importState)
require.NoError(t, err)
// verify wasm code
@@ -655,77 +614,6 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) {
assert.Equal(t, uint64(3), keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID))
}
func TestSupportedGenMsgTypes(t *testing.T) {
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
var (
myAddress sdk.AccAddress = bytes.Repeat([]byte{1}, types.ContractAddrLen)
verifierAddress sdk.AccAddress = bytes.Repeat([]byte{2}, types.ContractAddrLen)
beneficiaryAddress sdk.AccAddress = bytes.Repeat([]byte{3}, types.ContractAddrLen)
)
const denom = "stake"
importState := types.GenesisState{
Params: types.DefaultParams(),
GenMsgs: []types.GenesisState_GenMsgs{
{
Sum: &types.GenesisState_GenMsgs_StoreCode{
StoreCode: &types.MsgStoreCode{
Sender: myAddress.String(),
WASMByteCode: wasmCode,
},
},
},
{
Sum: &types.GenesisState_GenMsgs_InstantiateContract{
InstantiateContract: &types.MsgInstantiateContract{
Sender: myAddress.String(),
CodeID: 1,
Label: "testing",
Msg: HackatomExampleInitMsg{
Verifier: verifierAddress,
Beneficiary: beneficiaryAddress,
}.GetBytes(t),
Funds: sdk.NewCoins(sdk.NewCoin(denom, sdk.NewInt(10))),
},
},
},
{
Sum: &types.GenesisState_GenMsgs_ExecuteContract{
ExecuteContract: &types.MsgExecuteContract{
Sender: verifierAddress.String(),
Contract: BuildContractAddressClassic(1, 1).String(),
Msg: []byte(`{"release":{}}`),
},
},
},
},
}
require.NoError(t, importState.ValidateBasic())
ctx, keepers := CreateDefaultTestInput(t)
keeper := keepers.WasmKeeper
ctx = ctx.WithBlockHeight(0).WithGasMeter(sdk.NewInfiniteGasMeter())
keepers.Faucet.Fund(ctx, myAddress, sdk.NewCoin(denom, sdk.NewInt(100)))
// when
_, err = InitGenesis(ctx, keeper, importState, &StakingKeeperMock{}, TestHandler(keepers.ContractKeeper))
require.NoError(t, err)
// verify code stored
gotWasmCode, err := keeper.GetByteCode(ctx, 1)
require.NoError(t, err)
assert.Equal(t, wasmCode, gotWasmCode)
codeInfo := keeper.GetCodeInfo(ctx, 1)
require.NotNil(t, codeInfo)
// verify contract instantiated
cInfo := keeper.GetContractInfo(ctx, BuildContractAddressClassic(1, 1))
require.NotNil(t, cInfo)
// verify contract executed
gotBalance := keepers.BankKeeper.GetBalance(ctx, beneficiaryAddress, denom)
assert.Equal(t, sdk.NewCoin(denom, sdk.NewInt(10)), gotBalance)
}
func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []sdk.StoreKey) {
t.Helper()
tempDir, err := os.MkdirTemp("", "wasm")
@@ -781,39 +669,3 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []sdk.StoreKey) {
)
return &srcKeeper, ctx, []sdk.StoreKey{keyWasm, keyParams}
}
type StakingKeeperMock struct {
err error
validatorUpdate []abci.ValidatorUpdate
expCalls int
gotCalls int
}
func (s *StakingKeeperMock) ApplyAndReturnValidatorSetUpdates(_ sdk.Context) ([]abci.ValidatorUpdate, error) {
s.gotCalls++
return s.validatorUpdate, s.err
}
func (s *StakingKeeperMock) verifyCalls(t *testing.T) {
assert.Equal(t, s.expCalls, s.gotCalls, "number calls")
}
type MockMsgHandler struct {
result *sdk.Result
err error
expCalls int
gotCalls int
expMsg sdk.Msg
gotMsg sdk.Msg
}
func (m *MockMsgHandler) Handle(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
m.gotCalls++
m.gotMsg = msg
return m.result, m.err
}
func (m *MockMsgHandler) verifyCalls(t *testing.T) {
assert.Equal(t, m.expMsg, m.gotMsg, "message param")
assert.Equal(t, m.expCalls, m.gotCalls, "number calls")
}

View File

@@ -168,7 +168,7 @@ func (AppModule) QuerierRoute() string {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
validators, err := InitGenesis(ctx, am.keeper, genesisState, am.validatorSetSource, am.Route().Handler())
validators, err := InitGenesis(ctx, am.keeper, genesisState)
if err != nil {
panic(err)
}

View File

@@ -16,7 +16,6 @@ func RandomizedGenState(simstate *module.SimulationState) {
Sequences: []types.Sequence{
{IDKey: types.KeyLastCodeID, Value: simstate.Rand.Uint64()},
},
GenMsgs: nil,
}
_, err := simstate.Cdc.MarshalJSON(&wasmGenesis)

View File

@@ -32,11 +32,7 @@ func (s GenesisState) ValidateBasic() error {
return sdkerrors.Wrapf(err, "sequence: %d", i)
}
}
for i := range s.GenMsgs {
if err := s.GenMsgs[i].ValidateBasic(); err != nil {
return sdkerrors.Wrapf(err, "gen message: %d", i)
}
}
return nil
}
@@ -80,28 +76,6 @@ func (c Contract) ValidateBasic() error {
return nil
}
// AsMsg returns the underlying cosmos-sdk message instance. Null when can not be mapped to a known type.
func (m GenesisState_GenMsgs) AsMsg() sdk.Msg {
if msg := m.GetStoreCode(); msg != nil {
return msg
}
if msg := m.GetInstantiateContract(); msg != nil {
return msg
}
if msg := m.GetExecuteContract(); msg != nil {
return msg
}
return nil
}
func (m GenesisState_GenMsgs) ValidateBasic() error {
msg := m.AsMsg()
if msg == nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "unknown message")
}
return msg.ValidateBasic()
}
// ValidateGenesis performs basic validation of supply genesis data returning an
// error for any failed validation criteria.
func ValidateGenesis(data GenesisState) error {

View File

@@ -28,11 +28,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// GenesisState - genesis state of x/wasm
type GenesisState struct {
Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"`
Codes []Code `protobuf:"bytes,2,rep,name=codes,proto3" json:"codes,omitempty"`
Contracts []Contract `protobuf:"bytes,3,rep,name=contracts,proto3" json:"contracts,omitempty"`
Sequences []Sequence `protobuf:"bytes,4,rep,name=sequences,proto3" json:"sequences,omitempty"`
GenMsgs []GenesisState_GenMsgs `protobuf:"bytes,5,rep,name=gen_msgs,json=genMsgs,proto3" json:"gen_msgs,omitempty"`
Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"`
Codes []Code `protobuf:"bytes,2,rep,name=codes,proto3" json:"codes,omitempty"`
Contracts []Contract `protobuf:"bytes,3,rep,name=contracts,proto3" json:"contracts,omitempty"`
Sequences []Sequence `protobuf:"bytes,4,rep,name=sequences,proto3" json:"sequences,omitempty"`
}
func (m *GenesisState) Reset() { *m = GenesisState{} }
@@ -101,120 +100,6 @@ func (m *GenesisState) GetSequences() []Sequence {
return nil
}
func (m *GenesisState) GetGenMsgs() []GenesisState_GenMsgs {
if m != nil {
return m.GenMsgs
}
return nil
}
// 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.
type GenesisState_GenMsgs struct {
// sum is a single message
//
// Types that are valid to be assigned to Sum:
// *GenesisState_GenMsgs_StoreCode
// *GenesisState_GenMsgs_InstantiateContract
// *GenesisState_GenMsgs_ExecuteContract
Sum isGenesisState_GenMsgs_Sum `protobuf_oneof:"sum"`
}
func (m *GenesisState_GenMsgs) Reset() { *m = GenesisState_GenMsgs{} }
func (m *GenesisState_GenMsgs) String() string { return proto.CompactTextString(m) }
func (*GenesisState_GenMsgs) ProtoMessage() {}
func (*GenesisState_GenMsgs) Descriptor() ([]byte, []int) {
return fileDescriptor_2ab3f539b23472a6, []int{0, 0}
}
func (m *GenesisState_GenMsgs) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *GenesisState_GenMsgs) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_GenesisState_GenMsgs.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 *GenesisState_GenMsgs) XXX_Merge(src proto.Message) {
xxx_messageInfo_GenesisState_GenMsgs.Merge(m, src)
}
func (m *GenesisState_GenMsgs) XXX_Size() int {
return m.Size()
}
func (m *GenesisState_GenMsgs) XXX_DiscardUnknown() {
xxx_messageInfo_GenesisState_GenMsgs.DiscardUnknown(m)
}
var xxx_messageInfo_GenesisState_GenMsgs proto.InternalMessageInfo
type isGenesisState_GenMsgs_Sum interface {
isGenesisState_GenMsgs_Sum()
MarshalTo([]byte) (int, error)
Size() int
}
type GenesisState_GenMsgs_StoreCode struct {
StoreCode *MsgStoreCode `protobuf:"bytes,1,opt,name=store_code,json=storeCode,proto3,oneof" json:"store_code,omitempty"`
}
type GenesisState_GenMsgs_InstantiateContract struct {
InstantiateContract *MsgInstantiateContract `protobuf:"bytes,2,opt,name=instantiate_contract,json=instantiateContract,proto3,oneof" json:"instantiate_contract,omitempty"`
}
type GenesisState_GenMsgs_ExecuteContract struct {
ExecuteContract *MsgExecuteContract `protobuf:"bytes,3,opt,name=execute_contract,json=executeContract,proto3,oneof" json:"execute_contract,omitempty"`
}
func (*GenesisState_GenMsgs_StoreCode) isGenesisState_GenMsgs_Sum() {}
func (*GenesisState_GenMsgs_InstantiateContract) isGenesisState_GenMsgs_Sum() {}
func (*GenesisState_GenMsgs_ExecuteContract) isGenesisState_GenMsgs_Sum() {}
func (m *GenesisState_GenMsgs) GetSum() isGenesisState_GenMsgs_Sum {
if m != nil {
return m.Sum
}
return nil
}
func (m *GenesisState_GenMsgs) GetStoreCode() *MsgStoreCode {
if x, ok := m.GetSum().(*GenesisState_GenMsgs_StoreCode); ok {
return x.StoreCode
}
return nil
}
func (m *GenesisState_GenMsgs) GetInstantiateContract() *MsgInstantiateContract {
if x, ok := m.GetSum().(*GenesisState_GenMsgs_InstantiateContract); ok {
return x.InstantiateContract
}
return nil
}
func (m *GenesisState_GenMsgs) GetExecuteContract() *MsgExecuteContract {
if x, ok := m.GetSum().(*GenesisState_GenMsgs_ExecuteContract); ok {
return x.ExecuteContract
}
return nil
}
// XXX_OneofWrappers is for the internal use of the proto package.
func (*GenesisState_GenMsgs) XXX_OneofWrappers() []interface{} {
return []interface{}{
(*GenesisState_GenMsgs_StoreCode)(nil),
(*GenesisState_GenMsgs_InstantiateContract)(nil),
(*GenesisState_GenMsgs_ExecuteContract)(nil),
}
}
// Code struct encompasses CodeInfo and CodeBytes
type Code struct {
CodeID uint64 `protobuf:"varint,1,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"`
@@ -424,7 +309,6 @@ func (m *Sequence) GetValue() uint64 {
func init() {
proto.RegisterType((*GenesisState)(nil), "cosmwasm.wasm.v1.GenesisState")
proto.RegisterType((*GenesisState_GenMsgs)(nil), "cosmwasm.wasm.v1.GenesisState.GenMsgs")
proto.RegisterType((*Code)(nil), "cosmwasm.wasm.v1.Code")
proto.RegisterType((*Contract)(nil), "cosmwasm.wasm.v1.Contract")
proto.RegisterType((*Sequence)(nil), "cosmwasm.wasm.v1.Sequence")
@@ -433,50 +317,42 @@ func init() {
func init() { proto.RegisterFile("cosmwasm/wasm/v1/genesis.proto", fileDescriptor_2ab3f539b23472a6) }
var fileDescriptor_2ab3f539b23472a6 = []byte{
// 676 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x94, 0xcf, 0x6e, 0xd3, 0x40,
0x10, 0xc6, 0xe3, 0x24, 0x4e, 0x93, 0x69, 0xa0, 0xd5, 0xb6, 0xb4, 0xc6, 0x80, 0x13, 0x05, 0x54,
0x05, 0x84, 0x12, 0xb5, 0x48, 0xdc, 0x10, 0xe0, 0xb6, 0xa2, 0x51, 0x55, 0x09, 0x5c, 0x21, 0x24,
0xa4, 0x2a, 0x72, 0xed, 0xad, 0x6b, 0x51, 0x7b, 0x43, 0x76, 0x53, 0xea, 0x33, 0x2f, 0xc0, 0x23,
0xc0, 0x9d, 0x07, 0xe9, 0xb1, 0x47, 0x4e, 0x11, 0x4a, 0x6f, 0x3c, 0x05, 0xda, 0x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0xda, 0x2a, 0x7c, 0xdc, 0x08, 0x42, 0x76, 0x3a, 0x3a, 0xee, 0x78,
0x24, 0xea, 0x6e, 0x13, 0x1a, 0x7d, 0x48, 0x5f, 0x3e, 0xbf, 0x7b, 0x21, 0x5f, 0x40, 0xf1, 0x38,
0x1e, 0x57, 0xc4, 0x13, 0xf8, 0xec, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x55, 0xb6, 0x2c, 0x20,
0x85, 0x05, 0x00, 0x00,
// 546 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xcf, 0x6e, 0xd3, 0x40,
0x10, 0xc6, 0xe3, 0xd4, 0x31, 0xe9, 0x36, 0xd0, 0x6a, 0x29, 0xad, 0x15, 0xc0, 0x89, 0x82, 0x84,
0x02, 0x42, 0xb6, 0x5a, 0x24, 0x6e, 0x48, 0xe0, 0xa6, 0x02, 0xab, 0x42, 0x42, 0xae, 0x10, 0x12,
0x97, 0xc8, 0xf1, 0x6e, 0x53, 0x8b, 0xda, 0x6b, 0xbc, 0x9b, 0x80, 0xdf, 0x82, 0x57, 0xe0, 0xce,
0x1b, 0xf0, 0x02, 0x3d, 0xf6, 0xc8, 0x29, 0x42, 0xce, 0x8d, 0xa7, 0x40, 0xfb, 0xc7, 0xae, 0x45,
0x9a, 0x8b, 0xe5, 0x9d, 0xf9, 0xe6, 0xe7, 0xf5, 0x37, 0x33, 0xc0, 0x0a, 0x09, 0x8d, 0xbf, 0x06,
0x34, 0x76, 0xc4, 0x63, 0x7e, 0xe0, 0x4c, 0x71, 0x82, 0x69, 0x44, 0xed, 0x34, 0x23, 0x8c, 0xc0,
0x9d, 0x32, 0x6f, 0x8b, 0xc7, 0xfc, 0xa0, 0xbb, 0x3b, 0x25, 0x53, 0x22, 0x92, 0x0e, 0x7f, 0x93,
0xba, 0xee, 0x83, 0x15, 0x0e, 0xcb, 0x53, 0xac, 0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0x8f, 0xa7, 0x11, 0x3b, 0x9f, 0x4d, 0xec, 0x90,
0xc4, 0xce, 0x11, 0xa1, 0xf1, 0xc7, 0x72, 0x2f, 0x91, 0xf3, 0x4d, 0xee, 0xa7, 0x58, 0xce, 0x89,
0x21, 0xb6, 0xf3, 0xf9, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x14, 0x33, 0x7b, 0x9f, 0x05, 0x04,
0x00, 0x00,
}
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
@@ -499,20 +375,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if len(m.GenMsgs) > 0 {
for iNdEx := len(m.GenMsgs) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.GenMsgs[iNdEx].MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintGenesis(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x2a
}
}
if len(m.Sequences) > 0 {
for iNdEx := len(m.Sequences) - 1; iNdEx >= 0; iNdEx-- {
{
@@ -568,104 +430,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *GenesisState_GenMsgs) 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 *GenesisState_GenMsgs) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *GenesisState_GenMsgs) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.Sum != nil {
{
size := m.Sum.Size()
i -= size
if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil {
return 0, err
}
}
}
return len(dAtA) - i, nil
}
func (m *GenesisState_GenMsgs_StoreCode) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *GenesisState_GenMsgs_StoreCode) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
if m.StoreCode != nil {
{
size, err := m.StoreCode.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintGenesis(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *GenesisState_GenMsgs_InstantiateContract) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *GenesisState_GenMsgs_InstantiateContract) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
if m.InstantiateContract != nil {
{
size, err := m.InstantiateContract.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintGenesis(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x12
}
return len(dAtA) - i, nil
}
func (m *GenesisState_GenMsgs_ExecuteContract) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *GenesisState_GenMsgs_ExecuteContract) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
if m.ExecuteContract != nil {
{
size, err := m.ExecuteContract.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintGenesis(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
}
return len(dAtA) - i, nil
}
func (m *Code) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
@@ -862,63 +626,6 @@ func (m *GenesisState) Size() (n int) {
n += 1 + l + sovGenesis(uint64(l))
}
}
if len(m.GenMsgs) > 0 {
for _, e := range m.GenMsgs {
l = e.Size()
n += 1 + l + sovGenesis(uint64(l))
}
}
return n
}
func (m *GenesisState_GenMsgs) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.Sum != nil {
n += m.Sum.Size()
}
return n
}
func (m *GenesisState_GenMsgs_StoreCode) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.StoreCode != nil {
l = m.StoreCode.Size()
n += 1 + l + sovGenesis(uint64(l))
}
return n
}
func (m *GenesisState_GenMsgs_InstantiateContract) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.InstantiateContract != nil {
l = m.InstantiateContract.Size()
n += 1 + l + sovGenesis(uint64(l))
}
return n
}
func (m *GenesisState_GenMsgs_ExecuteContract) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.ExecuteContract != nil {
l = m.ExecuteContract.Size()
n += 1 + l + sovGenesis(uint64(l))
}
return n
}
@@ -1158,196 +865,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field GenMsgs", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenesis
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthGenesis
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthGenesis
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.GenMsgs = append(m.GenMsgs, GenesisState_GenMsgs{})
if err := m.GenMsgs[len(m.GenMsgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipGenesis(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthGenesis
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *GenesisState_GenMsgs) 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 ErrIntOverflowGenesis
}
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: GenMsgs: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: GenMsgs: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field StoreCode", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenesis
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthGenesis
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthGenesis
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &MsgStoreCode{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
m.Sum = &GenesisState_GenMsgs_StoreCode{v}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field InstantiateContract", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenesis
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthGenesis
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthGenesis
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &MsgInstantiateContract{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
m.Sum = &GenesisState_GenMsgs_InstantiateContract{v}
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ExecuteContract", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenesis
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthGenesis
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthGenesis
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &MsgExecuteContract{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
m.Sum = &GenesisState_GenMsgs_ExecuteContract{v}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipGenesis(dAtA[iNdEx:])

View File

@@ -47,30 +47,6 @@ func TestValidateGenesisState(t *testing.T) {
},
expError: true,
},
"genesis store code message invalid": {
srcMutator: func(s *GenesisState) {
s.GenMsgs[0].GetStoreCode().WASMByteCode = nil
},
expError: true,
},
"genesis instantiate contract message invalid": {
srcMutator: func(s *GenesisState) {
s.GenMsgs[1].GetInstantiateContract().CodeID = 0
},
expError: true,
},
"genesis execute contract message invalid": {
srcMutator: func(s *GenesisState) {
s.GenMsgs[2].GetExecuteContract().Sender = "invalid"
},
expError: true,
},
"genesis invalid message type": {
srcMutator: func(s *GenesisState) {
s.GenMsgs[0].Sum = nil
},
expError: true,
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {

View File

@@ -148,7 +148,8 @@ func (m *InstantiateContractProposal) XXX_DiscardUnknown() {
var xxx_messageInfo_InstantiateContractProposal proto.InternalMessageInfo
// InstantiateContract2Proposal gov proposal content type to instantiate contract 2
// InstantiateContract2Proposal gov proposal content type to instantiate
// contract 2
type InstantiateContract2Proposal struct {
// Title is a short summary
Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"`

View File

@@ -36,11 +36,7 @@ func GenesisFixture(mutators ...func(*GenesisState)) GenesisState {
Value: uint64(i),
}
}
fixture.GenMsgs = []GenesisState_GenMsgs{
{Sum: &GenesisState_GenMsgs_StoreCode{StoreCode: MsgStoreCodeFixture()}},
{Sum: &GenesisState_GenMsgs_InstantiateContract{InstantiateContract: MsgInstantiateContractFixture()}},
{Sum: &GenesisState_GenMsgs_ExecuteContract{ExecuteContract: MsgExecuteContractFixture()}},
}
for _, m := range mutators {
m(&fixture)
}