Skip to content

Commit

Permalink
Update python deps including substrate-interface (#139)
Browse files Browse the repository at this point in the history
* update python deps including substrate-interface

fix #138

* add new rpc flags required for tests --unsafe-force-node-key-generation

* add --unsafe-force-node-key-generation to docker-compose as well

* fix RPC FLAGS in tests

* fix docker-compose basic relay+para setup
  • Loading branch information
PierreBesson authored Jun 12, 2024
1 parent 7bbcde1 commit d70c15b
Show file tree
Hide file tree
Showing 11 changed files with 849 additions and 737 deletions.
1,501 changes: 800 additions & 701 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ APScheduler = "^3.10.1"
gunicorn = "^20.1.0"
uvicorn = "^0.21.1"
kubernetes = "^27.2.0"
substrate-interface = "^1.6.2"
substrate-interface = "^1.7.9"
Jinja2 = "^3.1.3"
fastapi = "^0.109.1"
python-multipart = "^0.0.7"
Expand Down
6 changes: 3 additions & 3 deletions tests/balance_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

from app.lib.balance_utils import get_funds, transfer_funds, fund_accounts, teleport_funds
from tests.test_utils import wait_for_http_ready

from tests.test_constants import RPC_DEV_FLAGS

class BalanceUtilsTest(unittest.TestCase):

def setUp(self):
# Start Alice validator
self.alice_validator = DockerContainer('parity/polkadot:latest')
self.alice_validator.with_command('--chain rococo-local --validator --alice --unsafe-rpc-external --rpc-cors=all --rpc-methods=unsafe')
self.alice_validator.with_command(f'--chain rococo-local --validator --alice {RPC_DEV_FLAGS}')
self.alice_validator.with_exposed_ports(9944)
self.alice_validator.start()
self.alice_validator_rpc_ws_url = 'ws://{}:{}'.format(self.alice_validator.get_container_host_ip(),
self.alice_validator.get_exposed_port(9944))

# Start Bob validator
self.bob_validator = DockerContainer('parity/polkadot:latest')
self.bob_validator.with_command('--chain rococo-local --validator --bob --unsafe-rpc-external --rpc-cors=all --rpc-methods=unsafe')
self.bob_validator.with_command(f'--chain rococo-local --validator --bob {RPC_DEV_FLAGS}')
self.bob_validator.with_exposed_ports(9944)
self.bob_validator.start()
self.bob_validator_http_url = 'http://{}:{}'.format(self.bob_validator.get_container_host_ip(),
Expand Down
23 changes: 20 additions & 3 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,47 @@ services:
depends_on: &depends_on_chainspec
chainspec:
condition: service_completed_successfully
command: >
command: |
--chain=/chainspec/rococo-local.json
--rpc-port 9944
--rpc-cors all
--unsafe-rpc-external
--unsafe-force-node-key-generation
--validator
--insecure-validator-i-know-what-i-do
--alice
--tmp
node_bob:
image: *polkadotimage
ports:
- "9944"
volumes: *chainspec
depends_on: *depends_on_chainspec
command: --chain=/chainspec/rococo-local.json --bob --tmp
command: |
--chain=/chainspec/rococo-local.json
--rpc-port 9944
--rpc-cors all
--unsafe-rpc-external
--unsafe-force-node-key-generation
--validator
--insecure-validator-i-know-what-i-do
--bob
--tmp
collator:
image: parity/polkadot-parachain:latest
volumes: *chainspec
ports:
- "9944"
depends_on: *depends_on_chainspec
command: >
command: |
--chain shell
--unsafe-rpc-external
--rpc-cors=all
--rpc-methods=unsafe
--unsafe-force-node-key-generation
--collator
--tmp
--
--chain /chainspec/rococo-local.json
Expand Down
3 changes: 2 additions & 1 deletion tests/node_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from app.lib.node_utils import is_node_ready, get_node_health, is_node_ready_ws, get_node_version, \
get_node_sync_state
from app.lib.substrate import get_substrate_client, substrate_rpc_request
from tests.test_constants import RPC_DEV_FLAGS
from tests.test_utils import wait_for_http_ready


class NodeUtilsTest(unittest.TestCase):

def setUp(self):
self.polkadot = DockerContainer('parity/polkadot:latest')
self.polkadot.with_command('--dev --validator --node-key 4b067400ba508d783ccf86b73aa825ebafea96c95ebdff3f307ab6dd854f0852 --unsafe-rpc-external --rpc-methods=unsafe --rpc-cors=all')
self.polkadot.with_command(f'--dev --validator --node-key 4b067400ba508d783ccf86b73aa825ebafea96c95ebdff3f307ab6dd854f0852 {RPC_DEV_FLAGS}')
self.polkadot.with_exposed_ports(9944)
self.polkadot.start()
self.polkadot_rpc_http_url = 'http://{}:{}'.format(self.polkadot.get_container_host_ip(), self.polkadot.get_exposed_port(9944))
Expand Down
3 changes: 2 additions & 1 deletion tests/session_keys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
from testcontainers.core.container import DockerContainer

from app.lib.session_keys import rotate_node_session_keys, set_node_session_key
from tests.test_constants import RPC_DEV_FLAGS
from tests.test_utils import wait_for_http_ready


class NodeSessionKeysTest(unittest.TestCase):

def setUp(self):
self.polkadot = DockerContainer('parity/polkadot:latest')
self.polkadot.with_command('--dev --validator --unsafe-rpc-external --rpc-methods=unsafe --rpc-cors=all')
self.polkadot.with_command(f'--dev --validator {RPC_DEV_FLAGS}')
self.polkadot.with_exposed_ports(9944)
self.polkadot.start()
self.polkadot_rpc_http_url = 'http://{}:{}'.format(self.polkadot.get_container_host_ip(), self.polkadot.get_exposed_port(9944))
Expand Down
3 changes: 2 additions & 1 deletion tests/stash_account_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
from substrateinterface import Keypair

from app.lib.stash_accounts import get_account_funds
from tests.test_constants import RPC_DEV_FLAGS
from tests.test_utils import wait_for_http_ready


class StashAccountTest(unittest.TestCase):

def setUp(self):
self.polkadot = DockerContainer('parity/polkadot:latest')
self.polkadot.with_command('--dev --validator --unsafe-rpc-external --rpc-methods=unsafe --rpc-cors=all')
self.polkadot.with_command(f'--dev --validator {RPC_DEV_FLAGS}')
self.polkadot.with_exposed_ports(9944)
self.polkadot.start()

Expand Down
3 changes: 2 additions & 1 deletion tests/substrate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

from app.lib.substrate import get_substrate_client, get_sudo_keys, substrate_call, substrate_proxy_call, substrate_check_sudo_key_and_call
from app.lib.balance_utils import get_funds
from tests.test_constants import RPC_DEV_FLAGS
from tests.test_utils import wait_for_http_ready


class SubstrateTest(unittest.TestCase):

def setUp(self):
self.polkadot = DockerContainer('parity/polkadot:latest')
self.polkadot.with_command('--dev --validator --unsafe-rpc-external --rpc-methods=unsafe --rpc-cors=all')
self.polkadot.with_command(f'--dev --validator {RPC_DEV_FLAGS}')
self.polkadot.with_exposed_ports(9944)
self.polkadot.start()
self.polkadot_rpc_http_url = 'http://{}:{}'.format(self.polkadot.get_container_host_ip(), self.polkadot.get_exposed_port(9944))
Expand Down
1 change: 1 addition & 0 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RPC_DEV_FLAGS = '--unsafe-rpc-external --rpc-cors=all --rpc-methods=unsafe --unsafe-force-node-key-generation'
21 changes: 7 additions & 14 deletions tests/validator_manager_pos_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from app.lib.substrate import get_substrate_client
from app.lib.validator_manager import get_validator_set, setup_pos_validator, get_validators_pending_addition, staking_chill, \
get_validators_pending_deletion
from tests.test_constants import RPC_DEV_FLAGS
from tests.test_utils import wait_for_http_ready
from unittest import mock

Expand All @@ -15,27 +16,19 @@ class ValidatorManagerTestPoS(unittest.TestCase):
def setUp(self):
# Start Alice validator
self.alice_validator = DockerContainer('parity/polkadot:latest')
self.alice_validator.with_command("""
--chain westend-local --validator --alice --unsafe-rpc-external --rpc-cors=all --rpc-methods=unsafe
""")
self.alice_validator.with_command(f'--chain westend-local --validator --alice {RPC_DEV_FLAGS}')
self.alice_validator.with_exposed_ports(9944, 10333)
self.alice_validator.start()

self.alice_validator_rpc_ws_url = 'ws://{}:{}'.format(self.alice_validator.get_container_host_ip(),
self.alice_validator.get_exposed_port(9944))
self.alice_validator_rpc_ws_url = f'ws://{self.alice_validator.get_container_host_ip()}:{self.alice_validator.get_exposed_port(9944)}'

# Start Bob validator and connect it to Alice
self.bob_validator = DockerContainer('parity/polkadot:latest')
self.bob_validator.with_command("""
--chain westend-local --validator --bob --unsafe-rpc-external --rpc-cors=all \
--rpc-methods=unsafe --bootnodes /ip4/127.0.0.1/tcp/{}/p2p/12D3KooWAvdwXzjmRpkHpz8PzUTaX1o23SdpgAWVyTGMSQ68QXK6
""".format(self.alice_validator.get_exposed_port(10333)))
self.bob_validator.with_exposed_ports( 9944)
self.bob_validator.with_command(f'-chain westend-local --validator --bob --unsafe-rpc-external {RPC_DEV_FLAGS} --bootnodes /ip4/127.0.0.1/tcp/{self.alice_validator.get_exposed_port(10333)}/p2p/12D3KooWAvdwXzjmRpkHpz8PzUTaX1o23SdpgAWVyTGMSQ68QXK6')
self.bob_validator.with_exposed_ports(9944)
self.bob_validator.start()
self.bob_validator_http_url = 'http://{}:{}'.format(self.bob_validator.get_container_host_ip(),
self.bob_validator.get_exposed_port(9944))
self.bob_validator_rpc_ws_url = 'ws://{}:{}'.format(self.bob_validator.get_container_host_ip(),
self.bob_validator.get_exposed_port(9944))
self.bob_validator_http_url = f'http://{self.bob_validator.get_container_host_ip()}:{self.bob_validator.get_exposed_port(9944)}'
self.bob_validator_rpc_ws_url = f'ws://{self.bob_validator.get_container_host_ip()}:{self.bob_validator.get_exposed_port(9944)}'
self.alice_key = '0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a'

wait_for_http_ready(self.bob_validator_http_url + '/health')
Expand Down
20 changes: 9 additions & 11 deletions tests/validator_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from app.lib.validator_manager import get_validator_set, register_validators, get_validators_pending_addition, deregister_validators, \
get_validators_pending_deletion
from tests.test_constants import RPC_DEV_FLAGS
from tests.test_utils import wait_for_http_ready


Expand All @@ -13,25 +14,22 @@ class ValidatorManagerTest(unittest.TestCase):
def setUp(self):
# Start Alice validator
self.alice_validator = DockerContainer('parity/polkadot:latest')
self.alice_validator.with_command('--chain rococo-local --validator --alice --unsafe-rpc-external --rpc-cors=all')
self.alice_validator.with_command(f'--chain rococo-local --validator --alice {RPC_DEV_FLAGS}')
self.alice_validator.with_exposed_ports(9944, 10333)
self.alice_validator.start()

self.alice_validator_rpc_ws_url = 'ws://{}:{}'.format(self.alice_validator.get_container_host_ip(),
self.alice_validator.get_exposed_port(9944))
self.alice_validator_rpc_ws_url = f'ws://{self.alice_validator.get_container_host_ip()}:{self.alice_validator.get_exposed_port(9944)}'

# Start Bob validator and connect it to Alice
self.bob_validator = DockerContainer('parity/polkadot:latest')
self.bob_validator.with_command("""
--chain rococo-local --validator --bob --unsafe-rpc-external --rpc-cors=all \
--bootnodes /ip4/127.0.0.1/tcp/{}/p2p/12D3KooWAvdwXzjmRpkHpz8PzUTaX1o23SdpgAWVyTGMSQ68QXK6
""".format(self.alice_validator.get_exposed_port(10333)))
self.bob_validator.with_command(f"""
--chain rococo-local --validator --bob {RPC_DEV_FLAGS} \
--bootnodes /ip4/127.0.0.1/tcp/{self.alice_validator.get_exposed_port(10333)}/p2p/12D3KooWAvdwXzjmRpkHpz8PzUTaX1o23SdpgAWVyTGMSQ68QXK6
""")
self.bob_validator.with_exposed_ports(9944)
self.bob_validator.start()
self.bob_validator_http_url = 'http://{}:{}'.format(self.bob_validator.get_container_host_ip(),
self.bob_validator.get_exposed_port(9944))
self.bob_validator_rpc_ws_url = 'ws://{}:{}'.format(self.bob_validator.get_container_host_ip(),
self.bob_validator.get_exposed_port(9944))
self.bob_validator_http_url = f'http://{self.bob_validator.get_container_host_ip()}:{self.bob_validator.get_exposed_port(9944)}'
self.bob_validator_rpc_ws_url = f'ws://{self.bob_validator.get_container_host_ip()}:{self.bob_validator.get_exposed_port(9944)}'
self.alice_key = '0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a'

wait_for_http_ready(self.bob_validator_http_url + '/health')
Expand Down

0 comments on commit d70c15b

Please sign in to comment.