def userC_challenges_the_coin_spent_exit(context):
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userC_key)
    client.challenge_exit(uid, tx_blk_num=TRANSFER_TX_2_BLOCK)
    time.sleep(5)

    operator = Client(container.get_root_chain(), container.get_child_chain_client(), operator_key)
    operator.submit_block()
def userB_starts_to_exit_some_eth_from_plasma_cash(context, amount):
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userB_key)
    client.start_exit(uid, prev_tx_blk_num=DEPOSIT_TX_BLOCK, tx_blk_num=TRANSFER_TX_1_BLOCK)
    time.sleep(5)

    operator = Client(container.get_root_chain(), container.get_child_chain_client(), operator_key)
    operator.submit_block()
예제 #3
0
def userA_deposits_some_amount_of_eth_in_plasma_cash(context, amount):
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userA_key)
    client.deposit(amount=amount, currency=eth_currency)
    time.sleep(5)

    operator = Client(container.get_root_chain(), container.get_child_chain_client(), operator_key)
    operator.submit_block()
예제 #4
0
def userA_transfers_some_eth_to_userB(context, amount):
    prev_block = DEPOSIT_TX_BLOCK
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userA_key)
    client.send_transaction(prev_block, uid, amount, userB)

    operator = Client(container.get_root_chain(), container.get_child_chain_client(), operator_key)
    operator.submit_block()
예제 #5
0
def userB_start_exit_some_eth_from_plasma_cash(context, amount):
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userB_key)
    client.start_exit(uid, prev_tx_blk_num=1, tx_blk_num=2)
    time.sleep(5)

    operator = Client(container.get_root_chain(), container.get_child_chain_client(), operator_key)
    operator.submit_block()
예제 #6
0
def userA_starts_to_exit_deposit_from_plasma_cash(context, amount):
    client = Client(container.get_root_chain(),
                    container.get_child_chain_client(), userA_key)
    client.start_deposit_exit(uid, tx_blk_num=DEPOSIT_TX_BLOCK)
    time.sleep(5)

    operator = Client(container.get_root_chain(),
                      container.get_child_chain_client(), operator_key)
    operator.submit_block()
def then_root_chain_cancels_the_challenge(context):
    client = Client(container.get_root_chain(),
                    container.get_child_chain_client(), userD_key)
    deposit_block = client.get_block(DEPOSIT_TX_BLOCK)
    deposit_tx = deposit_block.get_tx_by_uid(uid)

    root_chain = container.get_root_chain()
    assert not root_chain.functions.isChallengeExisted(
        uid, rlp.encode(deposit_tx)).call({'from': userD})
def userC_transfers_some_eth_to_userD(context, amount):
    prev_block = TRANSFER_TX_2_BLOCK
    client = Client(container.get_root_chain(),
                    container.get_child_chain_client(), userC_key)
    client.send_transaction(prev_block, uid, amount, userD)

    operator = Client(container.get_root_chain(),
                      container.get_child_chain_client(), operator_key)
    operator.submit_block()
예제 #9
0
def sendTransaction():
    print('sendTransaction')
    #TODO
    userA = Client(container.get_root_chain(), container.get_child_chain_client()    , request.args.get('key'))
    preblock = requests.post("http://127.0.0.1:26657/status").json()['result']['sync_info']['latest_block_height']
    userA.send_transaction(int(preblock), int(request.args.get('uid')), int(request.args.get('amount')), request.args.get('receiver'))
    return '0'
예제 #10
0
def userB_has_some_amount_of_eth_in_plasma_cash(context, amount):
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userB_key)
    block = client.get_block(TRANSFER_TX_BLOCK)
    tx = block.get_tx_by_uid(uid)
    assert tx.amount == amount, 'tx.amount {} != amount: {}'.format(tx.amount, amount)

    assert_msg = 'tx.new_owner {} not same address as userB: {}'.format(tx.new_owner.hex(), userB)
    assert address_equals(tx.new_owner.hex(), userB), assert_msg
예제 #11
0
def userA_tries_to_double_spend_some_eth_to_userC(context, amount):
    invalid_tx = Transaction(DEPOSIT_TX_BLOCK, uid, 1, utils.normalize_address(userC))
    invalid_tx.sign(utils.normalize_key(userA_key))
    invalid_tx_merkle = SparseMerkleTree(257, {uid: invalid_tx.merkle_hash})

    root_chain = container.get_root_chain()
    root_chain.functions.submitBlock(invalid_tx_merkle.root, TRANSFER_TX_2_BLOCK).transact({
        'from': operator
    })
def userD_responds_to_the_history_challenge(context):
    client = Client(container.get_root_chain(),
                    container.get_child_chain_client(), userD_key)
    deposit_block = client.get_block(DEPOSIT_TX_BLOCK)
    deposit_tx = deposit_block.get_tx_by_uid(uid)

    client.respond_challenge_exit(rlp.encode(deposit_tx),
                                  uid,
                                  tx_blk_num=TRANSFER_TX_1_BLOCK)
    time.sleep(5)
예제 #13
0
def userC_starts_to_exit_some_eth_from_plasma_cash(context, amount):
    client = Client(container.get_root_chain(),
                    container.get_child_chain_client(), userC_key)

    deposit_block = client.get_block(DEPOSIT_TX_BLOCK)
    deposit_tx = deposit_block.get_tx_by_uid(uid)
    deposit_block.merklize_transaction_set()
    deposit_tx_proof = deposit_block.merkle.create_merkle_proof(uid)

    # invalid tx doesn't exist in child chain
    invalid_tx = Transaction(DEPOSIT_TX_BLOCK, uid, 1,
                             utils.normalize_address(userC))
    invalid_tx.sign(utils.normalize_key(userA_key))
    invalid_tx_merkle = SparseMerkleTree(257, {uid: invalid_tx.merkle_hash})
    invalid_tx_proof = invalid_tx_merkle.create_merkle_proof(uid)

    root_chain = container.get_root_chain()
    root_chain.functions.startExit(
        rlp.encode(deposit_tx), deposit_tx_proof, DEPOSIT_TX_BLOCK,
        rlp.encode(invalid_tx), invalid_tx_proof,
        TRANSFER_TX_2_BLOCK).transact({'from': userC})
    time.sleep(5)
예제 #14
0
def setup_job_handler(job_handler):
    root_chain = container.get_root_chain()
    child_chain_client = container.get_child_chain_client()

    apply_deposit_job = ApplyDepositJob(root_chain, child_chain_client)
    submit_block_job = SubmitBlockJob(child_chain_client,
                                      plasma_config['AUTHORITY_KEY'])

    job_handler.add_job(submit_block_job, time_interval=SUBMIT_BLOCK_INTERVAL)
    job_handler.add_job(apply_deposit_job,
                        time_interval=APPLY_DEPOSIT_INTERVAL)

    return job_handler
예제 #15
0
def root_chain_got_the_start_deposit_exit_record(context):
    root_chain = container.get_root_chain()
    assert has_value(root_chain.functions.exits(uid).call({'from': userA}))
예제 #16
0
def the_challenge_is_successful_and_root_chain_cancels_the_exit(context):
    root_chain = container.get_root_chain()
    assert not has_value(root_chain.functions.exits(uid).call({'from': userB}))
예제 #17
0
def root_chain_got_userB_start_exit(context, amount):
    root_chain = container.get_root_chain()
    assert has_value(root_chain.functions.exits(uid).call())
def userC_challenges_the_spent_coin_exit(context):
    client = Client(container.get_root_chain(),
                    container.get_child_chain_client(), userB_key)
    client.challenge_exit(uid, tx_blk_num=DEPOSIT_TX_BLOCK)
    time.sleep(5)
예제 #19
0
def startExit():
    print('startExit')
    #TODO
    userB = Client(container.get_root_chain(), container.get_child_chain_client(), request.args.get('key'))
    userB.start_exit(int(request.args.get('uid')), int(request.args.get('block1')), int(request.args.get('block2')))
    return '0'
예제 #20
0
def finalizeExit():
    print('finalizeExit')
    #TODO
    userB = Client(container.get_root_chain(), container.get_child_chain_client(), request.args.get('key'))
    userB.finalize_exit(int(request.args.get('uid')))
    return '0'
예제 #21
0
def deposit():
    print(deposit)
    #TODO
    userA = Client(container.get_root_chain(), container.get_child_chain_client(), request.args.get('key'))
    userA.deposit(int(request.args.get('amount')), '0x0000000000000000000000000000000000000000')
    return '0'
예제 #22
0
def root_chain_got_the_start_exit_record_from_double_spending_challenge(context):
    root_chain = container.get_root_chain()
    assert has_value(root_chain.functions.exits(uid).call({'from': userC}))
예제 #23
0
def userA_deposit_some_eth_to_plasma(context, amount):
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userA_key)
    client.deposit(amount=amount, currency=eth_currency)
    time.sleep(5)
예제 #24
0
def userB_finalize_exit(context):
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userB_key)
    client.finalize_exit(uid)
    time.sleep(5)
예제 #25
0
def userC_challenges_the_exit(context):
    client = Client(container.get_root_chain(), container.get_child_chain_client(), userC_key)
    client.challenge_exit(uid, tx_blk_num=TRANSFER_TX_1_BLOCK)
    time.sleep(5)
예제 #26
0
def root_chain_got_userB_start_exit_event(context, amount):
    root_chain = container.get_root_chain()
    assert root_chain.functions.exits(uid).call(
        {'from': userA}) != [False, 0, 0, b'', 0, b'']