Uncomment tests

This commit is contained in:
Justin Drake 2019-06-29 09:28:46 +01:00
parent d5d3e49c5f
commit a7ceec1e8a
1 changed files with 86 additions and 85 deletions

View File

@ -21,101 +21,102 @@ from eth2spec.utils.ssz.ssz_impl import (
)
# @pytest.fixture
# def deposit_input():
# """
# pubkey: bytes[48]
# withdrawal_credentials: bytes[32]
# signature: bytes[96]
# """
# return (
# b'\x11' * 48,
# b'\x22' * 32,
# b'\x33' * 96,
# )
@pytest.fixture
def deposit_input():
"""
pubkey: bytes[48]
withdrawal_credentials: bytes[32]
signature: bytes[96]
"""
return (
b'\x11' * 48,
b'\x22' * 32,
b'\x33' * 96,
)
# @pytest.mark.parametrize(
# 'success,deposit_amount',
# [
# (True, FULL_DEPOSIT_AMOUNT),
# (True, MIN_DEPOSIT_AMOUNT),
# (False, MIN_DEPOSIT_AMOUNT - 1),
# (True, FULL_DEPOSIT_AMOUNT + 1)
# ]
# )
# def test_deposit_amount(registration_contract,
# w3,
# success,
# deposit_amount,
# assert_tx_failed,
# deposit_input):
# call = registration_contract.functions.deposit(*deposit_input)
# if success:
# assert call.transact({"value": deposit_amount * eth_utils.denoms.gwei})
# else:
# assert_tx_failed(
# lambda: call.transact({"value": deposit_amount * eth_utils.denoms.gwei})
# )
@pytest.mark.parametrize(
'success,deposit_amount',
[
(True, FULL_DEPOSIT_AMOUNT),
(True, MIN_DEPOSIT_AMOUNT),
(False, MIN_DEPOSIT_AMOUNT - 1),
(True, FULL_DEPOSIT_AMOUNT + 1)
]
)
def test_deposit_amount(registration_contract,
w3,
success,
deposit_amount,
assert_tx_failed,
deposit_input):
call = registration_contract.functions.deposit(*deposit_input)
if success:
assert call.transact({"value": deposit_amount * eth_utils.denoms.gwei})
else:
assert_tx_failed(
lambda: call.transact({"value": deposit_amount * eth_utils.denoms.gwei})
)
# @pytest.mark.parametrize(
# 'invalid_pubkey,invalid_withdrawal_credentials,invalid_signature,success',
# [
# (False, False, False, True),
# (True, False, False, False),
# (False, True, False, False),
# (False, False, True, False),
# ]
# )
# def test_deposit_inputs(registration_contract,
# w3,
# assert_tx_failed,
# deposit_input,
# invalid_pubkey,
# invalid_withdrawal_credentials,
# invalid_signature,
# success):
# pubkey = deposit_input[0][2:] if invalid_pubkey else deposit_input[0]
# if invalid_withdrawal_credentials: # this one is different to satisfy linter
# withdrawal_credentials = deposit_input[1][2:]
# else:
# withdrawal_credentials = deposit_input[1]
# signature = deposit_input[2][2:] if invalid_signature else deposit_input[2]
@pytest.mark.parametrize(
'invalid_pubkey,invalid_withdrawal_credentials,invalid_signature,success',
[
(False, False, False, True),
(True, False, False, False),
(False, True, False, False),
(False, False, True, False),
]
)
def test_deposit_inputs(registration_contract,
w3,
assert_tx_failed,
deposit_input,
invalid_pubkey,
invalid_withdrawal_credentials,
invalid_signature,
success):
pubkey = deposit_input[0][2:] if invalid_pubkey else deposit_input[0]
if invalid_withdrawal_credentials: # this one is different to satisfy linter
withdrawal_credentials = deposit_input[1][2:]
else:
withdrawal_credentials = deposit_input[1]
signature = deposit_input[2][2:] if invalid_signature else deposit_input[2]
# call = registration_contract.functions.deposit(
# pubkey,
# withdrawal_credentials,
# signature,
# )
# if success:
# assert call.transact({"value": FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei})
# else:
# assert_tx_failed(
# lambda: call.transact({"value": FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei})
# )
call = registration_contract.functions.deposit(
pubkey,
withdrawal_credentials,
signature,
)
if success:
assert call.transact({"value": FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei})
else:
assert_tx_failed(
lambda: call.transact({"value": FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei})
)
# def test_deposit_log(registration_contract, a0, w3, deposit_input):
# log_filter = registration_contract.events.Deposit.createFilter(
# fromBlock='latest',
# )
def test_deposit_log(registration_contract, a0, w3, deposit_input):
log_filter = registration_contract.events.Deposit.createFilter(
fromBlock='latest',
)
# deposit_amount_list = [randint(MIN_DEPOSIT_AMOUNT, FULL_DEPOSIT_AMOUNT * 2) for _ in range(3)]
# for i in range(3):
# registration_contract.functions.deposit(
# *deposit_input,
# ).transact({"value": deposit_amount_list[i] * eth_utils.denoms.gwei})
deposit_amount_list = [randint(MIN_DEPOSIT_AMOUNT, FULL_DEPOSIT_AMOUNT * 2) for _ in range(3)]
for i in range(3):
registration_contract.functions.deposit(
*deposit_input,
).transact({"value": deposit_amount_list[i] * eth_utils.denoms.gwei})
# logs = log_filter.get_new_entries()
# assert len(logs) == 1
# log = logs[0]['args']
logs = log_filter.get_new_entries()
assert len(logs) == 1
log = logs[0]['args']
assert log['pubkey'] == deposit_input[0]
assert log['withdrawal_credentials'] == deposit_input[1]
assert log['amount'] == deposit_amount_list[i].to_bytes(8, 'little')
assert log['signature'] == deposit_input[2]
assert log['index'] == i.to_bytes(8, 'little')
# assert log['pubkey'] == deposit_input[0]
# assert log['withdrawal_credentials'] == deposit_input[1]
# assert log['amount'] == deposit_amount_list[i].to_bytes(8, 'little')
# assert log['signature'] == deposit_input[2]
# assert log['index'] == i.to_bytes(8, 'little')
def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input):
log_filter = registration_contract.events.Deposit.createFilter(