Skip to content
Draft
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
27 changes: 21 additions & 6 deletions e2e-tests/tests/reserve/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<env>_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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this line is errornous. I would keep it like it was before.
I have no problem with honest docs and long name of this function.

if api.cardano_cli.run_command.copy_secrets:
with open(payment_key_path, "r") as f:
content = json.load(f)
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/tests/reserve/test_main_chain_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions e2e-tests/tests/reserve/test_reserve_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
Loading