예제 #1
0
def test_start_exit_wrong_position_should_fail(testlang):
    owner, amount = testlang.accounts[0], 100

    # Create a deposit
    deposit_blknum = testlang.deposit(owner, amount)
    deposit_utxo_position = encode_utxo_position(deposit_blknum, 0, 0)

    # Spend the deposit and submit the block
    spend_utxo_position = testlang.spend_utxo(deposit_utxo_position, owner, amount, owner)
    testlang.confirm(spend_utxo_position, 0, owner)

    # Start an exit
    bond = testlang.root_chain.EXIT_BOND()
    utxo_position = encode_utxo_position(0, 0, 0)  # Using wrong utxo position
    with pytest.raises(TransactionFailed):
        testlang.root_chain.startExit(utxo_position, *testlang.get_exit_proof(spend_utxo_position), value=bond)
예제 #2
0
def test_challenge_exit_should_succeed(testlang):
    owner, amount = testlang.accounts[0], 100

    # Create a deposit
    deposit_blknum = testlang.deposit(owner, amount)
    deposit_utxo_position = encode_utxo_position(deposit_blknum, 0, 0)

    # Start an exit
    testlang.start_exit(owner, deposit_utxo_position)

    # Check that the exit was created
    plasma_exit = testlang.get_plasma_exit(deposit_utxo_position)
    assert plasma_exit.owner == owner.address
    assert plasma_exit.amount == amount

    # Spend the deposit
    spending_utxo_position = testlang.spend_utxo(deposit_utxo_position, owner, amount, owner)
    testlang.confirm(spending_utxo_position, 0, owner)

    # Challenge the exit
    testlang.challenge_exit(deposit_utxo_position, spending_utxo_position)

    # Check that the exit was removed
    plasma_exit = testlang.get_plasma_exit(deposit_utxo_position)
    assert plasma_exit.is_valid == False
예제 #3
0
def test_start_exit_invalid_proof_should_fail(testlang):
    owner, amount = testlang.accounts[0], 100

    # Create a deposit
    deposit_blknum = testlang.deposit(owner, amount)
    deposit_utxo_position = encode_utxo_position(deposit_blknum, 0, 0)

    # Spend the deposit and submit the block
    spend_utxo_position = testlang.spend_utxo(deposit_utxo_position, owner,
                                              amount, owner)
    testlang.confirm(spend_utxo_position, 0, owner)

    # Start an exit
    bond = testlang.root_chain.EXIT_BOND()
    proof = b''  # Using empty proof
    (encoded_tx, _, signatures,
     confirmations) = testlang.get_exit_proof(spend_utxo_position)
    with pytest.raises(TransactionFailed):
        testlang.root_chain.startExit(
            *decode_utxo_position(spend_utxo_position),
            encoded_tx,
            proof,
            signatures,
            confirmations,
            value=bond)
예제 #4
0
def test_start_exit_twice_should_fail(testlang):
    owner, amount = testlang.accounts[0], 100

    # Create a deposit
    deposit_blknum = testlang.deposit(owner, amount)
    deposit_utxo_position = encode_utxo_position(deposit_blknum, 0, 0)

    # Start an exit
    testlang.start_exit(owner, deposit_utxo_position)

    # Try to start a second exit
    with pytest.raises(TransactionFailed):
        testlang.start_exit(owner, deposit_utxo_position)
예제 #5
0
def test_start_exit_from_deposit_should_succeed(testlang):
    owner, amount = testlang.accounts[0], 100

    # Create a deposit
    deposit_blknum = testlang.deposit(owner, amount)
    deposit_utxo_position = encode_utxo_position(deposit_blknum, 0, 0)

    # Start an exit
    testlang.start_exit(owner, deposit_utxo_position)

    # Check the exit was created correctly
    plasma_exit = testlang.get_plasma_exit(deposit_utxo_position)
    assert plasma_exit.owner == owner.address
    assert plasma_exit.amount == amount
예제 #6
0
def start_exit_spend(testlang):
    owner, amount = testlang.accounts[0], 100

    # Create a deposit
    deposit_blknum = testlang.deposit(owner, amount)
    deposit_utxo_position = encode_utxo_position(deposit_blknum, 0, 0)

    # Start an exit
    testlang.start_exit(owner, deposit_utxo_position)

    # Spend the deposit
    spending_utxo_position = testlang.spend_utxo(deposit_utxo_position, owner, amount, owner)
    testlang.confirm(spending_utxo_position, 0, owner)

    return (deposit_utxo_position, spending_utxo_position)
예제 #7
0
def test_start_exit_wrong_tx_should_fail(testlang):
    owner, amount = testlang.accounts[0], 100

    # Create a deposit
    deposit_blknum = testlang.deposit(owner, amount)
    deposit_utxo_position = encode_utxo_position(deposit_blknum, 0, 0)

    # Spend the deposit and submit the block
    spend_utxo_position = testlang.spend_utxo(deposit_utxo_position, owner, amount, owner)
    testlang.confirm(spend_utxo_position, 0, owner)

    # Start an exit
    bond = testlang.root_chain.EXIT_BOND()
    encoded_tx = testlang.child_chain.get_transaction(deposit_utxo_position).encoded  # Using wrong encoded tx
    (_, proof, signatures, confirmation_signatures) = testlang.get_exit_proof(spend_utxo_position)
    with pytest.raises(TransactionFailed):
        testlang.root_chain.startExit(spend_utxo_position, encoded_tx, proof, signatures, confirmation_signatures, value=bond)
def test_process_exits_should_succeed(testlang):
    owner, amount = testlang.accounts[0], 100

    # Create a deposit
    deposit_blknum = testlang.deposit(owner, amount)
    deposit_utxo_position = encode_utxo_position(deposit_blknum, 0, 0)

    # Start an exit
    testlang.start_exit(owner, deposit_utxo_position)

    # Move forward in time
    testlang.forward_timestamp(2 * WEEKS)

    # Process exits
    testlang.process_exits()

    # Check that the exit was processed
    plasma_exit = testlang.get_plasma_exit(deposit_utxo_position)
    assert plasma_exit.owner == NULL_ADDRESS_HEX  # owner should be deleted
    assert plasma_exit.amount == amount  # amount should be unchanged
예제 #9
0
    def spend_utxo(self, utxo_position, new_owner, amount, signer):
        """Creates a spending transaction and inserts it into the chain.

        Args:
            utxo_position (int): Identifier of the UTXO to spend.
            new_owner (EthereumAccount): Account to own the output of this spend.
            amount (int): Amount to spend.
            signer (EthereumAccount): Account to sign this transaction.

        Returns:
            int: Unique identifier of the spend.
        """

        spend_tx = Transaction(inputs=[decode_utxo_position(utxo_position)],
                               outputs=[(new_owner.address, amount)])
        spend_tx.sign(0, signer.key)

        blknum = self.root_chain.currentPlasmaBlockNumber()
        block = Block(transactions=[spend_tx], number=blknum)
        self.commit_plasma_block_root(block)
        return encode_utxo_position(blknum, 0, 0)
 def position(self):
     """This input's position in the chain"""
     return encode_utxo_position(self.blknum, self.txindex, self.oindex)