diff --git a/scripts/__init__.py b/scripts/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/scripts/stack_benchmark/contract_data/test_stack.sol b/scripts/stack_benchmark/contract_data/test_stack.sol deleted file mode 100644 index 918758b4ba..0000000000 --- a/scripts/stack_benchmark/contract_data/test_stack.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma solidity >=0.4.23; - -contract TestStack { - function doLotsOfPops() public{ - uint v = 0; - for (uint i=0; i<100; i++) { - v += 100; - } - } -} diff --git a/scripts/stack_benchmark/contract_data/test_stack.sol-compiled/combined.json b/scripts/stack_benchmark/contract_data/test_stack.sol-compiled/combined.json deleted file mode 100644 index 4ff0528306..0000000000 --- a/scripts/stack_benchmark/contract_data/test_stack.sol-compiled/combined.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "contracts" : - { - "scripts/stack_benchmark/contract_data/test_stack.sol:TestStack" : - { - "abi" : "[{\"constant\":false,\"inputs\":[],\"name\":\"doLotsOfPops\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", - "bin" : "608060405234801561001057600080fd5b5060a78061001f6000396000f3fe6080604052348015600f57600080fd5b50600436106045576000357c010000000000000000000000000000000000000000000000000000000090048063a2b86eb614604a575b600080fd5b60506052565b005b600080905060008090505b60648110156077576064820191508080600101915050605d565b505056fea165627a7a7230582095c50d5af0ee6c9d807acda8903e20ebad2919c44f22bc7508d97b7f35b62d660029" - } - }, - "version" : "0.5.2+commit.1df8f40c.Linux.g++" -} \ No newline at end of file diff --git a/scripts/stack_benchmark/package_manifests/1.0.0.json b/scripts/stack_benchmark/package_manifests/1.0.0.json new file mode 100644 index 0000000000..c3c3bbcd92 --- /dev/null +++ b/scripts/stack_benchmark/package_manifests/1.0.0.json @@ -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"} \ No newline at end of file diff --git a/scripts/stack_benchmark/run.py b/scripts/stack_benchmark/run.py index bbcf3634c0..01b13d1484 100755 --- a/scripts/stack_benchmark/run.py +++ b/scripts/stack_benchmark/run.py @@ -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 @@ -20,14 +20,13 @@ 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 @@ -35,24 +34,20 @@ 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(), @@ -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)