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

test: update tss address on connectors and custody contracts #2661

Merged
merged 33 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4258421
rebase develop
kingpinXD Jul 25, 2024
82f52e5
rebase develop
kingpinXD Jul 25, 2024
f7a0d0f
add connectors
kingpinXD Jul 26, 2024
40a2580
debug fees
kingpinXD Jul 30, 2024
6bbe25e
debug fees
kingpinXD Jul 30, 2024
052dbd9
auto remove tracker
kingpinXD Jul 31, 2024
ea915d4
rebase develop
kingpinXD Aug 6, 2024
e7bdf68
rebase develop
kingpinXD Aug 7, 2024
40683ab
debug crosschainswap
kingpinXD Aug 7, 2024
fa403b4
debud btc swap
kingpinXD Aug 7, 2024
d9d1039
enable deposit btc
kingpinXD Aug 7, 2024
310840f
enable deposit btc
kingpinXD Aug 7, 2024
258ed35
fix btc block rewards mining
kingpinXD Aug 8, 2024
028bf50
ad changelog
kingpinXD Aug 8, 2024
e964cee
update cctx timeout
kingpinXD Aug 8, 2024
a68a1b3
update cctx timeout
kingpinXD Aug 9, 2024
865f565
move to unreleased
kingpinXD Aug 9, 2024
86e2921
move to unreleased
kingpinXD Aug 9, 2024
d223a8f
move to unreleased
kingpinXD Aug 9, 2024
c2da535
generate
kingpinXD Aug 9, 2024
0e6fa1c
refactor migration to tss-migration
kingpinXD Aug 12, 2024
a9b72ed
add issue to track increase in DefaultCctxTimeout
kingpinXD Aug 13, 2024
08ecc22
move migration test to a separate file
kingpinXD Aug 16, 2024
ab6c963
rebase develop
kingpinXD Aug 19, 2024
d006585
generate files
kingpinXD Aug 19, 2024
fd6548b
generate files
kingpinXD Aug 19, 2024
6e0a3cd
increase DefaultCctxTimeout
kingpinXD Aug 19, 2024
6f63131
rename to admin evm
kingpinXD Aug 19, 2024
b66c368
add unit test for failed to set outbound info
kingpinXD Aug 20, 2024
cde07a3
Merge branch 'develop' into update-connectors
kingpinXD Aug 21, 2024
c9a49f8
reduce cctx time to try getting CI to run successfully
kingpinXD Aug 21, 2024
bff9cc1
increase cctx timeout
kingpinXD Aug 22, 2024
01587c2
increase timeout for tss migration tests
kingpinXD Aug 22, 2024
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: 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
Loading