Skip to content

Commit

Permalink
fix(crosschain): use event index in inbound tx digest (#1372)
Browse files Browse the repository at this point in the history
* add event index in observer inbound

* rename messages

* update method usage

* use event index

* fix cosmos-gosec

* depositor contract

* smoketest refactor

* fix contracts

* mutiple deposits smoke tests

* fix depositor

* withdrawer contract

* fix smoketest deposits

* fix withdrawer contract

* multiple withdraw test

* fix contracts

* fix withdraws

* update changelog
  • Loading branch information
lumtis authored Nov 11, 2023
1 parent 5420527 commit 5e635ca
Show file tree
Hide file tree
Showing 35 changed files with 1,266 additions and 320 deletions.
14 changes: 4 additions & 10 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# CHANGELOG

## Unreleasd
## Unreleased

### Features

### Fixes

* [1372](https://github.com/zeta-chain/node/pull/1372) - Include Event Index as part for inbound tx digest
* [1358](https://github.com/zeta-chain/node/pull/1358) - add a new thread to zetaclient which checks zeta supply in all connected chains in every block

### Refactoring

### Chores
Expand Down Expand Up @@ -67,12 +70,3 @@
* [1218](https://github.com/zeta-chain/node/pull/1218) - cross-compile release binaries and simplify PR testings
* [1302](https://github.com/zeta-chain/node/pull/1302) - add mainnet builds to goreleaser





### Unreleased:
* add a new thread to zetaclient which checks zeta supply in all connected chains in every block



1 change: 0 additions & 1 deletion contrib/localnet/orchestrator/smoketest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ func LocalSmokeTest(_ *cobra.Command, _ []string) {
smokeTest.CheckZRC20ReserveAndSupply()

smokeTest.TestERC20Withdraw()
//smokeTest.WithdrawBitcoinMultipleTimes(5)
smokeTest.CheckZRC20ReserveAndSupply()

smokeTest.TestSendZetaOut()
Expand Down
194 changes: 0 additions & 194 deletions contrib/localnet/orchestrator/smoketest/test_erc20.go

This file was deleted.

163 changes: 163 additions & 0 deletions contrib/localnet/orchestrator/smoketest/test_erc20_deposit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
//go:build PRIVNET
// +build PRIVNET

package main

import (
"fmt"
"math/big"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
testcontract "github.com/zeta-chain/zetacore/testutil/contracts"
)

func (sm *SmokeTest) TestERC20Deposit() {
startTime := time.Now()
defer func() {
fmt.Printf("test finishes in %s\n", time.Since(startTime))
}()
LoudPrintf("Deposit USDT ERC20 into ZEVM\n")

initialBal, err := sm.USDTZRC20.BalanceOf(&bind.CallOpts{}, DeployerAddress)
if err != nil {
panic(err)
}
txhash := sm.DepositERC20(big.NewInt(1e9), []byte{})
WaitCctxMinedByInTxHash(txhash.Hex(), sm.cctxClient)

bal, err := sm.USDTZRC20.BalanceOf(&bind.CallOpts{}, DeployerAddress)
if err != nil {
panic(err)
}

diff := big.NewInt(0)
diff.Sub(bal, initialBal)

fmt.Printf("balance of deployer on USDT ZRC20: %d\n", bal)
supply, err := sm.USDTZRC20.TotalSupply(&bind.CallOpts{})
if err != nil {
panic(err)
}
fmt.Printf("supply of USDT ZRC20: %d\n", supply)
if diff.Int64() != 1e9 {
panic("balance is not correct")
}

LoudPrintf("Same-transaction multiple deposit USDT ERC20 into ZEVM\n")
initialBal, err = sm.USDTZRC20.BalanceOf(&bind.CallOpts{}, DeployerAddress)
if err != nil {
panic(err)
}
txhash = sm.MultipleDeposits(big.NewInt(1e9), big.NewInt(10))
cctxs := WaitCctxsMinedByInTxHash(txhash.Hex(), sm.cctxClient)
if len(cctxs) != 10 {
panic(fmt.Sprintf("cctxs length is not correct: %d", len(cctxs)))
}

// check new balance is increased by 1e9 * 10
bal, err = sm.USDTZRC20.BalanceOf(&bind.CallOpts{}, DeployerAddress)
if err != nil {
panic(err)
}
diff = big.NewInt(0).Sub(bal, initialBal)
if diff.Int64() != 1e10 {
panic(fmt.Sprintf("balance difference is not correct: %d", diff.Int64()))
}
}

func (sm *SmokeTest) DepositERC20(amount *big.Int, msg []byte) ethcommon.Hash {
USDT := sm.USDTERC20
tx, err := USDT.Mint(sm.goerliAuth, big.NewInt(1e10))
if err != nil {
panic(err)
}
receipt := MustWaitForTxReceipt(sm.goerliClient, tx)
fmt.Printf("Mint receipt tx hash: %s\n", tx.Hash().Hex())

tx, err = USDT.Approve(sm.goerliAuth, sm.ERC20CustodyAddr, big.NewInt(1e10))
if err != nil {
panic(err)
}
receipt = MustWaitForTxReceipt(sm.goerliClient, tx)
fmt.Printf("USDT Approve receipt tx hash: %s\n", tx.Hash().Hex())

tx, err = sm.ERC20Custody.Deposit(sm.goerliAuth, DeployerAddress.Bytes(), sm.USDTERC20Addr, amount, msg)
if err != nil {
panic(err)
}
receipt = MustWaitForTxReceipt(sm.goerliClient, tx)
if receipt.Status == 0 {
panic("deposit failed")
}
fmt.Printf("Deposit receipt tx hash: %s, status %d\n", receipt.TxHash.Hex(), receipt.Status)
for _, log := range receipt.Logs {
event, err := sm.ERC20Custody.ParseDeposited(*log)
if err != nil {
continue
}
fmt.Printf("Deposited event: \n")
fmt.Printf(" Recipient address: %x, \n", event.Recipient)
fmt.Printf(" ERC20 address: %s, \n", event.Asset.Hex())
fmt.Printf(" Amount: %d, \n", event.Amount)
fmt.Printf(" Message: %x, \n", event.Message)
}
fmt.Printf("gas limit %d\n", sm.zevmAuth.GasLimit)
return tx.Hash()
}

func (sm *SmokeTest) MultipleDeposits(amount, count *big.Int) ethcommon.Hash {
// deploy depositor
depositorAddr, _, depositor, err := testcontract.DeployDepositor(sm.goerliAuth, sm.goerliClient, sm.ERC20CustodyAddr)
if err != nil {
panic(err)
}

// mint
tx, err := sm.USDTERC20.Mint(sm.goerliAuth, big.NewInt(0).Mul(amount, count))
if err != nil {
panic(err)
}
receipt := MustWaitForTxReceipt(sm.goerliClient, tx)
if receipt.Status == 0 {
panic("mint failed")
}
fmt.Printf("Mint receipt tx hash: %s\n", tx.Hash().Hex())

// approve
tx, err = sm.USDTERC20.Approve(sm.goerliAuth, depositorAddr, big.NewInt(1e10))
if err != nil {
panic(err)
}
receipt = MustWaitForTxReceipt(sm.goerliClient, tx)
if receipt.Status == 0 {
panic("approve failed")
}
fmt.Printf("USDT Approve receipt tx hash: %s\n", tx.Hash().Hex())

// deposit
tx, err = depositor.RunDeposits(sm.goerliAuth, DeployerAddress.Bytes(), sm.USDTERC20Addr, amount, []byte{}, count)
if err != nil {
panic(err)
}
receipt = MustWaitForTxReceipt(sm.goerliClient, tx)
if receipt.Status == 0 {
panic("deposits failed")
}
fmt.Printf("Deposits receipt tx hash: %s\n", tx.Hash().Hex())

for _, log := range receipt.Logs {
event, err := sm.ERC20Custody.ParseDeposited(*log)
if err != nil {
continue
}
fmt.Printf("Multiple deposit event: \n")
fmt.Printf(" Recipient address: %x, \n", event.Recipient)
fmt.Printf(" ERC20 address: %s, \n", event.Asset.Hex())
fmt.Printf(" Amount: %d, \n", event.Amount)
fmt.Printf(" Message: %x, \n", event.Message)
}
fmt.Printf("gas limit %d\n", sm.zevmAuth.GasLimit)
return tx.Hash()
}
Loading

0 comments on commit 5e635ca

Please sign in to comment.