Skip to content

Commit

Permalink
More work getting tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
pipermerriam committed Sep 18, 2015
1 parent 89c7b71 commit 043d0c7
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 66 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion contracts/Alarm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions contracts/Testers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ contract TestDataRegistry {

contract NoArgs {
bool public value;
bytes32 public dataHash;

function doIt() public {
value = true;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -253,7 +251,10 @@ contract SpecifyBlock {


contract AuthorizesOthers {
address public calledBy;

function doIt() public {
calledBy = msg.sender;
}

function authorize(address to) public {
Expand All @@ -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);
}
}


Expand Down
10 changes: 7 additions & 3 deletions tests/get-call-information/test_get_called_at_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from populus.contracts import get_max_gas
from populus.utils import wait_for_transaction, wait_for_block


Expand All @@ -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

Expand All @@ -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)
3 changes: 2 additions & 1 deletion tests/get-call-information/test_get_gas_used.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
20 changes: 8 additions & 12 deletions tests/get-call-information/test_get_scheduled_by.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from populus.contracts import get_max_gas
from populus.utils import wait_for_transaction


Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions tests/get-call-information/test_get_target_block.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from populus.contracts import get_max_gas
from populus.utils import wait_for_transaction


Expand All @@ -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)
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
72 changes: 43 additions & 29 deletions tests/scheduling-authorization/test_authorization_for_scheduling.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 043d0c7

Please sign in to comment.