Skip to content

Commit

Permalink
fix: change ContractAddrLen
Browse files Browse the repository at this point in the history
  • Loading branch information
shiki-tak committed Jul 7, 2022
1 parent f38b645 commit cce1ef5
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion x/ibc/applications/transfer/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
validPort = "testportid"
invalidPort = "(invalidport1)"
invalidShortPort = "p"
invalidLongPort = "invalidlongportinvalidlongportinvalidlongportinvalidlongportinvalid"
invalidLongPort = "invalidlongportinvalidlongportinvalidlongportidinvalidlongportidinvalidinvalidlongportinvalidlongportinvalidlongportinvalidlongport"

validChannel = "testchannel"
invalidChannel = "(invalidchannel1)"
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
// invalid constants used for testing
invalidPort = "(invalidport1)"
invalidShortPort = "p"
invalidLongPort = "invalidlongportinvalidlongportinvalidlongportidinvalidlongportidinvalid"
invalidLongPort = "invalidlongportinvalidlongportinvalidlongportidinvalidlongportidinvalidinvalidlongportinvalidlongportinvalidlongportinvalidlongport"

invalidChannel = "(invalidchannel1)"
invalidShortChannel = "invalid"
Expand Down
6 changes: 5 additions & 1 deletion x/ibc/core/24-host/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/client/cli/genesis_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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)
},
Expand Down
24 changes: 12 additions & 12 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

}

Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions x/wasm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestErrorsCreateAndInstantiate(t *testing.T) {

invalidInitMsgBz, err := json.Marshal(emptyMsg{})

expectedContractBech32Addr := "link14hj2tavq8fpesdwxxcu44rty3hh90vhud63e6j"
expectedContractBech32Addr := "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8"

// test cases
cases := map[string]struct {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{}{},
Expand Down
12 changes: 7 additions & 5 deletions x/wasm/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
3 changes: 1 addition & 2 deletions x/wasm/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit cce1ef5

Please sign in to comment.