-
Notifications
You must be signed in to change notification settings - Fork 0
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
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 7fe81c6
Fixes
vsuharnikov 34aac8a
Asserts in tests
vsuharnikov 0921ad5
Fix
vsuharnikov 493946a
Fix
vsuharnikov 0009726
Remove the setup directory
vsuharnikov 10ee93b
Updated README.md
vsuharnikov 6c70ae4
Test with multiple e2c transfers
vsuharnikov 7640030
Test with multiple c2e transfers
vsuharnikov e7560a9
Fixed transfer-c2e.py balances comparison
vsuharnikov 801552d
Cleanup
vsuharnikov 7ac7131
Cleanup
vsuharnikov 052caf7
BaseTransfer
vsuharnikov 57cb51c
Renaming
vsuharnikov 30fd707
Up
vsuharnikov 29ac45f
Logs in file
vsuharnikov c54bd5e
Force Accounts to depend on Network to guarantee right network addres…
vsuharnikov bca8e78
Up
vsuharnikov aab750f
pyproject.toml instead of setup.py
vsuharnikov fcf6d72
Test accounts instead of miners
vsuharnikov 6914dd3
Moving functions to unit0-examples, better logs
vsuharnikov a6b5e3f
Accounts in ExtendedNetwork
vsuharnikov 90525aa
Decimals instead of float, logs improvements
vsuharnikov ee96e95
Removed files
vsuharnikov ba9219e
Fixes
vsuharnikov 5d106b1
Issue and transfer chain contract tokens to run tests in any order
vsuharnikov 9c651d6
Run basic tests
vsuharnikov 05007d6
Fixed tests
vsuharnikov 369d5f5
local-network: removed logs directory, run test with docker compose p…
vsuharnikov d78da29
Up
vsuharnikov ef95673
Logging from unit0-examples
vsuharnikov e442f55
Test improvements
vsuharnikov 40fbd8a
Docker compose context for BlockScout
vsuharnikov 0fdcbde
Merge github/main
vsuharnikov 38bb073
Fix
vsuharnikov aab9817
Review fixes
vsuharnikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.env | ||
.cache/ | ||
data/ | ||
logs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
logs | ||
.venv/ | ||
.solc-select/ | ||
__pycache__/ | ||
*.egg-info/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
devnet-0
sodevnet-3
can be a miner