From c6c8000546b82897f9ab59716a284fd8954af638 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 13 Dec 2024 11:42:31 -0500 Subject: [PATCH] add protocol v2 --- pkg/memo/memo_test.go | 2 ++ testutil/sample/crosschain.go | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pkg/memo/memo_test.go b/pkg/memo/memo_test.go index 4eabd6a18f..59a135f697 100644 --- a/pkg/memo/memo_test.go +++ b/pkg/memo/memo_test.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" "github.com/zeta-chain/node/pkg/memo" + "github.com/zeta-chain/node/testutil/sample" crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" ) @@ -324,6 +325,7 @@ func Test_DecodeLegacyMemoHex(t *testing.T) { {"empty msg", "", common.Address{}, nil, false}, {"invalid hex", "invalidHex", common.Address{}, nil, true}, {"short msg", "1a2b3c4d5e6f708192a3b4c5d6e7f808", common.Address{}, expectedShortMsgResult, false}, + {"random message", sample.EthAddress().String(), common.Address{}, nil, true}, } for _, tt := range tests { diff --git a/testutil/sample/crosschain.go b/testutil/sample/crosschain.go index db0b943964..a545429616 100644 --- a/testutil/sample/crosschain.go +++ b/testutil/sample/crosschain.go @@ -370,19 +370,26 @@ func InboundVoteFromRand(from, to int64, r *rand.Rand, asset string) types.MsgVo Receiver: EthAddressFromRand(r).String(), ReceiverChain: to, Amount: math.NewUint(r.Uint64()), - Message: "95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5", + Message: EthAddressFromRand(r).String(), InboundBlockHeight: r.Uint64(), CallOptions: &types.CallOptions{ GasLimit: 1000000000, }, - InboundHash: ethcommon.BytesToHash(RandomBytes(r)).String(), - CoinType: coinType, - TxOrigin: EthAddressFromRand(r).String(), - Asset: asset, - EventIndex: r.Uint64(), + InboundHash: ethcommon.BytesToHash(RandomBytes(r)).String(), + CoinType: coinType, + TxOrigin: EthAddressFromRand(r).String(), + Asset: asset, + EventIndex: r.Uint64(), + ProtocolContractVersion: ProtocolVersionFromRand(r), } } +func ProtocolVersionFromRand(r *rand.Rand) types.ProtocolContractVersion { + versions := []types.ProtocolContractVersion{types.ProtocolContractVersion_V1, types.ProtocolContractVersion_V2} + return versions[r.Intn(len(versions))] + +} + func CoinTypeFromRand(r *rand.Rand) coin.CoinType { coinTypes := []coin.CoinType{coin.CoinType_Gas, coin.CoinType_ERC20, coin.CoinType_Zeta} coinType := coinTypes[r.Intn(len(coinTypes))] @@ -441,8 +448,9 @@ func CCTXfromRand(r *rand.Rand, IsAbortRefunded: false, Status: types.CctxStatus_PendingOutbound, }, - InboundParams: inbound, - OutboundParams: []*types.OutboundParams{outbound}, + InboundParams: inbound, + OutboundParams: []*types.OutboundParams{outbound}, + ProtocolContractVersion: ProtocolVersionFromRand(r), } return cctx }