Skip to content

Commit

Permalink
Merge branch 'v2.7.x' into decrease-ima-frame
Browse files Browse the repository at this point in the history
  • Loading branch information
badrogger committed May 10, 2024
2 parents 90d82b0 + 13a95c1 commit 37bfae3
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 119 deletions.
2 changes: 1 addition & 1 deletion core/schains/config/skale_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def generate_skale_section(

schain_type = get_schain_type(schain['partOfNode'])
static_node_info = get_static_node_info(schain_type)
static_schain_info = get_static_schain_info()
static_schain_info = get_static_schain_info(schain['name'])

node_info = generate_current_node_info(
node_id=node_id,
Expand Down
17 changes: 15 additions & 2 deletions core/schains/config/static_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,22 @@ def get_static_schain_cmd(env_type: str = ENV_TYPE) -> list:
return static_params['schain_cmd']


def get_static_schain_info(env_type: str = ENV_TYPE) -> dict:
def get_static_schain_info(schain_name: str, env_type: str = ENV_TYPE) -> dict | None:
static_params = get_static_params(env_type)
return static_params['schain']
static_params_schain = static_params['schain']
processed_params = {}
for param_name, param in static_params_schain.items():
processed_params[param_name] = get_schain_static_param(param, schain_name)
return processed_params


def get_schain_static_param(static_param_schain: dict | int, schain_name: str) -> int:
if isinstance(static_param_schain, int):
return static_param_schain
elif isinstance(static_param_schain, dict) and schain_name in static_param_schain:
return static_param_schain[schain_name]
else:
return static_param_schain.get('default', None)


def get_static_node_info(schain_type: SchainType, env_type: str = ENV_TYPE) -> dict:
Expand Down
51 changes: 51 additions & 0 deletions scripts/test_generate_config_sync_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import json
import pytest

from core.schains.config.generator import SChainBaseConfig
from core.schains.config.accounts import generate_dynamic_accounts

from tools.helper import read_json
from tools.configs.schains import BASE_SCHAIN_CONFIG_FILEPATH

# Run only on admin 2.0.2 or older
# Add config with node groups to the root admin folder

CHAINS = ['']


@pytest.mark.skip(reason="test only used to generate static accounts for a sync node")
def test_generate_config(skale):
for schain_name in CHAINS:

current_config = read_json(f'{schain_name}.json')
original_group = current_config["skaleConfig"]["sChain"]["nodeGroups"]["0"]["nodes"]

schain = skale.schains.get_by_name(schain_name)

schain_nodes_with_schains = []
for key, value in original_group.items():
schain_nodes_with_schains.append({
'id': int(key),
'publicKey': value[2]
})

base_config = SChainBaseConfig(BASE_SCHAIN_CONFIG_FILEPATH)

print('base_config')
print(base_config.config)
print(base_config.config['accounts'])

# assert False

dynamic_accounts = generate_dynamic_accounts(
schain=schain,
schain_nodes=schain_nodes_with_schains
)

accounts = {
**base_config.config['accounts'],
**dynamic_accounts
}

with open(f'accounts/schain-{schain_name}.json', 'w') as outfile:
json.dump({'accounts': accounts}, outfile, indent=4)
46 changes: 45 additions & 1 deletion tests/schains/config/static_params_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from core.schains.config.helper import get_static_params
from core.schains.types import SchainType
from core.schains.config.static_params import (
get_automatic_repair_option,
get_schain_static_param,
get_static_schain_cmd,
get_static_schain_info,
get_static_node_info
)
from tools.configs import ENV_TYPE


TEST_SCHAIN_NAME = 'test-schain'
LEGACY_TS_NAME = 'revertableFSPatchTimestamp'
NEW_TS_NAME = 'contractStorageZeroValuePatchTimestamp'


def test_get_static_schain_cmd():
Expand All @@ -13,8 +21,9 @@ def test_get_static_schain_cmd():


def test_get_static_schain_info():
schain_info = get_static_schain_info()
schain_info = get_static_schain_info(TEST_SCHAIN_NAME)
assert schain_info == {
"contractStorageZeroValuePatchTimestamp": 1500000,
"revertableFSPatchTimestamp": 1000000,
"contractStoragePatchTimestamp": 1000000,
"snapshotIntervalSec": 0,
Expand All @@ -24,6 +33,41 @@ def test_get_static_schain_info():
}


def test_get_static_schain_info_custom_chain_ts():
custom_schain_info = get_static_schain_info(TEST_SCHAIN_NAME)
default_schain_info = get_static_schain_info('test')

assert custom_schain_info[LEGACY_TS_NAME] == default_schain_info[LEGACY_TS_NAME]
assert custom_schain_info[NEW_TS_NAME] != default_schain_info[NEW_TS_NAME]

assert custom_schain_info[NEW_TS_NAME] == 1500000
assert default_schain_info[NEW_TS_NAME] == 800000


def test_get_schain_static_param():
static_params = get_static_params(ENV_TYPE)
legacy_ts_info = get_schain_static_param(
static_params['schain'][LEGACY_TS_NAME],
TEST_SCHAIN_NAME
)
assert legacy_ts_info == static_params['schain'].get(LEGACY_TS_NAME)

new_ts_info_custom_chain = get_schain_static_param(
static_params['schain'][NEW_TS_NAME],
TEST_SCHAIN_NAME
)
assert new_ts_info_custom_chain != static_params['schain'][NEW_TS_NAME]
assert new_ts_info_custom_chain == static_params['schain'][NEW_TS_NAME][TEST_SCHAIN_NAME]

new_ts_info_default_chain = get_schain_static_param(
static_params['schain'][NEW_TS_NAME],
'test'
)
assert new_ts_info_default_chain != static_params['schain'][NEW_TS_NAME]
assert new_ts_info_default_chain != static_params['schain'][NEW_TS_NAME].get('test')
assert new_ts_info_default_chain == static_params['schain'][NEW_TS_NAME].get('default')


def test_get_static_node_info():
node_info_small = get_static_node_info(SchainType.small)
node_info_medium = get_static_node_info(SchainType.medium)
Expand Down
115 changes: 0 additions & 115 deletions tests/skale-data/config/environment_params.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions tests/skale-data/config/static_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ envs:
docker-compose: 1.27.4

schain:
contractStorageZeroValuePatchTimestamp:
default: 800000
test-schain: 1500000
revertableFSPatchTimestamp: 1000000
contractStoragePatchTimestamp: 1000000
snapshotIntervalSec: 0
Expand Down Expand Up @@ -111,6 +114,9 @@ envs:
docker-compose: 1.27.4

schain:
contractStorageZeroValuePatchTimestamp:
default: 800000
test-schain: 1500000
revertableFSPatchTimestamp: 1000000
contractStoragePatchTimestamp: 1000000
snapshotIntervalSec: 0
Expand Down Expand Up @@ -185,6 +191,9 @@ envs:
docker-compose: 1.27.4

schain:
contractStorageZeroValuePatchTimestamp:
default: 800000
test-schain: 1500000
revertableFSPatchTimestamp: 1000000
contractStoragePatchTimestamp: 1000000
snapshotIntervalSec: 0
Expand Down Expand Up @@ -262,6 +271,9 @@ envs:
docker-compose: 1.27.4

schain:
contractStorageZeroValuePatchTimestamp:
default: 800000
test-schain: 1500000
revertableFSPatchTimestamp: 1000000
contractStoragePatchTimestamp: 1000000
snapshotIntervalSec: 0
Expand Down

0 comments on commit 37bfae3

Please sign in to comment.