Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable backwards compat feature: only contracts after migration are charged for ice creation NTRN-135 #334

Merged
merged 11 commits into from
Nov 3, 2023
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
checkTxHandler mev_lane.CheckTx

// Lanes
Mempool blocksdk.Mempool

Check failure on line 331 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
MEVLane auctionante.MEVLane
}

Expand Down Expand Up @@ -977,7 +977,6 @@
mevLane.SetAnteHandler(anteHandler)
baseLane.SetAnteHandler(anteHandler)


app.SetEndBlocker(app.EndBlocker)

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

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 @@
}

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 @@
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 {

Check failure on line 230 in app/upgrades/nextupgrade/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
store := ctx.KVStore(storeKey)
var currParams interchaintxstypes.Params
subspace, _ := paramsKeepers.GetSubspace(interchaintxstypes.StoreKey)
Expand All @@ -238,10 +240,17 @@

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")
}
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
store.Set(interchaintxstypes.ICARegistrationFeeFirstCodeID, bzWasm)
return nil
}

func migrateGlobalFees(ctx sdk.Context, keepers *upgrades.UpgradeKeepers) error {

Check failure on line 253 in app/upgrades/nextupgrade/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

migrateGlobalFees - result 0 (error) is always nil (unparam)
ctx.Logger().Info("Implementing GlobalFee Params...")

// global fee is empty set, set global fee to equal to 0.05 USD (for 200k of gas) in appropriate coin
Expand Down Expand Up @@ -290,7 +299,7 @@
return nil
}

func migrateAdminModule(ctx sdk.Context, keepers *upgrades.UpgradeKeepers) error {

Check failure on line 302 in app/upgrades/nextupgrade/upgrades.go

View workflow job for this annotation

GitHub Actions / lint

migrateAdminModule - result 0 (error) is always nil (unparam)
ctx.Logger().Info("Migrating admin module...")

keepers.AdminModule.SetProposalID(ctx, 1)
Expand Down
48 changes: 48 additions & 0 deletions app/upgrades/nextupgrade/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import (
"testing"

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

crontypes "github.com/neutron-org/neutron/x/cron/types"
feeburnertypes "github.com/neutron-org/neutron/x/feeburner/types"
Expand Down Expand Up @@ -61,6 +63,9 @@
subspace, _ = app.ParamsKeeper.GetSubspace(interchaintxstypes.StoreKey)
pICAtx := interchaintxstypes.DefaultParams()
subspace.SetParamSet(ctx, &pICAtx)

codeIDBefore := suite.StoreTestCode(ctx, sdk.AccAddress("neutron1weweewe"), "testdata/neutron_interchain_txs.wasm")
suite.InstantiateTestContract(ctx, sdk.AccAddress("neutron1weweewe"), codeIDBefore)
}

func (suite *UpgradeTestSuite) TestGlobalFeesUpgrade() {
Expand Down Expand Up @@ -141,7 +146,7 @@
ctx = suite.ChainA.GetContext()
)

//emulate lack of ProposalIDKey like on a real mainnet

Check failure on line 149 in app/upgrades/nextupgrade/upgrades_test.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
store := ctx.KVStore(app.GetKey(adminmoduletypes.StoreKey))
store.Delete(adminmoduletypes.ProposalIDKey)

Expand All @@ -159,3 +164,46 @@
suite.Require().NoError(err)
suite.Require().Equal(uint64(1), id)
}

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

suite.FundAcc(sdk.AccAddress("neutron1weweewe"), sdk.NewCoins(sdk.NewCoin("untrn", sdk.NewInt(10000))))
contractKeeper := keeper.NewDefaultPermissionKeeper(app.WasmKeeper)
// store contract for register ica w/o fees
codeIDBefore := suite.StoreTestCode(ctx, sdk.AccAddress("neutron1_ica"), "testdata/neutron_interchain_txs.wasm")
contractAddressBeforeUpgrade := suite.InstantiateTestContract(ctx, sdk.AccAddress("neutron1_ica"), codeIDBefore)

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

lastCodeID := app.InterchainTxsKeeper.GetICARegistrationFeeFirstCodeID(ctx)
// ensure that wasm module stores next code id
suite.Require().Equal(lastCodeID, codeIDBefore+1)
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved

// store contract after upgrade
codeID := suite.StoreTestCode(ctx, sdk.AccAddress("neutron1_ica"), "testdata/neutron_interchain_txs.wasm")
contractAddressAfterUpgrade := suite.InstantiateTestContract(ctx, sdk.AccAddress("neutron1_ica"), codeID)
// register w/o actual fees
jsonStringBeforeUpgrade := `{"register": {"connection_id":"connection-1","interchain_account_id":"test-2"}}`
byteEncodedMsgBeforeUpgrade := []byte(jsonStringBeforeUpgrade)
_, err := contractKeeper.Execute(ctx, contractAddressBeforeUpgrade, sdk.AccAddress("neutron1_ica"), byteEncodedMsgBeforeUpgrade, nil)
suite.Require().NoError(err)

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

// failed register due lack of fees (fees required)
_, err = contractKeeper.Execute(ctx, contractAddressAfterUpgrade, sdk.AccAddress("neutron1weweewe"), byteEncodedMsgAfterUpgrade, nil)
suite.ErrorIs(err, errors.ErrInsufficientFunds)
}
6 changes: 6 additions & 0 deletions testutil/mocks/contractmanager/types/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions testutil/mocks/interchaintxs/types/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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