Skip to content

Commit

Permalink
Merge branch 'main' into dev/ica_host
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored May 25, 2022
2 parents b0d7ae5 + 78ed877 commit 61862fc
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 176 deletions.
14 changes: 8 additions & 6 deletions ante/sendblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ func TestSendBlockDecorator(t *testing.T) {
to sdk.AccAddress
expectPass bool
}{
{sdk.AccAddress("honest-sender"), sdk.AccAddress("honest-address"), true},
{sdk.AccAddress("honest-sender"), sdk.AccAddress("recovery-address"), true},
{sdk.AccAddress("malicious-sender"), sdk.AccAddress("recovery-address"), true},
{sdk.AccAddress("malicious-sender"), sdk.AccAddress("random-address"), false},
{sdk.AccAddress("honest-sender_______"), sdk.AccAddress("honest-address"), true},
{sdk.AccAddress("honest-sender_______"), sdk.AccAddress("recovery-address"), true},
{sdk.AccAddress("malicious-sender____"), sdk.AccAddress("recovery-address"), true},
{sdk.AccAddress("malicious-sender____"), sdk.AccAddress("random-address"), false},
}

permittedOnlySendTo := map[string]string{
sdk.AccAddress("malicious-sender").String(): sdk.AccAddress("recovery-address").String(),
sdk.AccAddress("malicious-sender____").String(): sdk.AccAddress("recovery-address").String(),
}
decorator := NewSendBlockDecorator(SendBlockOptions{permittedOnlySendTo})

for _, testCase := range testCases {
err := decorator.CheckIfBlocked([]sdk.Msg{bank.NewMsgSend(testCase.from, testCase.to, sdk.NewCoins(sdk.NewInt64Coin("test", 1)))})
err := decorator.CheckIfBlocked(
[]sdk.Msg{
bank.NewMsgSend(testCase.from, testCase.to, sdk.NewCoins(sdk.NewInt64Coin("test", 1)))})
if testCase.expectPass {
require.NoError(t, err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/signing"

osmoante "github.com/osmosis-labs/osmosis/v7/ante"
v9 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v9"

v8 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v8"
txfeeskeeper "github.com/osmosis-labs/osmosis/v7/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/v7/x/txfees/types"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ func NewAnteHandler(
wasmkeeper.NewLimitSimulationGasDecorator(wasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(txCounterStoreKey),
ante.NewRejectExtensionOptionsDecorator(),
v8.MsgFilterDecorator{},
v9.MsgFilterDecorator{},
// Use Mempool Fee Decorator from our txfees module instead of default one from auth
// https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/middleware/fee.go#L34
mempoolFeeDecorator,
Expand Down
35 changes: 35 additions & 0 deletions app/upgrades/v9/msg_filter_ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package v9

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
)

// MsgFilterDecorator defines an AnteHandler decorator for the v9 upgrade that
// provide height-gated message filtering acceptance.
type MsgFilterDecorator struct{}

// AnteHandle performs an AnteHandler check that returns an error if the tx contains a message
// that is blocked.
// Right now, we block MsgTimeoutOnClose due to incorrect behavior that could occur if a packet is re-enabled.
func (mfd MsgFilterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if hasInvalidMsgs(tx.GetMsgs()) {
currHeight := ctx.BlockHeight()
return ctx, fmt.Errorf("tx contains unsupported message types at height %d", currHeight)
}

return next(ctx, tx, simulate)
}

func hasInvalidMsgs(msgs []sdk.Msg) bool {
for _, msg := range msgs {
switch msg.(type) {
case *ibcchanneltypes.MsgTimeoutOnClose:
return true
}
}

return false
}
70 changes: 70 additions & 0 deletions app/upgrades/v9/msg_filter_ante_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package v9_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"

ibcchanneltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"

"github.com/osmosis-labs/osmosis/v7/app"
v8 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v8"
v9 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v9"
)

func noOpAnteDecorator() sdk.AnteHandler {
return func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) {
return ctx, nil
}
}

func TestMsgFilterDecorator(t *testing.T) {
handler := v9.MsgFilterDecorator{}
txCfg := app.MakeEncodingConfig().TxConfig

addr1 := sdk.AccAddress([]byte("addr1_______________"))
addr2 := sdk.AccAddress([]byte("addr2_______________"))

testCases := []struct {
name string
ctx sdk.Context
msgs []sdk.Msg
expectErr bool
}{
{
name: "valid tx",
ctx: sdk.Context{}.WithBlockHeight(v8.UpgradeHeight - 1),
msgs: []sdk.Msg{
banktypes.NewMsgSend(addr1, addr2, sdk.NewCoins(sdk.NewInt64Coin("foo", 5))),
},
expectErr: false,
},
{
name: "invalid tx",
ctx: sdk.Context{}.WithBlockHeight(v8.UpgradeHeight),
msgs: []sdk.Msg{
banktypes.NewMsgSend(addr1, addr2, sdk.NewCoins(sdk.NewInt64Coin("foo", 5))),
&ibcchanneltypes.MsgTimeoutOnClose{},
},
expectErr: true,
},
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
txBuilder := txCfg.NewTxBuilder()
require.NoError(t, txBuilder.SetMsgs(tc.msgs...))

_, err := handler.AnteHandle(tc.ctx, txBuilder.GetTx(), false, noOpAnteDecorator())
if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}
64 changes: 64 additions & 0 deletions tests/e2e/docker/image_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package docker

// ImageConfig contains all images and their respective tags
// needed for running e2e tests.
type ImageConfig struct {
InitRepository string
InitTag string

OsmosisRepository string
OsmosisTag string

RelayerRepository string
RelayerTag string
}

const (
// Local osmosis repo/version.
// It is used when skipping upgrade by setting OSMOSIS_E2E_SKIP_UPGRADE to true).
// This image should be pre-built with `make docker-build-debug` either in CI or locally.
LocalOsmoRepository = "osmosis"
LocalOsmoTag = "debug"
// Local osmosis repo/version for osmosis initialization.
// It is used when skipping upgrade by setting OSMOSIS_E2E_SKIP_UPGRADE to true).
// This image should be pre-built with `make docker-build-e2e-chain-init` either in CI or locally.
localInitRepository = "osmosis-e2e-chain-init"
localInitTag = "debug"
// Pre-upgrade osmosis repo/tag to pull.
// It should be uploaded to Docker Hub. OSMOSIS_E2E_SKIP_UPGRADE should be unset
// for this functionality to be used.
previousVersionOsmoRepository = "osmolabs/osmosis-dev"
previousVersionOsmoTag = "v8.0.0-debug"
// Pre-upgrade repo/tag for osmosis initialization (this should be one version below upgradeVersion)
previousVersionInitRepository = "osmolabs/osmosis-init"
previousVersionInitTag = "v8.0.0"
// Hermes repo/version for relayer
relayerRepository = "osmolabs/hermes"
relayerTag = "0.13.0"
)

// Returns ImageConfig needed for running e2e test.
// If isUpgrade is true, returns images for running the upgrade
// Otherwise, returns images for running non-upgrade e2e tests.
func NewImageConfig(isUpgrade bool) *ImageConfig {
config := &ImageConfig{
RelayerRepository: relayerRepository,
RelayerTag: relayerTag,
}

if isUpgrade {
config.InitRepository = previousVersionInitRepository
config.InitTag = previousVersionInitTag

config.OsmosisRepository = previousVersionOsmoRepository
config.OsmosisTag = previousVersionOsmoTag
} else {
config.InitRepository = localInitRepository
config.InitTag = localInitTag

config.OsmosisRepository = LocalOsmoRepository
config.OsmosisTag = LocalOsmoTag
}

return config
}
Loading

0 comments on commit 61862fc

Please sign in to comment.