Skip to content

Commit

Permalink
feat(ton): TON localnet integration (#2833)
Browse files Browse the repository at this point in the history
* Dockerize TON localnet

* Use docker ip for the sidecar

* Wire TON into localnet. Add sidecar client

* Rename utils to config

* Please linter

* Add faucet; build gateway data

* Move TON localnet to a separate repository

* E2E demo

* Add TON_TESTS labeled tests

* Update changelog

* Fix gosec

* Skip ton tests w/o --test-ton

* Remove todos

* Fix typo

* Fix typo; update ton image

* update e2e.yml gh workflow

* Bring  back brackets formatting in yml
  • Loading branch information
swift1337 authored Sep 16, 2024
1 parent d4cd477 commit aa81140
Show file tree
Hide file tree
Showing 30 changed files with 1,162 additions and 30 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
STATEFUL_DATA_TESTS: ${{ steps.matrix-conditionals.outputs.STATEFUL_DATA_TESTS }}
TSS_MIGRATION_TESTS: ${{ steps.matrix-conditionals.outputs.TSS_MIGRATION_TESTS }}
SOLANA_TESTS: ${{ steps.matrix-conditionals.outputs.SOLANA_TESTS }}
TON_TESTS: ${{ steps.matrix-conditionals.outputs.TON_TESTS }}
V2_TESTS: ${{ steps.matrix-conditionals.outputs.V2_TESTS }}
V2_MIGRATION_TESTS: ${{ steps.matrix-conditionals.outputs.V2_MIGRATION_TESTS }}
steps:
Expand All @@ -62,6 +63,7 @@ jobs:
core.setOutput('STATEFUL_DATA_TESTS', labels.includes('STATEFUL_DATA_TESTS'));
core.setOutput('TSS_MIGRATION_TESTS', labels.includes('TSS_MIGRATION_TESTS'));
core.setOutput('SOLANA_TESTS', labels.includes('SOLANA_TESTS'));
core.setOutput('TON_TESTS', labels.includes('TON_TESTS'));
core.setOutput('V2_TESTS', labels.includes('V2_TESTS')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
core.setOutput('V2_MIGRATION_TESTS', labels.includes('V2_MIGRATION_TESTS')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
} else if (context.eventName === 'merge_group') {
Expand All @@ -77,6 +79,8 @@ jobs:
core.setOutput('ADMIN_TESTS', true);
core.setOutput('PERFORMANCE_TESTS', true);
core.setOutput('STATEFUL_DATA_TESTS', true);
core.setOutput('SOLANA_TESTS', true);
core.setOutput('TON_TESTS', true);
core.setOutput('V2_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
core.setOutput('V2_MIGRATION_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
} else if (context.eventName === 'schedule') {
Expand All @@ -89,6 +93,7 @@ jobs:
core.setOutput('STATEFUL_DATA_TESTS', true);
core.setOutput('TSS_MIGRATION_TESTS', true);
core.setOutput('SOLANA_TESTS', true);
core.setOutput('TON_TESTS', true);
core.setOutput('V2_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
core.setOutput('V2_MIGRATION_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
} else if (context.eventName === 'workflow_dispatch') {
Expand All @@ -102,6 +107,7 @@ jobs:
core.setOutput('STATEFUL_DATA_TESTS', makeTargets.includes('import-mainnet-test'));
core.setOutput('TSS_MIGRATION_TESTS', makeTargets.includes('tss-migration-test'));
core.setOutput('SOLANA_TESTS', makeTargets.includes('solana-test'));
core.setOutput('TON_TESTS', makeTargets.includes('ton-test'));
core.setOutput('V2_TESTS', makeTargets.includes('v2-test')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
core.setOutput('V2_MIGRATION_TESTS', makeTargets.includes('v2-migration-test')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
}
Expand Down Expand Up @@ -142,6 +148,9 @@ jobs:
- make-target: "start-solana-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.SOLANA_TESTS == 'true' }}
- make-target: "start-ton-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.TON_TESTS == 'true' }}
- make-target: "start-v2-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.V2_TESTS == 'true' }}
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ start-solana-test: zetanode solana
export E2E_ARGS="--skip-regular --test-solana" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile solana -f docker-compose.yml up -d

start-ton-test: zetanode
@echo "--> Starting TON test"
export E2E_ARGS="--skip-regular --test-ton" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile ton -f docker-compose.yml up -d

start-v2-test: zetanode
@echo "--> Starting e2e smart contracts v2 test"
export E2E_ARGS="--skip-regular --test-v2" && \
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [2703](https://github.com/zeta-chain/node/pull/2703) - add e2e tests for stateful precompiled contracts
* [2830](https://github.com/zeta-chain/node/pull/2830) - extend staking precompile tests
* [2867](https://github.com/zeta-chain/node/pull/2867) - skip precompiles test for tss migration
* [2833](https://github.com/zeta-chain/node/pull/2833) - add e2e framework for TON blockchain
* [2874](https://github.com/zeta-chain/node/pull/2874) - add support for multiple runs for precompile tests

### Fixes
Expand Down
64 changes: 54 additions & 10 deletions cmd/zetae2e/config/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,51 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/gagliardetto/solana-go/rpc"
ton "github.com/tonkeeper/tongo/liteapi"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/runner"
tonrunner "github.com/zeta-chain/node/e2e/runner/ton"
"github.com/zeta-chain/node/pkg/retry"
zetacore_rpc "github.com/zeta-chain/node/pkg/rpc"
tonconfig "github.com/zeta-chain/node/zetaclient/chains/ton"
)

// getClientsFromConfig get clients from config
func getClientsFromConfig(ctx context.Context, conf config.Config, account config.Account) (
runner.Clients,
error,
) {
var solanaClient *rpc.Client
if conf.RPCs.Solana != "" {
if solanaClient = rpc.New(conf.RPCs.Solana); solanaClient == nil {
return runner.Clients{}, fmt.Errorf("failed to get solana client")
}
}
func getClientsFromConfig(ctx context.Context, conf config.Config, account config.Account) (runner.Clients, error) {
btcRPCClient, err := getBtcClient(conf.RPCs.Bitcoin)
if err != nil {
return runner.Clients{}, fmt.Errorf("failed to get btc client: %w", err)
}

evmClient, evmAuth, err := getEVMClient(ctx, conf.RPCs.EVM, account)
if err != nil {
return runner.Clients{}, fmt.Errorf("failed to get evm client: %w", err)
}

var solanaClient *rpc.Client
if conf.RPCs.Solana != "" {
if solanaClient = rpc.New(conf.RPCs.Solana); solanaClient == nil {
return runner.Clients{}, fmt.Errorf("failed to get solana client")
}
}

var tonClient *tonrunner.Client
if conf.RPCs.TONSidecarURL != "" {
c, err := getTONClient(ctx, conf.RPCs.TONSidecarURL)
if err != nil {
return runner.Clients{}, fmt.Errorf("failed to get ton client: %w", err)
}
tonClient = c
}

zetaCoreClients, err := GetZetacoreClient(conf)
if err != nil {
return runner.Clients{}, fmt.Errorf("failed to get zetacore client: %w", err)
}

zevmClient, zevmAuth, err := getEVMClient(ctx, conf.RPCs.Zevm, account)
if err != nil {
return runner.Clients{}, fmt.Errorf("failed to get zevm client: %w", err)
Expand All @@ -48,6 +62,7 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, account confi
Zetacore: zetaCoreClients,
BtcRPC: btcRPCClient,
Solana: solanaClient,
TON: tonClient,
Evm: evmClient,
EvmAuth: evmAuth,
Zevm: zevmClient,
Expand Down Expand Up @@ -106,6 +121,35 @@ func getEVMClient(
return evmClient, evmAuth, nil
}

func getTONClient(ctx context.Context, sidecarURL string) (*tonrunner.Client, error) {
if sidecarURL == "" {
return nil, fmt.Errorf("sidecar URL is empty")
}

sidecar := tonrunner.NewSidecarClient(sidecarURL)

// It might take some time to bootstrap the sidecar
cfg, err := retry.DoTypedWithRetry(
func() (*tonconfig.GlobalConfigurationFile, error) {
return tonconfig.ConfigFromURL(ctx, sidecar.LiteServerURL())
},
)

if err != nil {
return nil, fmt.Errorf("failed to get ton config: %w", err)
}

client, err := ton.NewClient(ton.WithConfigurationFile(*cfg))
if err != nil {
return nil, fmt.Errorf("failed to create ton client: %w", err)
}

return &tonrunner.Client{
Client: client,
SidecarClient: sidecar,
}, nil
}

func GetZetacoreClient(conf config.Config) (zetacore_rpc.Clients, error) {
if conf.RPCs.ZetaCoreGRPC != "" {
return zetacore_rpc.NewGRPCClients(
Expand Down
84 changes: 81 additions & 3 deletions cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,85 @@
zeta_chain_id: "athens_7001-1"
zeta_chain_id: "athens_101-1"
default_account:
bech32_address: zeta1uhznv7uzyjq84s3q056suc8pkme85lkvhrz3dd
bech32_address: "zeta1uhznv7uzyjq84s3q056suc8pkme85lkvhrz3dd"
evm_address: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC"
private_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263"
additional_accounts:
user_erc20:
bech32_address: "zeta1datate7xmwm4uk032f9rmcu0cwy7ch7kg6y6zv"
evm_address: "0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6"
private_key: "fda3be1b1517bdf48615bdadacc1e6463d2865868dc8077d2cdcfa4709a16894"
user_zeta_test:
bech32_address: "zeta1tnp0hvsq4y5mxuhrq9h3jfwulxywpq0ads0rer"
evm_address: "0x5cC2fBb200A929B372e3016F1925DcF988E081fd"
private_key: "729a6cdc5c925242e7df92fdeeb94dadbf2d0b9950d4db8f034ab27a3b114ba7"
user_zevm_mp_test:
bech32_address: "zeta13t3zjxvwec7g38q8mdjga37rpes9zkfvv7tkn2"
evm_address: "0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c"
private_key: "105460aebf71b10bfdb710ef5aa6d2932ee6ff6fc317ac9c24e0979903b10a5d"
user_bitcoin:
bech32_address: "zeta19q7czqysah6qg0n4y3l2a08gfzqxydla492v80"
evm_address: "0x283d810090EdF4043E75247eAeBcE848806237fD"
private_key: "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a"
user_solana:
bech32_address: "zeta1zqlajgj0qr8rqylf2c572t0ux8vqt45d4zngpm"
evm_address: "0x103FD9224F00ce3013e95629e52DFc31D805D68d"
private_key: "dd53f191113d18e57bd4a5494a64a020ba7919c815d0a6d34a42ebb2839e9d95"
solana_private_key: "4yqSQxDeTBvn86BuxcN5jmZb2gaobFXrBqu8kiE9rZxNkVMe3LfXmFigRsU4sRp7vk4vVP1ZCFiejDKiXBNWvs2C"
user_ether:
bech32_address: "zeta134rakuus43xn63yucgxhn88ywj8ewcv6ezn2ga"
evm_address: "0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A"
private_key: "098e74a1c2261fa3c1b8cfca8ef2b4ff96c73ce36710d208d1f6535aef42545d"
user_misc:
bech32_address: "zeta1jqfx6qhyrj0t9ggvl3p64vaax3s9y0xldt020w"
evm_address: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf"
private_key: "853c0945b8035a501b1161df65a17a0a20fc848bda8975a8b4e9222cc6f84cd4"
user_admin:
bech32_address: "zeta17w0adeg64ky0daxwd2ugyuneellmjgnx4e483s"
evm_address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
private_key: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
user_migration:
bech32_address: "zeta1pvtxa708yvdmszn687nne6nl8qn704daf420xz"
evm_address: "0x0B166ef9e7231Bb80A7A3FA73CEA7F3827E7D5BD"
private_key: "0bcc2fa28b526f90e1d54648d612db901e860bf68248555593f91ea801c6b482"
user_precompile:
bech32_address: "zeta1k4f0l2e9qqjccxnstwj0uaarxvn44lj990she9"
evm_address: "0xb552FFAb2500258C1A705Ba4Fe77A333275AFE45"
private_key: "bd6b74387f11b31d21e87c2ae7a23ec269aee08a355dad6c508a6fceb79d1f48"
user_v2_ether:
bech32_address: "zeta1erlqlpl5da7a9r3emzw60kax9fxc3h0r3z7c5e"
evm_address: "0xC8fe0F87f46F7Dd28e39D89Da7Dba62A4D88dde3"
private_key: "11c25af71c82602a681ce622bf76f4f0fbc3b7f23ce935db6249d1517322f436"
user_v2_erc20:
bech32_address: "zeta12wp6syndml6jd32m7f9mn2wscsxz6cff8nczl4"
evm_address: "0x5383A8126ddff526C55bF24Bb9a9D0c40c2d6129"
private_key: "77b0e4dcc29c5c47b6999dabd42abcfdf7750ccc86d6659c1373ec1ea3b4af6c"
user_v2_ether_revert:
bech32_address: "zeta1m7m5xd79x9qmlyfpqxcwuac04r3dewfpdcfw5e"
evm_address: "0xdFb74337c53141bf912101b0Ee770FA8e2DCB921"
private_key: "be7098604cc40f95d68298a3b4ae13972ac8a3df271ba19ddf169070d30e8ba8"
user_v2_erc20_revert:
bech32_address: "zeta1nry9yeg6njhjrp2ctppa8558vqxal9fxk69zxg"
evm_address: "0x98c852651A9CAF2185585843d3D287600Ddf9526"
private_key: "bf9456c679bb5a952a9a137fcfc920e0413efdb97c36de1e57455763084230cb"
policy_accounts:
emergency_policy_account:
bech32_address: "zeta16m2cnrdwtgweq4njc6t470vl325gw4kp6s7tap"
evm_address: "0xd6d5898dAE5A1D905672c6975F3d9f8aA88756C1"
private_key: "88BE93D11624B794F4BCC77BEA7385AF7EAD0B183B913485C74F0A803ABBC3F0"
operational_policy_account:
bech32_address: "zeta1pgx85vzx4fzh5zzyjqgs6a6cmaujd0xs8efrkc"
evm_address: "0x0A0c7a3046AA457A084490110d7758Df7926bcd0"
private_key: "59D1B982BD446545A1740ABD01F1ED9C162B72ACC1522B9B71B6DB5A9C37FA7D"
admin_policy_account:
bech32_address: "zeta142ds9x7raljv2qz9euys93e64gjmgdfnc47dwq"
evm_address: "0xAa9b029BC3EFe4c50045Cf0902c73aAa25b43533"
private_key: "0595CB0CD9BF5264A85A603EC8E43C30ADBB5FD2D9E2EF84C374EA4A65BB616C"
observer_relayer_accounts:
relayer_accounts:
- solana_address: "2qBVcNBZCubcnSR3NyCnFjCfkCVUB3G7ECPoaW5rxVjx"
solana_private_key: "3EMjCcCJg53fMEGVj13UPQpo6py9AKKyLE2qroR4yL1SvAN2tUznBvDKRYjntw7m6Jof1R2CSqjTddL27rEb6sFQ"
- solana_address: "4kkCV8H38xirwQTkE5kL6FHNtYGHnMQQ7SkCjAxibHFK"
solana_private_key: "5SSv7jWzamtjWNKGiKf3gvCPHcq9mE5x6LhYgzJCKNSxoQ83gFpmMgmg2JS2zdKcBEdwy7y9bvWgX4LBiUpvnrPf"
rpcs:
zevm: "http://localhost:9545"
evm: "http://localhost:8545"
Expand All @@ -15,7 +92,8 @@ rpcs:
params: regnet
zetacore_grpc: "localhost:9090"
zetacore_rpc: "http://localhost:26657"
solana: "http://solana:8899"
solana: "http://localhost:8899"
ton_sidecar_url: "http://localhost:8111"
contracts:
zevm:
system_contract: "0x91d18e54DAf4F677cB28167158d6dd21F6aB3921"
Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ rpcs:
disable_tls: true
params: regnet
solana: "http://solana:8899"
ton_sidecar_url: "http://ton:8000"
zetacore_grpc: "zetacore0:9090"
zetacore_rpc: "http://zetacore0:26657"
# contracts will be populated on first run
2 changes: 2 additions & 0 deletions cmd/zetae2e/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func NewInitCmd() *cobra.Command {
InitCmd.Flags().StringVar(&initConf.RPCs.Bitcoin.Host, "btcURL", "bitcoin:18443", "--grpcURL bitcoin:18443")
InitCmd.Flags().
StringVar(&initConf.RPCs.Solana, "solanaURL", "http://solana:8899", "--solanaURL http://solana:8899")
InitCmd.Flags().
StringVar(&initConf.RPCs.TONSidecarURL, "tonSidecarURL", "http://ton:8000", "--tonSidecarURL http://ton:8000")
InitCmd.Flags().StringVar(&initConf.ZetaChainID, "chainID", "athens_101-1", "--chainID athens_101-1")
InitCmd.Flags().StringVar(&configFile, local.FlagConfigFile, "e2e.config", "--cfg ./e2e.config")

Expand Down
21 changes: 21 additions & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
flagTestPerformance = "test-performance"
flagTestCustom = "test-custom"
flagTestSolana = "test-solana"
flagTestTON = "test-ton"
flagSkipRegular = "skip-regular"
flagLight = "light"
flagSetupOnly = "setup-only"
Expand Down Expand Up @@ -69,6 +70,7 @@ func NewLocalCmd() *cobra.Command {
cmd.Flags().Bool(flagTestPerformance, false, "set to true to run performance tests")
cmd.Flags().Bool(flagTestCustom, false, "set to true to run custom tests")
cmd.Flags().Bool(flagTestSolana, false, "set to true to run solana tests")
cmd.Flags().Bool(flagTestTON, false, "set to true to run TON tests")
cmd.Flags().Bool(flagSkipRegular, false, "set to true to skip regular tests")
cmd.Flags().Bool(flagLight, false, "run the most basic regular tests, useful for quick checks")
cmd.Flags().Bool(flagSetupOnly, false, "set to true to only setup the networks")
Expand Down Expand Up @@ -98,6 +100,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
testPerformance = must(cmd.Flags().GetBool(flagTestPerformance))
testCustom = must(cmd.Flags().GetBool(flagTestCustom))
testSolana = must(cmd.Flags().GetBool(flagTestSolana))
testTON = must(cmd.Flags().GetBool(flagTestTON))
skipRegular = must(cmd.Flags().GetBool(flagSkipRegular))
light = must(cmd.Flags().GetBool(flagLight))
setupOnly = must(cmd.Flags().GetBool(flagSetupOnly))
Expand Down Expand Up @@ -136,6 +139,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
conf, err := GetConfig(cmd)
noError(err)

// temporary spaghetti to overcome e2e flags limitations
if !testTON {
conf.RPCs.TONSidecarURL = ""
}

// initialize context
ctx, cancel := context.WithCancel(context.Background())

Expand Down Expand Up @@ -379,6 +387,19 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
eg.Go(solanaTestRoutine(conf, deployerRunner, verbose, solanaTests...))
}

if testTON {
if deployerRunner.Clients.TON == nil {
logger.Print("❌ TON client is nil, maybe TON lite-server config is not set")
os.Exit(1)
}

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

eg.Go(tonTestRoutine(conf, deployerRunner, verbose, tonTests...))
}

if testV2 {
// update the ERC20 custody contract for v2 tests
// note: not run in testV2Migration because it is already run in the migration process
Expand Down
Loading

0 comments on commit aa81140

Please sign in to comment.