Replies: 3 comments 10 replies
-
Hello @miladad8, The test is failing because of how you set it up. Let's understand what your test is doing. I will comment on your test to explain what your test does. function testCantDeployVrfcoordinatorMockIfExists() public {
//Here, you are getting out all the values in the `activeNetworkConfig.` This means you have initialized an `HelperConfig` in your `setup` function, most likely
(
uint256 _entranceFee,
uint256 _interval,
address _vrfCoordinator,
bytes32 _gasLane,
uint64 _subscriptionId,
uint32 _callbackGasLimit,
address _link
) = helperConfig.activeNetworkConfig();
// Here, you declare a variable named `baseFee,` and you set it to `0.25 ether.`
uint96 baseFee = 0.25 ether;
// Here, you declared a variable named `gasPriceLink` and set it to `1e9.`
uint96 gasPriceLink = 1e9;
// Here, you check to see if the `_vrfCoordinator` variable you get from the `helperConfig.activeNetworkConfig()` is not `address(0)`, If so you enter the code of block
if (_vrfCoordinator != address(0)) {
// Here, you tell your test to expect a revert, so now the test is patiently waiting for some transaction to revert so that your test will pass
vm.expectRevert();
// Here you prank `USER` to send the transaction that comes next
vm.prank(USER);
// Here, you created a new `VRFCoordinatorV2Mock` and passed in all the necessary arguments to initialize a contract of type `VRFCoordinatorV2Mock`. The contract was created, and the transaction didn't revert
new VRFCoordinatorV2Mock(baseFee, gasPriceLink);
// Your whole process finishes running, and nothing reverts while you have told your test to expect a revert. Your test concluded that the test failed since it didn't revert as you expected.
} Testing the code below can be tricky. if (activeNetworkConfig.vrfCoordinator != address(0)) {
return activeNetworkConfig;
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
This line of code |
Beta Was this translation helpful? Give feedback.
4 replies
-
If anything is Confusing, please ask questions. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been playing around with my test and I don't get it why it doesn't revert. In
HelperConfig
file lesson 9 when we are trying to set our Anvil chain configuration, first we check:I am trying to write a test for this line of code to check that we couldn't deploy a new
vrfCoordinatorMock
if we already deployed one and if we try to deploy one we should expect a revert. below is my test:But test fails. However when I set
_vrfCoordinator == address(0)
, the test passed successfully.I was thinking it should be reversed. what am I missing here?
Any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions