Skip to content

Commit

Permalink
fix tracker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Mar 11, 2024
1 parent 4457358 commit fc6ceaa
Show file tree
Hide file tree
Showing 2 changed files with 315 additions and 304 deletions.
147 changes: 74 additions & 73 deletions x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,79 +43,6 @@ func setupVerificationParams(zk keepertest.ZetaKeepers, ctx sdk.Context, tx_inde
}

func TestMsgServer_AddToInTxTracker(t *testing.T) {
t.Skip("add proof based tracker with correct proof", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)

chainID := int64(5)

txIndex, block, header, headerRLP, proof, tx, err := sample.Proof()
require.NoError(t, err)
setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block)
msgServer := keeper.NewMsgServerImpl(*k)

_, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{
Creator: sample.AccAddress(),
ChainId: chainID,
TxHash: tx.Hash().Hex(),
CoinType: common.CoinType_Zeta,
Proof: proof,
BlockHash: block.Hash().Hex(),
TxIndex: txIndex,
})
require.NoError(t, err)
_, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex())
require.True(t, found)
})

t.Skip("fail to add proof based tracker with wrong tx hash", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)

chainID := getValidEthChainID(t)

txIndex, block, header, headerRLP, proof, tx, err := sample.Proof()
require.NoError(t, err)
setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block)
msgServer := keeper.NewMsgServerImpl(*k)

_, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{
Creator: sample.AccAddress(),
ChainId: chainID,
TxHash: "fake_hash",
CoinType: common.CoinType_Zeta,
Proof: proof,
BlockHash: block.Hash().Hex(),
TxIndex: txIndex,
})
require.ErrorIs(t, err, types.ErrTxBodyVerificationFail)
_, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex())
require.False(t, found)
})

t.Skip("fail to add proof based tracker with wrong chain id", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)

chainID := getValidEthChainID(t)

txIndex, block, header, headerRLP, proof, tx, err := sample.Proof()
require.NoError(t, err)
setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block)

msgServer := keeper.NewMsgServerImpl(*k)

_, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{
Creator: sample.AccAddress(),
ChainId: 97,
TxHash: tx.Hash().Hex(),
CoinType: common.CoinType_Zeta,
Proof: proof,
BlockHash: block.Hash().Hex(),
TxIndex: txIndex,
})
require.ErrorIs(t, err, observertypes.ErrSupportedChains)
_, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex())
require.False(t, found)
})

t.Run("fail normal user submit without proof", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
tx_hash := "string"
Expand Down Expand Up @@ -198,4 +125,78 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) {
_, found = k.GetInTxTracker(ctx, chainID, tx_hash)
require.False(t, found)
})

// Commented out as these tests don't work without using RPC
// TODO: Reenable these tests
// https://github.com/zeta-chain/node/issues/1875
//t.Run("add proof based tracker with correct proof", func(t *testing.T) {
// k, ctx, _, zk := keepertest.CrosschainKeeper(t)
//
// chainID := int64(5)
//
// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof()
// require.NoError(t, err)
// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block)
// msgServer := keeper.NewMsgServerImpl(*k)
//
// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{
// Creator: sample.AccAddress(),
// ChainId: chainID,
// TxHash: tx.Hash().Hex(),
// CoinType: common.CoinType_Zeta,
// Proof: proof,
// BlockHash: block.Hash().Hex(),
// TxIndex: txIndex,
// })
// require.NoError(t, err)
// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex())
// require.True(t, found)
//})
//t.Run("fail to add proof based tracker with wrong tx hash", func(t *testing.T) {
// k, ctx, _, zk := keepertest.CrosschainKeeper(t)
//
// chainID := getValidEthChainID(t)
//
// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof()
// require.NoError(t, err)
// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block)
// msgServer := keeper.NewMsgServerImpl(*k)
//
// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{
// Creator: sample.AccAddress(),
// ChainId: chainID,
// TxHash: "fake_hash",
// CoinType: common.CoinType_Zeta,
// Proof: proof,
// BlockHash: block.Hash().Hex(),
// TxIndex: txIndex,
// })
// require.ErrorIs(t, err, types.ErrTxBodyVerificationFail)
// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex())
// require.False(t, found)
//})
//t.Run("fail to add proof based tracker with wrong chain id", func(t *testing.T) {
// k, ctx, _, zk := keepertest.CrosschainKeeper(t)
//
// chainID := getValidEthChainID(t)
//
// txIndex, block, header, headerRLP, proof, tx, err := sample.Proof()
// require.NoError(t, err)
// setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block)
//
// msgServer := keeper.NewMsgServerImpl(*k)
//
// _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{
// Creator: sample.AccAddress(),
// ChainId: 97,
// TxHash: tx.Hash().Hex(),
// CoinType: common.CoinType_Zeta,
// Proof: proof,
// BlockHash: block.Hash().Hex(),
// TxIndex: txIndex,
// })
// require.ErrorIs(t, err, observertypes.ErrSupportedChains)
// _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex())
// require.False(t, found)
//})
}
Loading

0 comments on commit fc6ceaa

Please sign in to comment.