def test_returns_random_number_testnet( get_account, get_vrf_coordinator, get_keyhash, get_link_token, chainlink_fee, get_seed, ): # Arrange if network.show_active() not in ["kovan", "rinkeby"]: pytest.skip("Only for testnet testing") vrf_consumer = VRFConsumer.deploy( get_keyhash, get_vrf_coordinator.address, get_link_token.address, {"from": get_account}, ) get_link_token.transfer(vrf_consumer.address, chainlink_fee * 3, {"from": get_account}) # Act transaction_receipt = vrf_consumer.getRandomNumber(get_seed, {"from": get_account}) assert isinstance(transaction_receipt.txid, str) transaction_receipt.wait(1) time.sleep(35) # Assert assert vrf_consumer.randomResult() > 0 assert isinstance(vrf_consumer.randomResult(), int)
def main(): dev = accounts.add(os.getenv(config['wallets']['from_key'])) print(network.show_active()) return VRFConsumer.deploy( config['networks'][network.show_active()]['keyhash'], config['networks'][network.show_active()]['vrf_coordinator'], config['networks'][network.show_active()]['link_token'], {'from': dev})
def test_returns_random_number_local( get_account, get_vrf_coordinator, get_keyhash, get_link_token, chainlink_fee, get_seed, ): # Arrange if network.show_active() not in ["development" ] or "fork" in network.show_active(): pytest.skip("Only for local testing") vrf_consumer = VRFConsumer.deploy( get_keyhash, get_vrf_coordinator.address, get_link_token.address, {"from": get_account}, ) get_link_token.transfer(vrf_consumer.address, chainlink_fee * 3, {"from": get_account}) # Act transaction_receipt = vrf_consumer.getRandomNumber(get_seed, {"from": get_account}) requestId = vrf_consumer.getRandomNumber.call(get_seed, {"from": get_account}) assert isinstance(transaction_receipt.txid, str) get_vrf_coordinator.callBackWithRandomness(requestId, 777, vrf_consumer.address, {"from": get_account}) # Assert assert vrf_consumer.randomResult() > 0 assert isinstance(vrf_consumer.randomResult(), int)
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"]) print(network.show_active()) return VRFConsumer.deploy( config["networks"][network.show_active()]["keyhash"], config["networks"][network.show_active()]["vrf_coordinator"], config["networks"][network.show_active()]["link_token"], {"from": dev}, publish_source=config["verify"], )
def test_can_request_random_number(get_account, get_vrf_coordinator, get_keyhash, get_link_token, chainlink_fee, get_seed): # Arrange vrf_consumer = VRFConsumer.deploy( get_keyhash, get_vrf_coordinator.address, get_link_token.address, {'from': get_account}) get_link_token.transfer(vrf_consumer.address, chainlink_fee * 3, {'from': get_account}) # Act requestId = vrf_consumer.getRandomNumber.call( get_seed, {'from': get_account}) assert isinstance(requestId, convert.datatypes.HexString)
def depoly_vrf(): account = get_account() print(f"On network {network.show_active()}") keyhash = config["networks"][network.show_active()]["keyhash"] fee = config["networks"][network.show_active()]["fee"] vrf_coordinator = get_contract("vrf_coordinator") link_token = get_contract("link_token") vrf_consumer = VRFConsumer.deploy( keyhash, vrf_coordinator, link_token, fee, {"from": account}, ) if (config["networks"][network.show_active()].get("verify", False)): vrf_consumer.tx.wait(BLOCK_CONFIRMATIONS_FOR_VERIFICATION) VRFConsumer.publish_source(vrf_consumer) else: vrf_consumer.tx.wait(1)
def deploy_vrf_contract(get_testnet_account): # Arrange if network.show_active() != 'kovan': pytest.skip('Only works for kovan network') # Act vrf_consumer = VRFConsumer.deploy(config['networks']['kovan']['keyhash'], config['networks']['kovan']['vrf_coordinator'], config['networks']['kovan']['link_token'], {'from': get_testnet_account}) # Assert assert vrf_consumer is not None return vrf_consumer
def test_can_request_random_number(get_keyhash, chainlink_fee): # Arrange vrf_consumer = VRFConsumer.deploy( get_keyhash, get_contract("vrf_coordinator").address, get_contract("link_token").address, chainlink_fee, {"from": get_account()}, ) get_contract("link_token").transfer(vrf_consumer.address, chainlink_fee * 3, {"from": get_account()}) # Act requestId = vrf_consumer.getRandomNumber.call({"from": get_account()}) assert isinstance(requestId, convert.datatypes.HexString)
def test_returns_random_number_local(get_keyhash, chainlink_fee): # Arrange if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS: pytest.skip("Only for local testing") vrf_consumer = VRFConsumer.deploy( get_keyhash, get_contract("vrf_coordinator").address, get_contract("link_token").address, chainlink_fee, {"from": get_account()}, ) get_contract("link_token").transfer(vrf_consumer.address, chainlink_fee * 3, {"from": get_account()}) # Act transaction_receipt = vrf_consumer.getRandomNumber({"from": get_account()}) # requestId = vrf_consumer.getRandomNumber.call({"from": get_account()}) requestId = transaction_receipt.return_value assert isinstance(transaction_receipt.txid, str) get_contract("vrf_coordinator").callBackWithRandomness( requestId, 777, vrf_consumer.address, {"from": get_account()}) # Assert assert vrf_consumer.randomResult() > 0 assert isinstance(vrf_consumer.randomResult(), int)