Skip to content

Commit

Permalink
Make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
pinosu committed Jul 26, 2023
1 parent cea00ff commit 77157c5
Show file tree
Hide file tree
Showing 24 changed files with 471 additions and 247 deletions.
21 changes: 18 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import (
icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types"
ibcfeekeeper "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types"
transfer "github.com/cosmos/ibc-go/v4/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
Expand Down Expand Up @@ -151,6 +153,7 @@ var (
maccPerms = map[string][]string{
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
ibcfeetypes.ModuleName: nil,
twasm.ModuleName: {authtypes.Minter, authtypes.Burner},
poetypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
}
Expand Down Expand Up @@ -185,6 +188,7 @@ type TgradeApp struct {
upgradeKeeper upgradekeeper.Keeper
paramsKeeper paramskeeper.Keeper
ibcKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
ibcFeeKeeper ibcfeekeeper.Keeper
transferKeeper ibctransferkeeper.Keeper
icaHostKeeper icahostkeeper.Keeper
feeGrantKeeper feegrantkeeper.Keeper
Expand Down Expand Up @@ -233,7 +237,7 @@ func NewTgradeApp(
authtypes.StoreKey, banktypes.StoreKey,
paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, poe.StoreKey, icahosttypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, poe.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -330,6 +334,14 @@ func NewTgradeApp(
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.upgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper))

// IBC Fee Module keeper
app.ibcFeeKeeper = ibcfeekeeper.NewKeeper(
appCodec, keys[ibcfeetypes.StoreKey], app.getSubspace(ibcfeetypes.ModuleName),
app.ibcKeeper.ChannelKeeper, // may be replaced with IBC middleware
app.ibcKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper, app.accountKeeper, app.bankKeeper,
)

// Create Transfer Keepers
app.transferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -366,7 +378,7 @@ func NewTgradeApp(

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := "staking,stargate,iterator,tgrade,cosmwasm_1_1"
availableCapabilities := "staking,stargate,iterator,tgrade,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3"

wasmOpts = append(SetupWasmHandlers(appCodec, app.bankKeeper, govRouter, &app.twasmKeeper, &app.poeKeeper, app), wasmOpts...)

Expand Down Expand Up @@ -397,7 +409,7 @@ func NewTgradeApp(
// Create static IBC router, add app routes, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.
AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.twasmKeeper, app.ibcKeeper.ChannelKeeper)).
AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.twasmKeeper, app.ibcKeeper.ChannelKeeper, app.ibcFeeKeeper)).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)
app.ibcKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -462,6 +474,7 @@ func NewTgradeApp(
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
poe.ModuleName,
twasm.ModuleName,
globalfee.ModuleName,
Expand All @@ -480,6 +493,7 @@ func NewTgradeApp(
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
globalfee.ModuleName,
twasm.ModuleName,
poe.ModuleName, // poe after twasm to have valset update at the end
Expand All @@ -506,6 +520,7 @@ func NewTgradeApp(
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// wasm after ibc transfer
twasm.ModuleName,
// poe after wasm contract instantiation
Expand Down
21 changes: 0 additions & 21 deletions cmd/tgrade/genwasm.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
package main

import (
wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"

"github.com/confio/tgrade/x/twasm/client/cli"
)

func AddGenesisWasmMsgCmd(defaultNodeHome string) *cobra.Command {
txCmd := &cobra.Command{
Use: "wasm-genesis-message",
Short: "Wasm genesis message subcommands",
Aliases: []string{"wasm-genesis-msg", "wasm-genesis-messages", "add-wasm-genesis-message"},
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
genIO := cli.NewGenesisIO()
txCmd.AddCommand(
wasmcli.GenesisStoreCodeCmd(defaultNodeHome, genIO),
wasmcli.GenesisInstantiateContractCmd(defaultNodeHome, genIO),
wasmcli.GenesisExecuteContractCmd(defaultNodeHome, genIO),
wasmcli.GenesisListContractsCmd(defaultNodeHome, genIO),
wasmcli.GenesisListCodesCmd(defaultNodeHome, genIO),
)
return txCmd
}

func GenesisWasmFlagsCmd(defaultNodeHome string) *cobra.Command {
txCmd := &cobra.Command{
Use: "wasm-genesis-flags",
Expand Down
1 change: 0 additions & 1 deletion cmd/tgrade/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig
cli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
AddGenesisWasmMsgCmd(app.DefaultNodeHome),
GenesisWasmFlagsCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
Expand Down
2 changes: 1 addition & 1 deletion docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ Contract struct encompasses ContractAddress, ContractInfo, and ContractState
| `contract_info` | [cosmwasm.wasm.v1.ContractInfo](#cosmwasm.wasm.v1.ContractInfo) | | |
| `kv_model` | [KVModel](#confio.twasm.v1beta1.KVModel) | | |
| `custom_model` | [CustomModel](#confio.twasm.v1beta1.CustomModel) | | |
| `contract_code_history` | [cosmwasm.wasm.v1.ContractCodeHistoryEntry](#cosmwasm.wasm.v1.ContractCodeHistoryEntry) | repeated | |



Expand Down Expand Up @@ -1002,7 +1003,6 @@ import
| `codes` | [cosmwasm.wasm.v1.Code](#cosmwasm.wasm.v1.Code) | repeated | Codes has all stored wasm codes and metadata |
| `contracts` | [Contract](#confio.twasm.v1beta1.Contract) | repeated | Contracts contains all instantiated contracts, state and metadata |
| `sequences` | [cosmwasm.wasm.v1.Sequence](#cosmwasm.wasm.v1.Sequence) | repeated | Sequences names and values |
| `gen_msgs` | [cosmwasm.wasm.v1.GenesisState.GenMsgs](#cosmwasm.wasm.v1.GenesisState.GenMsgs) | repeated | GenMsgs has wasmd sdk type messages to execute in the genesis phase |
| `privileged_contract_addresses` | [string](#string) | repeated | PrivilegedContractAddresses is a list of contract addresses that can have special permissions |
| `pinned_code_ids` | [uint64](#uint64) | repeated | PinnedCodeIDs has codeInfo ids for wasm codes that are pinned in cache |

Expand Down
10 changes: 5 additions & 5 deletions proto/confio/twasm/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ message GenesisState {
(gogoproto.jsontag) = "sequences,omitempty"
];

// GenMsgs has wasmd sdk type messages to execute in the genesis phase
repeated cosmwasm.wasm.v1.GenesisState.GenMsgs gen_msgs = 5 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "gen_msgs,omitempty"
];
// was "gen_msgs"
reserved 5;

// PrivilegedContractAddresses is a list of contract addresses that can have
// special permissions
Expand All @@ -59,6 +56,9 @@ message Contract {
KVModel kv_model = 3;
CustomModel custom_model = 4;
}

repeated cosmwasm.wasm.v1.ContractCodeHistoryEntry contract_code_history = 5
[ (gogoproto.nullable) = false ];
}

// KVModel is a wrapper around the wasmd default key value model.
Expand Down
118 changes: 118 additions & 0 deletions third_party/proto/cosmwasm/wasm/v1/authz.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
syntax = "proto3";
package cosmwasm.wasm.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/any.proto";

option go_package = "github.com/CosmWasm/wasmd/x/wasm/types";
option (gogoproto.goproto_getters_all) = false;

// ContractExecutionAuthorization defines authorization for wasm execute.
// Since: wasmd 0.30
message ContractExecutionAuthorization {
option (cosmos_proto.implements_interface) =
"cosmos.authz.v1beta1.Authorization";

// Grants for contract executions
repeated ContractGrant grants = 1 [ (gogoproto.nullable) = false ];
}

// ContractMigrationAuthorization defines authorization for wasm contract
// migration. Since: wasmd 0.30
message ContractMigrationAuthorization {
option (cosmos_proto.implements_interface) =
"cosmos.authz.v1beta1.Authorization";

// Grants for contract migrations
repeated ContractGrant grants = 1 [ (gogoproto.nullable) = false ];
}

// ContractGrant a granted permission for a single contract
// Since: wasmd 0.30
message ContractGrant {
// Contract is the bech32 address of the smart contract
string contract = 1;

// Limit defines execution limits that are enforced and updated when the grant
// is applied. When the limit lapsed the grant is removed.
google.protobuf.Any limit = 2 [ (cosmos_proto.accepts_interface) =
"cosmwasm.wasm.v1.ContractAuthzLimitX" ];

// 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.
google.protobuf.Any filter = 3
[ (cosmos_proto.accepts_interface) =
"cosmwasm.wasm.v1.ContractAuthzFilterX" ];
}

// MaxCallsLimit limited number of calls to the contract. No funds transferable.
// Since: wasmd 0.30
message MaxCallsLimit {
option (cosmos_proto.implements_interface) =
"cosmwasm.wasm.v1.ContractAuthzLimitX";

// Remaining number that is decremented on each execution
uint64 remaining = 1;
}

// MaxFundsLimit defines the maximal amounts that can be sent to the contract.
// Since: wasmd 0.30
message MaxFundsLimit {
option (cosmos_proto.implements_interface) =
"cosmwasm.wasm.v1.ContractAuthzLimitX";

// Amounts is the maximal amount of tokens transferable to the contract.
repeated cosmos.base.v1beta1.Coin amounts = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// 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
message CombinedLimit {
option (cosmos_proto.implements_interface) =
"cosmwasm.wasm.v1.ContractAuthzLimitX";

// Remaining number that is decremented on each execution
uint64 calls_remaining = 1;
// Amounts is the maximal amount of tokens transferable to the contract.
repeated cosmos.base.v1beta1.Coin amounts = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// AllowAllMessagesFilter is a wildcard to allow any type of contract payload
// message.
// Since: wasmd 0.30
message AllowAllMessagesFilter {
option (cosmos_proto.implements_interface) =
"cosmwasm.wasm.v1.ContractAuthzFilterX";
}

// AcceptedMessageKeysFilter accept only the specific contract message keys in
// the json object to be executed.
// Since: wasmd 0.30
message AcceptedMessageKeysFilter {
option (cosmos_proto.implements_interface) =
"cosmwasm.wasm.v1.ContractAuthzFilterX";

// Messages is the list of unique keys
repeated string keys = 1;
}

// AcceptedMessagesFilter accept only the specific raw contract messages to be
// executed.
// Since: wasmd 0.30
message AcceptedMessagesFilter {
option (cosmos_proto.implements_interface) =
"cosmwasm.wasm.v1.ContractAuthzFilterX";

// Messages is the list of raw contract messages
repeated bytes messages = 1 [ (gogoproto.casttype) = "RawContractMessage" ];
}
20 changes: 2 additions & 18 deletions third_party/proto/cosmwasm/wasm/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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
Expand All @@ -53,6 +35,8 @@ message Contract {
string contract_address = 1;
ContractInfo contract_info = 2 [ (gogoproto.nullable) = false ];
repeated Model contract_state = 3 [ (gogoproto.nullable) = false ];
repeated ContractCodeHistoryEntry contract_code_history = 4
[ (gogoproto.nullable) = false ];
}

// Sequence key and value of an id generation counter
Expand Down
6 changes: 6 additions & 0 deletions third_party/proto/cosmwasm/wasm/v1/ibc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ message MsgIBCSend {
bytes data = 6;
}

// MsgIBCSendResponse
message MsgIBCSendResponse {
// Sequence number of the IBC packet sent
uint64 sequence = 1;
}

// MsgIBCCloseChannel port and channel need to be owned by the contract
message MsgIBCCloseChannel {
string channel = 2 [ (gogoproto.moretags) = "yaml:\"source_channel\"" ];
Expand Down
Loading

0 comments on commit 77157c5

Please sign in to comment.