Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed May 9, 2024
1 parent 06c2272 commit 37c57bc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion testutil/network/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func AddCrosschainData(t *testing.T, n int, genesisState map[string]json.RawMess

for i := 0; i < n; i++ {
inboundHashToCctx := types.InboundHashToCctx{
inboundHash: strconv.Itoa(i),
InboundHash: strconv.Itoa(i),
}
nullify.Fill(&inboundHashToCctx)
state.InboundHashToCctxList = append(state.InboundHashToCctxList, inboundHashToCctx)
Expand Down
8 changes: 4 additions & 4 deletions x/crosschain/keeper/inbound_hash_to_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func createNInboundHashToCctx(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.InboundHashToCctx {
items := make([]types.InboundHashToCctx, n)
for i := range items {
items[i].inboundHash = strconv.Itoa(i)
items[i].InboundHash = strconv.Itoa(i)

keeper.SetInboundHashToCctx(ctx, items[i])
}
Expand All @@ -28,7 +28,7 @@ func TestInTxHashToCctxGet(t *testing.T) {
items := createNInboundHashToCctx(keeper, ctx, 10)
for _, item := range items {
rst, found := keeper.GetInboundHashToCctx(ctx,
item.inboundHash,
item.InboundHash,
)
require.True(t, found)
require.Equal(t,
Expand All @@ -42,10 +42,10 @@ func TestInTxHashToCctxRemove(t *testing.T) {
items := createNInboundHashToCctx(keeper, ctx, 10)
for _, item := range items {
keeper.RemoveInboundHashToCctx(ctx,
item.inboundHash,
item.InboundHash,
)
_, found := keeper.GetInboundHashToCctx(ctx,
item.inboundHash,
item.InboundHash,
)
require.False(t, found)
}
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/types/message_vote_inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestMsgVoteInbound_Digest(t *testing.T) {
ReceiverChain: 42,
Amount: math.NewUint(42),
Message: sample.String(),
inboundHash: sample.String(),
InboundHash: sample.String(),
InboundBlockHeight: 42,
GasLimit: 42,
CoinType: coin.CoinType_Zeta,
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestMsgVoteInbound_Digest(t *testing.T) {

// in tx hash used
msg2 = msg
msg2.inboundHash = sample.StringRandom(r, 32)
msg2.InboundHash = sample.StringRandom(r, 32)
hash2 = msg2.Digest()
require.NotEqual(t, hash, hash2, "in tx hash should change hash")

Expand Down
17 changes: 8 additions & 9 deletions zetaclient/evm/outbounds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func Test_IsOutboundProcessed(t *testing.T) {
cctx := testutils.LoadCctxByNonce(t, chainID, nonce)
receipt := testutils.LoadEVMOutboundReceipt(t, chainID, outtxHash, coin.CoinType_Zeta, testutils.EventZetaReceived)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, chainID, nonce, testutils.EventZetaReceived)

t.Run("should post vote and return true if outtx is processed", func(t *testing.T) {
// create evm client and set outtx and receipt
client := MockEVMClient(t, chain, nil, nil, nil, nil, 1, chainParam)
Expand Down Expand Up @@ -148,7 +147,7 @@ func Test_PostVoteOutbound(t *testing.T) {
chain := chains.EthChain
nonce := uint64(9718)
coinType := coin.CoinType_Zeta
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboudNReceipt(t, chain.ChainId, nonce, testutils.EventZetaReceived)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, chain.ChainId, nonce, testutils.EventZetaReceived)

t.Run("post vote outbound successfully", func(t *testing.T) {
// the amount and status to be used for vote
Expand Down Expand Up @@ -346,7 +345,7 @@ func Test_ParseOutboundReceivedValue(t *testing.T) {
// https://etherscan.io/tx/0x81342051b8a85072d3e3771c1a57c7bdb5318e8caf37f5a687b7a91e50a7257f
nonce := uint64(9718)
coinType := coin.CoinType_Zeta
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboudNReceipt(t, chainID, nonce, testutils.EventZetaReceived)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, chainID, nonce, testutils.EventZetaReceived)
params := cctx.GetCurrentOutboundParam()
value, status, err := evm.ParseOutboundReceivedValue(cctx, receipt, outtx, coinType, connectorAddr, connector, custodyAddr, custody)
require.NoError(t, err)
Expand All @@ -360,7 +359,7 @@ func Test_ParseOutboundReceivedValue(t *testing.T) {
nonce := uint64(14)
coinType := coin.CoinType_Zeta
connectorLocal, connectorAddrLocal, custodyLocal, custodyAddrLocal := getContractsByChainID(localChainID)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboudNReceipt(t, localChainID, nonce, testutils.EventZetaReverted)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, localChainID, nonce, testutils.EventZetaReverted)
params := cctx.GetCurrentOutboundParam()
value, status, err := evm.ParseOutboundReceivedValue(
cctx, receipt, outtx, coinType, connectorAddrLocal, connectorLocal, custodyAddrLocal, custodyLocal)
Expand All @@ -373,7 +372,7 @@ func Test_ParseOutboundReceivedValue(t *testing.T) {
// https://etherscan.io/tx/0xd2eba7ac3da1b62800165414ea4bcaf69a3b0fb9b13a0fc32f4be11bfef79146
nonce := uint64(8014)
coinType := coin.CoinType_ERC20
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboudNReceipt(t, chainID, nonce, testutils.EventERC20Withdraw)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, chainID, nonce, testutils.EventERC20Withdraw)
params := cctx.GetCurrentOutboundParam()
value, status, err := evm.ParseOutboundReceivedValue(cctx, receipt, outtx, coinType, connectorAddr, connector, custodyAddr, custody)
require.NoError(t, err)
Expand All @@ -385,7 +384,7 @@ func Test_ParseOutboundReceivedValue(t *testing.T) {
// https://etherscan.io/tx/0xd13b593eb62b5500a00e288cc2fb2c8af1339025c0e6bc6183b8bef2ebbed0d3
nonce := uint64(7260)
coinType := coin.CoinType_Gas
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboudNReceipt(t, chainID, nonce, "")
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, chainID, nonce, "")
params := cctx.GetCurrentOutboundParam()
value, status, err := evm.ParseOutboundReceivedValue(cctx, receipt, outtx, coinType, connectorAddr, connector, custodyAddr, custody)
require.NoError(t, err)
Expand All @@ -397,7 +396,7 @@ func Test_ParseOutboundReceivedValue(t *testing.T) {
// https://etherscan.io/tx/0x81342051b8a85072d3e3771c1a57c7bdb5318e8caf37f5a687b7a91e50a7257f
nonce := uint64(9718)
coinType := coin.CoinType(5) // unknown coin type
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboudNReceipt(t, chainID, nonce, testutils.EventZetaReceived)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, chainID, nonce, testutils.EventZetaReceived)
value, status, err := evm.ParseOutboundReceivedValue(cctx, receipt, outtx, coinType, connectorAddr, connector, custodyAddr, custody)
require.ErrorContains(t, err, "unknown coin type")
require.Nil(t, value)
Expand All @@ -408,7 +407,7 @@ func Test_ParseOutboundReceivedValue(t *testing.T) {
// https://etherscan.io/tx/0x81342051b8a85072d3e3771c1a57c7bdb5318e8caf37f5a687b7a91e50a7257f
nonce := uint64(9718)
coinType := coin.CoinType_Zeta
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboudNReceipt(t, chainID, nonce, testutils.EventZetaReceived)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, chainID, nonce, testutils.EventZetaReceived)

// use an arbitrary address to make event parsing fail
fakeConnectorAddress := sample.EthAddress()
Expand All @@ -422,7 +421,7 @@ func Test_ParseOutboundReceivedValue(t *testing.T) {
// https://etherscan.io/tx/0xd2eba7ac3da1b62800165414ea4bcaf69a3b0fb9b13a0fc32f4be11bfef79146
nonce := uint64(8014)
coinType := coin.CoinType_ERC20
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboudNReceipt(t, chainID, nonce, testutils.EventERC20Withdraw)
cctx, outtx, receipt := testutils.LoadEVMCctxNOutboundNReceipt(t, chainID, nonce, testutils.EventERC20Withdraw)

// use an arbitrary address to make event parsing fail
fakeCustodyAddress := sample.EthAddress()
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/testutils/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ func LoadEVMOutboundNReceipt(
return tx, receipt
}

// LoadEVMCctxNOutboudNReceipt loads archived cctx, outtx and receipt from file
func LoadEVMCctxNOutboudNReceipt(
// LoadEVMCctxNOutboundNReceipt loads archived cctx, outtx and receipt from file
func LoadEVMCctxNOutboundNReceipt(
t *testing.T,
chainID int64,
nonce uint64,
Expand Down

0 comments on commit 37c57bc

Please sign in to comment.