Skip to content

Commit

Permalink
test: add configuration for Bech32 prefixes and CoinType
Browse files Browse the repository at this point in the history
  • Loading branch information
da1suk8 committed Mar 28, 2024
1 parent c1844ef commit 6dcb1b5
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 12 deletions.
8 changes: 8 additions & 0 deletions x/wasm/client/cli/gov_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions x/wasm/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions x/wasm/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/testdata/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
ChecksumHackatom = "3f4cd47c39c57fe1733fb41ed176eebd9d5c67baf5df8a1eeda1455e758f8514"
ChecksumHackatom = "470c5b703a682f778b8b088d48169b8d6e43f7f44ac70316692cdbe69e6605e3"
)

var (
Expand Down
21 changes: 21 additions & 0 deletions x/wasm/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions x/wasm/types/proposal_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions x/wasm/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 13 additions & 11 deletions x/wasmplus/types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6dcb1b5

Please sign in to comment.