Lesson 9 ----- [FAIL. Reason: InvalidConsumer()] testCantEnterRaffleWhenCalculating() #1728
-
Heres my Raffle.sol: ` // Layout of Contract: // Layout of Functions: // SPDX-License-Identifier: MIT /*
import {VRFCoordinatorV2Interface} from "@chainlink/contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol"; contract Raffle is VRFConsumerBaseV2 {
} my HelperConfig.s.sol: ` // SPDX-License-Identifier: SEE LICENSE IN LICENSE import {Script} from "forge-std/Script.sol"; contract HelperConfig is Script {
} my DeployRaffle.s.sol: ` // SPDX-License-Identifier: MIT import {Script} from "forge-std/Script.sol"; contract DeployRaffle is Script {
} my interactions.s.sol: ` // SPDX-License-Identifier: MIT import {Script,console} from "forge-std/Script.sol"; contract CreateSubscription is Script {
} contract FundSubscription is Script {
} contract AddConsumer is Script {
} ` and finally RaffleTest.t.sol: ` // SPDX-License-Identifier: MIT import {Test,console} from "forge-std/Test.sol"; contract RaffleTest is Test {
} if i run ` Ran 1 test for test/unit/RaffleTest.t.sol:RaffleTest Traces: [101937] RaffleTest::testCantEnterRaffleWhenCalculating() Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 3.94ms (91.00µs CPU time) Ran 1 test suite in 7.05s (3.94ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests) Failing tests: Encountered a total of 1 failing tests, 0 tests succeeded i took a Look at the Function that reverts the InvalidConsumer() error, i couldn't understand what's the Problem Causing this. i Appreciate all the Helps im Gonna get :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @Tornado06, below is my // SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.23;
import {Script, console2} from "forge-std/Script.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {Lottery} from "../src/Lottery.sol";
import {CreateSubscription} from "../script/Interactions/CreateSubscription.s.sol";
import {FundSubscription} from "../script/Interactions/FundSubscription.s.sol";
import {AddConsumer} from "../script/Interactions/AddConsumer.s.sol";
contract DeployLottery is Script {
uint256 _entryFee;
uint256 _interval;
address _vrfCoordinatorContractAddress;
bytes32 _keyHash;
uint64 _subscriptionId;
address _linkToken;
uint256 _deployerKey;
function run() external returns(Lottery, HelperConfig){
HelperConfig helperConfig = new HelperConfig();
(_entryFee, _interval, _vrfCoordinatorContractAddress, _keyHash, _subscriptionId, _linkToken, _deployerKey) = helperConfig.activeNetworkConfig();
console2.log("The subscriptionIs is: ", _subscriptionId);
if(_subscriptionId == 0) {
CreateSubscription createSubscriptionScript = new CreateSubscription();
_subscriptionId = createSubscriptionScript.createSubscription(_vrfCoordinatorContractAddress, _deployerKey);
FundSubscription fundSubscriptionScript = new FundSubscription();
fundSubscriptionScript.fundSubscription(_subscriptionId, _linkToken, _vrfCoordinatorContractAddress, _deployerKey);
}
vm.startBroadcast();
Lottery lotteryContract = new Lottery(_entryFee, _interval, _vrfCoordinatorContractAddress, _keyHash, _subscriptionId);
vm.stopBroadcast();
AddConsumer addConsumerScript = new AddConsumer();
addConsumerScript.addConsumer(_subscriptionId,address(lotteryContract), _vrfCoordinatorContractAddress, _deployerKey);
return (lotteryContract, helperConfig);
}
} I notice one difference between my |
Beta Was this translation helpful? Give feedback.
God Damn Man, i Hate it When i Make Such Silly Mistakes!
you're right, i need to create Subscription ID before Deploying the Raffle Contract!
my old DeployRaffle.s.sol Which Caused an Error When Running test:
`
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import {Script} from "forge-std/Script.sol";
import {Raffle} from "../src/Raffle.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {CreateSubscription,FundSubscription,AddConsumer} from "./interactions.s.sol";
contract DeployRaffle is Script {