Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit tests for crosschain evm hooks #1787

Merged
merged 21 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Tests

* [1767](https://github.com/zeta-chain/node/pull/1767) - add unit tests for emissions module begin blocker
* [1787](https://github.com/zeta-chain/node/pull/1787) - add unit tests for cross-chain evm hooks

## Version: v13.0.0

Expand Down
10 changes: 10 additions & 0 deletions e2e/e2etests/test_bitcoin_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
// mine blocks
stop := r.MineBlocks()

// withdraw 0.1 BTC from ZRC20 to BTC legacy address
tx, err = r.BTCZRC20.Withdraw(r.ZevmAuth, []byte("1EYVvXLusCxtVuEwoYvWRyN5EZTXwPVvo3"), amount)
if err != nil {
panic(err)
}
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZevmClient, tx, r.Logger, r.ReceiptTimeout)
if receipt.Status == 1 {
panic(fmt.Errorf("withdraw receipt status is successfull for an invalid BTC address"))

Check failure on line 42 in e2e/e2etests/test_bitcoin_withdraw.go

View workflow job for this annotation

GitHub Actions / lint

`successfull` is a misspelling of `successful` (misspell)
}

// withdraw 0.1 BTC from ZRC20 to BTC address
tx, err = r.BTCZRC20.Withdraw(r.ZevmAuth, []byte(r.BTCDeployerAddress.EncodeAddress()), amount)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import (
func NewContext(stateStore sdk.CommitMultiStore) sdk.Context {
header := tmproto.Header{
Height: 1,
ChainID: "test_1-1",
ChainID: "test_7000-1",
Time: time.Now().UTC(),
LastBlockId: tmproto.BlockID{
Hash: tmhash.Sum([]byte("block_id")),
Expand Down
6 changes: 4 additions & 2 deletions x/crosschain/keeper/evm_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (k Keeper) ProcessLogs(ctx sdk.Context, logs []*ethtypes.Log, emittingContr
if connectorZEVMAddr == (ethcommon.Address{}) {
return fmt.Errorf("connectorZEVM address is empty")
}

for _, log := range logs {
eventZrc20Withdrawal, errZrc20 := ParseZRC20WithdrawalEvent(*log)
eventZetaSent, errZetaSent := ParseZetaSentEvent(*log, connectorZEVMAddr)
Expand Down Expand Up @@ -103,6 +102,7 @@ func (k Keeper) ProcessLogs(ctx sdk.Context, logs []*ethtypes.Log, emittingContr
ctx.Logger().Info(fmt.Sprintf("cannot find foreign coin with contract address %s", eventZrc20Withdrawal.Raw.Address.Hex()))
continue
}

// If Validation fails, we will not process the event and return and error. This condition means that the event was correct, and emitted from a registered ZRC20 contract
// But the information entered by the user is incorrect. In this case we can return an error and roll back the transaction
if err := ValidateZrc20WithdrawEvent(eventZrc20Withdrawal, coin.ForeignChainId); err != nil {
Expand Down Expand Up @@ -133,8 +133,10 @@ func (k Keeper) ProcessZRC20WithdrawalEvent(ctx sdk.Context, event *zrc20.ZRC20W
if !found {
return fmt.Errorf("cannot find foreign coin with emittingContract address %s", event.Raw.Address.Hex())
}

receiverChain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, foreignCoin.ForeignChainId)
if receiverChain == nil {
return errorsmod.Wrap(observertypes.ErrSupportedChains, fmt.Sprintf("chain with chainID %d not supported", foreignCoin.ForeignChainId))
}
senderChain, err := common.ZetaChainFromChainID(ctx.ChainID())
if err != nil {
return fmt.Errorf("ProcessZRC20WithdrawalEvent: failed to convert chainID: %s", err.Error())
Expand Down
Loading
Loading