Skip to content

Commit

Permalink
test: add a test checking all index-variants of ChallengeIFEOutputSpent
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Dobaczewski Imapp committed Mar 4, 2020
1 parent 4e1b643 commit 2f02189
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from eth_utils import keccak
from eth_tester.exceptions import TransactionFailed
from plasma_core.constants import NULL_ADDRESS
from plasma_core.utils.transactions import decode_utxo_id, encode_utxo_id


# challenge should succeed even when phase 2 of in-flight exit is over
Expand All @@ -21,6 +22,57 @@ def test_challenge_in_flight_exit_output_spent_should_succeed(testlang, period):
assert not in_flight_exit.output_piggybacked(0)


@pytest.mark.parametrize(
"ife_tx_num_outputs,double_spend_output_index,challenging_tx_num_inputs,double_spend_input_index",
[(i, j, k, l) for i in range(1, 5) for j in range(0, i) for k in range(1, 5) for l in range(0, k)]
)
def test_challenge_in_flight_exit_output_spent_should_succeed_for_all_indices(testlang,
ife_tx_num_outputs,
double_spend_output_index,
challenging_tx_num_inputs,
double_spend_input_index):
deposit_amount = 100
deposit_id = testlang.deposit(testlang.accounts[0], deposit_amount)

owners = []
outputs = []
tx_output_amount = deposit_amount // ife_tx_num_outputs
for i in range(0, ife_tx_num_outputs):
owners.append(testlang.accounts[i])
outputs.append((testlang.accounts[i].address, NULL_ADDRESS, tx_output_amount))

ife_tx_id = testlang.spend_utxo([deposit_id], owners, outputs=outputs)
blknum, tx_index, _ = decode_utxo_id(ife_tx_id)
double_spend_owner = owners[double_spend_output_index]
double_spend_utxo = encode_utxo_id(blknum, tx_index, double_spend_output_index)

testlang.start_in_flight_exit(ife_tx_id)
testlang.piggyback_in_flight_exit_output(ife_tx_id, double_spend_output_index, double_spend_owner)

MAX_INDEX_SIZE = 4
inputs = []
for i in range(0, MAX_INDEX_SIZE):
if i == double_spend_input_index:
inputs.append(double_spend_utxo)
else:
inputs.append(testlang.deposit(double_spend_owner, tx_output_amount))

challenge_tx_id = testlang.spend_utxo(
inputs,
[double_spend_owner for i in range(0, MAX_INDEX_SIZE)],
[
(double_spend_owner.address, NULL_ADDRESS, tx_output_amount),
],
force_invalid=True
)

testlang.challenge_in_flight_exit_output_spent(ife_tx_id, challenge_tx_id, double_spend_output_index, double_spend_owner)

in_flight_exit = testlang.get_in_flight_exit(ife_tx_id)
for i in range(0, MAX_INDEX_SIZE):
assert not in_flight_exit.output_piggybacked(i)


def test_challenge_in_flight_exit_output_spent_not_piggybacked_should_fail(testlang):
owner_1, owner_2, amount = testlang.accounts[0], testlang.accounts[1], 100
deposit_id = testlang.deposit(owner_1, amount)
Expand Down

0 comments on commit 2f02189

Please sign in to comment.