Skip to content

Commit

Permalink
enable backwards compat feat
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Oct 24, 2023
1 parent 8e460a7 commit bf6d010
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 75 deletions.
5 changes: 2 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ type App struct {
checkTxHandler mev_lane.CheckTx

// Lanes
Mempool auctionante.Mempool
MEVLane auctionante.MEVLane
Mempool auctionante.Mempool
MEVLane auctionante.MEVLane
}

func (app *App) GetTestBankKeeper() integration.TestBankKeeper {
Expand Down Expand Up @@ -977,7 +977,6 @@ func New(
mevLane.SetAnteHandler(anteHandler)
baseLane.SetAnteHandler(anteHandler)


app.SetEndBlocker(app.EndBlocker)

handler := blocksdkabci.NewProposalHandler(
Expand Down
14 changes: 12 additions & 2 deletions app/upgrades/nextupgrade/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package nextupgrade

import (
"fmt"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/baseapp"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
Expand Down Expand Up @@ -79,7 +81,7 @@ func CreateUpgradeHandler(
}

ctx.Logger().Info("Migrating interchaintxs module parameters...")
if err := setInterchainTxsParams(ctx, keepers.ParamsKeeper, storeKeys.GetKey(interchaintxstypes.StoreKey), codec); err != nil {
if err := setInterchainTxsParams(ctx, keepers.ParamsKeeper, storeKeys.GetKey(interchaintxstypes.StoreKey), storeKeys.GetKey(wasmtypes.StoreKey), codec); err != nil {
return nil, err
}

Expand Down Expand Up @@ -225,7 +227,7 @@ func migrateInterchainQueriesParams(ctx sdk.Context, paramsKeepers paramskeeper.
return nil
}

func setInterchainTxsParams(ctx sdk.Context, paramsKeepers paramskeeper.Keeper, storeKey storetypes.StoreKey, codec codec.Codec) error {
func setInterchainTxsParams(ctx sdk.Context, paramsKeepers paramskeeper.Keeper, storeKey storetypes.StoreKey, wasmStoreKey storetypes.StoreKey, codec codec.Codec) error {
store := ctx.KVStore(storeKey)
var currParams interchaintxstypes.Params
subspace, _ := paramsKeepers.GetSubspace(interchaintxstypes.StoreKey)
Expand All @@ -238,6 +240,14 @@ func setInterchainTxsParams(ctx sdk.Context, paramsKeepers paramskeeper.Keeper,

bz := codec.MustMarshal(&currParams)
store.Set(interchaintxstypes.ParamsKey, bz)

wasmStore := ctx.KVStore(wasmStoreKey)
bzWasm := wasmStore.Get(wasmtypes.KeyLastCodeID)
if bzWasm == nil {
return fmt.Errorf("last code ID not found during the upgrade")
}

store.Set(interchaintxstypes.LastCodeIdBeforeUpgrade, bzWasm)
return nil
}

Expand Down
50 changes: 50 additions & 0 deletions app/upgrades/nextupgrade/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nextupgrade_test
import (
"testing"

"github.com/CosmWasm/wasmd/x/wasm/keeper"
adminmoduletypes "github.com/cosmos/admin-module/x/adminmodule/types"

crontypes "github.com/neutron-org/neutron/x/cron/types"
Expand Down Expand Up @@ -54,6 +55,9 @@ func (suite *UpgradeTestSuite) SetupTest() {
pTokenfactory := tokenfactorytypes.DefaultParams()
subspace.SetParamSet(ctx, &pTokenfactory)

pWasmTypes := icqtypes.DefaultParams()
subspace.SetParamSet(ctx, &pWasmTypes)

subspace, _ = app.ParamsKeeper.GetSubspace(icqtypes.StoreKey)
pICQTypes := icqtypes.DefaultParams()
subspace.SetParamSet(ctx, &pICQTypes)
Expand Down Expand Up @@ -159,3 +163,49 @@ func (suite *UpgradeTestSuite) TestAdminModuleUpgrade() {
suite.Require().NoError(err)
suite.Require().Equal(uint64(1), id)
}

func (suite *UpgradeTestSuite) TestRegisterInterchainAccountCreationFee() {
var (
app = suite.GetNeutronZoneApp(suite.ChainA)
ccvConsumerSubspace = app.GetSubspace(ccvconsumertypes.ModuleName)
ctx = suite.ChainA.GetContext()
)

suite.Require().True(ccvConsumerSubspace.Has(ctx, ccvconsumertypes.KeyRewardDenoms))

// emulate mainnet/testnet state
ccvConsumerSubspace.Set(ctx, ccvconsumertypes.KeyRewardDenoms, &[]string{params.DefaultDenom})

var denomsBefore []string
ccvConsumerSubspace.Get(ctx, ccvconsumertypes.KeyRewardDenoms, &denomsBefore)
suite.Require().Equal(denomsBefore, []string{params.DefaultDenom})
contractKeeper := keeper.NewDefaultPermissionKeeper(app.WasmKeeper)
codeIDBefore := suite.StoreTestCode(ctx, sdk.AccAddress("neutron1weweewe"), "../../wasmbiding/testdata/neutron_interchain_txs.wasm.wasm")
contractAddressBefore := suite.InstantiateTestContract(ctx, sdk.AccAddress("neutron1weweewe"), codeIDBefore)

upgrade := upgradetypes.Plan{
Name: nextupgrade.UpgradeName,
Info: "some text here",
Height: 100,
}
app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade)

// Store code and instantiate reflect contract
codeID := suite.StoreTestCode(ctx, sdk.AccAddress("neutron1weweewe"), "../../wasmbinding/testdata/neutron_interchain_txs.wasm")
contractAddressAfter := suite.InstantiateTestContract(ctx, sdk.AccAddress("neutron1weweewe"), codeID)
// register w/o actual fees
jsonStringBefore := `{"connection_id":"1","interchain_account_id":"test-1"}`
byteEncodedMsgBefore := []byte(jsonStringBefore)
_, err := contractKeeper.Execute(ctx, contractAddressBefore, sdk.AccAddress("neutron1weweewe"), byteEncodedMsgBefore, nil)
suite.Require().Error(err)

// register with fees
jsonStringAfter := `{"connection_id":"1","interchain_account_id":"test-2"}`
byteEncodedMsgAfter := []byte(jsonStringAfter)
_, err = contractKeeper.Execute(ctx, contractAddressAfter, sdk.AccAddress("neutron1weweewe"), byteEncodedMsgAfter, sdk.NewCoins(sdk.NewCoin("untrn", sdk.NewInt(1000))))
suite.Require().NoError(err)

// failed register due lack of fees
_, err = contractKeeper.Execute(ctx, contractAddressAfter, sdk.AccAddress("neutron1weweewe"), byteEncodedMsgAfter, nil)
suite.Require().Error(err)
}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,6 @@ github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OS
github.com/neilotoole/errgroup v0.1.6/go.mod h1:Q2nLGf+594h0CLBs/Mbg6qOr7GtqDK7C2S41udRnToE=
github.com/neutron-org/admin-module v0.0.0-20230906150724-9ccb75c61fc5 h1:96ZjLWoN4nCIcFdxrz51Xu2Y8aqpcScy3eva3S5hM60=
github.com/neutron-org/admin-module v0.0.0-20230906150724-9ccb75c61fc5/go.mod h1:INknneN2W3Fr9Eld7SpfLRdjyHR1muzFbbqXln1ixic=
github.com/neutron-org/cosmos-sdk v0.47.5-0.20230921074823-5d5ff8b93265 h1:CIyjGN+/WTIgGyUEAiL7HcxQ2/XYX3r2Nv4RWBbhl8o=
github.com/neutron-org/cosmos-sdk v0.47.5-0.20230921074823-5d5ff8b93265/go.mod h1:4xMyIVekAs2OEUz/yh9JwzhLBMk+olM2sxgKuQdlhLg=
github.com/neutron-org/cosmos-sdk v0.47.5-0.20230929200416-6c59762e84ad h1:BvYliP3KHiay2VLQwUSmDNCXm380TSTLDud8PH4RV6A=
github.com/neutron-org/cosmos-sdk v0.47.5-0.20230929200416-6c59762e84ad/go.mod h1:4xMyIVekAs2OEUz/yh9JwzhLBMk+olM2sxgKuQdlhLg=
github.com/neutron-org/wasmd v0.40.0-rc.0.0.20230808084410-6083b888424e h1:uVJCBWf1vcCYY0pzOA2SCPIZT8WsR8fsOxs57mnJbM4=
Expand Down
5 changes: 3 additions & 2 deletions testutil/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ func (suite *IBCConnectionTestSuite) GetNeutronZoneApp(chain *ibctesting.TestCha
return testApp
}

func (suite *IBCConnectionTestSuite) StoreReflectCode(ctx sdk.Context, addr sdk.AccAddress, path string) uint64 {
func (suite *IBCConnectionTestSuite) StoreTestCode(ctx sdk.Context, addr sdk.AccAddress, path string) uint64 {
// wasm file built with https://github.com/neutron-org/neutron-contracts/tree/main/contracts/reflect
// wasm file built with https://github.com/neutron-org/neutron-dev/tree/feat/ica-register-fee-update/contracts/neutron_interchain_txs
wasmCode, err := os.ReadFile(path)
suite.Require().NoError(err)

Expand All @@ -292,7 +293,7 @@ func (suite *IBCConnectionTestSuite) StoreReflectCode(ctx sdk.Context, addr sdk.
return codeID
}

func (suite *IBCConnectionTestSuite) InstantiateReflectContract(ctx sdk.Context, funder sdk.AccAddress, codeID uint64) sdk.AccAddress {
func (suite *IBCConnectionTestSuite) InstantiateTestContract(ctx sdk.Context, funder sdk.AccAddress, codeID uint64) sdk.AccAddress {
initMsgBz := []byte("{}")
contractKeeper := keeper.NewDefaultPermissionKeeper(suite.GetNeutronZoneApp(suite.ChainA).WasmKeeper)
addr, _, err := contractKeeper.Instantiate(ctx, codeID, funder, funder, initMsgBz, "demo contract", nil)
Expand Down
2 changes: 1 addition & 1 deletion wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type SubmitTxResponse struct {
type RegisterInterchainAccount struct {
ConnectionId string `json:"connection_id"`
InterchainAccountId string `json:"interchain_account_id"`
RegisterFee sdk.Coins `json:"register_fee"`
RegisterFee sdk.Coins `json:"register_fee,omitempty"`
}

// RegisterInterchainAccountResponse holds response for RegisterInterchainAccount.
Expand Down
9 changes: 8 additions & 1 deletion wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ func (m *CustomMessenger) performRegisterInterchainAccount(ctx sdk.Context, cont
FromAddress: contractAddr.String(),
ConnectionId: reg.ConnectionId,
InterchainAccountId: reg.InterchainAccountId,
RegisterFee: reg.RegisterFee,
RegisterFee: getRegisterFee(reg.RegisterFee),
}
if err := msg.ValidateBasic(); err != nil {
return nil, errors.Wrap(err, "failed to validate incoming RegisterInterchainAccount message")
Expand Down Expand Up @@ -921,3 +921,10 @@ func (m *CustomMessenger) isAdmin(ctx sdk.Context, contractAddr sdk.AccAddress)

return false
}

func getRegisterFee(fee sdk.Coins) sdk.Coins {
if fee == nil {
return make(sdk.Coins, 0)
}
return fee
}
52 changes: 26 additions & 26 deletions wasmbinding/test/custom_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (suite *CustomMessengerTestSuite) SetupTest() {

func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccount() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

err := suite.neutron.FeeBurnerKeeper.SetParams(suite.ctx, feeburnertypes.Params{
Expand Down Expand Up @@ -111,8 +111,8 @@ func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccount() {

func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccountLongID() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

// Craft RegisterInterchainAccount message
Expand All @@ -135,8 +135,8 @@ func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccountLongID() {

func (suite *CustomMessengerTestSuite) TestRegisterInterchainQuery() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

err := testutil.SetupICAPath(suite.Path, suite.contractAddress.String())
Expand Down Expand Up @@ -173,8 +173,8 @@ func (suite *CustomMessengerTestSuite) TestRegisterInterchainQuery() {
}

func (suite *CustomMessengerTestSuite) TestCreateDenomMsg() {
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress()
Expand All @@ -201,8 +201,8 @@ func (suite *CustomMessengerTestSuite) TestMintMsg() {
lucky = keeper.RandomAccountAddress(suite.T()) // We don't care what this address is
)

codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress()
Expand Down Expand Up @@ -377,8 +377,8 @@ func (suite *CustomMessengerTestSuite) TestRemoveInterchainQueryFailed() {

func (suite *CustomMessengerTestSuite) TestSubmitTx() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress()
Expand Down Expand Up @@ -410,8 +410,8 @@ func (suite *CustomMessengerTestSuite) TestSubmitTx() {

func (suite *CustomMessengerTestSuite) TestSubmitTxTooMuchTxs() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

err := testutil.SetupICAPath(suite.Path, suite.contractAddress.String())
Expand Down Expand Up @@ -507,8 +507,8 @@ func (suite *CustomMessengerTestSuite) TestSoftwareUpgradeProposal() {

func (suite *CustomMessengerTestSuite) TestTooMuchProposals() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

err := testutil.SetupICAPath(suite.Path, suite.contractAddress.String())
Expand Down Expand Up @@ -547,8 +547,8 @@ func (suite *CustomMessengerTestSuite) TestTooMuchProposals() {

func (suite *CustomMessengerTestSuite) TestNoProposals() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

err := testutil.SetupICAPath(suite.Path, suite.contractAddress.String())
Expand All @@ -572,8 +572,8 @@ func (suite *CustomMessengerTestSuite) TestNoProposals() {

func (suite *CustomMessengerTestSuite) TestAddRemoveSchedule() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

// Set admin so that we can execute this proposal without permission error
Expand Down Expand Up @@ -625,8 +625,8 @@ func (suite *CustomMessengerTestSuite) TestAddRemoveSchedule() {

func (suite *CustomMessengerTestSuite) TestResubmitFailureAck() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

// Add failure
Expand Down Expand Up @@ -660,8 +660,8 @@ func (suite *CustomMessengerTestSuite) TestResubmitFailureAck() {

func (suite *CustomMessengerTestSuite) TestResubmitFailureTimeout() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

// Add failure
Expand Down Expand Up @@ -692,8 +692,8 @@ func (suite *CustomMessengerTestSuite) TestResubmitFailureTimeout() {

func (suite *CustomMessengerTestSuite) TestResubmitFailureFromDifferentContract() {
// Store code and instantiate reflect contract
codeID := suite.StoreReflectCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateReflectContract(suite.ctx, suite.contractOwner, codeID)
codeID := suite.StoreTestCode(suite.ctx, suite.contractOwner, "../testdata/reflect.wasm")
suite.contractAddress = suite.InstantiateTestContract(suite.ctx, suite.contractOwner, codeID)
suite.Require().NotEmpty(suite.contractAddress)

// Add failure
Expand Down
Loading

0 comments on commit bf6d010

Please sign in to comment.