### Start General/Bridge Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-network/README.md Starts a General or Bridge node as a detached Docker container. It requires the PRIVATE_CONFIG environment variable and mounts a local directory for data. The 'run.sh' script is executed to start the node. ```bash docker run -d --name general -e PRIVATE_CONFIG=ignore -v {mount_direcotry}:/eth \ ghcr.io/boostryjp/ibet-network/general:{version} run.sh ``` -------------------------------- ### Start General Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/test-network/README.md Starts the general node as a detached Docker container. This command is also used for Bridge nodes. It requires the mount directory and version to be specified. The node will run in the background. ```bash docker run -d --name general -e PRIVATE_CONFIG=ignore -v {mount_direcotry}:/eth \ ghcr.io/boostryjp/ibet-testnet/general:{version} run.sh ``` -------------------------------- ### Start Validator Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-network/README.md Starts a Validator node as a detached Docker container. It requires environment variables for private configuration and the node key, and mounts a local directory for the node's data. The 'run.sh' script is executed to start the node process. ```bash docker run -d --name validator -e PRIVATE_CONFIG=ignore -e nodekeyhex={nodekey} -v ./:/eth \ ghcr.io/boostryjp/ibet-network/validator:{version} run.sh ``` -------------------------------- ### Start Validator Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/test-network/README.md Starts the validator node as a detached Docker container. It requires the mount directory, node key, and version to be specified. The node will run in the background. ```bash docker run -d --name validator -e PRIVATE_CONFIG=ignore -e nodekeyhex={nodekey} -v {mount_directory}:/eth \ ghcr.io/boostryjp/ibet-testnet/validator:{version} run.sh ``` -------------------------------- ### Initialize General Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/test-network/README.md Initializes a general node for the first time. This command sets up the necessary data directory and configuration. It requires the mount directory and version to be specified. ```bash docker run --rm --name generalInit -e PRIVATE_CONFIG=ignore -v {mount_directory}:/eth \ ghcr.io/boostryjp/ibet-testnet/general:{version} \ geth --datadir /eth init /eth/genesis.json_init ``` -------------------------------- ### Start Validator Node with Docker Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-for-fin-network/README.md Starts a validator node as a detached Docker container. This command requires a `nodekeyhex` to be provided. It mounts a directory for node data and executes the node's run script. ```bash docker run -d --name validator -e PRIVATE_CONFIG=ignore -e nodekeyhex={nodekey} -v {mount_directory}:/eth \ ghcr.io/boostryjp/ibet-fin-network/validator:{version} run.sh ``` -------------------------------- ### Start General/Bridge Node with Docker Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-for-fin-network/README.md Starts a general or bridge node as a detached Docker container. This command mounts the specified directory for node data and executes the node's run script. It's used for both general and bridge nodes. ```bash docker run -d --name general -e PRIVATE_CONFIG=ignore -v {mount_direcotry}:/eth \ ghcr.io/boostryjp/ibet-fin-network/general:{version} run.sh ``` -------------------------------- ### Initialize Validator Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/test-network/README.md Initializes a validator node for the first time. This command sets up the necessary data directory and configuration. It requires the mount directory and version to be specified. ```bash docker run --rm --name validatorInit -e PRIVATE_CONFIG=ignore -v {mount_directory}:/eth \ ghcr.io/boostryjp/ibet-testnet/validator:{version} \ geth --datadir /eth init /eth/genesis.json_init ``` -------------------------------- ### Node Startup and Configuration Script Source: https://context7.com/boostryjp/ibet-network/llms.txt This shell script prepares the Geth environment, parses various configuration options from environment variables, and constructs the Geth command. It optionally starts a block sync monitoring service and the Geth node itself. The script includes logic to wait for the Geth node to become active and implements a graceful shutdown handler for SIGINT and SIGTERM signals. ```bash #!/bin/ash # ibet-Network node startup script mkdir -p /eth/geth # Parse environment variables for optional configurations test ! -z "${rpccorsdomain}" && CORS_OPT="--http.corsdomain ${rpccorsdomain}" test ! -z "${rpcvhosts}" && VHOST_OPT="--http.vhosts ${rpcvhosts}" test ! -z "${maxpeers}" && PEERS_OPT="--maxpeers ${maxpeers}" test ! -z "${syncmode}" && SYNCMODE_OPT="--syncmode ${syncmode}" test ! -z "${identity}" && IDENTITY_OPT="--identity ${identity}" test ! -z "${cache}" && CACHE_OPT="--cache ${cache}" # Construct Geth command GETH_CMD="geth \ --http \ --http.addr 0.0.0.0 \ --http.port 8545 \ ${CORS_OPT} \ ${IDENTITY_OPT} \ --datadir /eth \ --port 30303 \ --http.api admin,debug,miner,txpool,eth,net,web3,istanbul,personal \ ${VHOST_OPT} \ --networkid 1500002 \ --nat any \ --verbosity ${verbosity:-2} \ --nodiscover \ --allow-insecure-unlock \ --miner.gastarget 800000000 \ ${PEERS_OPT} \ ${SYNCMODE_OPT} \ ${CACHE_OPT}" # Start block sync monitoring service (for general nodes) if [ -z "${BLOCK_SYNC_MONITORING_DISABLED}" ] || \ [ "${BLOCK_SYNC_MONITORING_DISABLED}" -ne 1 ]; then ash -c "nohup python monitoring/monitor_block_sync.py > /dev/stdout 2>&1 &" fi # Start Geth node ash -c "nohup ${GETH_CMD} > /dev/stdout 2>&1 &" # Wait for Geth to start for i in $(seq 1 300); do sleep 1 ps -ef | grep -v grep | grep "geth --http" > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "$0: geth Running." break fi done # Graceful shutdown handler function trap_sigint() { echo "$0: geth Shutdown." PID=$(ps -ef | grep "geth --http" | grep -v grep | awk '{print $1}') kill -SIGINT ${PID} while ps -ef | grep -v grep | grep "geth --http" > /dev/null 2>&1; sleep 1 done exit 0 } trap trap_sigint SIGINT SIGTERM # Keep container alive while :; sleep 5 done ``` -------------------------------- ### Install Python Packages with Make Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/tests/e2e_testing.md Installs the required Python packages for running the end-to-end tests using the make utility. This command typically downloads and installs dependencies listed in a project's configuration file. ```shell #!/bin/bash $ make install ``` -------------------------------- ### Pull Validator Docker Image Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/test-network/README.md Pulls the Docker image for the ibet testnet validator nodes. Replace {version} with the desired version tag. ```bash docker pull ghcr.io/boostryjp/ibet-testnet/validator:{version} ``` -------------------------------- ### Ethereum JSON-RPC API Calls via cURL Source: https://context7.com/boostryjp/ibet-network/llms.txt Examples of interacting with the Ethereum JSON-RPC API using cURL commands. These examples demonstrate how to retrieve the current block number and specific block details by number. This is useful for direct blockchain data access without using a dedicated library. ```bash # Get current block number curl -X POST http://localhost:8545 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1 }' # Get block by number curl -X POST http://localhost:8545 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["0x1", true], "id": 1 }' ``` -------------------------------- ### Initialize Validator Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-network/README.md Initializes a Validator node's data directory. This command should be run only once. It uses a Docker container to perform the initialization, mounting a local directory for the node's data and configuration files. ```bash docker run --rm --name validatorInit -e PRIVATE_CONFIG=ignore -v {mount_directory}:/eth \ ghcr.io/boostryjp/ibet-network/validator:{version} \ geth --datadir /eth init /eth/genesis.json_init ``` -------------------------------- ### Pull General Docker Image Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/test-network/README.md Pulls the Docker image for the ibet testnet general nodes. The same image is used for Bridge nodes. Replace {version} with the desired version tag. ```bash docker pull ghcr.io/boostryjp/ibet-testnet/general:{version} ``` -------------------------------- ### Initialize General/Bridge Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-network/README.md Initializes the data directory for a General or Bridge node. Similar to the Validator initialization, this command is run once and uses Docker to mount local directories for configuration and data. ```bash docker run --rm --name generalInit -e PRIVATE_CONFIG=ignore -v {mount_directory}:/eth \ ghcr.io/boostryjp/ibet-network/general:{version} \ geth --datadir /eth init /eth/genesis.json_init ``` -------------------------------- ### Initialize General/Bridge Node with Docker Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-for-fin-network/README.md Initializes a general or bridge node using Docker. This command, run once, sets up the data directory and initializes the node with a genesis file. It requires the `PRIVATE_CONFIG` environment variable to be set to 'ignore'. ```bash docker run --rm --name generalInit -e PRIVATE_CONFIG=ignore -v {mount_directory}:/eth \ ghcr.io/boostryjp/ibet-fin-network/general:{version} \ geth --datadir /eth init /eth/genesis.json ``` -------------------------------- ### Pull General Node Docker Image Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-for-fin-network/README.md Pulls the Docker image for general nodes. The same image is used for Bridge nodes. Replace `{version}` with the desired version tag. ```bash docker pull ghcr.io/boostryjp/ibet-fin-network/general:{version} ``` -------------------------------- ### Initialize Validator Node with Docker Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-for-fin-network/README.md Initializes a validator node using Docker. This command should be run only once. It sets up the necessary data directory and initializes the node with a genesis file. The `PRIVATE_CONFIG` environment variable is set to 'ignore'. ```bash docker run --rm --name validatorInit -e PRIVATE_CONFIG=ignore -v {mount_directory}:/eth \ ghcr.io/boostryjp/ibet-fin-network/validator:{version} \ geth --datadir /eth init /eth/genesis.json ``` -------------------------------- ### Pull General Node Docker Image Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-network/README.md Pulls the Docker image for the ibet network General nodes. The same image is used for Bridge nodes. Replace {version} with the desired version tag. ```bash docker pull ghcr.io/boostryjp/ibet-network/general:{version} ``` -------------------------------- ### Stop General/Bridge Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-network/README.md Stops a running General or Bridge node Docker container. This command halts the container. ```bash docker stop general ``` -------------------------------- ### Get Contract Bytecode via curl Source: https://context7.com/boostryjp/ibet-network/llms.txt Fetches the bytecode of a smart contract at a given address. This can be used to verify contract deployment or analyze its code. ```shell curl -X POST http://localhost:8545 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_getCode", "params": ["0xContractAddress", "latest"], "id": 1 }' ``` -------------------------------- ### Pull Validator Node Docker Image Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-for-fin-network/README.md Pulls the Docker image for the validator nodes. Replace `{version}` with the desired version tag. This image is essential for running validator nodes. ```bash docker pull ghcr.io/boostryjp/ibet-fin-network/validator:{version} ``` -------------------------------- ### Pull Validator Node Docker Image Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-network/README.md Pulls the Docker image for the ibet network Validator nodes. Replace {version} with the desired version tag. This is a prerequisite for setting up a Validator node. ```bash docker pull ghcr.io/boostryjp/ibet-network/validator:{version} ``` -------------------------------- ### Stop Validator Node Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/ibet-network/README.md Stops a running Validator node Docker container. This is a simple command to halt the container process. ```bash docker stop validator ``` -------------------------------- ### Docker Compose Local Network Setup for ibet-Network Source: https://context7.com/boostryjp/ibet-network/llms.txt This YAML configuration sets up a local ibet-network using Docker Compose. It defines services for validator and general nodes, specifying their images, volumes, environment variables, and network configurations. This allows for easy local development and testing of the blockchain network. ```yaml services: validator-0: hostname: validator-0 image: ghcr.io/boostryjp/ibet-localnet/validator:v2.6.0 volumes: - /home/ubuntu/quorum_data/v0:/eth environment: - PRIVATE_CONFIG=ignore - rpccorsdomain=* - rpcvhosts=* - maxpeers=* - nodekeyhex='2ad84f0c2e0b87137bd91a2aee2b28cc0bc7eba38922d752bb080d5b4fa34506' - identity='validator-0' - testQBFTBlock=4 - berlinBlock=4 - cache=1024 - verbosity=3 - metrics=1 ports: - '30303:30303' - '8545:8545' - '6060:6060' networks: app_net: ipv4_address: 172.16.239.10 restart: always general-0: hostname: general-0 image: ghcr.io/boostryjp/ibet-localnet/general:v2.6.0 volumes: - /home/ubuntu/quorum_data/g0:/eth environment: - PRIVATE_CONFIG=ignore - rpccorsdomain=* - rpcvhosts=* - identity='general-0' - verbosity=3 ports: - '30307:30303' - '8549:8545' networks: app_net: ipv4_address: 172.16.239.14 restart: always networks: app_net: driver: bridge ipam: driver: default config: - subnet: 172.16.239.0/24 ``` -------------------------------- ### Get Sync Status via curl Source: https://context7.com/boostryjp/ibet-network/llms.txt Checks the synchronization status of the Ethereum node. This API call returns information about whether the node is syncing and its current progress. ```shell curl -X POST http://localhost:8545 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_syncing", "params": [], "id": 1 }' ``` -------------------------------- ### Get Transaction Receipt via curl Source: https://context7.com/boostryjp/ibet-network/llms.txt Retrieves the receipt of a specific transaction using its hash. This is useful for checking transaction status, gas used, and emitted events. ```shell curl -X POST http://localhost:8545 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_getTransactionReceipt", "params": ["0xTransactionHash"], "id": 1 }' ``` -------------------------------- ### Get Transaction Pool (Geth) via curl Source: https://context7.com/boostryjp/ibet-network/llms.txt Retrieves information about the transaction pool of a Geth node. This API is specific to Geth and provides insights into pending transactions. ```shell curl -X POST http://localhost:8545 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "txpool_inspect", "params": [], "id": 1 }' ``` -------------------------------- ### Python Smart Contract Deployment with Web3.py for ibet-Network Source: https://context7.com/boostryjp/ibet-network/llms.txt This Python script demonstrates how to deploy a smart contract to the ibet network using the Web3.py library. It includes connecting to the network, loading account credentials, compiling and deploying a contract with constructor arguments, and handling transaction signing and receipt validation. It requires the 'web3' and 'eth-keyfile' libraries. ```python from web3 import Web3 from web3.middleware import ExtraDataToPOAMiddleware from eth_keyfile import decode_keyfile_json import json # Initialize Web3 connection web3 = Web3(Web3.HTTPProvider("http://localhost:8545")) web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0) # Load test account keystore_json = json.load(open("tests/data/test_user.json", "r")) private_key = decode_keyfile_json( raw_keyfile_json=keystore_json, password="password".encode("utf-8") ) address = f'0x{keystore_json["address"]}' # Load compiled contract contract_json = json.load(open("tests/contracts/E2ETest.json", "r")) contract = web3.eth.contract( abi=contract_json["abi"], bytecode=contract_json["bytecode"] ) # Deploy contract with constructor arguments constructor_args = [ True, # bool "0x0123456789abcDEF0123456789abCDef01234567", # address "test text", # string 1, # uint256 2, # int256 b"0123456789abcdefghijklmnopqrstuv" # bytes32 ] tx = contract.constructor(*constructor_args).build_transaction({ "chainId": 2017, "from": address, "gas": 6000000, "gasPrice": 0, "nonce": web3.eth.get_transaction_count(address) }) # Sign and send transaction signed_tx = web3.eth.account.sign_transaction( transaction_dict=tx, private_key=private_key ) tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction.to_0x_hex()) txn_receipt = web3.eth.wait_for_transaction_receipt( transaction_hash=tx_hash, timeout=10 ) if txn_receipt["status"] == 1: contract_address = txn_receipt["contractAddress"] print(f"Contract deployed at: {contract_address}") else: raise Exception("Deployment failed") ``` -------------------------------- ### Build and Send Smart Contract Transaction with Web3.py Source: https://context7.com/boostryjp/ibet-network/llms.txt This snippet demonstrates how to prepare arguments for a smart contract function, build a transaction using `build_transaction`, sign it with a private key, and send it to the network. It also includes verification of transaction success and reading updated contract state. ```python function_args = [ False, # bool "0x0123456789ABCDeF0123456789aBcdEF01234568", # address "test text2", # string 4, # uint256 8, # int256 b"456789abcdefghijklmnopqrstuvwxyz", # bytes32 0 # error flag (0=success, 1=assert, 2=require, 3=revert) ] tx = contract.functions.setItem2(*function_args).build_transaction( transaction={ "chainId": 2017, "from": address, "gas": 6000000, "gasPrice": 0, "nonce": web3.eth.get_transaction_count(address) } ) # Send transaction signed_tx = web3.eth.account.sign_transaction( transaction_dict=tx, private_key=private_key ) tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction.to_0x_hex()) txn_receipt = web3.eth.wait_for_transaction_receipt( transaction_hash=tx_hash, timeout=10 ) # Verify transaction success assert txn_receipt["status"] == 1, "Transaction failed" # Read updated state assert contract.functions.item2_bool().call() is False assert contract.functions.item2_uint().call() == 4 assert contract.functions.getItemsValueSame().call() == 5 # sum of item1_uint + item2_uint ``` -------------------------------- ### Comprehensive End-to-End Testing with Python Source: https://context7.com/boostryjp/ibet-network/llms.txt A Python test suite using pytest and web3.py for comprehensive end-to-end testing of smart contracts. It covers deployment, state management, event handling, and error scenarios. ```python import pytest from web3 import Web3 from web3.middleware import ExtraDataToPOAMiddleware from web3.exceptions import ContractLogicError, Web3RPCError ``` -------------------------------- ### Python: Contract Deployment and Verification Test Source: https://context7.com/boostryjp/ibet-network/llms.txt Tests the deployment of a smart contract with various constructor argument types (boolean, address, string, uint, int, bytes) and verifies that the contract's getter functions return the correct values. It utilizes Web3.py for contract interaction. ```python import pytest from web3 import Web3 from web3.exceptions import Web3RPCError # Assuming ContractUtils, ExtraDataToPOAMiddleware, TestAccount are defined elsewhere WEB3_HTTP_PROVIDER = "http://localhost:8545" CHAIN_ID = 2017 TX_GAS_LIMIT = 6000000 web3 = Web3(Web3.HTTPProvider(WEB3_HTTP_PROVIDER)) web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0) class TestE2E: def test_deploy_and_verify(self): """Test contract deployment with constructor parameters""" args = [ True, "0x0123456789abcDEF0123456789abCDef01234567", "test text", 1, 2, b"0123456789abcdefghijklmnopqrstuv" ] contract_address, _, _ = ContractUtils.deploy_contract(args) contract = ContractUtils.get_contract(contract_address) assert contract.functions.item1_bool().call() is True assert contract.functions.item1_address().call() == \ "0x0123456789abcDEF0123456789abCDef01234567" assert contract.functions.item1_string().call() == "test text" assert contract.functions.item1_uint().call() == 1 assert contract.functions.item1_int().call() == 2 assert contract.functions.item1_bytes().call() == \ b"0123456789abcdefghijklmnopqrstuv" ``` -------------------------------- ### Python: Pytest Execution Command Source: https://context7.com/boostryjp/ibet-network/llms.txt Shows the command to execute the Python test suite using pytest. This command runs all tests in the specified file with verbose output. ```shell # Run tests pytest.main(["-v", "e2e_test.py"]) ``` -------------------------------- ### Python Smart Contract State Modification with Web3.py for ibet-Network Source: https://context7.com/boostryjp/ibet-network/llms.txt This Python snippet illustrates how to interact with a deployed smart contract on the ibet network to modify its state. It involves connecting to the network, obtaining a contract instance using its address and ABI, and preparing for function calls. This code requires the 'web3' library. ```python from web3 import Web3 from eth_utils import to_checksum_address # Get contract instance web3 = Web3(Web3.HTTPProvider("http://localhost:8545")) contract = web3.eth.contract( address=to_checksum_address("0xYourContractAddress"), abi=contract_json["abi"] ) ``` -------------------------------- ### Compile Solidity Contract with Python Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/tests/e2e_testing.md Compiles the 'E2ETest.sol' smart contract using a Python script. This process generates the contract's ABI and bytecode, typically saved as a JSON file, which is necessary for deployment. ```shell #!/bin/bash $ poetry run python compile.py ``` -------------------------------- ### Call Contract View Function via curl Source: https://context7.com/boostryjp/ibet-network/llms.txt Demonstrates how to call a view function on a smart contract using curl. It sends a POST request to the local RPC endpoint with the necessary parameters for eth_call. ```shell curl -X POST http://localhost:8545 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_call", "params": [{ "to": "0xContractAddress", "data": "0xFunctionSignatureHash" }, "latest"], "id": 1 }' ``` -------------------------------- ### Python: Test Event Retrieval Source: https://context7.com/boostryjp/ibet-network/llms.txt Demonstrates how to retrieve and assert emitted events from a smart contract. It triggers an event by modifying state and then uses `get_logs` to fetch events within a specific block range, verifying event arguments. ```python def test_event_retrieval(self, contract): """Test event emission and filtering""" block_from = web3.eth.block_number args = [False, "0x0123456789ABCDeF0123456789aBcdEF01234568", "test text2", 4, 8, b"456789abcdefghijklmnopqrstuvwxyz"] tx = contract.functions.setItem2(*args, 0).build_transaction({ "chainId": CHAIN_ID, "from": TestAccount.address, "gas": TX_GAS_LIMIT, "gasPrice": 0 }) ContractUtils.send_transaction(tx, TestAccount.private_key) block_to = web3.eth.block_number events = contract.events.SetItem.get_logs( from_block=block_from, to_block=block_to ) assert len(events) == 1 assert events[0]["args"]["item_uint"] == 4 assert events[0]["args"]["item_string"] == "test text2" ``` -------------------------------- ### Deploy Contract and Export Address with Python Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/tests/e2e_testing.md Deploys the compiled smart contract and exports its address to an environment variable. This step is crucial for subsequent test runs that need to interact with the deployed contract. ```shell #!/bin/bash $ poetry run python deploy.py DEPLOYED_CONTRACT_ADDRESS=0x79448CB02a0F8cff71005963075187aAD9a050f3 $ export DEPLOYED_CONTRACT_ADDRESS=0x79448CB02a0F8cff71005963075187aAD9a050f3 ``` -------------------------------- ### Python Script for Monitoring Ethereum Block Synchronization Source: https://context7.com/boostryjp/ibet-network/llms.txt A Python script utilizing the `web3.py` library to monitor Ethereum node block synchronization. It checks for incremental block numbers at a defined interval and logs warnings or errors if synchronization issues are detected. Dependencies include `web3` and `requests`. ```python import logging import time from web3 import Web3 from requests.exceptions import ConnectionError # Configuration BLOCK_SYNC_MONITORING_INTERVAL = 30 # seconds MINIMUM_INCREMENTAL_NUMBER = 1 # Initialize connection web3 = Web3(Web3.HTTPProvider("http://localhost:8545")) def monitor_block_sync(start_block_number): """Monitor block synchronization :param start_block_number: Monitoring start block number :return: Next monitoring start block number """ try: latest_block_number = web3.eth.block_number if latest_block_number - start_block_number > MINIMUM_INCREMENTAL_NUMBER: logging.info( f"Blocks successfully synchronized: " f"start={start_block_number}, latest={latest_block_number}" ) return latest_block_number else: logging.error( f"FATAL: Block number has not increased: " f"start={start_block_number}, latest={latest_block_number}" ) return start_block_number except ConnectionError: logging.warning("Unable to connect to node") return start_block_number except Exception as err: logging.exception("Exception during block sync monitoring", err) return start_block_number # Main monitoring loop if __name__ == "__main__": block_number = 0 while True: start_time = time.time() block_number = monitor_block_sync(start_block_number=block_number) elapsed_time = time.time() - start_time time.sleep(max(BLOCK_SYNC_MONITORING_INTERVAL - elapsed_time, 0)) ``` -------------------------------- ### Retrieve and Filter Smart Contract Events with Web3.py Source: https://context7.com/boostryjp/ibet-network/llms.txt This snippet shows how to capture block numbers before and after a transaction, then use `get_logs` to retrieve emitted events within that range. It processes the event data, printing details from the 'SetItem' event. ```python from web3 import Web3 web3 = Web3(Web3.HTTPProvider("http://localhost:8545")) contract = web3.eth.contract( address=to_checksum_address(contract_address), abi=contract_json["abi"] ) # Capture starting block block_from = web3.eth.block_number # Execute transaction that emits events tx = contract.functions.setItem2( False, "0x0123456789ABCDeF0123456789aBcdEF01234568", "test text2", 4, 8, b"456789abcdefghijklmnopqrstuvwxyz", 0 ).build_transaction({ "chainId": 2017, "from": address, "gas": 6000000, "gasPrice": 0, "nonce": web3.eth.get_transaction_count(address) }) signed_tx = web3.eth.account.sign_transaction(tx, private_key) tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction.to_0x_hex()) web3.eth.wait_for_transaction_receipt(tx_hash, timeout=10) # Retrieve events block_to = web3.eth.block_number events = contract.events.SetItem.get_logs( from_block=block_from, to_block=block_to ) # Process event data for event in events: args = event["args"] print(f"Event data: bool={args['item_bool']}, " f"address={args['item_address']}, " f"string={args['item_string']}, " f"uint={args['item_uint']}, " f"int={args['item_int']}, " f"bytes={args['item_bytes']}") ``` -------------------------------- ### Send Raw Transaction via curl Source: https://context7.com/boostryjp/ibet-network/llms.txt Submits a pre-signed raw transaction to the network. This method is used when you have already signed a transaction locally and want to broadcast it. ```shell curl -X POST http://localhost:8545 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_sendRawTransaction", "params": ["0xSignedTransactionData"], "id": 1 }' ``` -------------------------------- ### E2ETest Solidity Smart Contract for Blockchain Testing Source: https://context7.com/boostryjp/ibet-network/llms.txt A Solidity smart contract designed for end-to-end blockchain testing. It supports various data types and includes error handling mechanisms like assert, require, and revert. This contract is useful for simulating different testing scenarios on the blockchain. ```solidity // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; contract E2ETest { // State variables for different data types bool public item1_bool; address public item1_address; string public item1_string; uint256 public item1_uint; int256 public item1_int; bytes32 public item1_bytes; bool public item2_bool; address public item2_address; string public item2_string; uint256 public item2_uint; int256 public item2_int; bytes32 public item2_bytes; uint256 public optional_item; event SetItem( bool item_bool, address item_address, string item_string, uint256 item_uint, int256 item_int, bytes32 item_bytes ); constructor( bool _item1_bool, address _item1_address, string memory _item1_string, uint256 _item1_uint, int256 _item1_int, bytes32 _item1_bytes ) { item1_bool = _item1_bool; item1_address = _item1_address; item1_string = _item1_string; item1_uint = _item1_uint; item1_int = _item1_int; item1_bytes = _item1_bytes; } function setItem2( bool _item2_bool, address _item2_address, string memory _item2_string, uint256 _item2_uint, int256 _item2_int, bytes32 _item2_bytes, uint8 err_flg // 0=success, 1=assert, 2=require, 3=revert ) public { if (err_flg == 1) { assert(false); } else if (err_flg == 2) { require(false, "not-required"); } else if (err_flg == 3) { revert("reverted"); } item2_bool = _item2_bool; item2_address = _item2_address; item2_string = _item2_string; item2_uint = _item2_uint; item2_int = _item2_int; item2_bytes = _item2_bytes; emit SetItem( item2_bool, item2_address, item2_string, item2_uint, item2_int, item2_bytes ); } function getItemsValueSame() public view returns (uint256) { return item1_uint + item2_uint; } function setOptionalItem(uint256 _optional_item) public { optional_item = _optional_item; } } ``` -------------------------------- ### Python: Test Contract State Modification Source: https://context7.com/boostryjp/ibet-network/llms.txt Tests the ability to modify the state of a deployed smart contract using its setter functions. It builds, signs, and sends a transaction to update contract state and then verifies the changes using getter functions. Requires a pre-deployed contract instance. ```python def test_state_modification(self, contract): """Test setter and getter functions""" args = [False, "0x0123456789ABCDeF0123456789aBcdEF01234568", "test text2", 4, 8, b"456789abcdefghijklmnopqrstuvwxyz"] tx = contract.functions.setItem2(*args, 0).build_transaction( transaction={ "chainId": CHAIN_ID, "from": TestAccount.address, "gas": TX_GAS_LIMIT, "gasPrice": 0 } ) ContractUtils.send_transaction(tx, TestAccount.private_key) assert contract.functions.item2_bool().call() is False assert contract.functions.item2_uint().call() == 4 assert contract.functions.getItemsValueSame().call() == 5 ``` -------------------------------- ### Python: Test Transaction Revert Handling Source: https://context7.com/boostryjp/ibet-network/llms.txt Tests the handling of transactions that are expected to revert. It sends a transaction designed to fail (e.g., by triggering a revert condition in the contract) and asserts that the transaction receipt status indicates failure. ```python def test_revert_handling(self, contract): """Test error handling with revert flag""" err_flg = 3 # Trigger revert args = [False, "0x0123456789ABCDeF0123456789aBcdEF01234568", "test text2", 4, 8, b"456789abcdefghijklmnopqrstuvwxyz"] tx = contract.functions.setItem2(*args, err_flg).build_transaction({ "chainId": CHAIN_ID, "from": TestAccount.address, "gas": TX_GAS_LIMIT, "gasPrice": 0, "nonce": web3.eth.get_transaction_count(TestAccount.address) }) signed_tx = web3.eth.account.sign_transaction( tx, TestAccount.private_key ) tx_hash = web3.eth.send_raw_transaction( signed_tx.raw_transaction.to_0x_hex() ) txn_receipt = web3.eth.wait_for_transaction_receipt(tx_hash, timeout=10) assert txn_receipt["status"] == 0 # Transaction failed as expected ``` -------------------------------- ### Run End-to-End Tests with Pytest Source: https://github.com/boostryjp/ibet-network/blob/dev-2.6/tests/e2e_testing.md Executes the end-to-end non-degrade tests using the pytest framework. The '-vv' flag increases verbosity, providing more detailed output during test execution. ```shell #!/bin/bash $ poetry run pytest . -vv ``` -------------------------------- ### Python: Test Nonce Too Low Error Source: https://context7.com/boostryjp/ibet-network/llms.txt Tests the scenario where a transaction with a nonce that has already been used is submitted. It sends a transaction successfully once, then attempts to send the same transaction again and asserts that a `Web3RPCError` with a 'nonce too low' message is raised. ```python def test_nonce_too_low(self, contract): """Test duplicate transaction detection""" args = [False, "0x0123456789ABCDeF0123456789aBcdEF01234568", "test text2", 4, 8, b"456789abcdefghijklmnopqrstuvwxyz"] tx = contract.functions.setItem2(*args, 0).build_transaction({ "chainId": CHAIN_ID, "from": TestAccount.address, "gas": TX_GAS_LIMIT, "gasPrice": 0, "nonce": web3.eth.get_transaction_count(TestAccount.address) }) signed_tx = web3.eth.account.sign_transaction( tx, TestAccount.private_key ) # First send succeeds tx_hash = web3.eth.send_raw_transaction( signed_tx.raw_transaction.to_0x_hex() ) web3.eth.wait_for_transaction_receipt(tx_hash, timeout=10) # Second send with same nonce fails with pytest.raises(Web3RPCError, match="{'code': -32000, 'message': 'nonce too low'}"): web3.eth.send_raw_transaction( signed_tx.raw_transaction.to_0x_hex() ) ```