Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test checking that inputs can not be exited from restarted ife after outputs finalized on processing the first ife #611

Merged
merged 3 commits into from
Apr 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1002,3 +1002,63 @@ def test_challenged_standard_exit_does_not_block_ife_output_exit(testlang, plasm
# and does not get the tokens back
alice_token_balance = token.balanceOf(alice.address)
assert alice_token_balance == alice_token_balance_before


def test_after_canonical_ife_is_finalized_inputs_are_not_exited_when_ife_is_restarted_and_non_canonical(testlang, plasma_framework, token):
pgebal marked this conversation as resolved.
Show resolved Hide resolved
"""
1. Alice and Bob send a canonical transaction transfering their funds to Alice.
2. Alice starts an in-flight exit and exits her output.
3. Bob creates a competing transaction spending his input.
4. In-flight exit is restarted and is non-canonical as Bob produces a comepeting transaction.
5. Alice and Bob piggyback on their inputs and exit is processed.
6. Funds from inputs are not withdrawn as they were marked as finalized when Alice exited her output in step 2.
"""
alice, bob, deposit_amount = testlang.accounts[0], testlang.accounts[1], 100
alice_deposit_id = testlang.deposit(alice, deposit_amount)
bob_deposit_id = testlang.deposit(bob, deposit_amount)
alice_output_amount = 2 * deposit_amount

spend_id = testlang.spend_utxo([alice_deposit_id, bob_deposit_id], [alice, bob], [(alice.address, NULL_ADDRESS, alice_output_amount)])

alice_eth_balance_before = testlang.get_balance(alice)

# transaction is not included in child chain and canonical in-flight exit is started and processed
testlang.start_in_flight_exit(spend_id)
testlang.piggyback_in_flight_exit_output(spend_id, 0, alice)
testlang.forward_timestamp(2 * MIN_EXIT_PERIOD + 1)
testlang.process_exits(NULL_ADDRESS, 0, 1)

# alice exits with her Eth output
alice_eth_balance = testlang.get_balance(alice)
assert alice_eth_balance == alice_eth_balance_before + alice_output_amount

# bob spends his inputs in a competing transaction
competing_spend_id = testlang.spend_utxo(
[bob_deposit_id], [bob], [(bob.address, NULL_ADDRESS, deposit_amount)],
force_invalid=True
)

# in-flight exit is restarted
testlang.start_in_flight_exit(spend_id)

# it's canonicity is challenged with the competing transaction
testlang.challenge_in_flight_exit_not_canonical(spend_id, competing_spend_id, account=bob)

# in-flight exit is not canonical
in_flight_exit = testlang.get_in_flight_exit(spend_id)
assert not in_flight_exit.is_canonical

# owners piggyback on inputs
testlang.piggyback_in_flight_exit_input(spend_id, 0, alice)
testlang.piggyback_in_flight_exit_input(spend_id, 1, bob)

eth_balance_before_processing_exits = testlang.get_balance(plasma_framework.eth_vault)

# exit is processed
testlang.forward_timestamp(2 * MIN_EXIT_PERIOD + 1)
testlang.process_exits(NULL_ADDRESS, 0, 2)

# users didn't exit their inputs - no funds were withdrawn from the eth vault
pgebal marked this conversation as resolved.
Show resolved Hide resolved
# because in-flight transaction output is already exited and the inputs were flagged as finalized
eth_balance = testlang.get_balance(plasma_framework.eth_vault)
assert eth_balance_before_processing_exits == eth_balance