Skip to content

Commit

Permalink
[CLI][E2E] Wait for reconfiguration in staking tests, use latest Pyth…
Browse files Browse the repository at this point in the history
…on SDK
  • Loading branch information
banool committed May 23, 2024
1 parent a061e5b commit cb4bd5b
Show file tree
Hide file tree
Showing 6 changed files with 712 additions and 294 deletions.
10 changes: 5 additions & 5 deletions crates/aptos/e2e/cases/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@test_case
def test_account_fund_with_faucet(run_helper: RunHelper, test_name=None):
async def test_account_fund_with_faucet(run_helper: RunHelper, test_name=None):
amount_in_octa = 100000000000

# Fund the account.
Expand All @@ -29,7 +29,7 @@ def test_account_fund_with_faucet(run_helper: RunHelper, test_name=None):

# Assert it has the requested balance.
balance = int(
run_helper.api_client.account_balance(
await run_helper.api_client.account_balance(
run_helper.get_account_info().account_address
)
)
Expand All @@ -40,7 +40,7 @@ def test_account_fund_with_faucet(run_helper: RunHelper, test_name=None):


@test_case
def test_account_create_and_transfer(run_helper: RunHelper, test_name=None):
async def test_account_create_and_transfer(run_helper: RunHelper, test_name=None):
# Create the new account.
run_helper.run_command(
test_name,
Expand All @@ -56,7 +56,7 @@ def test_account_create_and_transfer(run_helper: RunHelper, test_name=None):

# Assert it exists and has zero balance.
balance = int(
run_helper.api_client.account_balance(OTHER_ACCOUNT_ONE.account_address)
await run_helper.api_client.account_balance(OTHER_ACCOUNT_ONE.account_address)
)
if balance != 0:
raise TestError(
Expand All @@ -80,7 +80,7 @@ def test_account_create_and_transfer(run_helper: RunHelper, test_name=None):
)

balance = int(
run_helper.api_client.account_balance(OTHER_ACCOUNT_ONE.account_address)
await run_helper.api_client.account_balance(OTHER_ACCOUNT_ONE.account_address)
)

if balance != transfer_amount:
Expand Down
26 changes: 25 additions & 1 deletion crates/aptos/e2e/cases/stake.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Copyright © Aptos Foundation
# SPDX-License-Identifier: Apache-2.0

import asyncio
import json

from aptos_sdk.account_address import AccountAddress

from common import TestError
from test_helpers import RunHelper
from test_results import test_case
Expand Down Expand Up @@ -200,7 +203,10 @@ def test_stake_set_voter(run_helper: RunHelper, test_name=None):


@test_case
def test_stake_create_staking_contract(run_helper: RunHelper, test_name=None):
async def test_stake_create_staking_contract(run_helper: RunHelper, test_name=None):
# First wait for reconfiguration to finish.
await wait_for_reconfiguration(run_helper)

# run the set-operator command
# Note: This command has to run after set-operator and set-voter
# because it needs to know the operator and voter addresses
Expand Down Expand Up @@ -416,3 +422,21 @@ def test_stake_request_commission(run_helper: RunHelper, test_name=None):
result = json.loads(response.stdout)["Result"]
if result.get("success") != True:
raise TestError("Did not execute [request-commission] successfully")


async def wait_for_reconfiguration(run_helper: RunHelper):
# First wait for reconfiguration to finish.
print("Waiting for reconfiguration to finish...")
attempts = 0
while True:
response = await run_helper.api_client.account_resource(
AccountAddress.from_str("0x1"),
"0x1::reconfiguration_state::State",
)
if response["data"]["variant"]["data"] == "0x00":
break
attempts += 1
if attempts > 20:
raise TestError("Reconfiguration did not finish in time")
await asyncio.sleep(0.5)
print("Reconfiguration finished")
8 changes: 4 additions & 4 deletions crates/aptos/e2e/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def parse_args():
return args


def run_tests(run_helper):
async def run_tests(run_helper):
# Make sure the metrics port is accessible.
test_metrics_accessible(run_helper)

Expand All @@ -145,8 +145,8 @@ def run_tests(run_helper):
test_config_show_profiles(run_helper)

# Run account tests.
test_account_fund_with_faucet(run_helper)
test_account_create_and_transfer(run_helper)
await test_account_fund_with_faucet(run_helper)
await test_account_create_and_transfer(run_helper)
test_account_list(run_helper)
test_account_lookup_address(run_helper)
test_account_resource_account(run_helper)
Expand All @@ -170,7 +170,7 @@ def run_tests(run_helper):
test_stake_increase_lockup(run_helper)
test_stake_set_operator(run_helper)
test_stake_set_voter(run_helper)
test_stake_create_staking_contract(run_helper)
await test_stake_create_staking_contract(run_helper)
test_stake_request_commission(run_helper)

# Run node subcommand group tests.
Expand Down

0 comments on commit cb4bd5b

Please sign in to comment.