Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 7: endLottery TEST what about the other accounts? #1803

Open
emilrueh opened this issue Dec 5, 2022 · 0 comments
Open

Lesson 7: endLottery TEST what about the other accounts? #1803

emilrueh opened this issue Dec 5, 2022 · 0 comments

Comments

@emilrueh
Copy link

emilrueh commented Dec 5, 2022

(Around the 08:10:00 mark in the tutorial video.)

Hi, wondering how we could test whether the other accounts pass as recentWinner when setting our STATIC_RNG to 778.

Right now we use 777 as the random value which with 3 players equals to index 0 therefore our standard account.
I also want to test if another index can be the winner or only our standard account.

Right now it is unclear if the test is indeed doing what we want and not only passing the standard account if selected as winner, right?


I tried below but but that throws a TypeError: 'Account' object is not subscriptable so I might just not know how to get the other added players index:

STATIC_RNG = 778
assert lottery.recentWinner() == account[1]

I also tried to use lottery.players to get a players address but that does not work.


The full code of that test:

def test_can_pick_winner_correctly():

    # ARRANGE
    if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
        pytest.skip()
    lottery = deploy_lottery()
    account = get_account()

    # ACT
    lottery.startLottery({"from": account})

    lottery.enterLottery({"from": account, "value": lottery.getEntranceFee()})
    lottery.enterLottery(
        {"from": get_account(index=1), "value": lottery.getEntranceFee()}
    )
    lottery.enterLottery(
        {"from": get_account(index=2), "value": lottery.getEntranceFee()}
    )

    fund_with_link(lottery)

    starting_balance_of_account = account.balance()
    balance_of_lottery = lottery.balance()

    transaction = lottery.end({"from": account})
    request_id = transaction.events["RequestedRandomness"]["requestId"]
    STATIC_RNG = 777
    get_contract("vrf_coordinator").callBackWithRandomness(
        request_id, STATIC_RNG, lottery.address, {"from": account}
    )
    print(lottery.players)  # just a test to see how to use it to get a player

    # ASSERT
    assert lottery.recentWinner() == account
    assert lottery.balance() == 0
    assert account.balance() == starting_balance_of_account + balance_of_lottery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant