Beispiel #1
0
def test_filters_assets():

    # fund server
    for i in range(3):
        address = lib.get_funding_addresses([ASSET])[ASSET]
        rawtx = api.create_send(
            **{
                'source': FUNDING_ADDRESS,
                'destination': address,
                'asset': ASSET,
                'quantity': 1000000,
                'regular_dust_size': 1000000
            })
        api.sendrawtransaction(tx_hex=rawtx)

    # connect clients
    assert len(api.mph_connections()) == 0
    clients = []
    for i in range(3):
        bob_wif = util.gen_funded_wif(ASSET, 1000000, 1000000)
        client = Mph(util.MockAPI(auth_wif=bob_wif))
        client.connect(1000000, 65535, asset=ASSET)
        clients.append(client)

    connections = api.mph_connections(assets=[ASSET])
    assert len(connections) == 3

    connections = api.mph_connections(assets=["BTC"])
    assert len(connections) == 0
def test_simulation_xcp():

    # fund server
    for i in range(2):
        address = lib.get_funding_addresses([ASSET])[ASSET]
        rawtx = api.create_send(
            **{
                'source': FUNDING_ADDRESS,
                'destination': address,
                'asset': ASSET,
                'quantity': 1000000,
                'regular_dust_size': 1000000
            })
        api.sendrawtransaction(tx_hex=rawtx)

    # connect clients
    clients = []
    for i in range(2):
        bob_wif = util.gen_funded_wif(ASSET, 1000000, 1000000)
        client = Mph(util.MockAPI(auth_wif=bob_wif))
        txid = client.connect(1000000, 65535, asset=ASSET)
        assert txid is not None

        status = client.get_status()
        assert status["balance"] == 1000000
        assert status["c2h_deposit_ttl"] is not None
        assert status["h2c_deposit_ttl"] is None  # hub deposit not yet made

        clients.append(client)

    # server funds deposits
    cron.run_all()
    for client in clients:
        status = client.get_status()
        assert status["h2c_deposit_ttl"] is not None  # hub deposit now made
Beispiel #3
0
def test_all(server_db):

    # fund server
    for i in range(3):
        address = lib.get_funding_addresses([ASSET])[ASSET]
        rawtx = api.create_send(
            **{
                'source': FUNDING_ADDRESS,
                'destination': address,
                'asset': ASSET,
                'quantity': 1000000,
                'regular_dust_size': 1000000
            })
        api.sendrawtransaction(tx_hex=rawtx)

    # connect clients
    assert len(api.mph_connections()) == 0
    clients = []
    for i in range(3):
        bob_wif = util.gen_funded_wif(ASSET, 1000000, 1000000)
        client = Mph(util.MockAPI(auth_wif=bob_wif))
        client.connect(1000000, 65535, asset=ASSET)
        clients.append(client)

    connections = api.mph_connections()
    assert len(connections) == 3
    for connection in connections:
        jsonschema.validate(connection, CONNECTION_RESULT_SCHEMA)
        auth.verify_json(connection)
Beispiel #4
0
def connected_clients():

    # create asset
    rawtx = api.create_issuance(
        source=FUNDING_ADDRESS,
        asset="A7736697071037023001",
        quantity=100000000
    )
    api.sendrawtransaction(tx_hex=rawtx)

    # fund server
    for i in range(3):
        addresses = lib.get_funding_addresses(["XCP", "A7736697071037023001"])
        for asset, address in addresses.items():
            rawtx = api.create_send(**{
                'source': FUNDING_ADDRESS,
                'destination': address,
                'asset': asset,
                'quantity': 1000000,
                'regular_dust_size': 1000000
            })
            api.sendrawtransaction(tx_hex=rawtx)

    # connect clients
    clients = []

    # fund XCP clients
    for i in range(3):
        bob_wif = util.gen_funded_wif("XCP", 1000000, 1000000)
        client = Mph(util.MockAPI(auth_wif=bob_wif))
        client.connect(1000000, 42, asset="XCP")
        clients.append(client)

    # fund A7736697071037023001 clients
    for i in range(3):
        bob_wif = util.gen_funded_wif("A7736697071037023001", 1000000, 1000000)
        client = Mph(util.MockAPI(auth_wif=bob_wif))
        client.connect(1000000, 42, asset="A7736697071037023001")
        clients.append(client)

    cron.fund_deposits()

    return clients
Beispiel #5
0
def test_commit_tx_beta():

    rawtx = api.create_send(
        **{
            'source': ALICE_ADDRESS,
            'destination': BOB_ADDRESS,
            'asset': 'XCP',
            'quantity': 13,
            'regular_dust_size': 33
        })

    asset_balance, btc_balance = get_balance(dispatcher, "XCP", BOB_ADDRESS)
    assert asset_balance == 0
    assert btc_balance == 0

    api.sendrawtransaction(tx_hex=rawtx)

    asset_balance, btc_balance = get_balance(dispatcher, "XCP", BOB_ADDRESS)
    assert asset_balance == 13
    assert btc_balance == 33
Beispiel #6
0
def gen_funded_wif(asset, asset_quantity, btc_quantity):
    src_wif = DP["addresses"][0][2]
    src_address = address_from_wif(src_wif)
    dest_wif = generate_wif(netcode=etc.netcode)
    dest_address = address_from_wif(dest_wif)
    rawtx = api.create_send(
        **{
            'source': src_address,
            'destination': dest_address,
            'asset': asset,
            'quantity': asset_quantity,
            'regular_dust_size': btc_quantity
        })
    api.sendrawtransaction(tx_hex=rawtx)
    # entries = api.get_balances(filters=[
    #     {"field": "address", "op": "==", "value": dest_address},
    #     {"field": "asset", "op": "==", "value": asset},
    # ])
    # assert entries[0]["quantity"] == asset_quantity
    # assert entries[0]["address"] == dest_address
    # assert entries[0]["asset"] == asset
    return dest_wif
def test_standard_usage(server_db):

    # fund server
    for i in range(3):
        address = lib.get_funding_addresses([ASSET])[ASSET]
        rawtx = api.create_send(
            **{
                'source': FUNDING_ADDRESS,
                'destination': address,
                'asset': ASSET,
                'quantity': 1000000,
                'regular_dust_size': 1000000
            })
        api.sendrawtransaction(tx_hex=rawtx)

    # connect clients
    assert len(api.mph_connections()) == 0
    clients = []
    for i in range(3):
        auth_wif = util.gen_funded_wif(ASSET, 1000000, 1000000)
        client = Mph(util.MockAPI(auth_wif=auth_wif))
        txid = client.connect(1000000, 65535, asset=ASSET)
        assert txid is not None

        status = client.get_status()
        assert status["balance"] == 1000000
        assert status["c2h_deposit_ttl"] is not None
        assert status["h2c_deposit_ttl"] is None  # hub deposit not yet made
        clients.append(client)
    assert len(api.mph_connections()) == 3

    # server funds deposits
    assert len(cron.fund_deposits()) == 3
    assert len(cron.fund_deposits()) == 0
    for client in clients:
        status = client.get_status()
        assert status["h2c_deposit_ttl"] is not None  # hub deposit now made

    # after before status
    alpha, beta, gamma = clients
    alpha_before_status = alpha.get_status()
    beta_before_status = beta.get_status()
    gamma_before_status = gamma.get_status()

    # can send multiple payments
    alpha.micro_send(beta.handle, 5, "0000")
    alpha.micro_send(gamma.handle, 6, "0001")
    assert alpha.sync() == []
    assert beta.sync() == [{
        "payer_handle": alpha.handle,
        "amount": 5,
        "token": "0000"
    }]
    assert gamma.sync(), [{
        "payer_handle": alpha.handle,
        "amount": 6,
        "token": "0001"
    }]

    # send more back, commits are revoked to maximize liquidity
    beta.micro_send(alpha.handle, 42, "0003")
    assert beta.sync() == []
    assert alpha.sync() == [{
        "payer_handle": beta.handle,
        "amount": 42,
        "token": "0003"
    }]

    # multiple syncs/commtis from single client
    alpha.micro_send(beta.handle, 1, "0004")
    assert alpha.sync() == []

    # get after status
    alpha_after_status = alpha.get_status()
    beta_after_status = beta.get_status()
    gamma_after_status = gamma.get_status()

    # compare statuses
    alpha_after_status["balance"] == alpha_before_status["balance"] + 27
    beta_after_status["balance"] == beta_before_status["balance"] - 40
    gamma_after_status["balance"] == gamma_before_status["balance"] + 5

    # close alpha payment channel
    assert alpha.close() is not None  # commit txid returned (block created)
    assert len(alpha.update()) == 0  # payout delay not yet passed
    for i in range(alpha.c2h_commit_delay_time - 1):  # let payout delay pass
        util_test.create_next_block(server_db)
    assert len(alpha.update()) == 1  # payout txid

    # close beta payment channel
    assert beta.close() is not None  # commit txid returned (block created)
    assert len(beta.update()) == 0  # payout delay not yet passed
    for i in range(beta.c2h_commit_delay_time - 1):  # let payout delay pass
        util_test.create_next_block(server_db)
    assert len(beta.update()) == 1  # payout txid

    # close gamma payment channel
    assert gamma.close() is not None  # commit txid returned (block created)
    assert len(gamma.update()) == 0  # payout delay not yet passed
    for i in range(gamma.c2h_commit_delay_time - 1):  # let payout delay pass
        util_test.create_next_block(server_db)
    assert len(gamma.update()) == 1  # payout txid

    # hub close connections cron
    cron.run_all()
    assert len(api.mph_connections()) == 0

    # recover c2h change
    assert len(alpha.update()) == 1  # txid
    assert len(beta.update()) == 1  # txid
    assert len(gamma.update()) == 1  # txid