Error InsufficientBalance() foundry lottery test | SubscriptionId #2530
Replies: 3 comments 2 replies
-
Hello @KevinFalah, If you know where the problem arises, I believe that it should be easy to fix. You can just make your process fund subscription regardless of whether the subId is |
Beta Was this translation helpful? Give feedback.
-
I think in HelperConfig if chainId is Local we will createSubscriptionId here in my
after that we go to deployContract and we deploy the HelperConfig and then we get the subscriptionId, so the conditional of subscriptionId == 0 will not happen, correct me if I'm wrong.
|
Beta Was this translation helpful? Give feedback.
-
My HELPERCONFIG function getAnvilNetworkConfig() public returns(NetworkConfig memory anvilNetworkConfig) {
uint96 baseFee = 0.001 ether;
uint96 gasPriceLink = 1e9;
vm.startBroadcast();
VRFCoordinatorV2PlusMock vrfCoordinatorMockPlus = new VRFCoordinatorV2PlusMock(baseFee,gasPriceLink);
LinkToken linkToken = new LinkToken();
vm.stopBroadcast();
anvilNetworkConfig = NetworkConfig({
_entryFee: 0.01 ether,
_interval: 30,
_vrfCoordinatorContractAddress: address(vrfCoordinatorMockPlus),
_keyHash: 0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c,
_subscriptionId: 0,
_linkToken: address(linkToken),
_deployerKey: ANVIL_DEFAULT_PRIVATE_KEY
});
} So, In the function run() external returns(Raffle, HelperConfig){
HelperConfig helperConfig = new HelperConfig();
(_entryFee, _interval, _vrfCoordinatorContractAddress, _keyHash, _subscriptionId, _linkToken, _deployerKey) = helperConfig.activeNetworkConfig();
console.log("The subscriptionId 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(_deployerKey);
Raffle lotteryContract = new Raffle(_entryFee, _interval, _vrfCoordinatorContractAddress, _keyHash, _subscriptionId);
vm.stopBroadcast();
AddConsumer addConsumerScript = new AddConsumer();
addConsumerScript.addConsumer(_subscriptionId,address(lotteryContract), _vrfCoordinatorContractAddress, _deployerKey);
return (lotteryContract, helperConfig);
} |
Beta Was this translation helpful? Give feedback.
-
I got InsufficientBalance() error when testing, but I know where the problem come from
Below is the problem from config.subscriptionId is not zero so the program does not execute fundSubscription, but if I make the subscription in HelperConfig to be zero that test is succesfull, I just wanna know why mr @PatrickAlphaC still success funding but i don't, I think our code to create subscription is same, thank you for any help
Below is my HelperConfig, for now I forced to make the subscription to Zero so that my test was successful.
Beta Was this translation helpful? Give feedback.
All reactions