Skip to content

Commit

Permalink
test: update tss address on connectors and custody contracts (#2661)
Browse files Browse the repository at this point in the history
* rebase develop

* rebase develop

* add connectors

* debug fees

* debug fees

* auto remove tracker

* rebase develop

* debug crosschainswap

* debud btc swap

* enable deposit btc

* enable deposit btc

* ad changelog

* update cctx timeout

* update cctx timeout

* move to unreleased

* move to unreleased

* move to unreleased

* generate

* refactor migration to tss-migration

* add issue to track increase in DefaultCctxTimeout

* move migration test to a separate file

* generate files

* generate files

* increase DefaultCctxTimeout

* rename to admin evm

* add unit test for failed to set outbound info

* reduce cctx time to try getting CI to run successfully

* increase cctx timeout

* increase timeout for tss migration tests
  • Loading branch information
kingpinXD authored Aug 22, 2024
1 parent 1d5cee1 commit 1ad2bde
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 133 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ jobs:
- make-target: "start-tss-migration-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.TSS_MIGRATION_TESTS == 'true' }}
timeout-minutes: 40
- make-target: "start-solana-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.SOLANA_TESTS == 'true' }}
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ start-stress-test: zetanode
cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile stress -f docker-compose.yml up -d

start-tss-migration-test: zetanode
@echo "--> Starting migration test"
@echo "--> Starting tss migration test"
export LOCALNET_MODE=tss-migrate && \
export E2E_ARGS="--test-tss-migration" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) up -d

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

### Tests

* [2661](https://github.com/zeta-chain/node/pull/2661) - update connector and erc20Custody addresses in tss migration e2e tests
* [2726](https://github.com/zeta-chain/node/pull/2726) - add e2e tests for deposit and call, deposit and revert

### Fixes
Expand Down
45 changes: 1 addition & 44 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"

zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
Expand Down Expand Up @@ -439,7 +438,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
logger.Print("✅ e2e tests completed in %s", time.Since(testStartTime).String())

if testTSSMigration {
runTSSMigrationTest(deployerRunner, logger, verbose, conf)
TSSMigration(deployerRunner, logger, verbose, conf)
}
// Verify that there are no trackers left over after tests complete
if !skipTrackerCheck {
Expand Down Expand Up @@ -496,48 +495,6 @@ func waitKeygenHeight(
}
}

func runTSSMigrationTest(deployerRunner *runner.E2ERunner, logger *runner.Logger, verbose bool, conf config.Config) {
migrationStartTime := time.Now()
logger.Print("🏁 starting tss migration")

response, err := deployerRunner.CctxClient.LastZetaHeight(
deployerRunner.Ctx,
&crosschaintypes.QueryLastZetaHeightRequest{},
)
require.NoError(deployerRunner, err)
err = deployerRunner.ZetaTxServer.UpdateKeygen(response.Height)
require.NoError(deployerRunner, err)

// Generate new TSS
waitKeygenHeight(deployerRunner.Ctx, deployerRunner.CctxClient, deployerRunner.ObserverClient, logger, 0)

// migration test is a blocking thread, we cannot run other tests in parallel
// The migration test migrates funds to a new TSS and then updates the TSS address on zetacore.
// The necessary restarts are done by the zetaclient supervisor
fn := migrationTestRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTSSName)

if err := fn(); err != nil {
logger.Print("❌ %v", err)
logger.Print("❌ tss migration failed")
os.Exit(1)
}

logger.Print("✅ migration completed in %s ", time.Since(migrationStartTime).String())
logger.Print("🏁 starting post migration tests")

tests := []string{
e2etests.TestBitcoinWithdrawSegWitName,
e2etests.TestEtherWithdrawName,
}
fn = postMigrationTestRoutine(conf, deployerRunner, verbose, tests...)

if err := fn(); err != nil {
logger.Print("❌ %v", err)
logger.Print("❌ post migration tests failed")
os.Exit(1)
}
}

func must[T any](v T, err error) T {
return testutil.Must(v, err)
}
4 changes: 2 additions & 2 deletions cmd/zetae2e/local/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/zeta-chain/zetacore/e2e/runner"
)

// migrationTestRoutine runs migration related e2e tests
func migrationTestRoutine(
// migrationRoutine runs migration related e2e tests
func migrationRoutine(
conf config.Config,
deployerRunner *runner.E2ERunner,
verbose bool,
Expand Down
58 changes: 0 additions & 58 deletions cmd/zetae2e/local/post_migration.go

This file was deleted.

43 changes: 43 additions & 0 deletions cmd/zetae2e/local/tss_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package local

import (
"os"
"time"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/e2etests"
"github.com/zeta-chain/zetacore/e2e/runner"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

func TSSMigration(deployerRunner *runner.E2ERunner, logger *runner.Logger, verbose bool, conf config.Config) {
migrationStartTime := time.Now()
logger.Print("🏁 starting tss migration")

response, err := deployerRunner.CctxClient.LastZetaHeight(
deployerRunner.Ctx,
&crosschaintypes.QueryLastZetaHeightRequest{},
)
require.NoError(deployerRunner, err)
err = deployerRunner.ZetaTxServer.UpdateKeygen(response.Height)
require.NoError(deployerRunner, err)

// Generate new TSS
waitKeygenHeight(deployerRunner.Ctx, deployerRunner.CctxClient, deployerRunner.ObserverClient, logger, 0)

// Run migration
// migrationRoutine runs migration e2e test , which migrates funds from the older TSS to the new one
// The zetaclient restarts required for this process are managed by the background workers in zetaclient (TSSListener)
fn := migrationRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTSSName)

if err := fn(); err != nil {
logger.Print("❌ %v", err)
logger.Print("❌ tss migration failed")
os.Exit(1)
}
deployerRunner.UpdateTssAddressForConnector()
deployerRunner.UpdateTssAddressForErc20custody()
logger.Print("✅ migration completed in %s ", time.Since(migrationStartTime).String())
}
42 changes: 40 additions & 2 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,45 @@ fi

### Run zetae2e command depending on the option passed

# Mode migrate is used to run the e2e tests before and after the TSS migration
# It runs the e2e tests with the migrate flag which triggers a TSS migration at the end of the tests. Once the migrationis done the first e2e test is complete
# The second e2e test is run after the migration to ensure the network is still working as expected with the new tss address
if [ "$LOCALNET_MODE" == "tss-migrate" ]; then
if [[ ! -f deployed.yml ]]; then
zetae2e local $E2E_ARGS --setup-only --config config.yml --config-out deployed.yml --skip-header-proof
if [ $? -ne 0 ]; then
echo "e2e setup failed"
exit 1
fi
else
echo "skipping e2e setup because it has already been completed"
fi

echo "running e2e test before migrating TSS"
zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --skip-header-proof
if [ $? -ne 0 ]; then
echo "first e2e failed"
exit 1
fi

echo "waiting 10 seconds for node to restart"
sleep 10

zetae2e local --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof
ZETAE2E_EXIT_CODE=$?
if [ $ZETAE2E_EXIT_CODE -eq 0 ]; then
echo "E2E passed after migration"
exit 0
else
echo "E2E failed after migration"
exit 1
fi
fi


# Mode upgrade is used to run the e2e tests before and after the upgrade
# It runs the e2e tests , waits for the upgrade height to be reached, and then runs the e2e tests again once the ungrade is done.
# The second e2e test is run after the upgrade to ensure the network is still working as expected with the new version
if [ "$LOCALNET_MODE" == "upgrade" ]; then

# Run the e2e tests, then restart zetaclientd at upgrade height and run the e2e tests again
Expand Down Expand Up @@ -185,8 +224,7 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then
fi

else

# Run the e2e tests normally
# If no mode is passed, run the e2e tests normally
echo "running e2e setup..."

if [[ ! -f deployed.yml ]]; then
Expand Down
12 changes: 6 additions & 6 deletions e2e/e2etests/test_crosschain_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
)

func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
stop := r.MineBlocksIfLocalBitcoin()
defer stop()
r.ZEVMAuth.GasLimit = 10000000

// TODO: move into setup and skip it if already initialized
Expand All @@ -23,7 +25,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
// if the tx fails due to already initialized, it will be ignored
_, err := r.UniswapV2Factory.CreatePair(r.ZEVMAuth, r.ERC20ZRC20Addr, r.BTCZRC20Addr)
if err != nil {
r.Logger.Print("ℹ️create pair error")
r.Logger.Print("ℹ️ create pair error")
}

txERC20ZRC20Approve, err := r.ERC20ZRC20.Approve(r.ZEVMAuth, r.UniswapV2RouterAddr, big.NewInt(1e18))
Expand Down Expand Up @@ -90,10 +92,6 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
_, err = r.GenerateToAddressIfLocalBitcoin(10, r.BTCDeployerAddress)
require.NoError(r, err)

// mine blocks if testing on regnet
stop := r.MineBlocksIfLocalBitcoin()
defer stop()

// cctx1 index acts like the inboundHash for the second cctx (the one that withdraws BTC)
cctx2 := utils.WaitCctxMinedByInboundHash(r.Ctx, cctx1.Index, r.CctxClient, r.Logger, r.CctxTimeout)

Expand Down Expand Up @@ -145,7 +143,9 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
r.Logger.Info("memo length %d", len(memo))

amount := 0.1
txid, err := r.SendToTSSFromDeployerWithMemo(amount, utxos[1:2], memo)
utxos, err = r.ListDeployerUTXOs()
require.NoError(r, err)
txid, err := r.SendToTSSFromDeployerWithMemo(amount, utxos[0:1], memo)
require.NoError(r, err)

cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txid.String(), r.CctxClient, r.Logger, r.CctxTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestMessagePassingRevertFailExternalChains(r *runner.E2ERunner, args []stri
r.Logger.Info(" Zeta Value: %d", sentLog.ZetaValueAndGas)
}
}

// expect revert tx to fail
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, receipt.TxHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
receipt, err = r.EVMClient.TransactionReceipt(r.Ctx, ethcommon.HexToHash(cctx.GetCurrentOutboundParam().Hash))
Expand Down
1 change: 0 additions & 1 deletion e2e/e2etests/test_migrate_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {
require.LessOrEqual(r, btcTSSBalanceNew*1e8, btcTSSBalanceOld*1e8)

// ETH

r.TSSAddress = common.HexToAddress(newTss.Eth)
ethTSSBalanceNew, err := r.EVMClient.BalanceAt(context.Background(), r.TSSAddress, nil)
require.NoError(r, err)
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_zrc20_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestZRC20Swap(r *runner.E2ERunner, _ []string) {
// if the tx fails due to already initialized, it will be ignored
tx, err := r.UniswapV2Factory.CreatePair(r.ZEVMAuth, r.ERC20ZRC20Addr, r.ETHZRC20Addr)
if err != nil {
r.Logger.Print("ℹ️create pair error")
r.Logger.Print("ℹ️ create pair error")
} else {
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
}
Expand Down
38 changes: 38 additions & 0 deletions e2e/runner/admin_evm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package runner

import (
"fmt"

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

"github.com/zeta-chain/zetacore/e2e/utils"
)

func (r *E2ERunner) UpdateTssAddressForConnector() {
require.NoError(r, r.SetTSSAddresses())

tx, err := r.ConnectorEth.UpdateTssAddress(r.EVMAuth, r.TSSAddress)
require.NoError(r, err)
r.Logger.Info(fmt.Sprintf("TSS Address Update Tx: %s", tx.Hash().String()))
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)

tssAddressOnConnector, err := r.ConnectorEth.TssAddress(&bind.CallOpts{Context: r.Ctx})
require.NoError(r, err)
require.Equal(r, r.TSSAddress, tssAddressOnConnector)
}

func (r *E2ERunner) UpdateTssAddressForErc20custody() {
require.NoError(r, r.SetTSSAddresses())

tx, err := r.ERC20Custody.UpdateTSSAddress(r.EVMAuth, r.TSSAddress)
require.NoError(r, err)
r.Logger.Info(fmt.Sprintf("TSS ERC20 Address Update Tx: %s", tx.Hash().String()))
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)

tssAddressOnCustody, err := r.ERC20Custody.TSSAddress(&bind.CallOpts{Context: r.Ctx})
require.NoError(r, err)
require.Equal(r, r.TSSAddress, tssAddressOnCustody)
}
5 changes: 4 additions & 1 deletion e2e/utils/zetacore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ const (
EmergencyPolicyName = "emergency"
AdminPolicyName = "admin"
OperationalPolicyName = "operational"
// The timeout was increased from 4 to 6 , which allows for a higher success in test runs
// However this needs to be researched as to why the increase in timeout was needed.
// https://github.com/zeta-chain/node/issues/2690

DefaultCctxTimeout = 6 * time.Minute
DefaultCctxTimeout = 8 * time.Minute
)

// WaitCctxMinedByInboundHash waits until cctx is mined; returns the cctxIndex (the last one)
Expand Down
6 changes: 6 additions & 0 deletions x/crosschain/keeper/msg_server_migrate_tss_funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func (k Keeper) initiateMigrateTSSFundsCCTX(
return err
}

// Set the CCTX and the nonce for the outbound migration
err = k.SetObserverOutboundInfo(ctx, chainID, &cctx)
if err != nil {
return errorsmod.Wrap(types.ErrUnableToSetOutboundInfo, err.Error())
}

// The migrate funds can be run again to update the migration cctx index if the migration fails
// This should be used after carefully calculating the amount again
existingMigrationInfo, found := k.zetaObserverKeeper.GetFundMigrator(ctx, chainID)
Expand Down
Loading

0 comments on commit 1ad2bde

Please sign in to comment.