Replies: 1 comment
-
Hello @realglass cheers. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! to the end of lesson 7 , when I try to test "test_can_pick_winner" I am getting this error back. I am trying to deploy on rinkeby as instructed by the video.
Thank you so much for the help!
This is my code:

helpful scripts:
from brownie import (
network,
config,
accounts,
MockV3Aggregator,
Contract,
VRFCoordinatorMock,
LinkToken,
interface,
)
from web3 import Web3
FORKED_LOCAL_ENVIRONMENTS = ["mainnet-fork"]
LOCAL_BLOCKCHAIN_ENVIROMENTS = ["development", "ganache=local"]
DECIMALS = 8
STARTING_PRICE = 200000000000
contract_to_mock = {
"eth_usd_price_feed": MockV3Aggregator,
"vrf_coordinator": VRFCoordinatorMock,
"link_token": LinkToken,
}
def get_account(index=None, id=None):
if index:
return accounts[index]
if id:
return accounts.load(id)
if (
network.show_active() in LOCAL_BLOCKCHAIN_ENVIROMENTS
or network.show_active() in FORKED_LOCAL_ENVIRONMENTS
):
return accounts[0]
def get_contract(contract_name):
DECIMALS = 8
INITIAL_VALUE = 200000000000
def deploy_mocks(decimals=DECIMALS, initial_value=INITIAL_VALUE):
account = get_account()
MockV3Aggregator.deploy(decimals, initial_value, {"from": account})
link_token = LinkToken.deploy({"from": account})
VRFCoordinatorMock.deploy(link_token.address, {"from": account})
print("Deployed!")
def fund_with_link(
contract_address, account=None, link_token=None, amount=100000000000000000
): # 0.1 link
account = account if account else get_account()
link_token = link_token if link_token else get_contract("link_token")
tx = link_token.transfer(contract_address, amount, {"from": account})
# link_token_contract = interface.LinkTokenInterface(link_token.address)
# tx = link_token_contract.transfer(contract_address, amount, {"from": account})
tx.wait(1)
print("Fund contract!")
return tx
lottery contract:
//SPDX-License-Identifier: MIT
pragma solidity ^0.6.6;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";
contract Lottery is VRFConsumerBase, Ownable {
address payable[] public players;
address payable public recentWinner;
uint256 public usdEntryFee;
uint256 public randomness;
}
test lottery integration:
from brownie import network
from scripts.helpful_scripts import (
LOCAL_BLOCKCHAIN_ENVIROMENTS,
get_account,
fund_with_link,
)
from scripts.deploy_lottery import deploy_lottery
import pytest
import time
def test_can_pick_winner():
if network.show_active() in LOCAL_BLOCKCHAIN_ENVIROMENTS:
pytest.skip()
lottery = deploy_lottery()
account = get_account()
lottery.startLottery({"from": account})
lottery.enter({"from": account, "value": lottery.getEntraceFee()})
lottery.enter({"from": account, "value": lottery.getEntraceFee()})
fund_with_link(lottery)
lottery.endLottery({"from": account})
time.sleep(60)
assert lottery.recentWinner() == account
assert lottery.balance() == 0
deploy lottery:
from scripts.helpful_scripts import get_account, get_contract, fund_with_link
from brownie import Lottery, network, config
import time
def deploy_lottery():
account = get_account()
lottery = Lottery.deploy(
get_contract("eth_usd_price_feed").address,
get_contract("vrf_coordinator").address,
get_contract("link_token").address,
config["networks"][network.show_active()]["fee"],
config["networks"][network.show_active()]["keyhash"],
{"from": account},
publish_source=config["networks"][network.show_active()].get("verify", False),
)
print("Deployed lottery!")
return lottery
def start_lottery():
account = get_account()
lottery = Lottery[-1]
starting_tx = lottery.startLottery({"from": account})
starting_tx.wait(1)
print("The lottery is started!")
def enter_lottery():
account = get_account()
lottery = Lottery[-1]
value = lottery.getEntranceFee() + 100000
tx = lottery.enter({"from": account, "value": value})
tx.wait(1)
print("You entered the lottery!")
def end_lottery():
account = get_account()
lottery = Lottery[-1]
tx = fund_with_link(lottery.address)
tx.wait(1)
ending_transaction = lottery.endLottery({"from": account})
ending_transaction.wait(1)
time.sleep(60)
print(f"{lottery.recentWinner()} is the new winner!")
def main():
deploy_lottery()
start_lottery()
enter_lottery()
end_lottery()
Beta Was this translation helpful? Give feedback.
All reactions