Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python in local network deployment and tests #20

Merged
merged 36 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
03896c6
Deploy on Python (WIP)
vsuharnikov Sep 24, 2024
7fe81c6
Fixes
vsuharnikov Sep 25, 2024
34aac8a
Asserts in tests
vsuharnikov Sep 25, 2024
0921ad5
Fix
vsuharnikov Sep 25, 2024
493946a
Fix
vsuharnikov Sep 25, 2024
0009726
Remove the setup directory
vsuharnikov Sep 25, 2024
10ee93b
Updated README.md
vsuharnikov Sep 25, 2024
6c70ae4
Test with multiple e2c transfers
vsuharnikov Sep 25, 2024
7640030
Test with multiple c2e transfers
vsuharnikov Sep 26, 2024
e7560a9
Fixed transfer-c2e.py balances comparison
vsuharnikov Sep 26, 2024
801552d
Cleanup
vsuharnikov Sep 26, 2024
7ac7131
Cleanup
vsuharnikov Sep 26, 2024
052caf7
BaseTransfer
vsuharnikov Sep 26, 2024
57cb51c
Renaming
vsuharnikov Sep 26, 2024
30fd707
Up
vsuharnikov Sep 26, 2024
29ac45f
Logs in file
vsuharnikov Sep 26, 2024
c54bd5e
Force Accounts to depend on Network to guarantee right network addres…
vsuharnikov Sep 26, 2024
bca8e78
Up
vsuharnikov Sep 26, 2024
aab750f
pyproject.toml instead of setup.py
vsuharnikov Sep 27, 2024
fcf6d72
Test accounts instead of miners
vsuharnikov Sep 27, 2024
6914dd3
Moving functions to unit0-examples, better logs
vsuharnikov Sep 27, 2024
a6b5e3f
Accounts in ExtendedNetwork
vsuharnikov Sep 27, 2024
90525aa
Decimals instead of float, logs improvements
vsuharnikov Sep 27, 2024
ee96e95
Removed files
vsuharnikov Sep 27, 2024
ba9219e
Fixes
vsuharnikov Sep 30, 2024
5d106b1
Issue and transfer chain contract tokens to run tests in any order
vsuharnikov Sep 30, 2024
9c651d6
Run basic tests
vsuharnikov Oct 1, 2024
05007d6
Fixed tests
vsuharnikov Oct 1, 2024
369d5f5
local-network: removed logs directory, run test with docker compose p…
vsuharnikov Oct 2, 2024
d78da29
Up
vsuharnikov Oct 2, 2024
ef95673
Logging from unit0-examples
vsuharnikov Oct 2, 2024
e442f55
Test improvements
vsuharnikov Oct 2, 2024
40fbd8a
Docker compose context for BlockScout
vsuharnikov Oct 2, 2024
0fdcbde
Merge github/main
vsuharnikov Oct 2, 2024
38bb073
Fix
vsuharnikov Oct 2, 2024
aab9817
Review fixes
vsuharnikov Oct 3, 2024
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
1 change: 1 addition & 0 deletions local-network/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.cache/
data/
logs/
12 changes: 10 additions & 2 deletions local-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ You have to build consensus client. Run [./consensus_client-image-build.sh](./co

- Run `./all-images-build.sh` after pulling the repository, so docker compose will pull new external images and rebuild
the `deploy` image.
- If you need to run Blockscout, run `BS=1 ./restart.sh`. Otherwise, just [./restart.sh](./restart.sh).
- If deploy failed, and you want to retry, run `./deploy-run.sh`.
- Available docker compose contexts:
- BlockScout services: `bs`
- Tests in the end `tests`
- Run [./restart.sh](./restart.sh)
- With selected contexts, for example, `COMPOSE_PROFILES=bs,tests ./restart.sh`
- Or without any context: `./restart.sh`

To retry failed:
- deploy - run `./deploy-run.sh`.
- tests - run `./tests-run.sh`.

## How to stop

Expand Down
7 changes: 5 additions & 2 deletions local-network/all-images-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ echo "Update consensus client image"
./consensus_client-image-build.sh

echo "Update foreign images"
BS=enabled docker compose pull --ignore-buildable
docker compose pull --ignore-buildable

echo "Update deploy image"
docker compose build deploy
docker compose build deploy --no-cache

echo "Update test image"
docker compose build test

echo "Done."
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
extends:
file: ./redis/redis.yml
service: redis
profiles: [ bs ]

# db-init:
# extends:
Expand All @@ -16,6 +17,7 @@ services:
extends:
file: ./db/db.yml
service: db
profiles: [ bs ]

backend:
depends_on:
Expand All @@ -25,6 +27,7 @@ services:
extends:
file: ./backend/backend.yml
service: backend
profiles: [ bs ]

# visualizer:
# extends:
Expand All @@ -35,13 +38,15 @@ services:
extends:
file: ./sig-provider/sig-provider.yml
service: sig-provider
profiles: [ bs ]

frontend:
depends_on:
- backend
extends:
file: ./frontend/frontend.yml
service: frontend
profiles: [ bs ]

# stats-db-init:
# extends:
Expand All @@ -55,6 +60,7 @@ services:
extends:
file: ./stats/stats.yml
service: stats-db
profiles: [ bs ]

stats:
depends_on:
Expand All @@ -63,6 +69,7 @@ services:
extends:
file: ./stats/stats.yml
service: stats
profiles: [ bs ]

nginx:
depends_on:
Expand All @@ -72,3 +79,4 @@ services:
extends:
file: ./nginx/nginx.yml
service: nginx
profiles: [ bs ]
23 changes: 16 additions & 7 deletions local-network/configs/wavesnode/genesis-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ genesis-generator {
# Address: 3FSrRN8X7cDsLyYTScS8Yf8KSwZgJBwf1jU
{ seed-text = "devnet-2", nonce = 0, amount = 998036000000000 }

# Additional address
# Seed text: devnet-3
# Additional addresses

# Seed text: devnet-0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

devnet-0 so devnet-3 can be a miner

# Nonce: 0
# Seed: HnyGuCEnV1C
# Private account key: 6xx38JtyDrCBUox2HZ1F6qPZYcFHnfkYQzHRvs3wyRfH
# Public account key: 4rfG6p3Ep2dUr4QqWtJwDvy3ySumMejgTE5sdJLzB756
# Address: 3Fkh3dNmLS6NQtVbHcrADegwLo9DviBL5Ro
{ seed-text = "devnet-3", nonce = 0, amount = 4611685988427387903 }
# Seed: HnyGuCEnV19
# Private account key: 8aYKVCJVYfcSQeSH1kM4D2e4Fcj5cAQzMh8uZ5hW2tB9
# Public account key: GRKksNikCNXYT7HqxCnqzjP5pf4NctgtTnmCvCMDEhAT
# Address: 3Ffcu52v7ETMAFhNAqQvHsv4JuQjEVP9q6E
{ seed-text = "devnet-0", nonce = 0, amount = 2305842994213693951 }

# Seed text: devnet-0
# Nonce: 1
# Seed: HnyGuCEnV19
# Private account key: 5tE8jwZ3B4eLTvdz7LqEBMcmspoqXD9nPCEfcZgh2BeV
# Public account key: BArfnBGQ9gkNHC2EftXf42uJuBioSffZiJoyYCTtwxof
# Address: 3FQFFWxMCDmyZhkRzKA7QiAZL4RKMhJvFnu
{ seed-text = "devnet-0", nonce = 1, amount = 2305842994213693952 }
]
}
6 changes: 3 additions & 3 deletions local-network/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ shopt -s nullglob
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "${DIR}" || exit

BS=enabled docker compose down
rm -rf data/*/* || true
rm -rf logs/*/* || true
COMPOSE_PROFILES=bs,tests BS=enabled docker compose down
rm -rf data || true
rm -rf logs || true

echo "Deleted."
6 changes: 4 additions & 2 deletions local-network/deploy/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
logs
.venv/
.solc-select/
__pycache__/
*.egg-info/
10 changes: 6 additions & 4 deletions local-network/deploy/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
logs
.solc-select
**/*.js
.venv/
.solc-select/
__pycache__/
build/
setup/
*.egg-info/
19 changes: 11 additions & 8 deletions local-network/deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
FROM node:18-slim
FROM python:3.12-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
python3-pip \
curl \
&& pip3 install solc-select --break-system-packages \
git \
gcc \
libc6-dev \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

WORKDIR /home/node/app
COPY package.json package-lock.json /home/node/app/
RUN npm i
WORKDIR /usr/src/app

CMD ["/bin/bash", "deploy-run.sh"]
COPY local/__init__.py ./local/
COPY pyproject.toml ./

RUN pip install --no-cache-dir --editable .

CMD ["/bin/bash", "run.sh"]
8 changes: 4 additions & 4 deletions local-network/deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ To re-deploy from a container run the following command from the project's root
./deploy-run.sh
```

To run tests (from this directory):
```bash
npm test ./test/transfer-e2c.ts
```
To run tests on the host machine, from this directory:
1. If you're on macOS with Apple Silicon: install `gcc`.
2. Create the virtual environment and install dependencies: `./dev-setup.sh`
3. Run test, e.g.: `./tests/transfer-c2e.py`
2 changes: 0 additions & 2 deletions local-network/deploy/bridge-compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ DIR="$(cd "$(dirname "$0")" && pwd)"
cd "${DIR}" || exit

SOLC_VERSION=0.8.26
export VIRTUAL_ENV="${DIR}" # for solc-select and solc

solc-select use $SOLC_VERSION --always-install

echo "Compile bridge.sol"
Expand Down
11 changes: 0 additions & 11 deletions local-network/deploy/common-settings-show.ts

This file was deleted.

112 changes: 112 additions & 0 deletions local-network/deploy/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env python
from decimal import Decimal
from time import sleep

from units_network import units, waves
from units_network.chain_contract import HexStr
from units_network.common_utils import configure_cli_logger
from units_network.node import Node

from local.network import get_local

log = configure_cli_logger(__file__)
network = get_local()


node = Node()
min_peers = len(network.cl_miners) - 1
while True:
r = node.connected_peers()
if len(r) >= min_peers:
break

log.info(f"Wait for {min_peers} peers, now: {r}")
sleep(2)

log.info(f"Chain contract address: {network.cl_chain_contract.oracleAddress}")

script_info = network.cl_chain_contract.oracleAcc.scriptInfo()
if script_info["script"] is None:
log.info("Set chain contract script")

with open("setup/waves/main.ride", "r", encoding="utf-8") as file:
source = file.read()
r = network.cl_chain_contract.setScript(source)
waves.force_success(log, r, "Can not set the chain contract script")

if not network.cl_chain_contract.isContractSetup():
log.info("Call ChainContract.setup")
el_genesis_block = network.w3.eth.get_block(0)

assert "hash" in el_genesis_block
el_genesis_block_hash = HexStr(el_genesis_block["hash"].to_0x_hex())

log.info(f"Genesis block hash: {el_genesis_block_hash}")

r = network.cl_chain_contract.setup(el_genesis_block_hash)
waves.force_success(log, r, "Can not setup the chain contract")

cl_token = network.cl_chain_contract.getToken()
cl_poor_accounts = []
for cl_account in network.cl_rich_accounts:
if cl_account.balance(cl_token.assetId) <= 0:
cl_poor_accounts.append(cl_account)

cl_poor_accounts_number = len(cl_poor_accounts)
txn_ids = []
if cl_poor_accounts_number > 0:
user_amount_for_each = Decimal(100)
atomic_amount_for_each = units.raw_to_waves_atomic(user_amount_for_each)
quantity = units.raw_to_waves_atomic(user_amount_for_each * cl_poor_accounts_number)
log.info(
f"Issue {user_amount_for_each * cl_poor_accounts_number} UNIT0 additional tokens for testing purposes"
)
reissue_txn_id = network.cl_chain_contract.oracleAcc.reissueAsset(
cl_token, quantity, reissuable=True
)
waves.wait_for(reissue_txn_id)

for cl_account in cl_poor_accounts:
log.info(f"Send {user_amount_for_each} UNIT0 tokens to {cl_account.address}")
txn_result = network.cl_chain_contract.oracleAcc.sendAsset(
recipient=cl_account,
asset=cl_token,
amount=atomic_amount_for_each,
)
waves.force_success(log, txn_result, "Can not send UNIT0 tokens", wait=False)
txn_id = txn_result["id"] # type: ignore
log.info(f"Transaction id: {txn_id}")
txn_ids.append(txn_id)

r = network.cl_chain_contract.evaluate("allMiners")
joined_miners = []
for entry in r["result"]["value"]:
joined_miners.append(entry["value"])
log.info(f"Miners: {joined_miners}")

for miner in network.cl_miners:
if miner.account.address not in joined_miners:
log.info(f"Call ChainContract.join by miner f{miner.account.address}")
r = network.cl_chain_contract.join_v2(
miner.account, miner.el_reward_address_hex
)
waves.force_success(
log,
r,
f"{miner.account.address} can not join the chain contract",
wait=False,
)
txn_id = r["id"] # type: ignore
log.info(f"Transaction id: {txn_id}") # type: ignore
txn_ids.append(txn_id)

for txn_id in txn_ids:
waves.wait_for(txn_id)
log.info(f"{txn_id} confirmed")

while True:
r = network.w3.eth.get_block("latest")
if "number" in r and r["number"] >= 1:
break
log.info("Wait for at least one block on EL")
sleep(3)
2 changes: 0 additions & 2 deletions local-network/deploy/deploy.ts

This file was deleted.

12 changes: 12 additions & 0 deletions local-network/deploy/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
deploy:
build:
context: .
network: host
restart: no # Manual start
platform: linux/amd64 # HACK for Apple Silicon
environment:
LOGGING_CONFIG: /usr/src/app/logging.conf
volumes:
- .:/usr/src/app

18 changes: 18 additions & 0 deletions local-network/deploy/dev-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

if [ ! -d "$PWD/.venv" ]; then
echo "Create a virtual environment"
python3 -m venv .venv --prompt local-network
source .venv/bin/activate

if [[ "$(uname)" == "Darwin" && "$(uname -m)" == "arm64" ]]; then
# Otherwise python-axolotl-curve25519 won't compile
export CC=gcc
fi

echo "Install dependencies"
# --no-cache-dir is useful during development and local units-network in dependencies
pip install --editable .
fi

echo "Done."
Loading