Exemplo n.º 1
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'
Exemplo n.º 2
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
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 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)
Exemplo n.º 5
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()
Exemplo n.º 6
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()
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()
Exemplo n.º 9
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()
Exemplo n.º 10
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 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()
Exemplo n.º 12
0
    def test_constructor(self):
        DUMMY_ROOT_CHAIN = 'root chain'
        DUMMY_CHILD_CHAIN = 'child chain'
        DUMMY_KEY = 'key'

        when('plasma_cash.client.client.utils').normalize_key(
            DUMMY_KEY).thenReturn(DUMMY_KEY)
        c = Client(DUMMY_ROOT_CHAIN, DUMMY_CHILD_CHAIN, DUMMY_KEY)

        assert c.root_chain == DUMMY_ROOT_CHAIN
        assert c.child_chain == DUMMY_CHILD_CHAIN
        assert c.key == DUMMY_KEY
Exemplo n.º 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)
Exemplo n.º 14
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)
Exemplo n.º 15
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'
Exemplo n.º 16
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'
Exemplo n.º 17
0
 def client(self, root_chain, child_chain):
     DUMMY_KEY = '0xa18969817c2cefadf52b93eb20f917dce760ce13b2ac9025e0361ad1e7a1d448'
     return Client(root_chain, child_chain, DUMMY_KEY)
Exemplo n.º 18
0
 def test_constructor(self):
     DUMMY_ROOT_CHAIN = 'root chain'
     DUMMY_CHILD_CHAIN = 'child chain'
     c = Client(DUMMY_ROOT_CHAIN, DUMMY_CHILD_CHAIN)
     assert c.root_chain == DUMMY_ROOT_CHAIN
     assert c.child_chain == DUMMY_CHILD_CHAIN
Exemplo n.º 19
0
 def client(self, root_chain, child_chain):
     return Client(root_chain, child_chain)
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)
Exemplo n.º 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'
Exemplo n.º 22
0
 def get_client(self):
     if self._client is None:
         root_chain = self.get_root_chain()
         child_chain = self.get_child_chain_client()
         self._client = Client(root_chain, child_chain)
     return self._client
Exemplo n.º 23
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)
Exemplo n.º 24
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)