-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
000333a
commit 139f45b
Showing
9 changed files
with
245 additions
and
60 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pragma solidity >=0.4.23; | ||
|
||
contract TestStack { | ||
function doLotsOfPops() public{ | ||
uint v = 0; | ||
for (uint i=0; i<100; i++) { | ||
v += 100; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
scripts/stack_benchmark/contract_data/test_stack.sol-compiled/combined.json
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,11 @@ | ||
{ | ||
"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++" | ||
} |
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,100 @@ | ||
#!/usr/bin/env python | ||
|
||
import pathlib | ||
|
||
from eth_utils import ( | ||
encode_hex, | ||
decode_hex, | ||
) | ||
|
||
from web3 import ( | ||
Web3 | ||
) | ||
|
||
from eth.constants import ( | ||
CREATE_CONTRACT_ADDRESS | ||
) | ||
|
||
from scripts.benchmark._utils.chain_plumbing import ( | ||
FUNDED_ADDRESS, | ||
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' | ||
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() | ||
|
||
# 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'] | ||
) | ||
|
||
# Build transaction to deploy the contract | ||
w3_tx1 = test_stack_contract.constructor().buildTransaction(W3_TX_DEFAULTS) | ||
|
||
tx = new_transaction( | ||
vm=chain.get_vm(), | ||
private_key=FUNDED_ADDRESS_PRIVATE_KEY, | ||
from_=FUNDED_ADDRESS, | ||
to=CREATE_CONTRACT_ADDRESS, | ||
amount=0, | ||
gas=FIRST_TX_GAS_LIMIT, | ||
data=decode_hex(w3_tx1['data']), | ||
) | ||
|
||
block, receipt, computation = chain.apply_transaction(tx) | ||
deployed_contract_address = computation.msg.storage_address | ||
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'], | ||
) | ||
|
||
# Execute the computation | ||
w3_tx2 = test_stack_contract.functions.doLotsOfPops().buildTransaction(W3_TX_DEFAULTS) | ||
|
||
tx = new_transaction( | ||
vm=chain.get_vm(), | ||
private_key=FUNDED_ADDRESS_PRIVATE_KEY, | ||
from_=FUNDED_ADDRESS, | ||
to=deployed_contract_address, | ||
amount=0, | ||
gas=SECOND_TX_GAS_LIMIT, | ||
data=decode_hex(w3_tx2['data']), | ||
) | ||
|
||
block, receipt, computation = chain.apply_transaction(tx) | ||
# print(computation._memory._bytes) | ||
print(computation._stack.values) | ||
|
||
|
||
def main(): | ||
execute_TestStack_contract() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.