From cce1ef52462a2af3fc0483c508ebe93ad9eeddc2 Mon Sep 17 00:00:00 2001 From: "shiki.takahashi" Date: Thu, 7 Jul 2022 13:52:01 +0900 Subject: [PATCH] fix: change ContractAddrLen --- .../applications/transfer/types/msgs_test.go | 2 +- x/ibc/core/04-channel/types/msgs_test.go | 2 +- x/ibc/core/24-host/validate.go | 6 ++++- x/wasm/client/cli/genesis_msg_test.go | 4 ++-- x/wasm/keeper/keeper_test.go | 24 +++++++++---------- x/wasm/keeper/proposal_integration_test.go | 4 ++-- x/wasm/module_test.go | 10 ++++---- x/wasm/types/keys_test.go | 12 ++++++---- x/wasm/types/types.go | 2 +- x/wasm/types/types_test.go | 3 +-- 10 files changed, 37 insertions(+), 32 deletions(-) diff --git a/x/ibc/applications/transfer/types/msgs_test.go b/x/ibc/applications/transfer/types/msgs_test.go index a99603784a..3014befca1 100644 --- a/x/ibc/applications/transfer/types/msgs_test.go +++ b/x/ibc/applications/transfer/types/msgs_test.go @@ -16,7 +16,7 @@ const ( validPort = "testportid" invalidPort = "(invalidport1)" invalidShortPort = "p" - invalidLongPort = "invalidlongportinvalidlongportinvalidlongportinvalidlongportinvalid" + invalidLongPort = "invalidlongportinvalidlongportinvalidlongportidinvalidlongportidinvalidinvalidlongportinvalidlongportinvalidlongportinvalidlongport" validChannel = "testchannel" invalidChannel = "(invalidchannel1)" diff --git a/x/ibc/core/04-channel/types/msgs_test.go b/x/ibc/core/04-channel/types/msgs_test.go index 7637c10da0..db2388d958 100644 --- a/x/ibc/core/04-channel/types/msgs_test.go +++ b/x/ibc/core/04-channel/types/msgs_test.go @@ -33,7 +33,7 @@ const ( // invalid constants used for testing invalidPort = "(invalidport1)" invalidShortPort = "p" - invalidLongPort = "invalidlongportinvalidlongportinvalidlongportidinvalidlongportidinvalid" + invalidLongPort = "invalidlongportinvalidlongportinvalidlongportidinvalidlongportidinvalidinvalidlongportinvalidlongportinvalidlongportinvalidlongport" invalidChannel = "(invalidchannel1)" invalidShortChannel = "invalid" diff --git a/x/ibc/core/24-host/validate.go b/x/ibc/core/24-host/validate.go index f0802ff826..eda17cfd8a 100644 --- a/x/ibc/core/24-host/validate.go +++ b/x/ibc/core/24-host/validate.go @@ -16,6 +16,10 @@ import ( // adjusting this restriction. const DefaultMaxCharacterLength = 64 +// DefaultMaxPortCharacterLength defines the default maximum character length used +// in validation of port identifiers. +var DefaultMaxPortCharacterLength = 128 + // IsValidID defines regular expression to check if the string consist of // characters in one of the following categories only: // - Alphanumeric @@ -80,7 +84,7 @@ func ChannelIdentifierValidator(id string) error { // A valid Identifier must be between 2-64 characters and only contain alphanumeric and some allowed // special characters (see IsValidID). func PortIdentifierValidator(id string) error { - return defaultIdentifierValidator(id, 2, DefaultMaxCharacterLength) + return defaultIdentifierValidator(id, 2, DefaultMaxPortCharacterLength) } // NewPathValidator takes in a Identifier Validator function and returns diff --git a/x/wasm/client/cli/genesis_msg_test.go b/x/wasm/client/cli/genesis_msg_test.go index fb03d49af2..0ab60965d4 100644 --- a/x/wasm/client/cli/genesis_msg_test.go +++ b/x/wasm/client/cli/genesis_msg_test.go @@ -364,7 +364,7 @@ func TestInstantiateContractCmd(t *testing.T) { } func TestExecuteContractCmd(t *testing.T) { - const firstContractAddress = "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j" + const firstContractAddress = "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8" minimalWasmGenesis := types.GenesisState{ Params: types.DefaultParams(), } @@ -446,7 +446,7 @@ func TestExecuteContractCmd(t *testing.T) { }, mutator: func(cmd *cobra.Command) { // See TestBuildContractAddress in keeper_test.go - cmd.SetArgs([]string{"link1mujpjkwhut9yjw4xueyugc02evfv46y0qnephq", `{}`}) + cmd.SetArgs([]string{"link1mujpjkwhut9yjw4xueyugc02evfv46y0dtmnz4lh8xxkkdapym9skz93hr", `{}`}) flagSet := cmd.Flags() flagSet.Set("run-as", myWellFundedAccount) }, diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index a43590fc16..5b2d78f271 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -394,11 +394,11 @@ func TestInstantiate(t *testing.T) { // create with no balance is also legal gotContractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx.WithEventManager(em), codeID, creator, "", initMsgBz, "demo contract 1", nil) require.NoError(t, err) - require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", gotContractAddr.String()) + require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", gotContractAddr.String()) gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x18cb3), gasAfter-gasBefore) + require.Equal(t, uint64(0x19aff), gasAfter-gasBefore) } // ensure it is stored properly @@ -595,7 +595,7 @@ func TestExecute(t *testing.T) { addr, _, err := keepers.ContractKeeper.Instantiate(ctx, contractID, creator, "", initMsgBz, "demo contract 3", deposit) require.NoError(t, err) - require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", addr.String()) + require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", addr.String()) // ensure bob doesn't exist bobAcct := accKeeper.GetAccount(ctx, bob) @@ -632,7 +632,7 @@ func TestExecute(t *testing.T) { // make sure gas is properly deducted from ctx gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x16f60), gasAfter-gasBefore) + require.Equal(t, uint64(0x1739a), gasAfter-gasBefore) } // ensure bob now exists and got both payments released bobAcct = accKeeper.GetAccount(ctx, bob) @@ -1277,7 +1277,7 @@ func TestSudo(t *testing.T) { addr, _, err := keepers.ContractKeeper.Instantiate(ctx, contractID, creator, "", initMsgBz, "demo contract 3", deposit) require.NoError(t, err) - require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", addr.String()) + require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", addr.String()) // the community is broke _, _, community := keyPubAddr() @@ -1497,7 +1497,7 @@ func TestExecuteManualInactiveContractFailure(t *testing.T) { addr, _, err := keeper.Instantiate(ctx, contractID, creator, "", initMsgBz, "demo contract 3", deposit) require.NoError(t, err) - require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", addr.String()) + require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", addr.String()) // execute inactive contract through manual err = keeper.UpdateContractStatus(ctx, addr, creator, types.ContractStatusInactive) @@ -1762,13 +1762,13 @@ func TestPinnedContractLoops(t *testing.T) { }, }, 0, nil } - ctx = ctx.WithGasMeter(sdk.NewGasMeter(20000)) + ctx = ctx.WithGasMeter(sdk.NewGasMeter(10000)) require.PanicsWithValue(t, sdk.ErrorOutOfGas{Descriptor: "ReadFlat"}, func() { _, err := k.execute(ctx, example.Contract, RandomAccountAddress(t), anyMsg, nil) require.NoError(t, err) }) assert.True(t, ctx.GasMeter().IsOutOfGas()) - assert.Greater(t, loops, 2) + assert.Greater(t, loops, 1) } @@ -1963,12 +1963,12 @@ func TestBuildContractAddress(t *testing.T) { "initial contract": { srcCodeID: 1, srcInstanceID: 1, - expectedAddr: "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", + expectedAddr: "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", }, "demo value": { srcCodeID: 1, srcInstanceID: 100, - expectedAddr: "link1mujpjkwhut9yjw4xueyugc02evfv46y0qnephq", + expectedAddr: "link1mujpjkwhut9yjw4xueyugc02evfv46y0dtmnz4lh8xxkkdapym9skz93hr", }, "both below max": { srcCodeID: math.MaxUint32 - 1, @@ -1981,12 +1981,12 @@ func TestBuildContractAddress(t *testing.T) { "codeID > max u32": { srcCodeID: math.MaxUint32 + 1, srcInstanceID: 17, - expectedAddr: "link1673hrexz4h6s0ft04l96ygq667djzh2ne27tt5", + expectedAddr: "link1673hrexz4h6s0ft04l96ygq667djzh2nsr335kstjp49x5dk6rps5267na", }, "instanceID > max u32": { srcCodeID: 22, srcInstanceID: math.MaxUint32 + 1, - expectedAddr: "link10q3pgfvmeyy0veekgtqhxujxkhz0vm9z06c5ml", + expectedAddr: "link10q3pgfvmeyy0veekgtqhxujxkhz0vm9zmalqgc7evrhj68q3l62q7nceel", }, } for name, spec := range specs { diff --git a/x/wasm/keeper/proposal_integration_test.go b/x/wasm/keeper/proposal_integration_test.go index 2293a9c351..45fbcc4593 100644 --- a/x/wasm/keeper/proposal_integration_test.go +++ b/x/wasm/keeper/proposal_integration_test.go @@ -101,7 +101,7 @@ func TestInstantiateProposal(t *testing.T) { require.NoError(t, err) // then - contractAddr := "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j" + contractAddr := "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8" err = sdk.ValidateAccAddress(contractAddr) require.NoError(t, err) @@ -181,7 +181,7 @@ func TestInstantiateProposal_NoAdmin(t *testing.T) { require.NoError(t, err) // then - contractAddr := "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j" + contractAddr := "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8" err = sdk.ValidateAccAddress(contractAddr) require.NoError(t, err) diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index 323e4a920f..c1851aefb7 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -179,7 +179,7 @@ func TestHandleInstantiate(t *testing.T) { require.NoError(t, err) contractBech32Addr := parseInitResponse(t, res.Data) - assert.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", contractBech32Addr) + assert.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", contractBech32Addr) // this should be standard x/wasm init event, nothing from contract assert.Equal(t, 3, len(res.Events), prettyEvents(res.Events)) assert.Equal(t, "message", res.Events[0].Type) @@ -232,7 +232,7 @@ func TestHandleStoreAndInstantiate(t *testing.T) { codeID, contractBech32Addr := parseStoreAndInitResponse(t, res.Data) require.Equal(t, uint64(1), codeID) - require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", contractBech32Addr) + require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", contractBech32Addr) // this should be standard x/wasm init event, nothing from contract require.Equal(t, 4, len(res.Events), prettyEvents(res.Events)) assert.Equal(t, "store_code", res.Events[0].Type) @@ -270,7 +270,7 @@ func TestErrorsCreateAndInstantiate(t *testing.T) { invalidInitMsgBz, err := json.Marshal(emptyMsg{}) - expectedContractBech32Addr := "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j" + expectedContractBech32Addr := "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8" // test cases cases := map[string]struct { @@ -413,7 +413,7 @@ func TestHandleExecute(t *testing.T) { require.NoError(t, err) contractBech32Addr := parseInitResponse(t, res.Data) - assert.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", contractBech32Addr) + assert.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", contractBech32Addr) // this should be standard x/wasm init event, plus a bank send event (2), with no custom contract events assert.Equal(t, 6, len(res.Events), prettyEvents(res.Events)) assert.Equal(t, "message", res.Events[0].Type) @@ -551,7 +551,7 @@ func TestHandleExecuteEscrow(t *testing.T) { res, err = h(data.ctx, &initCmd) require.NoError(t, err) contractBech32Addr := parseInitResponse(t, res.Data) - require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j", contractBech32Addr) + require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", contractBech32Addr) handleMsg := map[string]interface{}{ "release": map[string]interface{}{}, diff --git a/x/wasm/types/keys_test.go b/x/wasm/types/keys_test.go index 01887f6713..60664636eb 100644 --- a/x/wasm/types/keys_test.go +++ b/x/wasm/types/keys_test.go @@ -46,11 +46,13 @@ func TestGetContractCodeHistoryElementPrefix(t *testing.T) { addr = sdk.BytesToAccAddress(bytes.Repeat([]byte{4}, ContractAddrLen)) got = GetContractCodeHistoryElementPrefix(addr) exp = []byte{5, // prefix - 0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x71, 0x73, 0x7a, 0x71, - 0x67, 0x70, 0x71, 0x79, 0x71, 0x73, 0x7a, 0x71, 0x67, - 0x70, 0x71, 0x79, 0x71, 0x73, 0x7a, 0x71, 0x67, 0x70, - 0x71, 0x79, 0x71, 0x73, 0x7a, 0x71, 0x67, 0x70, 0x71, - 0x79, 0x68, 0x65, 0x70, 0x61, 0x73, 0x6c, + 0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x71, 0x73, 0x7a, 0x71, 0x67, + 0x70, 0x71, 0x79, 0x71, 0x73, 0x7a, 0x71, 0x67, 0x70, 0x71, + 0x79, 0x71, 0x73, 0x7a, 0x71, 0x67, 0x70, 0x71, 0x79, 0x71, + 0x73, 0x7a, 0x71, 0x67, 0x70, 0x71, 0x79, 0x71, 0x73, 0x7a, + 0x71, 0x67, 0x70, 0x71, 0x79, 0x71, 0x73, 0x7a, 0x71, 0x67, + 0x70, 0x71, 0x79, 0x71, 0x73, 0x7a, 0x71, 0x77, 0x64, 0x6d, + 0x7a, 0x64, 0x75, } assert.Equal(t, exp, got) } diff --git a/x/wasm/types/types.go b/x/wasm/types/types.go index f873642d8c..3668806686 100644 --- a/x/wasm/types/types.go +++ b/x/wasm/types/types.go @@ -20,7 +20,7 @@ const ( defaultContractDebugMode = false // ContractAddrLen defines a valid address length for contracts - ContractAddrLen = 20 + ContractAddrLen = 32 // SDKAddrLen defines a valid address length that was used in sdk address generation SDKAddrLen = 20 ) diff --git a/x/wasm/types/types_test.go b/x/wasm/types/types_test.go index 4131fb837a..267884704d 100644 --- a/x/wasm/types/types_test.go +++ b/x/wasm/types/types_test.go @@ -340,8 +340,7 @@ func TestVerifyAddressLen(t *testing.T) { expErr bool }{ "valid contract address": { - src: bytes.Repeat([]byte{1}, 32), - expErr: true, + src: bytes.Repeat([]byte{1}, 32), }, "valid legacy address": { src: bytes.Repeat([]byte{1}, 20),