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

fix(crosschain): use event index in inbound tx digest #1372

Merged
merged 21 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
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: 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
Loading