From aa1ffb9eefaf277a7321ff24341632d9da80735b Mon Sep 17 00:00:00 2001 From: gabi-vuls Date: Tue, 16 Apr 2024 16:57:36 +0300 Subject: [PATCH 1/5] added test file --- testing-suite/staking-v4/scenarios/PR_6114.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 testing-suite/staking-v4/scenarios/PR_6114.py diff --git a/testing-suite/staking-v4/scenarios/PR_6114.py b/testing-suite/staking-v4/scenarios/PR_6114.py new file mode 100644 index 00000000..3dad4dae --- /dev/null +++ b/testing-suite/staking-v4/scenarios/PR_6114.py @@ -0,0 +1,26 @@ +import threading +import delegation +import time +from config import * +from delegation import * +from chain_commander import * +from get_info import * +from staking import * +from delegation import * +from core.wallet import * +from core.validatorKey import * +from core.chain_simulator import * +from threading import Thread + +# SCENARIO 1 +# Have every epoch auction list with enough nodes (let's say 8 qualified, 2 unqualified) +# Unstake 1 or more eligible/waiting nodes (no more than all nodes per shard or no more than all eligible) +# and call auction list api; we should see 8 qualified nodes. Next epoch we need to check that exactly 8 nodes were qualified. +# Afterwards(some epochs), those leaving nodes will be leaving and replaced by the auction nodes + +def main(): + + + +if __name__ == '__main__': + main() \ No newline at end of file From d4feeb4d9b64eac49bcc748a98864a80ddaf05bf Mon Sep 17 00:00:00 2001 From: gabi-vuls Date: Tue, 23 Apr 2024 17:56:35 +0300 Subject: [PATCH 2/5] added scenario for PR 6114 and a small refactor --- testing-suite/staking-v4/caching.py | 9 + testing-suite/staking-v4/chain_commander.py | 58 +++++- testing-suite/staking-v4/config.py | 5 + testing-suite/staking-v4/core/validatorKey.py | 49 ++++- testing-suite/staking-v4/core/wallet.py | 6 +- testing-suite/staking-v4/delegation.py | 1 - .../get_infos/get_delegation_info.py | 25 +++ .../staking-v4/get_infos/get_staking_info.py | 28 +++ .../get_infos/get_transaction_info.py | 32 ++++ .../get_validator_info.py} | 147 ++++++++------- testing-suite/staking-v4/scenarios/PR_6114.py | 175 +++++++++++++++++- testing-suite/staking-v4/scenarios/_48.py | 14 +- testing-suite/staking-v4/scenarios/_49_50.py | 10 +- testing-suite/staking-v4/scenarios/_68_69.py | 3 +- testing-suite/staking-v4/staking.py | 28 ++- 15 files changed, 471 insertions(+), 119 deletions(-) create mode 100644 testing-suite/staking-v4/caching.py create mode 100644 testing-suite/staking-v4/get_infos/get_delegation_info.py create mode 100644 testing-suite/staking-v4/get_infos/get_staking_info.py create mode 100644 testing-suite/staking-v4/get_infos/get_transaction_info.py rename testing-suite/staking-v4/{get_info.py => get_infos/get_validator_info.py} (52%) diff --git a/testing-suite/staking-v4/caching.py b/testing-suite/staking-v4/caching.py new file mode 100644 index 00000000..e7614b34 --- /dev/null +++ b/testing-suite/staking-v4/caching.py @@ -0,0 +1,9 @@ +import requests +from config import DEFAULT_PROXY + + +def force_reset_validator_statistics(): + route = f"{DEFAULT_PROXY}/simulator/force-reset-validator-statistics" + response = requests.post(route) + response.raise_for_status() + diff --git a/testing-suite/staking-v4/chain_commander.py b/testing-suite/staking-v4/chain_commander.py index bdd11b7c..59ef2fd4 100644 --- a/testing-suite/staking-v4/chain_commander.py +++ b/testing-suite/staking-v4/chain_commander.py @@ -2,9 +2,10 @@ import json from config import * -from get_info import * +from get_infos.get_transaction_info import get_status_of_tx from constants import * import time +from core.validatorKey import ValidatorKey def send_egld_to_address(egld_amount, erd_address): @@ -26,8 +27,19 @@ def add_blocks(nr_of_blocks): return req.text +def get_block() -> int: + response = requests.get(f"{DEFAULT_PROXY}/network/status/0") + parsed = response.json() + + general_data = parsed.get("data") + general_status = general_data.get("status") + nonce = general_status.get("erd_nonce") + return nonce + + def add_blocks_until_epoch_reached(epoch_to_be_reached: int): req = requests.post(f"{DEFAULT_PROXY}/simulator/generate-blocks-until-epoch-reached/{str(epoch_to_be_reached)}") + add_blocks(1) return req.text @@ -61,14 +73,11 @@ def is_chain_online() -> bool: return flag -def force_reset_validator_statistics(): - req = requests.post(f"{DEFAULT_PROXY}/simulator/force-reset-validator-statistics") - print(req.text) - - return req.text +def add_key(keys: list[ValidatorKey]) -> str: + private_keys = [] + for key in keys: + private_keys.append(key.get_private_key()) - -def add_key(private_keys: list) -> str: post_body = { "privateKeysBase64": private_keys } @@ -77,3 +86,36 @@ def add_key(private_keys: list) -> str: req = requests.post(f"{DEFAULT_PROXY}/simulator/add-keys", data=json_structure) return req.text + + +def add_blocks_until_key_eligible(keys: list[ValidatorKey]) -> ValidatorKey: + flag = False + while not flag: + for key in keys: + if key.get_state() == "eligible": + eligible_key = key + print("eligible key found") + flag = True + + else: + print("no eligible key found , moving to next epoch...") + current_epoch = proxy_default.get_network_status().epoch_number + add_blocks_until_epoch_reached(current_epoch+1) + add_blocks(3) + + return eligible_key + + +def add_blocks_until_last_block_of_current_epoch() -> str: + response = requests.get(f"{DEFAULT_PROXY}/network/status/4294967295") + response.raise_for_status() + parsed = response.json() + + general_data = parsed.get("data") + status = general_data.get("status") + passed_nonces = status.get("erd_nonces_passed_in_current_epoch") + + blocks_to_be_added = 50 - passed_nonces + response_from_add_blocks = add_blocks(blocks_to_be_added) + return response_from_add_blocks + diff --git a/testing-suite/staking-v4/config.py b/testing-suite/staking-v4/config.py index 48be9349..0603d197 100644 --- a/testing-suite/staking-v4/config.py +++ b/testing-suite/staking-v4/config.py @@ -8,6 +8,9 @@ DEFAULT_PROXY = PROXY_CHAIN_SIMULATOR +# TEMP +OBSERVER_META = "http://localhost:55802" + try: proxy_default = ProxyNetworkProvider(DEFAULT_PROXY) except: @@ -24,5 +27,7 @@ num_validators_meta = "10" num_waiting_validators_per_shard = "6" num_waiting_validators_meta = "6" +# real config after staking v4 full activation: eligible = 10 *4 , waiting = (6-2) *4, qualified = 2*4 +# qualified nodes from auction will stay in wiating 2 epochs rounds_per_epoch = "50" diff --git a/testing-suite/staking-v4/core/validatorKey.py b/testing-suite/staking-v4/core/validatorKey.py index f8dc5679..1742f7af 100644 --- a/testing-suite/staking-v4/core/validatorKey.py +++ b/testing-suite/staking-v4/core/validatorKey.py @@ -1,11 +1,15 @@ import requests +import time +import urllib.request, json +import wget + from core.wallet import * from pathlib import Path -from helpers import * -from get_info import * -from constants import * -from chain_commander import * +from caching import force_reset_validator_statistics +from get_infos.get_validator_info import get_bls_key_status +from get_infos.get_validator_info import get_owner +from config import DEFAULT_PROXY, OBSERVER_META class ValidatorKey: @@ -35,26 +39,53 @@ def get_status(self, owner_address: str) -> str: return status # is using /validator/statistics route - def get_state(self) -> str: + def get_state(self): + force_reset_validator_statistics() - # sometimes it needs a second until cache is resetting + # sometimes it needs few seconds until cache is resetting time.sleep(1) - response = requests.get(f"{DEFAULT_PROXY}/validator/statistics") + response = requests.get(f"{OBSERVER_META}/validator/statistics") response.raise_for_status() parsed = response.json() general_data = parsed.get("data") general_statistics = general_data.get("statistics") key_data = general_statistics.get(self.public_address()) + if key_data is None: - return "Key not present in validator/statistics" + return None else: status = key_data.get("validatorStatus") return status - # using getOwner vm-query + # is using /validator/auction + def get_auction_state(self): + force_reset_validator_statistics() + + # sometimes it needs few seconds until cache is resetting + time.sleep(1) + + response = requests.get(f"{OBSERVER_META}/validator/auction") + response.raise_for_status() + parsed = response.json() + + general_data = parsed.get("data") + auction_list_data = general_data.get("auctionList") + + for list in auction_list_data: + nodes_lists = list.get("nodes") + for node_list in nodes_lists: + if node_list.get("blsKey") == self.public_address(): + state = node_list.get("qualified") + if state: + return "qualified" + else: + return "unqualified" + + + # using getOwner vm-query def belongs_to(self, address: str) -> bool: owner = get_owner([self.public_address()]) if owner == address: diff --git a/testing-suite/staking-v4/core/wallet.py b/testing-suite/staking-v4/core/wallet.py index 7d433c88..f0db7b41 100644 --- a/testing-suite/staking-v4/core/wallet.py +++ b/testing-suite/staking-v4/core/wallet.py @@ -1,13 +1,9 @@ -from pathlib import Path + from config import * import requests import json -from multiversx_sdk_network_providers import ProxyNetworkProvider from multiversx_sdk_wallet import UserSigner from multiversx_sdk_core import Address -from multiversx_sdk_network_providers import accounts -from helpers import * -from constants import * class Wallet: diff --git a/testing-suite/staking-v4/delegation.py b/testing-suite/staking-v4/delegation.py index 6eab1128..da78fa75 100644 --- a/testing-suite/staking-v4/delegation.py +++ b/testing-suite/staking-v4/delegation.py @@ -5,7 +5,6 @@ from multiversx_sdk_core.transaction import TransactionComputer from multiversx_sdk_network_providers import ProxyNetworkProvider from multiversx_sdk_wallet import UserSigner -from get_info import * from config import * from helpers import * from core.wallet import * diff --git a/testing-suite/staking-v4/get_infos/get_delegation_info.py b/testing-suite/staking-v4/get_infos/get_delegation_info.py new file mode 100644 index 00000000..c546e9c0 --- /dev/null +++ b/testing-suite/staking-v4/get_infos/get_delegation_info.py @@ -0,0 +1,25 @@ +import requests +from config import DEFAULT_PROXY +from helpers import base64_to_hex +from multiversx_sdk_core import Address + + +def get_delegation_contract_address_from_tx(tx_hash): + + response = requests.get(f"{DEFAULT_PROXY}/transaction/{tx_hash}?withResults=True") + response.raise_for_status() + parsed = response.json() + + general_data = parsed.get("data") + transaction_data = general_data.get("transaction") + logs_data = transaction_data.get("logs") + events_data = logs_data.get("events") + first_set_of_events = events_data[0] + topics = first_set_of_events.get("topics") + delegation_contract_address = topics[1] + + delegation_contract_address = base64_to_hex(delegation_contract_address) + delegation_contract_address = Address.from_hex(delegation_contract_address, "erd").to_bech32() + + return delegation_contract_address + diff --git a/testing-suite/staking-v4/get_infos/get_staking_info.py b/testing-suite/staking-v4/get_infos/get_staking_info.py new file mode 100644 index 00000000..9677784a --- /dev/null +++ b/testing-suite/staking-v4/get_infos/get_staking_info.py @@ -0,0 +1,28 @@ +import requests +import json +from multiversx_sdk_core import Address +from constants import VALIDATOR_CONTRACT +from config import DEFAULT_PROXY +from helpers import base64_to_string + + +def get_total_staked(owner: str): + address_in_hex = Address.from_bech32(owner).to_hex() + post_body = { + "scAddress": VALIDATOR_CONTRACT, + "funcName": "getTotalStaked", + "args": [address_in_hex] + } + + json_structure = json.dumps(post_body) + response = requests.post(f"{DEFAULT_PROXY}/vm-values/query", data=json_structure) + response.raise_for_status() + parsed = response.json() + + general_data = parsed.get("data") + tx_response_data = general_data.get("data") + total_staked_list = tx_response_data.get("returnData") + total_staked = total_staked_list[0] + + total_staked = base64_to_string(total_staked) + return total_staked \ No newline at end of file diff --git a/testing-suite/staking-v4/get_infos/get_transaction_info.py b/testing-suite/staking-v4/get_infos/get_transaction_info.py new file mode 100644 index 00000000..377ba3ce --- /dev/null +++ b/testing-suite/staking-v4/get_infos/get_transaction_info.py @@ -0,0 +1,32 @@ + +import requests +from config import DEFAULT_PROXY +from helpers import string_to_base64 + +def get_status_of_tx(tx_hash: str) -> str: + response = requests.get(f"{DEFAULT_PROXY}/transaction/{tx_hash}/process-status") + response.raise_for_status() + parsed = response.json() + + if "transaction not found" in response.text: + return "expired" + + general_data = parsed.get("data") + status = general_data.get("status") + return status + + +def check_if_error_is_present_in_tx(error, tx_hash) -> bool: + flag = False + error_bytes = string_to_base64(error) + + response = requests.get(f"{DEFAULT_PROXY}/transaction/{tx_hash}?withResults=True") + response.raise_for_status() + + if error_bytes.decode() in response.text: + flag = True + + if error in response.text: + flag = True + + return flag \ No newline at end of file diff --git a/testing-suite/staking-v4/get_info.py b/testing-suite/staking-v4/get_infos/get_validator_info.py similarity index 52% rename from testing-suite/staking-v4/get_info.py rename to testing-suite/staking-v4/get_infos/get_validator_info.py index 9a209bb2..49efba2a 100644 --- a/testing-suite/staking-v4/get_info.py +++ b/testing-suite/staking-v4/get_infos/get_validator_info.py @@ -1,45 +1,14 @@ -import base64 - -import requests -from config import * -from helpers import * -from multiversx_sdk_core import Address import json import time -from constants import * - - -def get_status_of_tx(tx_hash: str) -> str: - response = requests.get(f"{DEFAULT_PROXY}/transaction/{tx_hash}/process-status") - response.raise_for_status() - parsed = response.json() - - if "transaction not found" in response.text: - return "expired" - - general_data = parsed.get("data") - status = general_data.get("status") - return status - - -def get_delegation_contract_address_from_tx(tx_hash): - - response = requests.get(f"{DEFAULT_PROXY}/transaction/{tx_hash}?withResults=True") - response.raise_for_status() - parsed = response.json() - general_data = parsed.get("data") - transaction_data = general_data.get("transaction") - logs_data = transaction_data.get("logs") - events_data = logs_data.get("events") - first_set_of_events = events_data[0] - topics = first_set_of_events.get("topics") - delegation_contract_address = topics[1] - - delegation_contract_address = base64_to_hex(delegation_contract_address) - delegation_contract_address = Address.from_hex(delegation_contract_address, "erd").to_bech32() - - return delegation_contract_address +import requests +from config import DEFAULT_PROXY, OBSERVER_META +from constants import STAKING_CONTRACT +from constants import VALIDATOR_CONTRACT +from helpers import base64_to_hex +from helpers import base64_to_string +from multiversx_sdk_core import Address +from caching import force_reset_validator_statistics def get_bls_key_status(owner_public_key_in_hex: list[str]): @@ -74,7 +43,6 @@ def get_bls_key_status(owner_public_key_in_hex: list[str]): def get_owner(public_validator_key: list[str]) -> str: - post_body = { "scAddress": STAKING_CONTRACT, "funcName": "getOwner", @@ -101,39 +69,90 @@ def get_owner(public_validator_key: list[str]) -> str: return address -def check_if_error_is_present_in_tx(error, tx_hash) -> bool: - flag = False - error_bytes = string_to_base64(error) +# using validator/statistics +def get_keys_state(keys: list) -> list[str]: + states = [] + + force_reset_validator_statistics() + time.sleep(1) - req = requests.get(f"{DEFAULT_PROXY}/transaction/{tx_hash}?withResults=True") - response = req.text + response = requests.get(f"{OBSERVER_META}/validator/statistics") + response.raise_for_status() - if error_bytes.decode() in response: - flag = True + parsed = response.json() - if error in response: - flag = True + general_data = parsed.get("data") + statistics = general_data.get("statistics") - return flag + for key in keys: + if not statistics.get(key) is None: + key_data = statistics.get(key) + state = key_data.get("validatorStatus") + states.append(state) + return states -def get_total_staked(owner: str): - address_in_hex = Address.from_bech32(owner).to_hex() - post_body = { - "scAddress": VALIDATOR_CONTRACT, - "funcName": "getTotalStaked", - "args": [address_in_hex] - } - json_structure = json.dumps(post_body) - response = requests.post(f"{DEFAULT_PROXY}/vm-values/query", data=json_structure) +def get_keys_from_validator_auction(QUALIFIED=True) -> list[str]: + keys = [] + + force_reset_validator_statistics() + time.sleep(1) + + response = requests.get(f"{OBSERVER_META}/validator/auction") response.raise_for_status() parsed = response.json() general_data = parsed.get("data") - tx_response_data = general_data.get("data") - total_staked_list = tx_response_data.get("returnData") - total_staked = total_staked_list[0] + auction_list_data = general_data.get("auctionList") + + for list in auction_list_data: + nodes_lists = list.get("nodes") + for node_list in nodes_lists: + if node_list.get("qualified") == QUALIFIED: + keys.append(node_list.get("blsKey")) + + return keys + + +def get_keys_from_validator_statistics(needed_state: str) -> list[str]: + keys = [] + + force_reset_validator_statistics() + time.sleep(1) + + response = requests.get(f"{OBSERVER_META}/validator/statistics") + response.raise_for_status() + parsed = response.json() + + general_data = parsed.get("data") + statistics = general_data.get("statistics") + + for dict in statistics: + key_data = statistics.get(dict) + state = key_data.get("validatorStatus") + if state == needed_state: + keys.append(dict) + + return keys + + +def find_same_shard_keys(num_keys: int, keys: list[str]) -> list[str]: + keys = [] + + force_reset_validator_statistics() + time.sleep(1) + + response = requests.get(f"{OBSERVER_META}/validator/statistics") + response.raise_for_status() + parsed = response.json() + + general_data = parsed.get("data") + statistics = general_data.get("statistics") + + + + + - total_staked = base64_to_string(total_staked) - return total_staked + return keys \ No newline at end of file diff --git a/testing-suite/staking-v4/scenarios/PR_6114.py b/testing-suite/staking-v4/scenarios/PR_6114.py index 3dad4dae..0dd6f4a9 100644 --- a/testing-suite/staking-v4/scenarios/PR_6114.py +++ b/testing-suite/staking-v4/scenarios/PR_6114.py @@ -1,16 +1,14 @@ import threading -import delegation import time -from config import * -from delegation import * -from chain_commander import * -from get_info import * -from staking import * -from delegation import * -from core.wallet import * + from core.validatorKey import * from core.chain_simulator import * -from threading import Thread +from chain_commander import * +from staking import stake, unStake, unBondNodes +from get_infos.get_validator_info import get_keys_state, get_keys_from_validator_statistics, \ + get_keys_from_validator_auction +import requests + # SCENARIO 1 # Have every epoch auction list with enough nodes (let's say 8 qualified, 2 unqualified) @@ -18,9 +16,166 @@ # and call auction list api; we should see 8 qualified nodes. Next epoch we need to check that exactly 8 nodes were qualified. # Afterwards(some epochs), those leaving nodes will be leaving and replaced by the auction nodes + +# Steps: +# +# 1) In epoch 5 stake with A that 2 keys - will go in auction +# 2) Add blocks and epochs until 1 of this 2 keys are eligible - let's call it epoch X +# 3) unStake the eligible key in epoch X +# 4) call auction list api after 2 blocks (we are still in epoch X) and: +# 4.1) unStaked key status should be "eligible (leaving)" on validator/statistics +# 4.2) we should have still 8 keys qualified +# 4.3) we should have still 2 keys not qualified +# 4.4) we should have 39 keys with status "eligible" +# 4.5) we should have still 16 keys with status "waiting" +# 5) go to epoch X+1 and 5 blocks and make sure: +# 5.1) unstaked key should be inactive +# 5.2) 8 keys from auction (qualified or not qualified , cause is not deterministic) are now waiting +# 5.3) we still have 9 keys in auction, 8 of them are qualified, 1 not qualified , 40 keys eligible, 16 waiting + + def main(): + print("Happy testing") + + +def test_PR_6114(): + + # === PRE-CONDITIONS ============================================================== + AMOUNT_TO_MINT = "10000" + "000000000000000000" + + _A = Wallet(Path("./wallets/walletKey_1.pem")) + key_1 = ValidatorKey(Path("./validatorKeys/validatorKey_1.pem")) + key_2 = ValidatorKey(Path("./validatorKeys/validatorKey_2.pem")) + all_keys = [key_1, key_2] + + # check if minting is successful + assert "success" in _A.set_balance(AMOUNT_TO_MINT) + + # add some blocks + response = add_blocks(5) + assert "success" in response + time.sleep(0.5) + + # check balance + assert _A.get_balance() == AMOUNT_TO_MINT + + # add keys to protocol. This way staked keys will not go to jail. + assert "success" in add_key(all_keys) + + # move to epoch + assert "success" in add_blocks_until_epoch_reached(5) + + # === STEP 1 ============================================================== + # 1) In epoch 5 stake with A that 2 keys - will go in auction + + tx_hash = stake(_A, all_keys) + + # check if tx is success + assert "success" in add_blocks_until_tx_fully_executed(tx_hash) + + # check that nodes are staked + for key in all_keys: + assert "staked" in key.get_status(_A.public_address()) + + # move 2 blocks before calling validator/statistics + assert "success" in add_blocks(2) + time.sleep(1) + + # check that nodes are in auction + for key in all_keys: + assert "auction" in key.get_state() + + # === STEP 2 ============================================================== + # 2) Add blocks and epochs until 1 of this 2 keys are eligible - let's call it epoch X + + eligible_key = add_blocks_until_key_eligible(all_keys) + + current_epoch = proxy_default.get_network_status().epoch_number + print("Eligible key: ", eligible_key.public_address()) + print("Current epoch:", current_epoch) + + # === STEP 3 ============================================================== + # 3) unStake the eligible key in epoch X + + tx_hash = unStake(_A, eligible_key) + + # check if tx is success + assert "success" in add_blocks_until_tx_fully_executed(tx_hash) + + current_epoch = proxy_default.get_network_status().epoch_number + print("Key unstaked in epoch:", current_epoch) + + # check if key is now unStaked on getBlsKeyStatus + assert "unStaked" in eligible_key.get_status(_A.public_address()) + + # eligible_key becomes un_staked_key to be easier to read the test + un_staked_key = eligible_key + + # === STEP 4 ============================================================== + # 4) call auction list api after 2 blocks and: + + # wait 1 sec and move to the last block of epoch before saving all qualified and unqualified keys + time.sleep(1) + assert "success" in add_blocks_until_last_block_of_current_epoch() + + # 4.1) unStaked key status should be "eligible (leaving)" on validator/statistics + assert un_staked_key.get_state() == "eligible (leaving)" + + epoch_x = proxy_default.get_network_status().epoch_number + print("Key is leaving in epoch:", epoch_x) + + # 4.2) we should have still 8 keys qualified + qualified_keys_in_epoch_x = get_keys_from_validator_auction(QUALIFIED=True) + assert len(qualified_keys_in_epoch_x) == 8 + + # 4.3) we should have still 2 keys not qualified + not_qualified_keys_in_epoch_x = get_keys_from_validator_auction(QUALIFIED=False) + assert len(not_qualified_keys_in_epoch_x) == 2 + + # 4.4) we should have 39 keys with status "eligible" + eligible_keys_in_epoch_x = get_keys_from_validator_statistics(needed_state="eligible") + assert len(eligible_keys_in_epoch_x) == 39 + + # 4.5) we should have still 16 keys with status "waiting" + waiting_keys_in_epoch_x = get_keys_from_validator_statistics(needed_state="waiting") + assert len(waiting_keys_in_epoch_x) == 16 + + # === STEP 5 ============================================================== + # 5) go to epoch X+1 and 5 blocks and make sure: + + # go to epoch X+1 + assert "success" in add_blocks_until_epoch_reached(epoch_x + 1) + print("Epoch: ", epoch_x + 1) + + # add 5 block + assert "success" in add_blocks(5) + + # 5.1) unstaked key should be inactive + assert "inactive" == eligible_key.get_state() + print("key", un_staked_key.get_state()) + + # 5.2) 8 keys from auction (qualified or not qualified , cause is not deterministic) are now waiting + all_auction_keys_from_epoch_x = qualified_keys_in_epoch_x + not_qualified_keys_in_epoch_x + waiting_keys_now = get_keys_from_validator_statistics("waiting") + to_be_checked_list = [] + for key in all_auction_keys_from_epoch_x: + if key in waiting_keys_now: + to_be_checked_list.append(key) + assert len(to_be_checked_list) == 8 + + # 5.3) we still have 9 keys in auction, 8 of them are qualified, 1 not qualified , 40 keys eligible, 16 waiting + qualified_keys = get_keys_from_validator_auction(QUALIFIED=True) + assert len(qualified_keys) == 8 + + not_qualified_keys = get_keys_from_validator_auction(QUALIFIED=False) + assert len(not_qualified_keys) == 1 + + eligible_keys = get_keys_from_validator_statistics("eligible") + assert len(eligible_keys) == 40 + waiting_keys = get_keys_from_validator_statistics("waiting") + assert len(waiting_keys) == 16 if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/testing-suite/staking-v4/scenarios/_48.py b/testing-suite/staking-v4/scenarios/_48.py index 83dbcfa6..3e07d32d 100644 --- a/testing-suite/staking-v4/scenarios/_48.py +++ b/testing-suite/staking-v4/scenarios/_48.py @@ -1,17 +1,9 @@ import threading - -import delegation -import time -from config import * -from delegation import * from chain_commander import * -from get_info import * +from get_infos.get_staking_info import get_total_staked from staking import * -from delegation import * -from core.wallet import * -from core.validatorKey import * -from core.chain_simulator import * -from threading import Thread +from core.validatorKey import ValidatorKey +from core.chain_simulator import ChainSimulator # Steps: # 1) Stake with A 2 nodes diff --git a/testing-suite/staking-v4/scenarios/_49_50.py b/testing-suite/staking-v4/scenarios/_49_50.py index a1907fd3..af8caafd 100644 --- a/testing-suite/staking-v4/scenarios/_49_50.py +++ b/testing-suite/staking-v4/scenarios/_49_50.py @@ -1,17 +1,11 @@ import threading -import delegation -import time -from config import * -from delegation import * +from get_infos.get_transaction_info import check_if_error_is_present_in_tx from chain_commander import * -from get_info import * from staking import * -from delegation import * -from core.wallet import * from core.validatorKey import * from core.chain_simulator import * -from threading import Thread + # Steps # 1) Test 49 : Stake a node with an invalid bls key diff --git a/testing-suite/staking-v4/scenarios/_68_69.py b/testing-suite/staking-v4/scenarios/_68_69.py index 2c6d90c2..b21dced8 100644 --- a/testing-suite/staking-v4/scenarios/_68_69.py +++ b/testing-suite/staking-v4/scenarios/_68_69.py @@ -20,7 +20,8 @@ from config import * from delegation import * from chain_commander import * -from get_info import * +from get_infos.get_delegation_info import get_delegation_contract_address_from_tx +from get_infos.get_transaction_info import check_if_error_is_present_in_tx from staking import * from delegation import * from core.wallet import * diff --git a/testing-suite/staking-v4/staking.py b/testing-suite/staking-v4/staking.py index 42d9f38c..adc36b76 100644 --- a/testing-suite/staking-v4/staking.py +++ b/testing-suite/staking-v4/staking.py @@ -5,7 +5,7 @@ from multiversx_sdk_core.transaction import TransactionComputer from multiversx_sdk_network_providers import ProxyNetworkProvider from multiversx_sdk_wallet import UserSigner -from get_info import * + from config import * from helpers import * from core.wallet import * @@ -101,7 +101,6 @@ def malicious_stake(wallet: Wallet, validatorKeys: list[ValidatorKey], AMOUNT_DE # send tx tx_hash = proxy_default.send_transaction(tx) - return tx_hash @@ -127,5 +126,30 @@ def unStake(wallet: Wallet, validator_key: ValidatorKey) -> str: # send tx tx_hash = proxy_default.send_transaction(tx) + return tx_hash + +def unBondNodes(wallet : Wallet, validator_key: ValidatorKey) -> str: + + # create transaction + tx = Transaction(sender=wallet.get_address().to_bech32(), + receiver=VALIDATOR_CONTRACT, + nonce=wallet.get_account().nonce, + gas_price=1000000000, + gas_limit=200000000, + chain_id=chain_id, + value=0) + + tx.data = f"unBondNodes@{validator_key.public_address()}".encode() + + # prepare signature + tx_comp = TransactionComputer() + result_bytes = tx_comp.compute_bytes_for_signing(tx) + + signature = wallet.get_signer().sign(result_bytes) + tx.signature = signature + + # send tx + tx_hash = proxy_default.send_transaction(tx) return tx_hash + From 72e9163c0d6889a6caa88a6bbf7997d2e67cd507 Mon Sep 17 00:00:00 2001 From: gabi-vuls Date: Thu, 25 Apr 2024 14:48:56 +0300 Subject: [PATCH 3/5] fixes after reviews --- testing-suite/staking-v4/caching.py | 6 ++++++ testing-suite/staking-v4/chain_commander.py | 9 +++++---- testing-suite/staking-v4/core/validatorKey.py | 4 ++-- .../get_delegation_info.py | 0 .../get_staking_info.py | 0 .../get_transaction_info.py | 0 .../get_validator_info.py | 20 ------------------- testing-suite/staking-v4/scenarios/PR_6114.py | 11 +++++----- testing-suite/staking-v4/scenarios/_48.py | 2 +- testing-suite/staking-v4/scenarios/_49_50.py | 2 +- testing-suite/staking-v4/scenarios/_68_69.py | 4 ++-- 11 files changed, 23 insertions(+), 35 deletions(-) rename testing-suite/staking-v4/{get_infos => network_provider}/get_delegation_info.py (100%) rename testing-suite/staking-v4/{get_infos => network_provider}/get_staking_info.py (100%) rename testing-suite/staking-v4/{get_infos => network_provider}/get_transaction_info.py (100%) rename testing-suite/staking-v4/{get_infos => network_provider}/get_validator_info.py (91%) diff --git a/testing-suite/staking-v4/caching.py b/testing-suite/staking-v4/caching.py index e7614b34..a3fbcb36 100644 --- a/testing-suite/staking-v4/caching.py +++ b/testing-suite/staking-v4/caching.py @@ -1,5 +1,6 @@ import requests from config import DEFAULT_PROXY +from chain_commander import add_blocks def force_reset_validator_statistics(): @@ -7,3 +8,8 @@ def force_reset_validator_statistics(): response = requests.post(route) response.raise_for_status() + # add an extra block + response = add_blocks(1) + + + diff --git a/testing-suite/staking-v4/chain_commander.py b/testing-suite/staking-v4/chain_commander.py index 59ef2fd4..a96c2195 100644 --- a/testing-suite/staking-v4/chain_commander.py +++ b/testing-suite/staking-v4/chain_commander.py @@ -2,7 +2,7 @@ import json from config import * -from get_infos.get_transaction_info import get_status_of_tx +from network_provider.get_transaction_info import get_status_of_tx from constants import * import time from core.validatorKey import ValidatorKey @@ -23,8 +23,9 @@ def send_egld_to_address(egld_amount, erd_address): def add_blocks(nr_of_blocks): - req = requests.post(f"{DEFAULT_PROXY}/simulator/generate-blocks/{nr_of_blocks}") - return req.text + response = requests.post(f"{DEFAULT_PROXY}/simulator/generate-blocks/{nr_of_blocks}") + response.raise_for_status() + return response.text def get_block() -> int: @@ -115,7 +116,7 @@ def add_blocks_until_last_block_of_current_epoch() -> str: status = general_data.get("status") passed_nonces = status.get("erd_nonces_passed_in_current_epoch") - blocks_to_be_added = 50 - passed_nonces + blocks_to_be_added = rounds_per_epoch - passed_nonces response_from_add_blocks = add_blocks(blocks_to_be_added) return response_from_add_blocks diff --git a/testing-suite/staking-v4/core/validatorKey.py b/testing-suite/staking-v4/core/validatorKey.py index 1742f7af..2926f2cc 100644 --- a/testing-suite/staking-v4/core/validatorKey.py +++ b/testing-suite/staking-v4/core/validatorKey.py @@ -7,8 +7,8 @@ from core.wallet import * from pathlib import Path from caching import force_reset_validator_statistics -from get_infos.get_validator_info import get_bls_key_status -from get_infos.get_validator_info import get_owner +from network_provider.get_validator_info import get_bls_key_status +from network_provider.get_validator_info import get_owner from config import DEFAULT_PROXY, OBSERVER_META diff --git a/testing-suite/staking-v4/get_infos/get_delegation_info.py b/testing-suite/staking-v4/network_provider/get_delegation_info.py similarity index 100% rename from testing-suite/staking-v4/get_infos/get_delegation_info.py rename to testing-suite/staking-v4/network_provider/get_delegation_info.py diff --git a/testing-suite/staking-v4/get_infos/get_staking_info.py b/testing-suite/staking-v4/network_provider/get_staking_info.py similarity index 100% rename from testing-suite/staking-v4/get_infos/get_staking_info.py rename to testing-suite/staking-v4/network_provider/get_staking_info.py diff --git a/testing-suite/staking-v4/get_infos/get_transaction_info.py b/testing-suite/staking-v4/network_provider/get_transaction_info.py similarity index 100% rename from testing-suite/staking-v4/get_infos/get_transaction_info.py rename to testing-suite/staking-v4/network_provider/get_transaction_info.py diff --git a/testing-suite/staking-v4/get_infos/get_validator_info.py b/testing-suite/staking-v4/network_provider/get_validator_info.py similarity index 91% rename from testing-suite/staking-v4/get_infos/get_validator_info.py rename to testing-suite/staking-v4/network_provider/get_validator_info.py index 49efba2a..3cd28dcc 100644 --- a/testing-suite/staking-v4/get_infos/get_validator_info.py +++ b/testing-suite/staking-v4/network_provider/get_validator_info.py @@ -136,23 +136,3 @@ def get_keys_from_validator_statistics(needed_state: str) -> list[str]: return keys - -def find_same_shard_keys(num_keys: int, keys: list[str]) -> list[str]: - keys = [] - - force_reset_validator_statistics() - time.sleep(1) - - response = requests.get(f"{OBSERVER_META}/validator/statistics") - response.raise_for_status() - parsed = response.json() - - general_data = parsed.get("data") - statistics = general_data.get("statistics") - - - - - - - return keys \ No newline at end of file diff --git a/testing-suite/staking-v4/scenarios/PR_6114.py b/testing-suite/staking-v4/scenarios/PR_6114.py index 0dd6f4a9..af0aba82 100644 --- a/testing-suite/staking-v4/scenarios/PR_6114.py +++ b/testing-suite/staking-v4/scenarios/PR_6114.py @@ -1,11 +1,12 @@ import threading import time + from core.validatorKey import * from core.chain_simulator import * from chain_commander import * from staking import stake, unStake, unBondNodes -from get_infos.get_validator_info import get_keys_state, get_keys_from_validator_statistics, \ +from network_provider.get_validator_info import get_keys_state, get_keys_from_validator_statistics, \ get_keys_from_validator_auction import requests @@ -30,8 +31,8 @@ # 4.5) we should have still 16 keys with status "waiting" # 5) go to epoch X+1 and 5 blocks and make sure: # 5.1) unstaked key should be inactive -# 5.2) 8 keys from auction (qualified or not qualified , cause is not deterministic) are now waiting -# 5.3) we still have 9 keys in auction, 8 of them are qualified, 1 not qualified , 40 keys eligible, 16 waiting +# 5.2) 8 keys were selected from auction in epoch x and are now waiting +# 5.3) we will now have 9 keys in auction, 8 of them are qualified, 1 not qualified , 40 keys eligible, 16 waiting def main(): @@ -154,7 +155,7 @@ def test_PR_6114(): assert "inactive" == eligible_key.get_state() print("key", un_staked_key.get_state()) - # 5.2) 8 keys from auction (qualified or not qualified , cause is not deterministic) are now waiting + # 5.2) 8 keys were selected from auction in epoch x and are now waiting all_auction_keys_from_epoch_x = qualified_keys_in_epoch_x + not_qualified_keys_in_epoch_x waiting_keys_now = get_keys_from_validator_statistics("waiting") to_be_checked_list = [] @@ -163,7 +164,7 @@ def test_PR_6114(): to_be_checked_list.append(key) assert len(to_be_checked_list) == 8 - # 5.3) we still have 9 keys in auction, 8 of them are qualified, 1 not qualified , 40 keys eligible, 16 waiting + # 5.3) we will now have 9 keys in auction, 8 of them are qualified, 1 not qualified , 40 keys eligible, 16 waiting qualified_keys = get_keys_from_validator_auction(QUALIFIED=True) assert len(qualified_keys) == 8 diff --git a/testing-suite/staking-v4/scenarios/_48.py b/testing-suite/staking-v4/scenarios/_48.py index 3e07d32d..09f52ea4 100644 --- a/testing-suite/staking-v4/scenarios/_48.py +++ b/testing-suite/staking-v4/scenarios/_48.py @@ -1,6 +1,6 @@ import threading from chain_commander import * -from get_infos.get_staking_info import get_total_staked +from network_provider.get_staking_info import get_total_staked from staking import * from core.validatorKey import ValidatorKey from core.chain_simulator import ChainSimulator diff --git a/testing-suite/staking-v4/scenarios/_49_50.py b/testing-suite/staking-v4/scenarios/_49_50.py index af8caafd..4a6067f1 100644 --- a/testing-suite/staking-v4/scenarios/_49_50.py +++ b/testing-suite/staking-v4/scenarios/_49_50.py @@ -1,6 +1,6 @@ import threading -from get_infos.get_transaction_info import check_if_error_is_present_in_tx +from network_provider.get_transaction_info import check_if_error_is_present_in_tx from chain_commander import * from staking import * from core.validatorKey import * diff --git a/testing-suite/staking-v4/scenarios/_68_69.py b/testing-suite/staking-v4/scenarios/_68_69.py index b21dced8..9f85df71 100644 --- a/testing-suite/staking-v4/scenarios/_68_69.py +++ b/testing-suite/staking-v4/scenarios/_68_69.py @@ -20,8 +20,8 @@ from config import * from delegation import * from chain_commander import * -from get_infos.get_delegation_info import get_delegation_contract_address_from_tx -from get_infos.get_transaction_info import check_if_error_is_present_in_tx +from network_provider.get_delegation_info import get_delegation_contract_address_from_tx +from network_provider.get_transaction_info import check_if_error_is_present_in_tx from staking import * from delegation import * from core.wallet import * From 3906bb2610f346372528ed00dfb9984e57cb44b9 Mon Sep 17 00:00:00 2001 From: gabi-vuls Date: Fri, 26 Apr 2024 11:30:40 +0300 Subject: [PATCH 4/5] fixes after review 2 --- testing-suite/staking-v4/caching.py | 7 ++++--- testing-suite/staking-v4/core/validatorKey.py | 20 +++++-------------- .../network_provider/get_validator_info.py | 3 --- testing-suite/staking-v4/scenarios/PR_6114.py | 12 ++++++++++- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/testing-suite/staking-v4/caching.py b/testing-suite/staking-v4/caching.py index a3fbcb36..fa870fb4 100644 --- a/testing-suite/staking-v4/caching.py +++ b/testing-suite/staking-v4/caching.py @@ -1,6 +1,7 @@ import requests from config import DEFAULT_PROXY from chain_commander import add_blocks +import time def force_reset_validator_statistics(): @@ -9,7 +10,7 @@ def force_reset_validator_statistics(): response.raise_for_status() # add an extra block - response = add_blocks(1) - - + add_blocks(1) + # wait 1 sec + time.sleep(1) \ No newline at end of file diff --git a/testing-suite/staking-v4/core/validatorKey.py b/testing-suite/staking-v4/core/validatorKey.py index 2926f2cc..a04bee8d 100644 --- a/testing-suite/staking-v4/core/validatorKey.py +++ b/testing-suite/staking-v4/core/validatorKey.py @@ -1,9 +1,5 @@ import requests - import time -import urllib.request, json -import wget - from core.wallet import * from pathlib import Path from caching import force_reset_validator_statistics @@ -29,23 +25,19 @@ def public_address(self) -> str: return address # is using vm-query with "getBlsKeysStatus" function - def get_status(self, owner_address: str) -> str: + def get_status(self, owner_address: str): owner_address = Address.from_bech32(owner_address).to_hex() key_status_pair = get_bls_key_status([owner_address]) if key_status_pair is None: - return "no bls keys on this owner" + return None for key, status in key_status_pair.items(): if key == self.public_address(): return status # is using /validator/statistics route def get_state(self): - force_reset_validator_statistics() - # sometimes it needs few seconds until cache is resetting - time.sleep(1) - response = requests.get(f"{OBSERVER_META}/validator/statistics") response.raise_for_status() parsed = response.json() @@ -64,9 +56,6 @@ def get_state(self): def get_auction_state(self): force_reset_validator_statistics() - # sometimes it needs few seconds until cache is resetting - time.sleep(1) - response = requests.get(f"{OBSERVER_META}/validator/auction") response.raise_for_status() parsed = response.json() @@ -83,9 +72,10 @@ def get_auction_state(self): return "qualified" else: return "unqualified" + else: + return None - - # using getOwner vm-query + # using getOwner vm-query def belongs_to(self, address: str) -> bool: owner = get_owner([self.public_address()]) if owner == address: diff --git a/testing-suite/staking-v4/network_provider/get_validator_info.py b/testing-suite/staking-v4/network_provider/get_validator_info.py index 3cd28dcc..125b4afd 100644 --- a/testing-suite/staking-v4/network_provider/get_validator_info.py +++ b/testing-suite/staking-v4/network_provider/get_validator_info.py @@ -74,7 +74,6 @@ def get_keys_state(keys: list) -> list[str]: states = [] force_reset_validator_statistics() - time.sleep(1) response = requests.get(f"{OBSERVER_META}/validator/statistics") response.raise_for_status() @@ -97,7 +96,6 @@ def get_keys_from_validator_auction(QUALIFIED=True) -> list[str]: keys = [] force_reset_validator_statistics() - time.sleep(1) response = requests.get(f"{OBSERVER_META}/validator/auction") response.raise_for_status() @@ -119,7 +117,6 @@ def get_keys_from_validator_statistics(needed_state: str) -> list[str]: keys = [] force_reset_validator_statistics() - time.sleep(1) response = requests.get(f"{OBSERVER_META}/validator/statistics") response.raise_for_status() diff --git a/testing-suite/staking-v4/scenarios/PR_6114.py b/testing-suite/staking-v4/scenarios/PR_6114.py index af0aba82..1b5e3671 100644 --- a/testing-suite/staking-v4/scenarios/PR_6114.py +++ b/testing-suite/staking-v4/scenarios/PR_6114.py @@ -17,9 +17,19 @@ # and call auction list api; we should see 8 qualified nodes. Next epoch we need to check that exactly 8 nodes were qualified. # Afterwards(some epochs), those leaving nodes will be leaving and replaced by the auction nodes +# Testnet configuration: +# num_validators_per_shard = 10 +# num_validators_meta = 10 +# num_waiting_validators_per_shard = 6 +# num_waiting_validators_meta = 6 +# nodes_to_shuffle_per_shard = 2 + +# from this config results: +# eligible nodes = 10*4 = 40 +# waiting nodes = (6 - 2 (auction)) * 4 = 16 +# auction nodes = 2*4 = 8 # Steps: -# # 1) In epoch 5 stake with A that 2 keys - will go in auction # 2) Add blocks and epochs until 1 of this 2 keys are eligible - let's call it epoch X # 3) unStake the eligible key in epoch X From 131bbb5559adae5667626a1bd861fc5c351b39f1 Mon Sep 17 00:00:00 2001 From: gabi-vuls Date: Fri, 26 Apr 2024 14:36:34 +0300 Subject: [PATCH 5/5] fixes after review 3 --- testing-suite/staking-v4/caching.py | 2 +- .../network_provider/get_delegation_info.py | 2 -- .../network_provider/get_staking_info.py | 2 +- .../network_provider/get_transaction_info.py | 3 ++- .../network_provider/get_validator_info.py | 5 +++-- testing-suite/staking-v4/scenarios/PR_6114.py | 22 +++++++++---------- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/testing-suite/staking-v4/caching.py b/testing-suite/staking-v4/caching.py index fa870fb4..214011c9 100644 --- a/testing-suite/staking-v4/caching.py +++ b/testing-suite/staking-v4/caching.py @@ -13,4 +13,4 @@ def force_reset_validator_statistics(): add_blocks(1) # wait 1 sec - time.sleep(1) \ No newline at end of file + time.sleep(1) diff --git a/testing-suite/staking-v4/network_provider/get_delegation_info.py b/testing-suite/staking-v4/network_provider/get_delegation_info.py index c546e9c0..acc83a1a 100644 --- a/testing-suite/staking-v4/network_provider/get_delegation_info.py +++ b/testing-suite/staking-v4/network_provider/get_delegation_info.py @@ -5,7 +5,6 @@ def get_delegation_contract_address_from_tx(tx_hash): - response = requests.get(f"{DEFAULT_PROXY}/transaction/{tx_hash}?withResults=True") response.raise_for_status() parsed = response.json() @@ -22,4 +21,3 @@ def get_delegation_contract_address_from_tx(tx_hash): delegation_contract_address = Address.from_hex(delegation_contract_address, "erd").to_bech32() return delegation_contract_address - diff --git a/testing-suite/staking-v4/network_provider/get_staking_info.py b/testing-suite/staking-v4/network_provider/get_staking_info.py index 9677784a..b6922694 100644 --- a/testing-suite/staking-v4/network_provider/get_staking_info.py +++ b/testing-suite/staking-v4/network_provider/get_staking_info.py @@ -25,4 +25,4 @@ def get_total_staked(owner: str): total_staked = total_staked_list[0] total_staked = base64_to_string(total_staked) - return total_staked \ No newline at end of file + return total_staked diff --git a/testing-suite/staking-v4/network_provider/get_transaction_info.py b/testing-suite/staking-v4/network_provider/get_transaction_info.py index 377ba3ce..f42cb178 100644 --- a/testing-suite/staking-v4/network_provider/get_transaction_info.py +++ b/testing-suite/staking-v4/network_provider/get_transaction_info.py @@ -3,6 +3,7 @@ from config import DEFAULT_PROXY from helpers import string_to_base64 + def get_status_of_tx(tx_hash: str) -> str: response = requests.get(f"{DEFAULT_PROXY}/transaction/{tx_hash}/process-status") response.raise_for_status() @@ -29,4 +30,4 @@ def check_if_error_is_present_in_tx(error, tx_hash) -> bool: if error in response.text: flag = True - return flag \ No newline at end of file + return error_bytes.decode() in response.text or error in response.text diff --git a/testing-suite/staking-v4/network_provider/get_validator_info.py b/testing-suite/staking-v4/network_provider/get_validator_info.py index 125b4afd..aaad0a95 100644 --- a/testing-suite/staking-v4/network_provider/get_validator_info.py +++ b/testing-suite/staking-v4/network_provider/get_validator_info.py @@ -92,7 +92,7 @@ def get_keys_state(keys: list) -> list[str]: return states -def get_keys_from_validator_auction(QUALIFIED=True) -> list[str]: +def get_keys_from_validator_auction(isQualified=True) -> list[str]: keys = [] force_reset_validator_statistics() @@ -107,7 +107,7 @@ def get_keys_from_validator_auction(QUALIFIED=True) -> list[str]: for list in auction_list_data: nodes_lists = list.get("nodes") for node_list in nodes_lists: - if node_list.get("qualified") == QUALIFIED: + if node_list.get("qualified") == isQualified: keys.append(node_list.get("blsKey")) return keys @@ -133,3 +133,4 @@ def get_keys_from_validator_statistics(needed_state: str) -> list[str]: return keys + diff --git a/testing-suite/staking-v4/scenarios/PR_6114.py b/testing-suite/staking-v4/scenarios/PR_6114.py index 1b5e3671..dd899927 100644 --- a/testing-suite/staking-v4/scenarios/PR_6114.py +++ b/testing-suite/staking-v4/scenarios/PR_6114.py @@ -54,13 +54,13 @@ def test_PR_6114(): # === PRE-CONDITIONS ============================================================== AMOUNT_TO_MINT = "10000" + "000000000000000000" - _A = Wallet(Path("./wallets/walletKey_1.pem")) + wallet_a = Wallet(Path("./wallets/walletKey_1.pem")) key_1 = ValidatorKey(Path("./validatorKeys/validatorKey_1.pem")) key_2 = ValidatorKey(Path("./validatorKeys/validatorKey_2.pem")) all_keys = [key_1, key_2] # check if minting is successful - assert "success" in _A.set_balance(AMOUNT_TO_MINT) + assert "success" in wallet_a.set_balance(AMOUNT_TO_MINT) # add some blocks response = add_blocks(5) @@ -68,7 +68,7 @@ def test_PR_6114(): time.sleep(0.5) # check balance - assert _A.get_balance() == AMOUNT_TO_MINT + assert wallet_a.get_balance() == AMOUNT_TO_MINT # add keys to protocol. This way staked keys will not go to jail. assert "success" in add_key(all_keys) @@ -79,14 +79,14 @@ def test_PR_6114(): # === STEP 1 ============================================================== # 1) In epoch 5 stake with A that 2 keys - will go in auction - tx_hash = stake(_A, all_keys) + tx_hash = stake(wallet_a, all_keys) # check if tx is success assert "success" in add_blocks_until_tx_fully_executed(tx_hash) # check that nodes are staked for key in all_keys: - assert "staked" in key.get_status(_A.public_address()) + assert "staked" in key.get_status(wallet_a.public_address()) # move 2 blocks before calling validator/statistics assert "success" in add_blocks(2) @@ -108,7 +108,7 @@ def test_PR_6114(): # === STEP 3 ============================================================== # 3) unStake the eligible key in epoch X - tx_hash = unStake(_A, eligible_key) + tx_hash = unStake(wallet_a, eligible_key) # check if tx is success assert "success" in add_blocks_until_tx_fully_executed(tx_hash) @@ -117,7 +117,7 @@ def test_PR_6114(): print("Key unstaked in epoch:", current_epoch) # check if key is now unStaked on getBlsKeyStatus - assert "unStaked" in eligible_key.get_status(_A.public_address()) + assert "unStaked" in eligible_key.get_status(wallet_a.public_address()) # eligible_key becomes un_staked_key to be easier to read the test un_staked_key = eligible_key @@ -136,11 +136,11 @@ def test_PR_6114(): print("Key is leaving in epoch:", epoch_x) # 4.2) we should have still 8 keys qualified - qualified_keys_in_epoch_x = get_keys_from_validator_auction(QUALIFIED=True) + qualified_keys_in_epoch_x = get_keys_from_validator_auction(isQualified=True) assert len(qualified_keys_in_epoch_x) == 8 # 4.3) we should have still 2 keys not qualified - not_qualified_keys_in_epoch_x = get_keys_from_validator_auction(QUALIFIED=False) + not_qualified_keys_in_epoch_x = get_keys_from_validator_auction(isQualified=False) assert len(not_qualified_keys_in_epoch_x) == 2 # 4.4) we should have 39 keys with status "eligible" @@ -175,10 +175,10 @@ def test_PR_6114(): assert len(to_be_checked_list) == 8 # 5.3) we will now have 9 keys in auction, 8 of them are qualified, 1 not qualified , 40 keys eligible, 16 waiting - qualified_keys = get_keys_from_validator_auction(QUALIFIED=True) + qualified_keys = get_keys_from_validator_auction(isQualified=True) assert len(qualified_keys) == 8 - not_qualified_keys = get_keys_from_validator_auction(QUALIFIED=False) + not_qualified_keys = get_keys_from_validator_auction(isQualified=False) assert len(not_qualified_keys) == 1 eligible_keys = get_keys_from_validator_statistics("eligible")