Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Apr 8, 2024
1 parent 1fab0d3 commit 3bfd237
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 291 deletions.
3 changes: 2 additions & 1 deletion testutil/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package sample

import (
"errors"
"github.com/zeta-chain/zetacore/pkg/chains"
"hash/fnv"
"math/rand"
"strconv"
"testing"

"github.com/zeta-chain/zetacore/pkg/chains"

sdkmath "cosmossdk.io/math"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
Expand Down
269 changes: 269 additions & 0 deletions x/crosschain/keeper/msg_server_add_to_intx_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,272 @@ func verifyProofAndInTxBody(ctx sdk.Context, k msgServer, msg *types.MsgAddToInT

return nil
}

// TODO: Implement tests for verifyOutTxBodyBTC
// https://github.com/zeta-chain/node/issues/1994

//func TestKeeper_VerifyEVMInTxBody(t *testing.T) {
//to := sample.EthAddress()
//tx := ethtypes.NewTx(&ethtypes.DynamicFeeTx{
// ChainID: big.NewInt(5),
// Nonce: 1,
// GasTipCap: nil,
// GasFeeCap: nil,
// Gas: 21000,
// To: &to,
// Value: big.NewInt(5),
// Data: nil,
//})
//
//t.Run("should error if msg tx hash not correct", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: "0x0",
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})

//t.Run("should error if msg chain id not correct", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: 1,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should error if not supported coin type", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_Cmd,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should error for cointype_zeta if chain params not found", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_Zeta,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should error for cointype_zeta if tx.to wrong", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{
// ConnectorContractAddress: sample.EthAddress().Hex(),
// }, true)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_Zeta,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should not error for cointype_zeta", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{
// ConnectorContractAddress: to.Hex(),
// }, true)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_Zeta,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.NoError(t, err)
//})
//
//t.Run("should error for cointype_erc20 if chain params not found", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{}, false)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_ERC20,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should error for cointype_erc20 if tx.to wrong", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{
// Erc20CustodyContractAddress: sample.EthAddress().Hex(),
// }, true)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_ERC20,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should not error for cointype_erc20", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(&observertypes.ChainParams{
// Erc20CustodyContractAddress: to.Hex(),
// }, true)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_ERC20,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.NoError(t, err)
//})
//
//t.Run("should error for cointype_gas if tss address not found", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{}, errors.New("err"))
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_Gas,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should error for cointype_gas if tss eth address is empty", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{
// Eth: "0x",
// }, nil)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_Gas,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should error for cointype_gas if tss eth address is wrong", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{
// Eth: sample.EthAddress().Hex(),
// }, nil)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_Gas,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.Error(t, err)
//})
//
//t.Run("should not error for cointype_gas", func(t *testing.T) {
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
// UseObserverMock: true,
// })
// observerMock := keepertest.GetCrosschainObserverMock(t, k)
// observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(&observertypes.QueryGetTssAddressResponse{
// Eth: to.Hex(),
// }, nil)
//
// txBytes, err := tx.MarshalBinary()
// require.NoError(t, err)
// msg := &types.MsgAddToInTxTracker{
// TxHash: tx.Hash().Hex(),
// ChainId: tx.ChainId().Int64(),
// CoinType: coin.CoinType_Gas,
// }
//
// err = k.VerifyEVMInTxBody(ctx, msg, txBytes)
// require.NoError(t, err)
//})
//}
Loading

0 comments on commit 3bfd237

Please sign in to comment.