Cyfrin / foundry-smart-contract-lottery-cu

47 stars 38 forks source link

Integration tests #7

Closed ShayanShamsi closed 1 year ago

ShayanShamsi commented 1 year ago

Hello!

I wrote some integration tests. Please check if they are ok.

I am dealing with some difficulties in testing the FundSubscription contract. The code for testing it is commented out as you can see. I will change it and push again based on feedback. The test was reverting with the InvalidSubscription() error from VRFCoordinatorV2Mock. Upon investigation, I found that the error is triggered in the fundSubscription method when the owner of a subscription is address(0). Here is the snippet from VRFCoordinatorV2Mock:

function fundSubscription(uint64 _subId, uint96 _amount) public {
    if (s_subscriptions[_subId].owner == address(0)) {
      revert InvalidSubscription();
    }
    uint96 oldBalance = s_subscriptions[_subId].balance;
    s_subscriptions[_subId].balance += _amount;
    emit SubscriptionFunded(_subId, oldBalance, oldBalance + _amount);
  }

Now, the question is how can the owner of the subscriptionId be address(0) when the subscription was created successfully as indicated by the uncommented assert (that assert is passing)? Can someone provide their valuable opinion on how I might implement the interactions test successfully?

PatrickAlphaC commented 1 year ago

Thanks for this!!

To allow others to keep attempting the challenges though, I'm going to close this PR.

I'll let you keep exploring, but nice work!