Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Empty file added scripts/__init__.py
Empty file.
10 changes: 0 additions & 10 deletions scripts/stack_benchmark/contract_data/test_stack.sol

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions scripts/stack_benchmark/package_manifests/1.0.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"contract_types":{"TestStack":{"abi":[{"constant":false,"inputs":[],"name":"doLotsOfPops","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}],"deployment_bytecode":{"bytecode":"0x608060405234801561001057600080fd5b5060ae8061001f6000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063a2b86eb6146044575b600080fd5b348015604f57600080fd5b5060566058565b005b60008060009150600090505b6064811015607e5760648201915080806001019150506064565b50505600a165627a7a72305820626a984b4497a9ed7d01394d7255151bcd19ca0669c8711d8818b96293f75ca90029"},"runtime_bytecode":{"bytecode":"0x608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063a2b86eb6146044575b600080fd5b348015604f57600080fd5b5060566058565b005b60008060009150600090505b6064811015607e5760648201915080806001019150506064565b50505600a165627a7a72305820626a984b4497a9ed7d01394d7255151bcd19ca0669c8711d8818b96293f75ca90029"}}},"manifest_version":"2","meta":{"authors":["bhargavasomu"],"description":"TestStack.sol for py-evm testing.","keywords":["py-evm"],"license":"MIT"},"package_name":"test-stack","sources":{"./TestStack.sol":"pragma solidity >=0.4.23;\n\ncontract TestStack {\n\tfunction doLotsOfPops() public{\n\t\tuint v = 0;\n\t\tfor (uint i=0; i<100; i++) {\n\t\t\tv += 100;\n\t\t}\n\t}\n}"},"version":"1.0.0"}
43 changes: 20 additions & 23 deletions scripts/stack_benchmark/run.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env python

import pathlib
import json
from pathlib import Path

from eth_utils import (
encode_hex,
decode_hex,
to_canonical_address,
)

from web3 import (
Web3
)
from ethpm import Package
from web3 import Web3

from eth.constants import (
CREATE_CONTRACT_ADDRESS
Expand All @@ -20,39 +20,34 @@
FUNDED_ADDRESS_PRIVATE_KEY,
get_all_chains,
)
from scripts.benchmark._utils.compile import (
get_compiled_contract
)
from scripts.benchmark._utils.tx import (
new_transaction,
)

CONTRACT_FILE = 'scripts/stack_benchmark/contract_data/test_stack.sol'

MANIFEST_PATH = Path(__file__).parent / 'package_manifests' / '1.0.0.json'
TEST_STACK_MANIFEST = json.loads(MANIFEST_PATH.read_text())
CONTRACT_NAME = 'TestStack'
W3_TX_DEFAULTS = {'gas': 0, 'gasPrice': 0}
FIRST_TX_GAS_LIMIT = 367724
SECOND_TX_GAS_LIMIT = 62050


def execute_TestStack_contract():
contract_interface = get_compiled_contract(
pathlib.Path(CONTRACT_FILE),
CONTRACT_NAME
)
w3 = Web3()

# Create a Package for the TestStack manifest
test_stack_pkg = Package(TEST_STACK_MANIFEST, w3)

# Get the chains
chains = tuple(get_all_chains())
chain = chains[0]

# Instantiate the contract
test_stack_contract = w3.eth.contract(
abi=contract_interface['abi'],
bytecode=contract_interface['bin']
)
# Grab the contract factory to easily deploy new TestStack instances
test_stack_contract_factory = test_stack_pkg.get_contract_factory("TestStack")

# Build transaction to deploy the contract
w3_tx1 = test_stack_contract.constructor().buildTransaction(W3_TX_DEFAULTS)
w3_tx1 = test_stack_contract_factory.constructor().buildTransaction(W3_TX_DEFAULTS)

tx = new_transaction(
vm=chain.get_vm(),
Expand All @@ -69,10 +64,12 @@ def execute_TestStack_contract():
assert computation.is_success

# Interact with the deployed contract by calling the totalSupply() API ?????
test_stack_contract = w3.eth.contract(
address=Web3.toChecksumAddress(encode_hex(deployed_contract_address)),
abi=contract_interface['abi'],
)

# Grab the contract instance for the newly deployed TestStack
test_stack_contract = test_stack_pkg.get_contract_instance(
"TestStack",
to_canonical_address(deployed_contract_address)
)

# Execute the computation
w3_tx2 = test_stack_contract.functions.doLotsOfPops().buildTransaction(W3_TX_DEFAULTS)
Expand Down