-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use chainParams from base observer * Improve base observer Start() semantics * Add pkg/ticker options * Add TON to pkg/chains & protos * Add liteapi wrapper client; locate first tx * Add TON tx scraper * Add client.GetTransactionsUntil * Gateway WIP * Implement Gateway inbound tx parsing * Add Gateway tx filtration * Add GetBlockHeader cache; Add masterchain seqno. Implement watchInbound * Improve ton contracts pkg * Add IsTONChain() * Refactor Gateway package * Implement samples for TON * Add liteClient mocks * Add unit tests for inbound TON observer * Localnet: add TON ZRC20 * Wire the TON observer into the orchestrator * Add TON chain params of the fly! * TON deposits E2E wip * Fix bugs during cctx; * TON Deposits E2E 🫡✅ * TON Deposit And Call E2E * Merge fixes * Update changelog * gosec * Improve testing * Simplify ticker.Stop(). Leverage ctx.cancel() * Simplify E2E * Simplify liteapi semantics * Fix comments * Update zetaclient/chains/base/observer.go Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]> * Add gw explanatory comments; address PR comments * Apply fixes for AI suggestions --------- Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>
- Loading branch information
Showing
84 changed files
with
3,921 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.