コード例 #1
0
def sequence_of_transfers(context):
    expected_transfers = {(wallet_from_name(context, row['source']),
                           wallet_from_name(context, row['destination']),
                           Decimal(row['amount']))
                          for row in context.table}

    actual_transfers = {(transfer.source, transfer.destination,
                         transfer.amount)
                        for transfer in context.leveller.proposed_transfers()}

    assert_that(actual_transfers, equal_to(expected_transfers))
コード例 #2
0
def proposed_transfers(context, transfer_amount, source, destination):
    source_wallet = wallet_from_name(context, source)
    destination_wallet = wallet_from_name(context, destination)

    transfers = list(context.leveller.proposed_transfers())

    assert_that(len(transfers), equal_to(1), 'One transfer expected')
    transfer = transfers[0]

    assert_that(transfer_amount, equal_to(transfer.amount))
    assert_that(source_wallet, equal_to(transfer.source))
    assert_that(destination_wallet, equal_to(transfer.destination))
コード例 #3
0
def connection_list(context):
    context.connections_correct = True
    for row in context.table:
        source_wallet = wallet_from_name(context, row['source'])
        destination_wallet = wallet_from_name(context, row['destination'])
        weight = int(row['weight']) if row['weight'] else 1

        try:
            context.leveller.connect(source_wallet, destination_wallet, weight)
        except DuplicateConnection:
            context.connections_correct = False

    context.connections_correct = context.connections_correct and context.leveller.is_valid
コード例 #4
0
def connection_list(context):
    context.connections_correct = True
    for row in context.table:
        source_wallet = wallet_from_name(context, row['source'])
        destination_wallet = wallet_from_name(context, row['destination'])
        weight = int(row['weight']) if row['weight'] else 1

        try:
            context.leveller.connect(source_wallet, destination_wallet, weight)
        except DuplicateConnection:
            context.connections_correct = False

    context.connections_correct = context.connections_correct and context.leveller.is_valid
コード例 #5
0
def introduce_funds(context, modified_wallet, payment_amount):
    wallet = wallet_from_name(context, modified_wallet)
    wallet.move_to_account(
        DEFAULT_ACCOUNT, context.account_names[modified_wallet],
        payment_amount,
        'Payment to/from test wallet'
    )
コード例 #6
0
def add_wallet(context, wallet_name, desired_level, low_water_mark, high_water_mark):
    wallet = wallet_from_name(context, wallet_name)
    try:
        context.leveller.add_wallet(wallet, desired_level, low_water_mark, high_water_mark)
    except ConflictingWaterMarks:
        context.watermark_conflict = True
    else:
        context.watermark_conflict = False
コード例 #7
0
def sequence_of_transfers(context):
    expected_transfers = {
        (
            wallet_from_name(context, row['source']),
            wallet_from_name(context, row['destination']),
            Decimal(row['amount'])
        )
        for row in context.table
    }

    actual_transfers = {
        (
            transfer.source,
            transfer.destination,
            transfer.amount
        )
        for transfer in context.leveller.proposed_transfers()
    }

    assert_that(actual_transfers, equal_to(expected_transfers))
コード例 #8
0
def check_balance_with_fee(context, wallet_name, expected_balance):
    wallet = wallet_from_name(context, wallet_name)
    assert_that(wallet.balance, equal_to(expected_balance + context.fee))
コード例 #9
0
def move_funds(context, transfer_amount, source, destination):
    source_wallet = wallet_from_name(context, source)
    destination_wallet = wallet_from_name(context, destination)

    context.transaction_id, context.fee = source_wallet.transfer_to(
        destination_wallet, transfer_amount)
コード例 #10
0
def check_balance(context, wallet_name, adjusted_balance):
    wallet = wallet_from_name(context, wallet_name)
    assert_that(context.leveller.adjusted_balance(wallet), equal_to(adjusted_balance))
コード例 #11
0
def add_wallet_no_hwm(context, desired_level, wallet_name, low_water_mark):
    wallet = wallet_from_name(context, wallet_name)
    context.leveller.add_wallet(wallet, desired_level, low_water_mark, None)
コード例 #12
0
def check_balance_with_fee(context, wallet_name, expected_balance):
    wallet = wallet_from_name(context, wallet_name)
    assert_that(wallet.balance, equal_to(expected_balance + context.fee))
コード例 #13
0
def connect_wallets(context, source, destination, link_weight):
    source_wallet = wallet_from_name(context, source)
    destination_wallet = wallet_from_name(context, destination)

    context.leveller.connect(source_wallet, destination_wallet, link_weight)
コード例 #14
0
def check_balance(context, wallet_name, adjusted_balance):
    wallet = wallet_from_name(context, wallet_name)
    assert_that(context.leveller.adjusted_balance(wallet),
                equal_to(adjusted_balance))
コード例 #15
0
def move_funds(context, transfer_amount, source, destination):
    source_wallet = wallet_from_name(context, source)
    destination_wallet = wallet_from_name(context, destination)

    context.transaction_id, context.fee = source_wallet.transfer_to(destination_wallet, transfer_amount)
コード例 #16
0
def add_wallet_no_lwm(context, desired_level, wallet_name, high_water_mark):
    wallet = wallet_from_name(context, wallet_name)
    context.leveller.add_wallet(wallet, desired_level, None, high_water_mark)
コード例 #17
0
def introduce_funds(context, modified_wallet, payment_amount):
    wallet = wallet_from_name(context, modified_wallet)
    wallet.move_to_account(DEFAULT_ACCOUNT,
                           context.account_names[modified_wallet],
                           payment_amount, 'Payment to/from test wallet')
コード例 #18
0
def leveller_moves_funds(context, transfer_amount, source, destination):
    # TODO which agent should be responsible for executing the transfers?
    source_wallet = wallet_from_name(context, source)
    destination_wallet = wallet_from_name(context, destination)

    context.transaction_id, context.fee = source_wallet.transfer_to(destination_wallet, transfer_amount)
コード例 #19
0
def required_funds(context, wallet_name, additional_amount):
    wallet = wallet_from_name(context, wallet_name)
    required = context.leveller.required_funds(wallet)

    assert_that(required, equal_to(additional_amount))
コード例 #20
0
def surplus_funds(context, wallet_name, surplus_amount):
    wallet = wallet_from_name(context, wallet_name)
    surplus = context.leveller.surplus_funds(wallet)

    assert_that(surplus, equal_to(surplus_amount))