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 f6d0c9b
Show file tree
Hide file tree
Showing 7 changed files with 722 additions and 326 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
51 changes: 24 additions & 27 deletions crates/aptos/e2e/cases/stake.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# 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 +202,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 All @@ -227,32 +232,6 @@ def test_stake_create_staking_contract(run_helper: RunHelper, test_name=None):
raise TestError("Did not set create staking contract successfully")


@test_case
def test_stake_create_staking_contract(run_helper: RunHelper, test_name=None):
# run the set-operator command
response = run_helper.run_command(
test_name,
[
"aptos",
"stake",
"create-staking-contract",
"--operator",
"operator",
"--voter",
"voter",
"--amount",
"1000000",
"--commission-percentage",
"1",
"--assume-yes",
],
)

result = json.loads(response.stdout)["Result"]
if result.get("success") != True:
raise TestError("Did not set create staking contract successfully")


@test_case
def test_stake_increase_lockup(run_helper: RunHelper, test_name=None):
# run the set-operator command
Expand Down Expand Up @@ -416,3 +395,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")
3 changes: 2 additions & 1 deletion crates/aptos/e2e/local_testnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ def run_node(network: Network, image_repo_with_project: str, pull=True):
]

# Run the container.
LOG.debug("Running command: %s", " ".join(args))
subprocess.run(
args,
**kwargs,
)

LOG.info(f"Running aptos CLI localnet from image: {image_name}")
LOG.info(f"Running aptos CLI localnet from image: {image_name}. Container name: {container_name}")
return container_name


Expand Down
22 changes: 13 additions & 9 deletions crates/aptos/e2e/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""

import argparse
import asyncio
import logging
import os
import pathlib
Expand All @@ -33,8 +34,8 @@

from cases.account import (
test_account_create_and_transfer,
test_account_list,
test_account_fund_with_faucet,
test_account_list,
test_account_lookup_address,
test_account_resource_account,
test_account_rotate_key,
Expand Down Expand Up @@ -134,7 +135,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 +146,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 +171,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 All @@ -182,7 +183,7 @@ def run_tests(run_helper):
test_account_rotate_key(run_helper)


def main():
async def main():
args = parse_args()

if args.debug:
Expand All @@ -197,7 +198,10 @@ def main():

# If we're on Mac and DOCKER_DEFAULT_PLATFORM is not already set, set it to
# linux/amd64 since we only publish images for that platform.
if platform.system().lower() == "darwin" and platform.processor().lower().startswith("arm"):
if (
platform.system().lower() == "darwin"
and platform.processor().lower().startswith("arm")
):
if not os.environ.get("DOCKER_DEFAULT_PLATFORM"):
os.environ["DOCKER_DEFAULT_PLATFORM"] = "linux/amd64"
LOG.info(
Expand Down Expand Up @@ -229,7 +233,7 @@ def main():
run_helper.prepare()

# Run tests.
run_tests(run_helper)
await run_tests(run_helper)
finally:
# Stop the node + faucet.
stop_node(container_name)
Expand Down Expand Up @@ -257,7 +261,7 @@ def main():


if __name__ == "__main__":
if main():
if asyncio.run(main()):
sys.exit(0)
else:
sys.exit(1)
Loading

0 comments on commit f6d0c9b

Please sign in to comment.