Example #1
0
def test_send_payment_between_vasps(lrw1, lrw2, vasp1, vasp2, user1, user2):
    sender_address = lrw1.context.config.vasp_diem_address()
    receiver_address = lrw2.context.config.vasp_diem_address()
    receiver_subaddress = generate_new_subaddress(account_id=user2.account_id)

    # setup global environment as lrw1 app
    context.set(lrw1.context)
    client.set(vasp1)

    txn = send_transaction(
        sender_id=user1.account_id,
        amount=2_000_000_000,
        currency=DiemCurrency.Coin1,
        destination_address=receiver_address.get_onchain_address_hex(),
        destination_subaddress=receiver_subaddress,
    )

    assert txn
    assert txn.off_chain
    assert len(txn.off_chain) == 1
    assert txn.off_chain[0].reference_id

    reference_id = txn.off_chain[0].reference_id

    num_tries = 20
    while num_tries > 1:
        txn = get_single_transaction(txn.id)
        if txn.status == TransactionStatus.COMPLETED:
            break
        num_tries -= 1
        time.sleep(1)

    payment = vasp1.get_payment_by_ref(reference_id)
    assert payment.sender.status.as_status() == Status.ready_for_settlement
    assert payment.receiver.status.as_status() == Status.ready_for_settlement

    payment = vasp2.get_payment_by_ref(reference_id)
    assert payment.sender.status.as_status() == Status.ready_for_settlement
    assert payment.receiver.status.as_status() == Status.ready_for_settlement
def test_get_set():
    ctx = context.from_env()
    context.set(ctx)
    assert context.get() == ctx
Example #3
0
def env_context():
    yield
    # always clean up global variables for making
    # sure tests won't depend on each other
    context.set(None)
Example #4
0
def env_context() -> typing.Generator[typing.Any, None, None]:
    context.set(context.from_env())
    yield
    context.set(None)
Example #5
0
def _init_context():
    context.set(context.from_env())
Example #6
0
ADMIN_LOGIN_ENABLED: bool = (
    True if os.getenv("ADMIN_LOGIN_ENABLED") is not None else False
)

SECRET_KEY: str = os.getenv("SECRET_KEY", "you-will-never-guess")
SESSION_TYPE: str = "redis"


# init redis and dramatiq broker
def setup_redis_broker() -> None:
    _connection_pool: redis.BlockingConnectionPool = redis.BlockingConnectionPool(
        host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, password=REDIS_PASSWORD
    )
    _redis_db: redis.StrictRedis = redis.StrictRedis(connection_pool=_connection_pool)
    _result_backend = RedisBackend(encoder=PickleEncoder(), client=_redis_db)
    _result_middleware = Results(backend=_result_backend)
    broker: Broker = RedisBroker(
        connection_pool=_connection_pool,
        middleware=[_result_middleware],
        namespace="lrw",
    )
    dramatiq.set_broker(broker)
    dramatiq.set_encoder(dramatiq.PickleEncoder())


if dramatiq.broker.global_broker is None:
    if "VASP_ADDR" in os.environ:
        context.set(context.from_env())

    setup_redis_broker()