Exemplo n.º 1
0
def test_free_money_success(
    dapp_registry: Registry,
    key_manager: KeyManager,
):
    """
    ARRANGE
    """
    receiver_address = key_manager.generate()
    receiver_initial_balance = 100
    free_money_amount = 100
    what_is_this_id = str(uuid4())

    transform = FreeMoney(
        receiver=receiver_address,
        amount=free_money_amount,
    )

    # Initialize the environment.
    state = create_state(dapp_registry)

    balance_state = state[BalanceModel.fqdn]

    balance_state[receiver_address] = BalanceModel(
        balance=receiver_initial_balance)
    """
    ACT
    """
    execute_transform(transform, state)

    the_receiver: BalanceModel = balance_state[receiver_address]
    """
    ASSERT
    """
    assert the_receiver.balance == receiver_initial_balance + free_money_amount
def test_kiwi_claim_id_not_found_error(
        dapp_registry: Registry,
        key_manager: KeyManager,
):
    #arrange
    claimer_address = key_manager.generate()

    transform = ClaimKiwi(
        claimer=claimer_address,
        kiwi_id="thisIDdoesnotexist"
    )

    config_file = (Path(crypto_kiwis.__path__[0]) / ".." / "config.yaml").resolve()
    config = Config(DEVELOP_NETWORK).load(config_file)
    state = create_state(dapp_registry, config['plug']['initial_state'])

    before_length_unclaimed = len(state[KiwiCollectionModel.fqdn]["_unclaimed"].kiwis)

    #act
    with pytest.raises(KiwiNotFoundError):
        execute_transform(transform, state)

    remaining_unclaimed = state[KiwiCollectionModel.fqdn]["_unclaimed"].kiwis
    #assert
    assert len(remaining_unclaimed) == before_length_unclaimed
def test_claim_initial_kiwi_success(
        dapp_registry: Registry,
        key_manager: KeyManager,
):
    #arrange
    claimer_address = key_manager.generate()

    transform = ClaimKiwi(
        claimer=claimer_address,
        kiwi_id="A123"
    )

    config_file = (Path(crypto_kiwis.__path__[0]) / ".." / "config.yaml").resolve()
    config = Config(DEVELOP_NETWORK).load(config_file)
    state = create_state(dapp_registry, config['plug']['initial_state'])

    before_length_unclaimed = len(state[KiwiCollectionModel.fqdn]["_unclaimed"].kiwis)

    #act
    execute_transform(transform, state)

    kiwi: KiwiModel = state[KiwiModel.fqdn]["A123"]

    remaining_unclaimed = state[KiwiCollectionModel.fqdn]["_unclaimed"].kiwis
    remaining_unclaimed_ids = [x['id'] for x in state[KiwiCollectionModel.fqdn]["_unclaimed"].kiwis if x['id'] != "A123"]
    #assert

    assert "A123" not in remaining_unclaimed_ids
    assert kiwi['owner_address'] == claimer_address
    assert len(remaining_unclaimed) == before_length_unclaimed - 1
Exemplo n.º 4
0
def test_balance_transfer_zero_money_error(
    dapp_registry: Registry,
    key_manager: KeyManager,
):
    """
    ARRANGE
    """
    #Define fake values for the transform
    sender_address = key_manager.generate()
    sender_initial_balance = 100
    receiver_initial_balance = 100
    receiver_address = key_manager.generate()
    send_amount = 0
    what_is_this_id = str(uuid4())

    ##Build the Transform
    transform = BalanceTransfer(
        sender=sender_address,
        receiver=receiver_address,
        amount=send_amount,
    )

    #Create a fake state
    state = create_state(dapp_registry)

    balance_state = state[BalanceModel.fqdn]
    #Set Initial Balance for Sender
    balance_state[sender_address] = BalanceModel(
        balance=sender_initial_balance)
    #Set Inital Balance for receiver
    balance_state[receiver_address] = BalanceModel(
        balance=receiver_initial_balance)
    """
    ACT
    """
    #Run the Transform
    with pytest.raises(InvalidAmountError):
        execute_transform(transform, state)

    #Define the balance models of the sender and receiver
    the_receiver: BalanceModel = balance_state[receiver_address]
    the_sender: BalanceModel = balance_state[sender_address]
    """
    ASSERT
    """
    assert the_receiver.balance == receiver_initial_balance
    assert the_sender.balance == sender_initial_balance
def test_kiwi_claim_id_not_found_error(
        dapp_registry: Registry,
        key_manager: KeyManager,
):
    #arrange
    claimer_address = key_manager.generate()

    transform = ClaimKiwi(
        claimer=claimer_address,
        kiwi_id="B234"
    )

    config_file = (Path(crypto_kiwis.__path__[0]) / ".." / "config.yaml").resolve()
    config = Config(DEVELOP_NETWORK).load(config_file)
    state = create_state(dapp_registry, config['plug']['initial_state'])

    unclaimed_kiwis = state[KiwiCollectionModel.fqdn]["_unclaimed"].kiwis
    claim_kiwi = unclaimed_kiwis[0]
    unclaimed_kiwis.remove(claim_kiwi)

    claimed_kiwis = state[KiwiModel.fqdn]
    state[KiwiModel.fqdn][claimer_address] = KiwiModel(
        id="A123",
        name=claim_kiwi['name'],
        owner_address=claimer_address,
        colour="blue",
        size=1

    )

    before_length_unclaimed = len(state[KiwiCollectionModel.fqdn]["_unclaimed"].kiwis)

    #act
    with pytest.raises(KiwiAlreadyClaimedError):
        execute_transform(transform, state)

    remaining_unclaimed = state[KiwiCollectionModel.fqdn]["_unclaimed"].kiwis
    #assert
    assert len(remaining_unclaimed) == before_length_unclaimed