diff --git a/README.md b/README.md index 5bec12cc2..33e2dcb58 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,14 @@ the future. * Update contract addresses * Documentation * New version created + + +current stuff. +.............. +test_get_called_at_block.py +test_get_contract_address.py +test_get_gas_price.py +test_get_gas_used.py +test_get_scheduled_by.py +test_get_target_block.py + diff --git a/contracts/Alarm.sol b/contracts/Alarm.sol index d4f4c4694..34c852ec7 100644 --- a/contracts/Alarm.sol +++ b/contracts/Alarm.sol @@ -670,7 +670,7 @@ contract Alarm { // This number represents the constant gas cost of the addition // operations that occur in `doCall` that cannot be tracked with // msg.gas. - uint constant EXTRA_CALL_GAS = 151751; + uint constant EXTRA_CALL_GAS = 151729; // This number represents the overall overhead involved in executing a // scheduled call. uint constant CALL_OVERHEAD = 145601; diff --git a/contracts/Testers.sol b/contracts/Testers.sol index 3f305d482..9a640e16f 100644 --- a/contracts/Testers.sol +++ b/contracts/Testers.sol @@ -62,7 +62,6 @@ contract TestDataRegistry { contract NoArgs { bool public value; - bytes32 public dataHash; function doIt() public { value = true; @@ -73,11 +72,10 @@ contract NoArgs { } function scheduleIt(address to) public { - dataHash = sha3(); to.call(bytes4(sha3("registerData()"))); AlarmTestAPI alarm = AlarmTestAPI(to); - alarm.scheduleCall(address(this), bytes4(sha3("doIt()")), dataHash, block.number + 40, 255, 0); + alarm.scheduleCall(address(this), bytes4(sha3("doIt()")), sha3(), block.number + 40, 255, 0); } } @@ -253,7 +251,10 @@ contract SpecifyBlock { contract AuthorizesOthers { + address public calledBy; + function doIt() public { + calledBy = msg.sender; } function authorize(address to) public { @@ -263,13 +264,6 @@ contract AuthorizesOthers { function unauthorize(address to) public { to.call(bytes4(sha3("removeAuthorization(address)")), msg.sender); } - - function scheduleIt(address to, uint blockNumber) public { - to.call(bytes4(sha3("registerData()")), block.timestamp); - - AlarmTestAPI alarm = AlarmTestAPI(to); - alarm.scheduleCall(address(this), bytes4(sha3("doIt()")), sha3(), block.number + 40, 255, 0); - } } diff --git a/tests/get-call-information/test_get_called_at_block.py b/tests/get-call-information/test_get_called_at_block.py index 4cd3fc726..1ef5ef5a3 100644 --- a/tests/get-call-information/test_get_called_at_block.py +++ b/tests/get-call-information/test_get_called_at_block.py @@ -1,3 +1,4 @@ +from populus.contracts import get_max_gas from populus.utils import wait_for_transaction, wait_for_block @@ -12,8 +13,11 @@ def test_getting_called_at_block(geth_node, rpc_client, deployed_contracts): alarm = deployed_contracts.Alarm client_contract = deployed_contracts.NoArgs + deposit_amount = get_max_gas(rpc_client) * rpc_client.get_gas_price() * 20 + alarm.deposit.sendTransaction(client_contract._meta.address, value=deposit_amount) + txn_hash = client_contract.scheduleIt.sendTransaction(alarm._meta.address) - wait_for_transaction(client_contract._meta.rpc_client, txn_hash) + wait_for_transaction(rpc_client, txn_hash) assert client_contract.value.call() is False @@ -24,9 +28,9 @@ def test_getting_called_at_block(geth_node, rpc_client, deployed_contracts): wait_for_block(rpc_client, alarm.getCallTargetBlock.call(callKey), 120) call_txn_hash = alarm.doCall.sendTransaction(callKey) - wait_for_transaction(alarm._meta.rpc_client, call_txn_hash) + wait_for_transaction(rpc_client, call_txn_hash) - call_txn = alarm._meta.rpc_client.get_transaction_by_hash(call_txn_hash) + call_txn = rpc_client.get_transaction_by_hash(call_txn_hash) assert client_contract.value.call() is True assert alarm.getCallCalledAtBlock.call(callKey) == int(call_txn['blockNumber'], 16) diff --git a/tests/get-call-information/test_get_gas_used.py b/tests/get-call-information/test_get_gas_used.py index e5255c0a6..2b4192c01 100644 --- a/tests/get-call-information/test_get_gas_used.py +++ b/tests/get-call-information/test_get_gas_used.py @@ -1,5 +1,5 @@ from populus.contracts import get_max_gas -from populus.utils import wait_for_transaction +from populus.utils import wait_for_transaction, wait_for_block deploy_max_wait = 15 deploy_max_first_block_wait = 180 @@ -25,6 +25,7 @@ def test_getting_gas_used(geth_node, rpc_client, deployed_contracts): assert alarm.getCallGasUsed.call(callKey) == 0 + wait_for_block(rpc_client, alarm.getCallTargetBlock.call(callKey), 120) call_txn_hash = alarm.doCall.sendTransaction(callKey) call_txn_receipt = wait_for_transaction(alarm._meta.rpc_client, call_txn_hash) diff --git a/tests/get-call-information/test_get_scheduled_by.py b/tests/get-call-information/test_get_scheduled_by.py index e0ebff528..e1a6d8953 100644 --- a/tests/get-call-information/test_get_scheduled_by.py +++ b/tests/get-call-information/test_get_scheduled_by.py @@ -1,3 +1,4 @@ +from populus.contracts import get_max_gas from populus.utils import wait_for_transaction @@ -8,20 +9,15 @@ geth_max_wait = 45 -from ethereum import utils as ethereum_utils - - -def test_get_scheduled_by(geth_node, geth_coinbase, deployed_contracts): +def test_get_scheduled_by(geth_node, geth_coinbase, rpc_client, deployed_contracts): alarm = deployed_contracts.Alarm + client_contract = deployed_contracts.NoArgs + + deposit_amount = get_max_gas(rpc_client) * rpc_client.get_gas_price() * 20 + alarm.deposit.sendTransaction(client_contract._meta.address, value=deposit_amount) - txn_hash = alarm.scheduleCall.sendTransaction( - geth_coinbase, - 'arst', - ethereum_utils.decode_hex('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'), - 1000, - value=12345, - ) - wait_for_transaction(alarm._meta.rpc_client, txn_hash) + txn_hash = client_contract.scheduleIt.sendTransaction(alarm._meta.address) + wait_for_transaction(rpc_client, txn_hash) call_key = alarm.getLastCallKey.call() assert call_key diff --git a/tests/get-call-information/test_get_target_block.py b/tests/get-call-information/test_get_target_block.py index 1b9a8c63a..4697a48ef 100644 --- a/tests/get-call-information/test_get_target_block.py +++ b/tests/get-call-information/test_get_target_block.py @@ -1,4 +1,3 @@ -from populus.contracts import get_max_gas from populus.utils import wait_for_transaction @@ -13,9 +12,6 @@ def test_getting_target_block(geth_node, rpc_client, deployed_contracts): alarm = deployed_contracts.Alarm client_contract = deployed_contracts.NoArgs - deposit_amount = get_max_gas(rpc_client) * rpc_client.get_gas_price() * 20 - alarm.deposit.sendTransaction(client_contract._meta.address, value=deposit_amount) - txn_hash = client_contract.scheduleIt.sendTransaction(alarm._meta.address) wait_for_transaction(client_contract._meta.rpc_client, txn_hash) txn = client_contract._meta.rpc_client.get_transaction_by_hash(txn_hash) @@ -25,4 +21,4 @@ def test_getting_target_block(geth_node, rpc_client, deployed_contracts): callKey = alarm.getLastCallKey.call() assert callKey is not None - assert alarm.getCallTargetBlock.call(callKey) == created_at_block + 100 + assert alarm.getCallTargetBlock.call(callKey) == created_at_block + 40 diff --git a/tests/scheduling-authorization/test_adding_and_removing_authorization.py b/tests/scheduling-authorization/test_adding_and_removing_authorization.py index 93f81e048..2a49b480d 100644 --- a/tests/scheduling-authorization/test_adding_and_removing_authorization.py +++ b/tests/scheduling-authorization/test_adding_and_removing_authorization.py @@ -12,14 +12,12 @@ def test_authorizing_other_address(geth_node, geth_coinbase, rpc_client, deploye alarm = deployed_contracts.Alarm client_contract = deployed_contracts.AuthorizesOthers - auth_key = alarm.getAuthorizationKey.call(geth_coinbase, client_contract._meta.address) - - assert alarm.accountAuthorizations.call(auth_key) is False + assert alarm.checkAuthorization.call(geth_coinbase, client_contract._meta.address) is False wait_for_transaction(rpc_client, client_contract.authorize.sendTransaction(alarm._meta.address)) - assert alarm.accountAuthorizations.call(auth_key) is True + assert alarm.checkAuthorization.call(geth_coinbase, client_contract._meta.address) is True wait_for_transaction(rpc_client, client_contract.unauthorize.sendTransaction(alarm._meta.address)) - assert alarm.accountAuthorizations.call(auth_key) is False + assert alarm.checkAuthorization.call(geth_coinbase, client_contract._meta.address) is False diff --git a/tests/scheduling-authorization/test_authorization_for_scheduling.py b/tests/scheduling-authorization/test_authorization_for_scheduling.py index 3ff915558..672d17038 100644 --- a/tests/scheduling-authorization/test_authorization_for_scheduling.py +++ b/tests/scheduling-authorization/test_authorization_for_scheduling.py @@ -1,6 +1,7 @@ from ethereum import utils -from populus.utils import wait_for_transaction +from populus.contracts import get_max_gas +from populus.utils import wait_for_transaction, wait_for_block deploy_max_wait = 15 @@ -14,41 +15,54 @@ def test_authorizing_other_address(geth_node, geth_coinbase, rpc_client, deploye alarm = deployed_contracts.Alarm client_contract = deployed_contracts.AuthorizesOthers - auth_key = alarm.getAuthorizationKey.call(geth_coinbase, client_contract._meta.address) + authed_addr = alarm.authorizedAddress.call() + unauthed_addr = alarm.unauthorizedAddress.call() - assert alarm.accountAuthorizations.call(auth_key) is False - assert alarm.getLastCallKey.call() is None + deposit_amount = get_max_gas(rpc_client) * rpc_client.get_gas_price() * 20 + alarm.deposit.sendTransaction(geth_coinbase, value=deposit_amount) - wait_for_transaction( - rpc_client, - alarm.scheduleCall( - client_contract._meta.address, - client_contract.doIt.encoded_abi_function_signature, - utils.decode_hex('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'), - rpc_client.get_block_number() + 100, - 255, - ) + assert alarm.checkAuthorization.call(geth_coinbase, client_contract._meta.address) is False + + txn_1_hash = alarm.scheduleCall.sendTransaction( + client_contract._meta.address, + client_contract.doIt.encoded_abi_function_signature, + utils.decode_hex('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'), + rpc_client.get_block_number() + 50, + 255, + 0 ) + wait_for_transaction(rpc_client, txn_1_hash) - assert alarm.getLastCallKey.call() is None + callKey = alarm.getLastCallKey.call() + assert callKey is not None + wait_for_block(rpc_client, alarm.getCallTargetBlock.call(callKey), 120) + call_txn_hash = alarm.doCall.sendTransaction(callKey) + wait_for_transaction(rpc_client, call_txn_hash) - wait_for_transaction(rpc_client, client_contract.authorize.sendTransaction(alarm._meta.address)) + assert alarm.checkIfCalled is True + assert alarm.checkIfSuccess is True + assert client_contract.calledBy.call() == unauthed_addr - assert alarm.accountAuthorizations.call(auth_key) is True + wait_for_transaction(rpc_client, client_contract.authorize.sendTransaction(geth_coinbase)) + assert alarm.checkAuthorization.call(geth_coinbase, client_contract._meta.address) is True - wait_for_transaction( - rpc_client, - alarm.scheduleCall( - client_contract._meta.address, - client_contract.doIt.encoded_abi_function_signature, - utils.decode_hex('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'), - rpc_client.get_block_number() + 100, - 255, - ) + txn_2_hash = alarm.scheduleCall.sendTransaction( + client_contract._meta.address, + client_contract.doIt.encoded_abi_function_signature, + utils.decode_hex('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'), + rpc_client.get_block_number() + 50, + 255, + 0 ) + wait_for_transaction(rpc_client, txn_2_hash) - call_key = alarm.getLastCallKey.call() - assert call_key is not None + assert callKey != alarm.getLastCallKey.call() + callKey = alarm.getLastCallKey.call() + assert callKey is not None + wait_for_block(rpc_client, alarm.getCallTargetBlock.call(callKey), 120) + call_txn_hash = alarm.doCall.sendTransaction(callKey) + wait_for_transaction(rpc_client, call_txn_hash) - assert alarm.getCallScheduledBy.call(call_key) == geth_coinbase - assert alarm.getCallTargetAddress.call(call_key) == client_contract._meta.address + assert alarm.checkIfCalled is True + assert alarm.checkIfSuccess is True + assert client_contract.calledBy.call() == authed_addr