Skip to content

Commit

Permalink
chore: rename sidechain main cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ladamesny committed Nov 20, 2024
1 parent 2dd19c3 commit d2060c5
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion E2E-tests/config/substrate/ci_stack.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"cli": "export CARDANO_NODE_SOCKET_PATH=/ipc/node.socket && /tools/cardano-cli",
"ssh": "${stack_config[ssh]}"
},
"sidechain_main_cli": {
"pc_contracts_cli": {
"cli": "/tools/partner-chains-smart-contracts-6.1.0/sidechain-cli",
"ssh": "${stack_config[ssh]}"
},
Expand Down
2 changes: 1 addition & 1 deletion E2E-tests/config/substrate/devnet_stack.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"cli": "export CARDANO_NODE_SOCKET_PATH=/ipc/node.socket && /tools/cardano-cli",
"ssh": "${stack_config[ssh]}"
},
"sidechain_main_cli": {
"pc_contracts_cli": {
"cli": "/tools/partner-chains-smart-contracts-6.2.2/pc-contracts-cli",
"ssh": "${stack_config[ssh]}"
},
Expand Down
2 changes: 1 addition & 1 deletion E2E-tests/config/substrate/local_stack.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"cli": "cardano-cli",
"shell": "docker exec cardano-node-1 bash -c"
},
"sidechain_main_cli": {
"pc_contracts_cli": {
"cli": "./pc-contracts-cli",
"shell": "docker exec pc-contracts-cli bash -c"
},
Expand Down
2 changes: 1 addition & 1 deletion E2E-tests/config/substrate/staging_stack.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"cli": "export CARDANO_NODE_SOCKET_PATH=/ipc/node.socket && /tools/cardano-cli",
"ssh": "${stack_config[ssh]}"
},
"sidechain_main_cli": {
"pc_contracts_cli": {
"cli": "/tools/partner-chains-smart-contracts-6.2.2/pc-contracts-cli",
"ssh": "${stack_config[ssh]}"
},
Expand Down
6 changes: 3 additions & 3 deletions E2E-tests/docs/configure-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ As a user, you can choose where to place those services and binaries: on the tes
In case of the test runner machine (and local execution), you will need to update the binaries path in `stack_config.tools` for `<env>-stack.json` file in the `config/<blockchain>/<env>` folder:

- `cardano_cli`
- `sidechain_main_cli`
- `pc_contracts_cli`
- `generate_signatures_cli`

## Set up stack on remote host
Expand All @@ -30,7 +30,7 @@ To configure the stack, you will need to do the following:
3. Set `stack_config.ssh.host_keys_path` to the file added at step 3
4. Set `stack_config.ssh.private_key_path` to the file added at step 4
6. Set `tools.cardano_cli.cli` to the path to the cardano-cli binary. Do not forget about exposing CARDANO_NODE_SOCKET_PATH. E.g. `export CARDANO_NODE_SOCKET_PATH=/ipc/node.socket && /cardano-cli`
7. Set `tools.sidechain_main_cli` to the path to the `partner-chains-smart-contracts` binary
7. Set `tools.pc_contracts_cli` to the path to the `partner-chains-smart-contracts` binary
8. Set `tools.generate_signatures_cli` to the path to the `partner-chains-node` binary

### `<env>-stack.json` template:
Expand All @@ -52,7 +52,7 @@ To configure the stack, you will need to do the following:
"cli": <STRING>,
"ssh": "${stack_config[ssh]}"
},
"sidechain_main_cli": {
"pc_contracts_cli": {
"cli": <STRING>,
"ssh": "${stack_config[ssh]}"
},
Expand Down
4 changes: 2 additions & 2 deletions E2E-tests/docs/run-tests-on-new-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ E.g. for Cardano Preview it will be:
"cardano_cli": {
"cli": <STRING>, // path to cardano-cli binary
},
"sidechain_main_cli": {
"cli": <STRING> // path to sidechain-main-cli binary
"pc_contracts_cli": {
"cli": <STRING> // path to pc-contracts-cli binary
},
"generate_signatures_cli": {
"cli": <STRING> // path to partner-chains-node binary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import logging as logger


class SidechainMainCliException(Exception):
def __init__(self, message="Sidechain Main CLI error occurred", status_code=None):
class PCContractsCliException(Exception):
def __init__(self, message="PC Contracts CLI error occurred", status_code=None):
self.message = message
self.status_code = status_code
super().__init__(self.message)
Expand All @@ -31,18 +31,17 @@ def __init__(
self.sidechain_signature = sidechain_signature


class SidechainMainCli:
class PCContractsCli:
def __init__(self, config: ApiConfig, cardano_cli: CardanoCli):
sidechain_main_cli_config = config.stack_config.tools["sidechain_main_cli"]
self.cli = sidechain_main_cli_config.cli
self.generate_signatures_cli = config.stack_config.tools["generate_signatures_cli"].cli
pc_contracts_cli_config = config.stack_config.tools["pc_contracts_cli"]
self.cli = pc_contracts_cli_config.cli
self.cardano_cli = cardano_cli
self.config = config
self.run_command = RunnerFactory.get_runner(sidechain_main_cli_config.ssh, sidechain_main_cli_config.shell)
self.run_command = RunnerFactory.get_runner(pc_contracts_cli_config.ssh, pc_contracts_cli_config.shell)

def get_signatures(
self,
sidechain_registration_utxo,
partner_chain_registration_utxo,
spo_signing_key,
sidechain_signing_key,
aura_verification_key,
Expand All @@ -57,7 +56,7 @@ def get_signatures(
f"--governance-authority {self.config.governance_authority} "
f"--mainchain-signing-key {spo_signing_key} "
f"--sidechain-signing-key {sidechain_signing_key} "
f"--registration-utxo {sidechain_registration_utxo}"
f"--registration-utxo {partner_chain_registration_utxo}"
)

result = self.run_command.run(get_signatures_cmd)
Expand Down Expand Up @@ -249,15 +248,15 @@ def update_permissioned_candidates(self, governance_key, add_candidates_list, re
def handle_response(self, result):
if result.stderr and not result.stdout:
logger.error(f"Error during command: {result.stderr}")
raise SidechainMainCliException(result.stderr)
raise PCContractsCliException(result.stderr)

try:
json_part = self._get_json_string(result.stdout)
response = json.loads(json_part)
return response
except json.JSONDecodeError:
logger.error(f"Could not parse response of command: {result}")
raise SidechainMainCliException(result.stdout)
raise PCContractsCliException(result.stdout)

def _get_json_string(self, s):
start = s.find('{')
Expand Down
18 changes: 9 additions & 9 deletions E2E-tests/src/substrate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging as logger
from .run_command import RunnerFactory
from .cardano_cli import CardanoCli
from .sidechain_main_cli import SidechainMainCli
from .pc_contracts_cli import PCContractsCli
from .partner_chain_rpc import PartnerChainRpc, PartnerChainRpcResponse, PartnerChainRpcException, DParam
import string
import time
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, config: ApiConfig, secrets, db_sync: Session):
self._substrate = None
self.run_command = RunnerFactory.get_runner(config.stack_config.ssh, config.stack_config.tools_shell)
self.cardano_cli = CardanoCli(config.main_chain, config.stack_config.tools["cardano_cli"])
self.sidechain_main_cli = SidechainMainCli(config, self.cardano_cli)
self.pc_contracts_cli = PCContractsCli(config, self.cardano_cli)
self.partner_chain_rpc = PartnerChainRpc(config.nodes_config.node.rpc_url)
self.partner_chain_epoch_calculator = PartnerChainEpochCalculator(config)
self.compact_encoder = RuntimeConfiguration().create_scale_object('Compact')
Expand Down Expand Up @@ -292,15 +292,15 @@ def register_candidate(self, candidate_name):
registration_utxo = next(filter(lambda utxo: utxos_json[utxo]["value"]["lovelace"] > 2500000, utxos_json), None)
assert registration_utxo is not None, "ERROR: Could not find a well funded utxo for registration"

signatures = self.sidechain_main_cli.get_signatures(
signatures = self.pc_contracts_cli.get_signatures(
registration_utxo,
self._read_cardano_key_file(keys_files.spo_signing_key),
self._read_json_file(keys_files.partner_chain_signing_key)['skey'],
self.config.nodes_config.nodes[candidate_name].aura_public_key,
self.config.nodes_config.nodes[candidate_name].grandpa_public_key,
)

txId, next_status_epoch = self.sidechain_main_cli.register_candidate(
txId, next_status_epoch = self.pc_contracts_cli.register_candidate(
signatures,
keys_files.cardano_payment_key,
self._read_cardano_key_file(keys_files.spo_public_key),
Expand All @@ -318,7 +318,7 @@ def register_candidate(self, candidate_name):

def deregister_candidate(self, candidate_name):
keys_files = self.config.nodes_config.nodes[candidate_name].keys_files
txId, next_status_epoch = self.sidechain_main_cli.deregister_candidate(
txId, next_status_epoch = self.pc_contracts_cli.deregister_candidate(
keys_files.cardano_payment_key,
self._read_cardano_key_file(keys_files.spo_public_key),
)
Expand Down Expand Up @@ -359,7 +359,7 @@ def burn_tokens(self, recipient, amount, payment_key):
return self.burn_tokens_for_hex_address(recipient_hex, amount, payment_key)

def burn_tokens_for_hex_address(self, recipient_hex, amount, payment_key):
txHash = self.sidechain_main_cli.burn_tokens(recipient_hex, amount, payment_key)
txHash = self.pc_contracts_cli.burn_tokens(recipient_hex, amount, payment_key)
if txHash:
tx_block_no = self.get_mc_block_no_by_tx_hash(txHash)
mc_stable_block = tx_block_no + self.config.main_chain.security_param
Expand Down Expand Up @@ -434,7 +434,7 @@ def get_epoch_signatures(self, epoch) -> PartnerChainRpcResponse:
return response

def claim_tokens(self, mc_private_key_file, combined_proof, distributed_set_utxo=None) -> bool:
return self.sidechain_main_cli.claim_tokens(
return self.pc_contracts_cli.claim_tokens(
mc_private_key_file, combined_proof, distributed_set_utxo=distributed_set_utxo
)

Expand Down Expand Up @@ -586,7 +586,7 @@ def check_epoch_signatures_uploaded(self, pc_epoch=None):

def add_permissioned_candidate(self, candidate_name: str):
candidate = PermissionedCandidate(self.config.nodes_config.nodes[candidate_name])
txId, next_status_epoch = self.sidechain_main_cli.update_permissioned_candidates(
txId, next_status_epoch = self.pc_contracts_cli.update_permissioned_candidates(
self.config.nodes_config.governance_authority.mainchain_key, [candidate], []
)

Expand All @@ -601,7 +601,7 @@ def add_permissioned_candidate(self, candidate_name: str):

def remove_permissioned_candidate(self, candidate_name: str):
candidate = PermissionedCandidate(self.config.nodes_config.nodes[candidate_name])
txId, next_status_epoch = self.sidechain_main_cli.update_permissioned_candidates(
txId, next_status_epoch = self.pc_contracts_cli.update_permissioned_candidates(
self.config.nodes_config.governance_authority.mainchain_key, [], [candidate]
)

Expand Down
10 changes: 5 additions & 5 deletions E2E-tests/tests/active_flow/test_active_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from src.db.models import OutgoingTx
from sqlalchemy.orm import Session
from pytest import mark, raises
from src.sidechain_main_cli import SidechainMainCliException
from src.pc_contracts_cli import PCContractsCliException


@mark.skip_blockchain("pc_evm", reason="not implemented yet")
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_claim_transactions(
"""Test that the user can claim tokens after committee handover
* wait until the next committee handover for a partner chain epoch
* claim tokens by executing claimTokens() from sidechain-main-cli
* claim tokens by executing claimTokens() from pc-contracts-cli
"""
for db_tx in unclaimed_outgoing_txs:
logging.info(f"Checking if committee handover happened for epoch {db_tx.available_on_pc_epoch}")
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_claim_transaction_signed_by_another_recipient_should_fail(
logging.info(f"Checking if committee handover happened for epoch {db_tx.available_on_pc_epoch}")
wait_until(api.check_epoch_signatures_uploaded, db_tx.available_on_pc_epoch, timeout=config.timeouts.claim_cmd)
logging.info(f"Handover for pc epoch {db_tx.available_on_pc_epoch} has happened")
with raises(SidechainMainCliException) as excinfo:
with raises(PCContractsCliException) as excinfo:
api.claim_tokens(config.nodes_config.random_mc_account.mainchain_key, db_tx.combined_proof)
assert "ERROR-FUEL-MINTING-POLICY-04" in excinfo.value.message

Expand All @@ -368,7 +368,7 @@ def test_claim_transaction_with_invalid_key_should_fail(
logging.info(f"Checking if committee handover happened for epoch {db_tx.available_on_pc_epoch}")
wait_until(api.check_epoch_signatures_uploaded, db_tx.available_on_pc_epoch, timeout=config.timeouts.claim_cmd)
logging.info(f"Handover for pc epoch {db_tx.available_on_pc_epoch} has happened")
with raises(SidechainMainCliException) as excinfo:
with raises(PCContractsCliException) as excinfo:
api.claim_tokens(config.nodes_config.invalid_mc_skey.mainchain_key, db_tx.combined_proof)
assert "Error while decoding key" in excinfo.value.message

Expand All @@ -384,7 +384,7 @@ def test_claim_on_already_claimed_transaction_should_fail(
* claiming tokens for that transaction again should fail
"""
logging.info(f"Claiming tx that should fail: {latest_claimed_outgoing_tx}")
with raises(SidechainMainCliException) as excinfo:
with raises(PCContractsCliException) as excinfo:
api.claim_tokens(
config.nodes_config.active_transfer_account.mainchain_key,
latest_claimed_outgoing_tx.combined_proof,
Expand Down
4 changes: 2 additions & 2 deletions E2E-tests/tests/committee/test_permissioned_registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from src.blockchain_api import BlockchainApi
from src.db.models import PermissionedCandidates
from sqlalchemy.orm import Session
from src.sidechain_main_cli import SidechainMainCliException
from src.pc_contracts_cli import PCContractsCliException
from pytest import mark


Expand All @@ -24,7 +24,7 @@ def test_add_permissioned_candidate(permissioned_candidate: PermissionedCandidat
logging.info(f"Adding permissioned candidate {permissioned_candidate.name}")
try:
result, next_status_epoch = api.add_permissioned_candidate(permissioned_candidate.name)
except SidechainMainCliException as e:
except PCContractsCliException as e:
if 'InvalidCLIParams "New candidates list is the same as the currently stored list."' in str(e):
pytest.skip("Skipping test because the candidate is already in the list")
else:
Expand Down
8 changes: 4 additions & 4 deletions E2E-tests/tests/passive_flow/test_passive_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlalchemy import Sequence
from pytest import mark
import pytest
from src.sidechain_main_cli import SidechainMainCliException
from src.pc_contracts_cli import PCContractsCliException


def get_burn_tx_from_rpc(api: BlockchainApi, tx_hash):
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_burn_more_than_balance_should_fail(api: BlockchainApi, config: ApiConfi
burning_key = config.nodes_config.passive_transfer_account.mainchain_key
pc_addr = config.nodes_config.negative_test_transfer_account.partner_chain_address

with pytest.raises(SidechainMainCliException) as excinfo:
with pytest.raises(PCContractsCliException) as excinfo:
api.burn_tokens(pc_addr, amount, burning_key)
assert "BalanceInsufficientError" in excinfo.value.message

Expand All @@ -133,7 +133,7 @@ def test_burn_negative_balance_should_fail(api: BlockchainApi, config: ApiConfig
burning_key = config.nodes_config.passive_transfer_account.mainchain_key
pc_addr = config.nodes_config.negative_test_transfer_account.partner_chain_address

with pytest.raises(SidechainMainCliException) as excinfo:
with pytest.raises(PCContractsCliException) as excinfo:
api.burn_tokens(pc_addr, amount, burning_key)
assert "ExUnitsEvaluationFailed" in excinfo.value.message

Expand All @@ -150,7 +150,7 @@ def test_burn_with_invalid_key_should_fail(api: BlockchainApi, config: ApiConfig
burning_key = config.nodes_config.invalid_mc_skey.mainchain_key
pc_addr = config.nodes_config.negative_test_transfer_account.partner_chain_address

with pytest.raises(SidechainMainCliException) as excinfo:
with pytest.raises(PCContractsCliException) as excinfo:
api.burn_tokens(pc_addr, amount, burning_key)
assert "Error while decoding key" in excinfo.value.message

Expand Down
2 changes: 1 addition & 1 deletion dev/local-environment/modules/pc-contracts-cli.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

pc-contracts-cli:
container_name: pc-contracts-cli
image: ${SIDECHAIN_MAIN_CLI_IMAGE}
image: ${PC_CONTRACTS_CLI_IMAGE}
platform: linux/amd64
volumes:
- shared-volume:/shared
Expand Down
4 changes: 2 additions & 2 deletions dev/local-environment/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DBSYNC_IMAGE="ghcr.io/intersectmbo/cardano-db-sync:13.5.0.2"
KUPO_IMAGE="cardanosolutions/kupo:v2.9.0"
OGMIOS_IMAGE="cardanosolutions/ogmios:v6.9.0"
POSTGRES_IMAGE="postgres:15.3"
SIDECHAIN_MAIN_CLI_IMAGE="node:22-bookworm"
PC_CONTRACTS_CLI_IMAGE="node:22-bookworm"
TESTS_IMAGE="python:3.10-slim"
PC_CONTRACTS_CLI_ZIP_URL="https://github.com/input-output-hk/partner-chains-smart-contracts/releases/download/v6.2.2/pc-contracts-cli-v6.2.2.zip"
PARTNER_CHAINS_NODE_URL="https://github.com/input-output-hk/partner-chains/releases/download/v1.3.0/partner-chains-node-v1.3.0-x86_64-linux"
Expand Down Expand Up @@ -367,7 +367,7 @@ DBSYNC_IMAGE=$DBSYNC_IMAGE
KUPO_IMAGE=$KUPO_IMAGE
OGMIOS_IMAGE=$OGMIOS_IMAGE
POSTGRES_IMAGE=$POSTGRES_IMAGE
SIDECHAIN_MAIN_CLI_IMAGE=$SIDECHAIN_MAIN_CLI_IMAGE
PC_CONTRACTS_CLI_IMAGE=$PC_CONTRACTS_CLI_IMAGE
TESTS_IMAGE=$TESTS_IMAGE
PARTNER_CHAINS_NODE_IMAGE=${node_image:-$PARTNER_CHAINS_NODE_IMAGE}
PC_CONTRACTS_CLI_ZIP_URL=$PC_CONTRACTS_CLI_ZIP_URL
Expand Down

0 comments on commit d2060c5

Please sign in to comment.