コード例 #1
0
def setup_state_with_open_channel(context: Context) -> Context:
    create_default_token_network(context)
    event = ReceiveChannelOpenedEvent(
        token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS,
        channel_identifier=DEFAULT_CHANNEL_IDENTIFIER,
        participant1=DEFAULT_PARTICIPANT1,
        participant2=DEFAULT_PARTICIPANT2,
        settle_timeout=DEFAULT_SETTLE_TIMEOUT,
        block_number=BlockNumber(42),
    )
    assert context.db.channel_count() == 0

    channel_opened_event_handler(event, context)

    return context
コード例 #2
0
def test_channel_opened_event_handler_adds_channel(context: Context):
    create_default_token_network(context)
    event = ReceiveChannelOpenedEvent(
        token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS,
        channel_identifier=DEFAULT_CHANNEL_IDENTIFIER,
        participant1=DEFAULT_PARTICIPANT1,
        participant2=DEFAULT_PARTICIPANT2,
        block_number=BlockNumber(42),
    )

    assert context.database.channel_count() == 0
    channel_opened_event_handler(event, context)

    assert context.database.channel_count() == 1
    assert_channel_state(context, ChannelState.OPENED)
コード例 #3
0
def setup_state_with_open_channel(context: Context) -> Context:
    create_default_token_network(context)
    event = ReceiveChannelOpenedEvent(
        token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS,
        channel_identifier=DEFAULT_CHANNEL_IDENTIFIER,
        participant1=DEFAULT_PARTICIPANT1,
        participant2=DEFAULT_PARTICIPANT2,
        block_number=BlockNumber(42),
    )
    assert context.database.channel_count() == 0

    channel_opened_event_handler(event, context)
    context.web3.eth.get_block = lambda x: Mock(
        timestamp=context.web3.eth.block_number * 15 if x == "latest" else x * 15
    )

    return context