-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8ebab6
commit 6587612
Showing
9 changed files
with
154 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ compiler: | |
remappings: | ||
- "@chainlink=smartcontractkit/[email protected]" | ||
- "@openzeppelin=OpenZeppelin/[email protected]" | ||
dotenv: .env | ||
networks: | ||
default: development | ||
development: | ||
|
@@ -17,6 +18,7 @@ networks: | |
link_token: "0x01BE23585060835E02B77ef475b0Cc51aA1e0709" | ||
keyhash: "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311" | ||
fee: 1_000_000_000_000_000_00 | ||
verify: true | ||
mainnet-fork: | ||
eth_usd_price_feed: "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" | ||
wallets: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pragma solidity ^0.6.6; | ||
|
||
interface LinkTokenInterface { | ||
function allowance(address owner, address spender) external view returns (uint256 remaining); | ||
function approve(address spender, uint256 value) external returns (bool success); | ||
function balanceOf(address owner) external view returns (uint256 balance); | ||
function decimals() external view returns (uint8 decimalPlaces); | ||
function decreaseApproval(address spender, uint256 addedValue) external returns (bool success); | ||
function increaseApproval(address spender, uint256 subtractedValue) external; | ||
function name() external view returns (string memory tokenName); | ||
function symbol() external view returns (string memory tokenSymbol); | ||
function totalSupply() external view returns (uint256 totalTokensIssued); | ||
function transfer(address to, uint256 value) external returns (bool success); | ||
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success); | ||
function transferFrom(address from, address to, uint256 value) external returns (bool success); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from brownie import network | ||
import pytest | ||
from scripts.helpers import LOCAL_BLOCKCHAIN_ENVIRONMENTS, get_account, get_contract, fund_with_link | ||
import time | ||
from scripts.deploy_lottery import deploy_lottery | ||
|
||
def test_can_pick_winner(): | ||
if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS: | ||
pytest.skip() | ||
lottery = deploy_lottery() | ||
account = get_account() | ||
lottery.startLottery({'from': account}) | ||
lottery.enter({'from':account, 'value': lottery.getEntranceFee()}) | ||
lottery.enter({'from':account, 'value': lottery.getEntranceFee()}) | ||
fund_with_link(lottery) | ||
lottery.endLottery({'from': account}) | ||
time.sleep(130) | ||
assert lottery.recentWinner() == account | ||
assert lottery.balance() == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from brownie import Lottery,accounts, config, network, exceptions | ||
from scripts.deploy_lottery import deploy_lottery | ||
from scripts.helpers import LOCAL_BLOCKCHAIN_ENVIRONMENTS, get_account, fund_with_link, get_contract | ||
from web3 import Web3 | ||
import pytest | ||
|
||
def test_get_entrance_fee(): | ||
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS: | ||
pytest.skip() | ||
# Arrange | ||
lottery = deploy_lottery() | ||
# Act | ||
# 50/4460 = | ||
expected_entrance_fee = Web3.toWei(0.025, 'ether') | ||
print(f"exp fee: {Web3.fromWei(expected_entrance_fee, 'ether')}") | ||
entrance_fee = lottery.getEntranceFee() | ||
print(f"ent fee: {Web3.fromWei(entrance_fee, 'ether')}") | ||
#Assert | ||
assert expected_entrance_fee == entrance_fee | ||
|
||
def test_cant_enter_unless_started(): | ||
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS: | ||
pytest.skip() | ||
lottery = deploy_lottery() | ||
with pytest.raises(exceptions.VirtualMachineError): | ||
lottery.enter({'from':get_account(), 'value': lottery.getEntranceFee()}) | ||
|
||
def test_can_start_and_enter_lottery(): | ||
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS: | ||
pytest.skip() | ||
lottery = deploy_lottery() | ||
account = get_account() | ||
lottery.startLottery({'from': account}) | ||
lottery.enter({'from':account, 'value': lottery.getEntranceFee()}) | ||
assert lottery.players(0) == account | ||
|
||
def test_can_end_lottery(): | ||
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS: | ||
pytest.skip() | ||
lottery = deploy_lottery() | ||
account = get_account() | ||
lottery.startLottery({'from': account}) | ||
lottery.enter({'from': account, 'value': lottery.getEntranceFee()}) | ||
fund_with_link(lottery) | ||
lottery.endLottery({'from': account}) | ||
assert lottery.lottery_state() == 2 | ||
|
||
def test_can_pick_winner_correctly(): | ||
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS: | ||
pytest.skip() | ||
lottery = deploy_lottery() | ||
account = get_account() | ||
lottery.startLottery({'from': account}) | ||
lottery.enter({'from': account, 'value': lottery.getEntranceFee()}) | ||
lottery.enter({'from': get_account(index=1), 'value': lottery.getEntranceFee()}) | ||
lottery.enter({'from': get_account(index = 2), 'value': lottery.getEntranceFee()}) | ||
fund_with_link(lottery) | ||
transaction = lottery.endLottery({'from': account}) | ||
request_id = transaction.events['RequestedRandomness']['requestId'] | ||
STATIC_RNG = 777 | ||
get_contract('vrf_coordinator').callBackWithRandomness(request_id, STATIC_RNG, lottery.address, {'from': account}) | ||
starting_balance_of_account = account.balance() | ||
balance_of_lottery = lottery.balance() | ||
# 777 % 3 = 0 - account will be the winner | ||
assert lottery.recentWinner() == account | ||
assert lottery.balance() == 0 | ||
assert account.balance() == starting_balance_of_account + balance_of_lottery |