Ejemplo n.º 1
0
def test_same_input_address_multiple_seq_nos(
        tokens_distributed,
        looper,  # noqa
        sdk_pool_handle,
        sdk_wallet_client,
        seller_token_wallet,
        seller_address,
        user1_address,
        user2_address,
        user3_address,
        user1_token_wallet,
        user2_token_wallet):
    # Send a PUBLIC_XFER with inputs using the same address but different
    # sequence nos.
    global seller_gets
    seq_no_1 = tokens_distributed

    for (w, a) in [(user1_token_wallet, user1_address),
                   (user2_token_wallet, user2_address)]:
        inputs = [
            [w, a, seq_no_1],
        ]
        amount = w.get_total_address_amount(address=a)
        outputs = [{"address": seller_address, "amount": amount}]
        send_xfer(looper, inputs, outputs, sdk_pool_handle)

    res1 = send_get_utxo(looper, seller_address, sdk_wallet_client,
                         sdk_pool_handle)
    assert len(res1[OUTPUTS]) > 1

    update_token_wallet_with_result(seller_token_wallet, res1)
    inputs = []
    output_amount = 0
    for s, amt in list(
            seller_token_wallet.get_all_address_utxos(
                seller_address).values())[0]:
        inputs.append([seller_token_wallet, seller_address, s])
        output_amount += amt

    outputs = [{"address": user3_address, "amount": output_amount}]
    new_seq_no = get_seq_no(send_xfer(looper, inputs, outputs,
                                      sdk_pool_handle))

    res2 = send_get_utxo(looper, user3_address, sdk_wallet_client,
                         sdk_pool_handle)

    assert len(res2[OUTPUTS]) > 0
    for output in res2[OUTPUTS]:
        if output["seqNo"] == new_seq_no:
            assert output["amount"] == output_amount
            break
    else:
        raise AssertionError('Needed to find output {}:{} with val {} but not '
                             'found'.format(user3_address, new_seq_no,
                                            output_amount))
Ejemplo n.º 2
0
def tokens_distributed(public_minting, seller_token_wallet, seller_address,
                       user1_address, user1_token_wallet,
                       user2_address, user2_token_wallet,
                       user3_address, user3_token_wallet, looper, sdk_pool_handle,
                       sdk_wallet_client):
    # register_token_wallet_with_client(client1, seller_token_wallet)
    res = send_get_utxo(looper, seller_address, sdk_wallet_client, sdk_pool_handle)
    update_token_wallet_with_result(seller_token_wallet, res)
    total_amount = seller_token_wallet.get_total_address_amount(seller_address)

    inputs = [[seller_token_wallet, seller_address, seq_no] for seq_no, _ in
              next(iter(seller_token_wallet.get_all_address_utxos(seller_address).values()))]
    each_user_share = total_amount // 3
    outputs = [{"address": user1_address, "amount": each_user_share},
               {"address": user2_address, "amount": each_user_share},
               {"address": user3_address, "amount": each_user_share},
               {"address": seller_address, "amount": total_amount % 3}]
    res = send_xfer(looper, inputs, outputs, sdk_pool_handle)
    update_token_wallet_with_result(seller_token_wallet, res)
    seq_no = get_seq_no(res)
    for w, a in [(user1_token_wallet, user1_address),
                 (user2_token_wallet, user2_address),
                 (user3_token_wallet, user3_address)]:
        res = send_get_utxo(looper, a, sdk_wallet_client, sdk_pool_handle)
        update_token_wallet_with_result(w, res)
    return seq_no
Ejemplo n.º 3
0
def test_state_proof(public_minting, looper,  # noqa
                     sdk_pool_handle, sdk_wallet_client,
                     seller_token_wallet, seller_address,
                     user1_token_wallet, user1_address):
    res = send_get_utxo(looper, seller_address, sdk_wallet_client, sdk_pool_handle)
    update_token_wallet_with_result(seller_token_wallet, res)

    # Do 20 XFER txns
    for _ in range(20):
        utxos = [_ for lst in
                 seller_token_wallet.get_all_wallet_utxos().values()
                 for _ in lst]
        seq_no, amount = utxos[0]
        inputs = [[seller_token_wallet, seller_address, seq_no]]
        outputs = [{"address": user1_address, "amount": 1}, {"address": seller_address, "amount": amount-1}]
        res = send_xfer(looper, inputs, outputs, sdk_pool_handle)
        update_token_wallet_with_result(seller_token_wallet, res)
        res = send_get_utxo(looper, seller_address, sdk_wallet_client,
                            sdk_pool_handle)
        update_token_wallet_with_result(seller_token_wallet, res)
        res = send_get_utxo(looper, user1_address, sdk_wallet_client,
                            sdk_pool_handle)
        update_token_wallet_with_result(user1_token_wallet, res)

    res = send_get_utxo(looper, user1_address, sdk_wallet_client,
                        sdk_pool_handle)

    # Check presence of state proof
    assert res[STATE_PROOF]
    encoded = {}
    outputs = res[OUTPUTS]
    for out in outputs:
        state_key = TokenStaticHelper.create_state_key(out["address"], out["seqNo"])
        encoded[state_key] = rlp_encode([str(out["amount"])])
    proof_nodes = decode_proof(res[STATE_PROOF][PROOF_NODES])
    client_trie = Trie(PersistentDB(KeyValueStorageInMemory()))
    assert client_trie.verify_spv_proof_multi(
        state_roots_serializer.deserialize(res[STATE_PROOF][ROOT_HASH]),
        encoded, proof_nodes)