Skip to content

Commit

Permalink
test: Add erc20/MsgConvertERC20 test
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Jul 10, 2024
1 parent c68de59 commit 200a4ef
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions app/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ package app
import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
protov2 "google.golang.org/protobuf/proto"

"cosmossdk.io/x/tx/signing"
coinswapapi "github.com/Canto-Network/Canto/v7/api/canto/coinswap/v1"
coinswaptypes "github.com/Canto-Network/Canto/v7/x/coinswap/types"
"github.com/cosmos/cosmos-sdk/codec/address"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
protov2 "google.golang.org/protobuf/proto"
)

func TestMsgSwapOrderSigners(t *testing.T) {
coinswapv1 "github.com/Canto-Network/Canto/v7/api/canto/coinswap/v1"
erc20v1 "github.com/Canto-Network/Canto/v7/api/canto/erc20/v1"
coinswaptypes "github.com/Canto-Network/Canto/v7/x/coinswap/types"
erc20types "github.com/Canto-Network/Canto/v7/x/erc20/types"
)

func TestDefineCustomGetSigners(t *testing.T) {
addr := "canto13e9t6s6ra8caz5zzmy5w9v23dm2dr5nrr9sz03"
accAddr, err := sdk.AccAddressFromBech32(addr)
require.NoError(t, err)
Expand All @@ -26,7 +30,8 @@ func TestMsgSwapOrderSigners(t *testing.T) {
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
}
signingOptions.DefineCustomGetSigners(protov2.MessageName(&coinswapapi.MsgSwapOrder{}), coinswaptypes.CreateGetSignersFromMsgSwapOrderV2(&signingOptions))
signingOptions.DefineCustomGetSigners(protov2.MessageName(&erc20v1.MsgConvertERC20{}), erc20types.GetSignersFromMsgConvertERC20V2)
signingOptions.DefineCustomGetSigners(protov2.MessageName(&coinswapv1.MsgSwapOrder{}), coinswaptypes.CreateGetSignersFromMsgSwapOrderV2(&signingOptions))

ctx, err := signing.NewContext(signingOptions)
require.NoError(t, err)
Expand All @@ -37,12 +42,19 @@ func TestMsgSwapOrderSigners(t *testing.T) {
want [][]byte
wantErr bool
}{
{
name: "MsgConvertERC20",
msg: &erc20v1.MsgConvertERC20{
Sender: common.BytesToAddress(accAddr.Bytes()).String(),
},
want: [][]byte{accAddr.Bytes()},
},
{
name: "MsgSwapOrder",
msg: &coinswapapi.MsgSwapOrder{
Input: &coinswapapi.Input{Address: addr},
msg: &coinswapv1.MsgSwapOrder{
Input: &coinswapv1.Input{Address: addr},
},
want: [][]byte{accAddr},
want: [][]byte{accAddr.Bytes()},
},
}
for _, test := range tests {
Expand Down

0 comments on commit 200a4ef

Please sign in to comment.