From 6dcb1b52260b8765cca431f896942bd898300e20 Mon Sep 17 00:00:00 2001 From: Daisuke Iuchi <42408108+da1suk8@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:22:08 +0900 Subject: [PATCH] test: add configuration for Bech32 prefixes and CoinType This commit based on https://github.com/Finschia/finschia-sdk/blob/e62a33006bbe19f12309be75a2771c6623eea155/types/address.go#L23-L73 --- x/wasm/client/cli/gov_tx_test.go | 8 +++++++ x/wasm/client/cli/query_test.go | 36 ++++++++++++++++++++++++++++ x/wasm/client/cli/tx_test.go | 7 ++++++ x/wasm/keeper/testdata/contracts.go | 2 +- x/wasm/types/genesis_test.go | 21 ++++++++++++++++ x/wasm/types/proposal_legacy_test.go | 7 ++++++ x/wasm/types/types_test.go | 7 ++++++ x/wasmplus/types/tx_test.go | 24 ++++++++++--------- 8 files changed, 100 insertions(+), 12 deletions(-) diff --git a/x/wasm/client/cli/gov_tx_test.go b/x/wasm/client/cli/gov_tx_test.go index 138798b6f0..6fc9eab362 100644 --- a/x/wasm/client/cli/gov_tx_test.go +++ b/x/wasm/client/cli/gov_tx_test.go @@ -5,6 +5,7 @@ import ( "strings" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -13,6 +14,13 @@ import ( ) func TestParseAccessConfigUpdates(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + specs := map[string]struct { src []string exp []types.AccessConfigUpdate diff --git a/x/wasm/client/cli/query_test.go b/x/wasm/client/cli/query_test.go index f423efa3ec..7a32015fd1 100644 --- a/x/wasm/client/cli/query_test.go +++ b/x/wasm/client/cli/query_test.go @@ -23,6 +23,7 @@ import ( cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/Finschia/wasmd/x/wasm/types" @@ -199,6 +200,13 @@ func TestGetCmdQueryCodeInfo(t *testing.T) { } func TestGetCmdGetContractInfo(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + res := types.QueryContractInfoResponse{} bz, err := res.Marshal() require.NoError(t, err) @@ -241,6 +249,13 @@ func TestGetCmdGetContractState(t *testing.T) { } func TestGetCmdGetContractStateAll(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + res := types.QueryAllContractStateResponse{} bz, err := res.Marshal() require.NoError(t, err) @@ -269,6 +284,13 @@ func TestGetCmdGetContractStateAll(t *testing.T) { } func TestGetCmdGetContractStateRaw(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + res := types.QueryRawContractStateResponse{} bz, err := res.Marshal() require.NoError(t, err) @@ -298,6 +320,13 @@ func TestGetCmdGetContractStateRaw(t *testing.T) { } func TestGetCmdGetContractStateSmart(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + res := types.QueryRawContractStateResponse{} bz, err := res.Marshal() require.NoError(t, err) @@ -327,6 +356,13 @@ func TestGetCmdGetContractStateSmart(t *testing.T) { } func TestGetCmdGetContractHistory(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + res := types.QueryContractHistoryResponse{} bz, err := res.Marshal() require.NoError(t, err) diff --git a/x/wasm/client/cli/tx_test.go b/x/wasm/client/cli/tx_test.go index fa7722372a..f0972159a6 100644 --- a/x/wasm/client/cli/tx_test.go +++ b/x/wasm/client/cli/tx_test.go @@ -77,6 +77,13 @@ func TestParseVerificationFlags(t *testing.T) { } func TestParseAccessConfigFlags(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + specs := map[string]struct { args []string expCfg *types.AccessConfig diff --git a/x/wasm/keeper/testdata/contracts.go b/x/wasm/keeper/testdata/contracts.go index ad0f290e5f..c695aca47d 100644 --- a/x/wasm/keeper/testdata/contracts.go +++ b/x/wasm/keeper/testdata/contracts.go @@ -9,7 +9,7 @@ import ( ) const ( - ChecksumHackatom = "3f4cd47c39c57fe1733fb41ed176eebd9d5c67baf5df8a1eeda1455e758f8514" + ChecksumHackatom = "470c5b703a682f778b8b088d48169b8d6e43f7f44ac70316692cdbe69e6605e3" ) var ( diff --git a/x/wasm/types/genesis_test.go b/x/wasm/types/genesis_test.go index 9eaf14f6b4..ce75a00523 100644 --- a/x/wasm/types/genesis_test.go +++ b/x/wasm/types/genesis_test.go @@ -18,6 +18,13 @@ import ( const invalidAddress = "invalid address" func TestValidateGenesisState(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + specs := map[string]struct { srcMutator func(*GenesisState) expError bool @@ -64,6 +71,13 @@ func TestValidateGenesisState(t *testing.T) { } func TestCodeValidateBasic(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + specs := map[string]struct { srcMutator func(*Code) expError bool @@ -114,6 +128,13 @@ func TestCodeValidateBasic(t *testing.T) { } func TestContractValidateBasic(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + specs := map[string]struct { srcMutator func(*Contract) expError bool diff --git a/x/wasm/types/proposal_legacy_test.go b/x/wasm/types/proposal_legacy_test.go index 85d747ba7c..e3b46fa1c8 100644 --- a/x/wasm/types/proposal_legacy_test.go +++ b/x/wasm/types/proposal_legacy_test.go @@ -98,6 +98,13 @@ func TestValidateProposalCommons(t *testing.T) { } func TestValidateStoreCodeProposal(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + var anyAddress sdk.AccAddress = bytes.Repeat([]byte{0x0}, ContractAddrLen) specs := map[string]struct { diff --git a/x/wasm/types/types_test.go b/x/wasm/types/types_test.go index 4a1b6b5a33..56b5148444 100644 --- a/x/wasm/types/types_test.go +++ b/x/wasm/types/types_test.go @@ -19,6 +19,13 @@ import ( ) func TestContractInfoValidateBasic(t *testing.T) { + config := sdk.GetConfig() + config.SetBech32PrefixForAccount("link", "pub") + config.SetBech32PrefixForValidator("link", "pub") + config.SetBech32PrefixForConsensusNode("link", "pub") + config.SetCoinType(438) + config.Seal() + specs := map[string]struct { srcMutator func(*ContractInfo) expError bool diff --git a/x/wasmplus/types/tx_test.go b/x/wasmplus/types/tx_test.go index 158f5769d9..9eb5678a2f 100644 --- a/x/wasmplus/types/tx_test.go +++ b/x/wasmplus/types/tx_test.go @@ -151,20 +151,22 @@ func TestMsgJsonSignBytes(t *testing.T) { InstantiatePermission: &wasmTypes.AccessConfig{Permission: wasmTypes.AccessTypeAnyOfAddresses, Addresses: []string{"address1", "address2"}}, Admin: "admin1", Label: "My", Msg: wasmTypes.RawContractMessage(myInnerMsg), Funds: sdk.Coins{{Denom: "denom1", Amount: sdkmath.NewInt(1)}}, }, - exp: ` -{ - "type":"wasm/MsgStoreCodeAndInstantiateContract", - "value": {"admin":"admin1","funds":[{"amount":"1","denom":"denom1"}],"instantiate_permission":{"addresses":["address1","address2"], - "permission":"AnyOfAddresses"},"label":"My","msg":{"foo":"bar"},"sender":"sender1","wasm_byte_code":"WUVMTE9XIFNVQk1BUklORQ=="} -}`, + exp: `{ + "admin": "admin1", + "funds": [{"amount": "1", "denom": "denom1"}], + "instantiate_permission": { + "addresses": ["address1", "address2"], + "permission": "AnyOfAddresses" + }, + "label": "My", + "msg": {"foo": "bar"}, + "sender": "sender1", + "wasm_byte_code": "WUVMTE9XIFNVQk1BUklORQ==" + }`, }, "MsgInstantiateContract with minimum field": { src: &MsgStoreCodeAndInstantiateContract{}, - exp: ` -{ - "type":"wasm/MsgStoreCodeAndInstantiateContract", - "value": {"funds":[]} -}`, + exp: `{"funds": []}`, }, } for name, spec := range specs {