diff --git a/operate/services/manage.py b/operate/services/manage.py index a39b3ec4..dd99749a 100644 --- a/operate/services/manage.py +++ b/operate/services/manage.py @@ -2205,9 +2205,7 @@ def refill_requirements( # pylint: disable=too-many-locals,too-many-statements, agent_addresses = {key.address for key in service.keys} service_safe = ( - chain_data.multisig - if chain_data.multisig and chain_data.multisig != NON_EXISTENT_MULTISIG - else "service_safe" + chain_data.multisig if chain_data.multisig else "service_safe" ) if not master_safe_exists: diff --git a/operate/services/service.py b/operate/services/service.py index 6d88817b..a1aeb366 100644 --- a/operate/services/service.py +++ b/operate/services/service.py @@ -96,10 +96,10 @@ ALL_PARTICIPANTS = "all_participants" CONSENSUS_THRESHOLD = "consensus_threshold" DELETE_PREFIX = "delete_" -SERVICE_CONFIG_VERSION = 6 +SERVICE_CONFIG_VERSION = 7 SERVICE_CONFIG_PREFIX = "sc-" -NON_EXISTENT_MULTISIG = "0xm" +NON_EXISTENT_MULTISIG = None NON_EXISTENT_TOKEN = -1 DEFAULT_TRADER_ENV_VARS = { @@ -935,25 +935,31 @@ def migrate_format(cls, path: Path) -> bool: # pylint: disable=too-many-stateme new_chain_configs[chain] = chain_data # type: ignore data["chain_configs"] = new_chain_configs - data["version"] = SERVICE_CONFIG_VERSION - - # Redownload service path - if "service_path" in data: - package_absolute_path = path / Path(data["service_path"]).name - data.pop("service_path") - else: - package_absolute_path = path / data["package_path"] + if version < 6: + # Redownload service path + if "service_path" in data: + package_absolute_path = path / Path(data["service_path"]).name + data.pop("service_path") + else: + package_absolute_path = path / data["package_path"] - if package_absolute_path.exists() and package_absolute_path.is_dir(): - shutil.rmtree(package_absolute_path) + if package_absolute_path.exists() and package_absolute_path.is_dir(): + shutil.rmtree(package_absolute_path) - package_absolute_path = Path( - IPFSTool().download( - hash_id=data["hash"], - target_dir=path, + package_absolute_path = Path( + IPFSTool().download( + hash_id=data["hash"], + target_dir=path, + ) ) - ) - data["package_path"] = str(package_absolute_path.name) + data["package_path"] = str(package_absolute_path.name) + + if version < 7: + for _, chain_data in data.get("chain_configs", {}).items(): + if chain_data["chain_data"]["multisig"] == "0xm": + chain_data["chain_data"]["multisig"] = NON_EXISTENT_MULTISIG + + data["version"] = SERVICE_CONFIG_VERSION with open(path / Service._file, "w", encoding="utf-8") as file: json.dump(data, file, indent=2) diff --git a/tests/test_services_service.py b/tests/test_services_service.py index 0b77d08c..5cf93490 100644 --- a/tests/test_services_service.py +++ b/tests/test_services_service.py @@ -27,6 +27,7 @@ from deepdiff import DeepDiff from operate.services.service import ( + NON_EXISTENT_MULTISIG, SERVICE_CONFIG_PREFIX, SERVICE_CONFIG_VERSION, Service, @@ -55,7 +56,7 @@ "keys_address_0": "0x0000000000000000000000000000000000000001", "keys_private_key_0": "0x0000000000000000000000000000000000000000000000000000000000000001", "instance_0": "0x0000000000000000000000000000000000000001", - "multisig": "0x0000000000000000000000000000000000000020", + "multisig": "0xm", "service_config_id": "sc-00000000-0000-0000-0000-000000000000", "package_path": "trader_pearl", } @@ -332,7 +333,57 @@ def get_config_json_data_v6(**kwargs: t.Any) -> t.Dict[str, t.Any]: } -get_expected_data = get_config_json_data_v6 +def get_config_json_data_v7(**kwargs: t.Any) -> t.Dict[str, t.Any]: + """get_config_json_data_v7""" + + return { + "version": 7, + "service_config_id": kwargs.get("service_config_id"), + "hash": kwargs.get("hash"), + "hash_history": {kwargs.get("hash_timestamp"): kwargs.get("hash")}, + "keys": [ + { + "ledger": "ethereum", + "address": kwargs.get("keys_address_0"), + "private_key": kwargs.get("keys_private_key_0"), + } + ], + "home_chain": "gnosis", + "chain_configs": { + "gnosis": { + "ledger_config": {"rpc": kwargs.get("rpc"), "chain": "gnosis"}, + "chain_data": { + "instances": [kwargs.get("instance_0")], + "token": kwargs.get("token"), + "multisig": NON_EXISTENT_MULTISIG, + "staked": kwargs.get("staked"), + "on_chain_state": kwargs.get("on_chain_state"), + "user_params": { + "staking_program_id": kwargs.get("staking_program_id"), + "nft": kwargs.get("nft"), + "threshold": kwargs.get("threshold"), + "agent_id": kwargs.get("agent_id"), + "use_staking": kwargs.get("use_staking"), + "use_mech_marketplace": kwargs.get("use_mech_marketplace"), + "cost_of_bond": kwargs.get("cost_of_bond"), + "fund_requirements": { + "0x0000000000000000000000000000000000000000": { + "agent": kwargs.get("fund_requirements_agent"), + "safe": kwargs.get("fund_requirements_safe"), + } + }, + }, + }, + } + }, + "description": kwargs.get("description"), + "env_variables": {}, + "package_path": kwargs.get("package_path"), + "name": kwargs.get("name"), + } + + +get_expected_data = get_config_json_data_v7 class TestService: @@ -351,6 +402,7 @@ class TestService: get_config_json_data_v3, get_config_json_data_v4, get_config_json_data_v5, + get_config_json_data_v6, ], ) def test_service_migrate_format(