Closed shrutic11 closed 1 year ago
This issue got resolved after I wrapped the the .addConsumer function between vm.startBroadcast vm.stopBroadcast
Interactions.s.sol:
function addConsumer(
address mostRecentRaffleContract,
address vrfCoordinator,
uint64 subId
) public {
console.log("msg.sender in add consumer: ", msg.sender);
console.log("Adding RaffleLottery Contract:", mostRecentRaffleContract);
console.log("subscription id: ", subId);
console.log("on chain: ", block.chainid);
vm.startBroadcast();
VRFCoordinatorV2Mock(vrfCoordinator).addConsumer(
subId,
mostRecentRaffleContract
);
vm.stopBroadcast();
}
Thanks @shrutic11 , it DOES help.
I have found the issue but I am not sure how to fix this. Someone please let me know what am I missing?
When I am trying to deploy the contract using
The msg.sender is one of the anvil accounts (0)0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
However, it is the deployer contract address that calls the createSubscription, fundSubscription, and addConsumer contracts/functions. There's a check in the addConsumer function of the VRFCoordinatorV2Mock
And since, even though I am running the command with an anvil user, the addConsumer function is being called by the deploy Script address, hence the mismatch.
Here's the error:
Due to this issue, my setUp is failing, hence the test. And if I run my test, just as Patrick showed in the video, the expected user is the default sender 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38, and the actual caller is the deploy smart contract.
How can I make this work? In an idea situation, it is the owner (the smart contract deployer's )responsibility to do all the funding and adding consumer stuff. So, how can I transfer control from the deploy script to the owner when calling these functions?