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

fix: support multiple runs for precomplies e2e test #2874

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 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
* [2874](https://github.com/zeta-chain/node/pull/2874) - add support for multiple runs for precompile tests

### Fixes

Expand Down
6 changes: 3 additions & 3 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ if [ "$LOCALNET_MODE" == "tss-migrate" ]; then
echo "waiting 10 seconds for node to restart"
sleep 10

zetae2e local --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof --skip-precompiles
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"
Expand Down Expand Up @@ -259,9 +259,9 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then
# When the upgrade height is greater than 100 for upgrade test, the Bitcoin tests have been run once, therefore the Bitcoin wallet is already set up
# Use light flag to skip advanced tests
if [ "$UPGRADE_HEIGHT" -lt 100 ]; then
zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --light --skip-precompiles ${COMMON_ARGS}
zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --light ${COMMON_ARGS}
else
zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-precompiles ${COMMON_ARGS}
zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --skip-bitcoin-setup --light ${COMMON_ARGS}
fi

ZETAE2E_EXIT_CODE=$?
Expand Down
28 changes: 28 additions & 0 deletions e2e/e2etests/test_precompiles_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestPrecompilesStaking(r *runner.E2ERunner, args []string) {
require.NoError(r, err)
require.GreaterOrEqual(r, len(validators), 2)

CleanValidatorDelegations(r, stakingContract, validators)

// shares are 0 for both validators at the start
sharesBeforeVal1, err := stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[0].OperatorAddress)
require.NoError(r, err)
Expand Down Expand Up @@ -109,3 +111,29 @@ func TestPrecompilesStaking(r *runner.E2ERunner, args []string) {
require.NoError(r, err)
require.Equal(r, int64(1), delegationAfterVal2.DelegationResponse.Balance.Amount.Int64())
}

// CleanValidatorDelegations unstakes all delegations from the given validators if delegations ar present
func CleanValidatorDelegations(r *runner.E2ERunner, stakingContract *staking.IStaking, validators []staking.Validator) {
for _, validator := range validators {
delegator := sdk.AccAddress(r.ZEVMAuth.From.Bytes()).String()
delegation, err := r.StakingClient.Delegation(r.Ctx, &types.QueryDelegationRequest{
DelegatorAddr: delegator,
ValidatorAddr: validator.OperatorAddress,
})
if err != nil || delegation.DelegationResponse == nil {
continue
}

delegationAmount := delegation.DelegationResponse.Balance.Amount.Int64()
if delegationAmount > 0 && err == nil {
tx, err := stakingContract.Unstake(
r.ZEVMAuth,
r.ZEVMAuth.From,
validator.OperatorAddress,
big.NewInt(delegationAmount),
)
require.NoError(r, err)
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
}
}
}
Loading