Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add-lock-zrc20-function-fungible
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac authored Oct 10, 2024
2 parents 98fb634 + 81fc485 commit 77b72e6
Show file tree
Hide file tree
Showing 106 changed files with 4,242 additions and 590 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,24 @@ start-v2-test: zetanode
###############################################################################

# build from source only if requested
# NODE_VERSION and NODE_COMMIT must be set as old-runtime depends on lastest-runtime
ifdef UPGRADE_TEST_FROM_SOURCE
zetanode-upgrade: zetanode
@echo "Building zetanode-upgrade from source"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source --build-arg OLD_VERSION='release/v20' .
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source \
--build-arg OLD_VERSION='release/v20' \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg NODE_COMMIT=$(NODE_COMMIT)
.
.PHONY: zetanode-upgrade
else
zetanode-upgrade: zetanode
@echo "Building zetanode-upgrade from binaries"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime --build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v20.0.2' .
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime \
--build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v20.0.2' \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg NODE_COMMIT=$(NODE_COMMIT) \
.
.PHONY: zetanode-upgrade
endif

Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* [2904](https://github.com/zeta-chain/node/pull/2904) - integrate authenticated calls smart contract functionality into protocol
* [2919](https://github.com/zeta-chain/node/pull/2919) - add inbound sender to revert context
* [2957](https://github.com/zeta-chain/node/pull/2957) - enable Bitcoin inscription support on testnet
* [2896](https://github.com/zeta-chain/node/pull/2896) - add TON inbound observation
* [2979](https://github.com/zeta-chain/node/pull/2979) - add fungible keeper ability to lock/unlock ZRC20 tokens

### Refactor
Expand All @@ -27,6 +28,7 @@
* [2826](https://github.com/zeta-chain/node/pull/2826) - remove unused code from emissions module and add new parameter for fixed block reward amount
* [2890](https://github.com/zeta-chain/node/pull/2890) - refactor `MsgUpdateChainInfo` to accept a single chain, and add `MsgRemoveChainInfo` to remove a chain
* [2899](https://github.com/zeta-chain/node/pull/2899) - remove btc deposit fee v1 and improve unit tests
* [2952](https://github.com/zeta-chain/node/pull/2952) - add error_message to cctx.status

### Tests

Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.C
conf.Contracts.ZEVM.ERC20ZRC20Addr = config.DoubleQuotedString(r.ERC20ZRC20Addr.Hex())
conf.Contracts.ZEVM.BTCZRC20Addr = config.DoubleQuotedString(r.BTCZRC20Addr.Hex())
conf.Contracts.ZEVM.SOLZRC20Addr = config.DoubleQuotedString(r.SOLZRC20Addr.Hex())
conf.Contracts.ZEVM.TONZRC20Addr = config.DoubleQuotedString(r.TONZRC20Addr.Hex())
conf.Contracts.ZEVM.UniswapFactoryAddr = config.DoubleQuotedString(r.UniswapV2FactoryAddr.Hex())
conf.Contracts.ZEVM.UniswapRouterAddr = config.DoubleQuotedString(r.UniswapV2RouterAddr.Hex())
conf.Contracts.ZEVM.ConnectorZEVMAddr = config.DoubleQuotedString(r.ConnectorZEVMAddr.Hex())
Expand Down
11 changes: 11 additions & 0 deletions cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error {
}
}

if c := conf.Contracts.ZEVM.TONZRC20Addr; c != "" {
r.TONZRC20Addr, err = c.AsEVMAddress()
if err != nil {
return fmt.Errorf("invalid TONZRC20Addr: %w", err)
}
r.TONZRC20, err = zrc20.NewZRC20(r.TONZRC20Addr, r.ZEVMClient)
if err != nil {
return err
}
}

if c := conf.Contracts.ZEVM.UniswapFactoryAddr; c != "" {
r.UniswapV2FactoryAddr, err = c.AsEVMAddress()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {

tonTests := []string{
e2etests.TestTONDepositName,
e2etests.TestTONDepositAndCallName,
}

eg.Go(tonTestRoutine(conf, deployerRunner, verbose, tonTests...))
Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/ton.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func tonTestRoutine(
deployerRunner,
conf.DefaultAccount,
runner.NewLogger(verbose, color.FgCyan, "ton"),
runner.WithZetaTxServer(deployerRunner.ZetaTxServer),
)
if err != nil {
return errors.Wrap(err, "unable to init ton test runner")
Expand Down
12 changes: 12 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56998,7 +56998,9 @@ definitions:
- bitcoin
- op_stack
- solana_consensus
- catchain_consensus
default: ethereum
description: '- catchain_consensus: ton'
title: |-
Consensus represents the consensus algorithm used by the chain
this can represent the consensus of a L1
Expand All @@ -57014,6 +57016,7 @@ definitions:
- optimism
- base
- solana
- ton
default: eth
title: |-
Network represents the network of the chain
Expand Down Expand Up @@ -57048,6 +57051,7 @@ definitions:
- no_vm
- evm
- svm
- tvm
default: no_vm
title: |-
Vm represents the virtual machine type of the chain to support smart
Expand Down Expand Up @@ -58446,6 +58450,14 @@ definitions:
$ref: '#/definitions/crosschainCctxStatus'
status_message:
type: string
description: |-
status_message carries information about the status transitions:
why they were triggered, old and new status.
error_message:
type: string
description: |-
error_message carries information about the error that caused the tx
to be PendingRevert, Reverted or Aborted.
lastUpdate_timestamp:
type: string
format: int64
Expand Down
1 change: 1 addition & 0 deletions e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type ZEVM struct {
ERC20ZRC20Addr DoubleQuotedString `yaml:"erc20_zrc20"`
BTCZRC20Addr DoubleQuotedString `yaml:"btc_zrc20"`
SOLZRC20Addr DoubleQuotedString `yaml:"sol_zrc20"`
TONZRC20Addr DoubleQuotedString `yaml:"ton_zrc20"`
UniswapFactoryAddr DoubleQuotedString `yaml:"uniswap_factory"`
UniswapRouterAddr DoubleQuotedString `yaml:"uniswap_router"`
ConnectorZEVMAddr DoubleQuotedString `yaml:"connector_zevm"`
Expand Down
13 changes: 11 additions & 2 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const (
/**
* TON tests
*/
TestTONDepositName = "ton_deposit"
TestTONDepositName = "ton_deposit"
TestTONDepositAndCallName = "ton_deposit_and_call"

/*
Bitcoin tests
Expand Down Expand Up @@ -445,10 +446,18 @@ var AllE2ETests = []runner.E2ETest{
TestTONDepositName,
"deposit TON into ZEVM",
[]runner.ArgDefinition{
{Description: "amount in nano tons", DefaultValue: "900000000"}, // 0.9 TON
{Description: "amount in nano tons", DefaultValue: "1000000000"}, // 1.0 TON
},
TestTONDeposit,
),
runner.NewE2ETest(
TestTONDepositAndCallName,
"deposit TON into ZEVM and call a contract",
[]runner.ArgDefinition{
{Description: "amount in nano tons", DefaultValue: "1000000000"}, // 1.0 TON
},
TestTONDepositAndCall,
),
/*
Bitcoin tests
*/
Expand Down
5 changes: 5 additions & 0 deletions e2e/e2etests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/big"
"strconv"

"cosmossdk.io/math"
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand Down Expand Up @@ -144,6 +145,10 @@ func parseBigInt(t require.TestingT, s string) *big.Int {
return v
}

func parseUint(t require.TestingT, s string) math.Uint {
return math.NewUintFromBigInt(parseBigInt(t, s))
}

// bigIntFromFloat64 takes float64 (e.g. 0.001) that represents btc amount
// and converts it to big.Int for downstream usage.
func btcAmountFromFloat64(t require.TestingT, amount float64) *big.Int {
Expand Down
9 changes: 7 additions & 2 deletions e2e/e2etests/test_eth_deposit_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) {

r.Logger.Info("Cross-chain call to reverter reverted")

// check the status message contains revert error hash in case of revert
require.Contains(r, cctx.CctxStatus.StatusMessage, utils.ErrHashRevertFoo)
// Check the error carries the revert executed.
// tolerate the error in both the ErrorMessage field and the StatusMessage field
if cctx.CctxStatus.ErrorMessage != "" {
require.Contains(r, cctx.CctxStatus.ErrorMessage, "revert executed")
} else {
require.Contains(r, cctx.CctxStatus.StatusMessage, utils.ErrHashRevertFoo)
}
}
9 changes: 7 additions & 2 deletions e2e/e2etests/test_solana_deposit_refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func TestSolanaDepositAndCallRefund(r *runner.E2ERunner, args []string) {
r.Logger.CCTX(*cctx, "solana_deposit_and_refund")
utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_Reverted)

// check the status message contains revert error hash in case of revert
require.Contains(r, cctx.CctxStatus.StatusMessage, utils.ErrHashRevertFoo)
// Check the error carries the revert executed.
// tolerate the error in both the ErrorMessage field and the StatusMessage field
if cctx.CctxStatus.ErrorMessage != "" {
require.Contains(r, cctx.CctxStatus.ErrorMessage, "revert executed")
} else {
require.Contains(r, cctx.CctxStatus.StatusMessage, utils.ErrHashRevertFoo)
}
}
60 changes: 41 additions & 19 deletions e2e/e2etests/test_ton_deposit.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,64 @@
package e2etests

import (
"time"

"cosmossdk.io/math"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/runner/ton"
"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/testutil/sample"
cctypes "github.com/zeta-chain/node/x/crosschain/types"
)

// TestTONDeposit (!) This boilerplate is a demonstration of E2E capabilities for TON integration
// Actual Deposit test is not implemented yet.
func TestTONDeposit(r *runner.E2ERunner, _ []string) {
ctx, deployer := r.Ctx, r.TONDeployer
func TestTONDeposit(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

// Given deployer
deployerBalance, err := deployer.GetBalance(ctx)
require.NoError(r, err, "failed to get deployer balance")
require.NotZero(r, deployerBalance, "deployer balance is zero")
ctx, deployer, chain := r.Ctx, r.TONDeployer, chains.TONLocalnet

// Given amount
amount := parseUint(r, args[0])

// https://github.com/zeta-chain/protocol-contracts-ton/blob/main/contracts/gateway.fc#L28
// (will be optimized & dynamic in the future)
depositFee := math.NewUint(10_000_000)

// Given sample wallet with a balance of 50 TON
sender, err := deployer.CreateWallet(ctx, ton.TONCoins(50))
require.NoError(r, err)

// That was funded (again) but the faucet
_, err = deployer.Fund(ctx, sender.GetAddress(), ton.TONCoins(30))
// Given sample EVM address
recipient := sample.EthAddress()

// ACT
err = r.TONDeposit(sender, amount, recipient)

// ASSERT
require.NoError(r, err)

// Check sender balance
sb, err := sender.GetBalance(ctx)
// Wait for CCTX mining
filter := func(cctx *cctypes.CrossChainTx) bool {
return cctx.InboundParams.SenderChainId == chain.ChainId &&
cctx.InboundParams.Sender == sender.GetAddress().ToRaw()
}

cctx := r.WaitForSpecificCCTX(filter, time.Minute)

// Check CCTX
expectedDeposit := amount.Sub(depositFee)

require.Equal(r, sender.GetAddress().ToRaw(), cctx.InboundParams.Sender)
require.Equal(r, expectedDeposit.Uint64(), cctx.InboundParams.Amount.Uint64())

// Check receiver's balance
balance, err := r.TONZRC20.BalanceOf(&bind.CallOpts{}, recipient)
require.NoError(r, err)

senderBalance := math.NewUint(sb)
r.Logger.Info("Recipient's zEVM TON balance after deposit: %d", balance.Uint64())

// note that it's not exactly 80 TON, but 79.99... due to gas fees
// We'll tackle gas math later.
r.Logger.Print(
"Balance of sender (%s): %s",
sender.GetAddress().ToHuman(false, true),
ton.FormatCoins(senderBalance),
)
require.Equal(r, expectedDeposit.Uint64(), balance.Uint64())
}
69 changes: 69 additions & 0 deletions e2e/e2etests/test_ton_deposit_and_call.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package e2etests

import (
"time"

"cosmossdk.io/math"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/runner/ton"
"github.com/zeta-chain/node/e2e/utils"
"github.com/zeta-chain/node/pkg/chains"
testcontract "github.com/zeta-chain/node/testutil/contracts"
cctypes "github.com/zeta-chain/node/x/crosschain/types"
)

func TestTONDepositAndCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

// Given deployer
ctx, deployer, chain := r.Ctx, r.TONDeployer, chains.TONLocalnet

// Given amount
amount := parseUint(r, args[0])

// https://github.com/zeta-chain/protocol-contracts-ton/blob/main/contracts/gateway.fc#L28
// (will be optimized & dynamic in the future)
depositFee := math.NewUint(10_000_000)

// Given sample wallet with a balance of 50 TON
sender, err := deployer.CreateWallet(ctx, ton.TONCoins(50))
require.NoError(r, err)

// Given sample zEVM contract
contractAddr, _, contract, err := testcontract.DeployExample(r.ZEVMAuth, r.ZEVMClient)
require.NoError(r, err)
r.Logger.Info("Example zevm contract deployed at: %s", contractAddr.String())

// Given call data
callData := []byte("hello from TON!")

// ACT
err = r.TONDepositAndCall(sender, amount, contractAddr, callData)

// ASSERT
require.NoError(r, err)

// Wait for CCTX mining
filter := func(cctx *cctypes.CrossChainTx) bool {
return cctx.InboundParams.SenderChainId == chain.ChainId &&
cctx.InboundParams.Sender == sender.GetAddress().ToRaw()
}

r.WaitForSpecificCCTX(filter, time.Minute)

expectedDeposit := amount.Sub(depositFee)

// check if example contract has been called, bar value should be set to amount
utils.MustHaveCalledExampleContract(r, contract, expectedDeposit.BigInt())

// Check receiver's balance
balance, err := r.TONZRC20.BalanceOf(&bind.CallOpts{}, contractAddr)
require.NoError(r, err)

r.Logger.Info("Contract's zEVM TON balance after deposit: %d", balance.Uint64())

require.Equal(r, expectedDeposit.Uint64(), balance.Uint64())
}
Loading

0 comments on commit 77b72e6

Please sign in to comment.