Skip to content

Commit

Permalink
Implement IBC contract support (#394)
Browse files Browse the repository at this point in the history
* Implement IBC contract support

* Update changelog

* Adjust tests for new event logic

* Review comment
  • Loading branch information
alpe authored Jan 29, 2021
1 parent e6735eb commit 0f46dee
Show file tree
Hide file tree
Showing 54 changed files with 6,963 additions and 596 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.15.0...HEAD)

- Implement IBC contract support [\#394](https://github.com/CosmWasm/wasmd/pull/394)

## [v0.15.0](https://github.com/CosmWasm/wasmd/tree/v0.15.0) (2021-01-27)

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.14.1...v0.15.0)
Expand Down
21 changes: 14 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ type WasmApp struct {
transferKeeper ibctransferkeeper.Keeper
wasmKeeper wasm.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
scopedIBCKeeper capabilitykeeper.ScopedKeeper
scopedTransferKeeper capabilitykeeper.ScopedKeeper
scopedWasmKeeper capabilitykeeper.ScopedKeeper

// the module manager
mm *module.Manager
Expand All @@ -240,7 +240,7 @@ type WasmApp struct {
// NewWasmApp returns a reference to an initialized WasmApp.
func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, enabledProposals []wasm.ProposalType,
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp)) *WasmApp {
appOpts servertypes.AppOptions, wasmOpts []wasm.Option, baseAppOptions ...func(*baseapp.BaseApp)) *WasmApp {

encodingConfig := MakeEncodingConfig()
appCodec, legacyAmino := encodingConfig.Marshaler, encodingConfig.Amino
Expand Down Expand Up @@ -281,6 +281,7 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
app.capabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
scopedIBCKeeper := app.capabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.capabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.capabilityKeeper.ScopeToModule(wasm.ModuleName)

// add keepers
app.accountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -355,7 +356,7 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
}
// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "staking"
supportedFeatures := "staking,stargate"
app.wasmKeeper = wasm.NewKeeper(
appCodec,
keys[wasm.StoreKey],
Expand All @@ -364,18 +365,23 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
app.bankKeeper,
app.stakingKeeper,
app.distrKeeper,
app.ibcKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper,
scopedWasmKeeper,
wasmRouter,
wasmDir,
wasmConfig,
supportedFeatures,
nil,
nil,
wasmOpts...,
)

// The gov proposal types can be individually enabled
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, enabledProposals))
}
ibcRouter.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.wasmKeeper))
app.ibcKeeper.SetRouter(ibcRouter)

app.govKeeper = govkeeper.NewKeeper(
Expand Down Expand Up @@ -503,8 +509,9 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
app.capabilityKeeper.InitializeAndSeal(ctx)
}

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.scopedIBCKeeper = scopedIBCKeeper
app.scopedTransferKeeper = scopedTransferKeeper
app.scopedWasmKeeper = scopedWasmKeeper
return app
}

Expand Down
8 changes: 5 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
)

var emptyWasmOpts []wasm.Option = nil

func TestWasmdExport(t *testing.T) {
db := db.NewMemDB()
gapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, wasm.EnableAllProposals, EmptyAppOptions{})
gapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, wasm.EnableAllProposals, EmptyBaseAppOptions{}, emptyWasmOpts)

genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand All @@ -32,15 +34,15 @@ func TestWasmdExport(t *testing.T) {
gapp.Commit()

// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, wasm.EnableAllProposals, EmptyAppOptions{})
newGapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, wasm.EnableAllProposals, EmptyBaseAppOptions{}, emptyWasmOpts)
_, err = newGapp.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

// ensure that blocked addresses are properly set in bank keeper
func TestBlockedAddrs(t *testing.T) {
db := db.NewMemDB()
gapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, wasm.EnableAllProposals, EmptyAppOptions{})
gapp := NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, wasm.EnableAllProposals, EmptyBaseAppOptions{}, emptyWasmOpts)

for acc := range maccPerms {
require.Equal(t, !allowedReceivingModAcc[acc], gapp.bankKeeper.BlockedAddr(gapp.accountKeeper.GetModuleAddress(acc)))
Expand Down
57 changes: 57 additions & 0 deletions app/test_access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package app

import (
"testing"

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/codec"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper"
ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/core/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)

type TestSupport struct {
t *testing.T
app *WasmApp
}

func NewTestSupport(t *testing.T, app *WasmApp) *TestSupport {
return &TestSupport{t: t, app: app}
}

func (s TestSupport) IBCKeeper() ibckeeper.Keeper {
return *s.app.ibcKeeper
}

func (s TestSupport) WasmKeeper() wasm.Keeper {
return s.app.wasmKeeper
}

func (s TestSupport) AppCodec() codec.Marshaler {
return s.app.appCodec
}
func (s TestSupport) ScopedWasmIBCKeeper() capabilitykeeper.ScopedKeeper {
return s.app.scopedWasmKeeper
}

func (s TestSupport) ScopeIBCKeeper() capabilitykeeper.ScopedKeeper {
return s.app.scopedIBCKeeper
}

func (s TestSupport) ScopedTransferKeeper() capabilitykeeper.ScopedKeeper {
return s.app.scopedTransferKeeper
}

func (s TestSupport) StakingKeeper() stakingkeeper.Keeper {
return s.app.stakingKeeper
}

func (s TestSupport) BankKeeper() bankkeeper.Keeper {
return s.app.bankKeeper
}

func (s TestSupport) TransferKeeper() ibctransferkeeper.Keeper {
return s.app.transferKeeper
}
Loading

0 comments on commit 0f46dee

Please sign in to comment.