diff --git a/e2e-tests/tests/reserve/conftest.py b/e2e-tests/tests/reserve/conftest.py index 20a50621d3..c199aef0ae 100644 --- a/e2e-tests/tests/reserve/conftest.py +++ b/e2e-tests/tests/reserve/conftest.py @@ -31,8 +31,19 @@ def payment_key(config: ApiConfig, governance_skey_with_cli): @fixture(scope="session") -def cardano_payment_key(config: ApiConfig, api: BlockchainApi, write_file): - payment_key_path = config.nodes_config.governance_authority.mainchain_key +def governance_skey_with_cardano_cli(config: ApiConfig, api: BlockchainApi, write_file): + """ + Securely copy the governance authority's init skey (a secret key used by the smart-contracts to authorize admin + operations) to a temporary file on the remote machine. + The temporary file is deleted after the test completes. + + The skey is copied to a remote host only if both conditions are met: + - you call this fixture in test or other fixture + - tools.cardano_cli.runner.copy_secrets is set to true in the config file `_stack.json` + + WARNING: This fixture copies secret file to a remote host and should be used with caution. + """ + payment_key_path = config.nodes_config.governance_authority.mainchain_key_local_path if api.cardano_cli.run_command.copy_secrets: with open(payment_key_path, "r") as f: content = json.load(f) @@ -91,7 +102,7 @@ def mint_token( transaction_input: str, minting_policy_filepath, api: BlockchainApi, - cardano_payment_key, + governance_skey_with_cardano_cli, ): lovelace_amount = MIN_LOVELACE_FOR_TX - MIN_LOVELACE_TO_COVER_FEES @@ -106,7 +117,9 @@ def _mint_token(amount: int): policy_script_filepath=minting_policy_filepath, ) - signed_tx_filepath = api.cardano_cli.sign_transaction(tx_filepath=tx_filepath, signing_key=cardano_payment_key) + signed_tx_filepath = api.cardano_cli.sign_transaction( + tx_filepath=tx_filepath, signing_key=governance_skey_with_cardano_cli + ) result = api.cardano_cli.submit_transaction(signed_tx_filepath) return result @@ -180,7 +193,9 @@ def _transaction_input(): @fixture(scope="package") -def attach_v_function_to_utxo(transaction_input, governance_address, cardano_payment_key, api: BlockchainApi): +def attach_v_function_to_utxo( + transaction_input, governance_address, governance_skey_with_cardano_cli, api: BlockchainApi +): def _attach_v_function_to_utxo(address, filepath): logging.info(f"Attaching V-function to {address}...") lovelace_amount = MIN_LOVELACE_FOR_TX - MIN_LOVELACE_TO_COVER_FEES @@ -193,7 +208,7 @@ def _attach_v_function_to_utxo(address, filepath): ) signed_tx_filepath = api.cardano_cli.sign_transaction( - tx_filepath=raw_tx_filepath, signing_key=cardano_payment_key + tx_filepath=raw_tx_filepath, signing_key=governance_skey_with_cardano_cli ) result = api.cardano_cli.submit_transaction(signed_tx_filepath) diff --git a/e2e-tests/tests/reserve/test_main_chain_setup.py b/e2e-tests/tests/reserve/test_main_chain_setup.py index 063310ffd9..d0c042741e 100644 --- a/e2e-tests/tests/reserve/test_main_chain_setup.py +++ b/e2e-tests/tests/reserve/test_main_chain_setup.py @@ -15,9 +15,9 @@ def test_mint_tokens_for_reserve( api: BlockchainApi, governance_address: str, reserve_asset_id, mint_token, wait_until, config: ApiConfig ): initial_balance = api.get_mc_balance(governance_address, reserve_asset_id) - tokens_to_mint = 1000 + tokens_to_mint = 2000 result = mint_token(tokens_to_mint) - assert "Transaction successfully submitted" in result + assert "Transaction successfully submitted" in result.stderr assert wait_until( lambda: api.get_mc_balance(governance_address, reserve_asset_id) == initial_balance + tokens_to_mint, timeout=config.timeouts.main_chain_tx, diff --git a/e2e-tests/tests/reserve/test_reserve_management.py b/e2e-tests/tests/reserve/test_reserve_management.py index f75b33a608..8572cbf558 100644 --- a/e2e-tests/tests/reserve/test_reserve_management.py +++ b/e2e-tests/tests/reserve/test_reserve_management.py @@ -152,7 +152,7 @@ def native_token_balance(self, api: BlockchainApi, governance_address, reserve_a def amount_to_deposit(self, reserve_initial_balance): return random.randint(1, min(reserve_initial_balance, 100)) - @fixture(scope="class", autouse=True) + @fixture(scope="class") def deposit_funds(self, native_token_balance, amount_to_deposit, api: BlockchainApi, genesis_utxo, payment_key): response = api.partner_chains_node.smart_contracts.reserve.deposit( genesis_utxo, @@ -161,13 +161,16 @@ def deposit_funds(self, native_token_balance, amount_to_deposit, api: Blockchain ) return response + def test_enough_tokens_to_deposit_to_reserve(self, native_token_balance, amount_to_deposit): + assert native_token_balance >= amount_to_deposit + def test_deposit_funds(self, deposit_funds): response = deposit_funds assert response.returncode == 0 assert response.json def test_reserve_balance_after_deposit( - self, reserve_initial_balance, amount_to_deposit, api: BlockchainApi, reserve_asset_id, addresses + self, reserve_initial_balance, amount_to_deposit, deposit_funds, api: BlockchainApi, reserve_asset_id, addresses ): reserve_balance = api.get_mc_balance(addresses["ReserveValidator"], reserve_asset_id) assert reserve_initial_balance + amount_to_deposit == reserve_balance @@ -176,6 +179,7 @@ def test_native_token_balance_after_deposit( self, native_token_balance, amount_to_deposit, + deposit_funds, api: BlockchainApi, reserve_asset_id, governance_address,