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))
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))
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
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' )
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
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))
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))
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)
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))
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)
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)
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)
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)
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')
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)
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))
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))