Beispiel #1
0
def test_can_pick_winner_correctly(check_local_blockchain_envs, lottery_contract):
    # Arrange (by fixtures)

    account = get_account()
    lottery_contract.startLottery({"from": account})
    lottery_contract.enter(
        {"from": account, "value": lottery_contract.getEntranceFee()}
    )
    lottery_contract.enter(
        {"from": get_account(index=1), "value": lottery_contract.getEntranceFee()}
    )
    lottery_contract.enter(
        {"from": get_account(index=2), "value": lottery_contract.getEntranceFee()}
    )
    fund_with_link(lottery_contract)
    starting_balance_of_account = account.balance()
    balance_of_lottery = lottery_contract.balance()
    transaction = lottery_contract.endLottery({"from": account})
    request_id = transaction.events["RequestedRandomness"]["requestId"]
    STATIC_RNG = 777
    get_contract("vrf_coordinator").callBackWithRandomness(
        request_id, STATIC_RNG, lottery_contract.address, {"from": account}
    )
    # 777 % 3 = 0
    assert lottery_contract.recentWinner() == account
    assert lottery_contract.balance() == 0
    assert account.balance() == starting_balance_of_account + balance_of_lottery
Beispiel #2
0
def test_can_end_lottery(check_local_blockchain_envs, lottery_contract):
    # Arrange (by fixtures)

    account = get_account()
    lottery_contract.startLottery({"from": account})
    lottery_contract.enter(
        {"from": account, "value": lottery_contract.getEntranceFee()}
    )
    fund_with_link(lottery_contract)
    lottery_contract.endLottery({"from": account})
    assert lottery_contract.lottery_state() == 2
def main():
    dev = accounts.add(config["wallets"]["from_key"])
    print(network.show_active())
    advanced_collectible = AdvancedCollectible.deploy(
        config["networks"][network.show_active()]["vrf_coordinator"],
        config["networks"][network.show_active()]["link_token"],
        config["networks"][network.show_active()]["keyhash"],
        {"from": dev},
        publish_source=get_publish_source(),
    )
    fund_with_link(advanced_collectible.address)
    return advanced_collectible
def test_returns_random_number_testnet(get_keyhash, ):
    # Arrange
    if network.show_active() not in ["kovan", "rinkeby", "ropsten"]:
        pytest.skip("Only for testnet testing")
    vrf_consumer = VRFConsumer.deploy(
        get_keyhash,
        get_contract("vrf_coordinator").address,
        get_contract("link_token").address,
        config["networks"][network.show_active()]["fee"],
        {"from": get_account()},
    )
    tx = fund_with_link(
        vrf_consumer.address,
        amount=config["networks"][network.show_active()]["fee"])
    tx.wait(1)
    # Act
    transaction_receipt = vrf_consumer.getRandomNumber({"from": get_account()})
    assert isinstance(transaction_receipt.txid, str)
    transaction_receipt.wait(1)
    event_response = listen_for_event(vrf_consumer, "ReturnedRandomness")

    # Assert
    assert event_response.event is not None
    assert vrf_consumer.randomResult() > 0
    assert isinstance(vrf_consumer.randomResult(), int)
def main():
    dev = accounts.add(config["wallets"]["from_key"])
    advanced_collectible = AdvancedCollectible[len(AdvancedCollectible) - 1]
    fund_with_link(advanced_collectible.address)
    transaction = advanced_collectible.createCollectible("None", {"from": dev})
    print("Waiting on second transaction...")
    # wait for the 2nd transaction
    transaction.wait(1)
    # time.sleep(35)
    listen_for_event(advanced_collectible,
                     "ReturnedCollectible",
                     timeout=200,
                     poll_interval=10)
    requestId = transaction.events["RequestedCollectible"]["requestId"]
    token_id = advanced_collectible.requestIdToTokenId(requestId)
    breed = get_breed(advanced_collectible.tokenIdToBreed(token_id))
    print("Dog breed of tokenId {} is {}".format(token_id, breed))
def main():
    account = get_account()
    api_contract = APIConsumer[-1]
    tx = fund_with_link(
        api_contract.address,
        amount=config["networks"][network.show_active()]["fee"])
    tx.wait(1)
    request_tx = api_contract.requestVolumeData({"from": account})
    request_tx.wait(1)
Beispiel #7
0
def test_can_pick_winner(check_local_blockchain_envs, lottery_contract):
    # Arrange (by fixtures)

    account = get_account()
    lottery_contract.startLottery({"from": account})
    lottery_contract.enter({
        "from": account,
        "value": lottery_contract.getEntranceFee()
    })
    lottery_contract.enter({
        "from": account,
        "value": lottery_contract.getEntranceFee()
    })
    fund_with_link(lottery_contract)
    lottery_contract.endLottery({"from": account})
    time.sleep(180)
    assert lottery_contract.recentWinner() == account
    assert lottery_contract.balance() == 0
def main():
    account = get_account()
    vrf_contract = VRFConsumer[-1]
    tx = fund_with_link(
        vrf_contract.address, amount=config["networks"][network.show_active()]["fee"]
    )
    tx.wait(1)
    vrf_contract.getRandomNumber({"from": account})
    print("Requested!")
def end_lottery():
    account = get_account()
    lottery = Lottery[-1]
    # fund the contract
    # then end the lottery
    tx = fund_with_link(lottery.address)
    tx.wait(1)
    ending_transaction = lottery.endLottery({"from": account})
    ending_transaction.wait(1)
    time.sleep(180)
    print(f"{lottery.recentWinner()} is the new winner!")
def test_send_api_request_testnet(deploy_api_contract, chainlink_fee):
    # Arrange
    if network.show_active() not in ["kovan", "rinkeby", "mainnet"]:
        pytest.skip("Only for local testing")
    api_contract = deploy_api_contract

    if (config["networks"][network.show_active()].get("verify", False)):
        APIConsumer.publish_source(api_contract)

    tx = fund_with_link(
        api_contract.address, amount=chainlink_fee
    )
    tx.wait(1)
    # Act
    transaction = api_contract.requestVolumeData({"from": get_account()})
    transaction.wait(1)

    # Assert
    event_response = listen_for_event(api_contract, "DataFullfilled")
    assert event_response.event is not None
    assert isinstance(api_contract.volume(), int)
    assert api_contract.volume() > 0
def main():
    advanced_collectible = AdvancedCollectible[len(AdvancedCollectible) - 1]
    fund_with_link(advanced_collectible.address)