Lesson 9 lottery test, can't pass raffle.performUpkeep([]) #359
-
In Lesson 9 ,video . Patrick made some tests with it("doesn't allow entrance when raffle is calculating", async function () {
await raffle.enterRaffle({ value: raffleEntranceFee });
await network.provider.send("evm_increaseTime", [interval.toNumber() + 1]);
await network.provider.send("evm_mine", []);
await raffle.performUpkeep([]);
await expect(raffle.enterRaffle({ value: raffleEntranceFee })).to.be.revertedWith(
"Raffle__NotOpen"
);
}); when I test it, it returns an error 1) Raffle Unit Tests
enterRaffle
doesn't allow entrance when raffle is calculating:
Error: VM Exception while processing transaction: reverted with custom error 'Raffle__UpkeepNotNeeded(10000000000000000, 1, 0)'
at Raffle.performUpkeep (contracts/Raffle.sol:100)
at HardhatNode._mineBlockWithPendingTxs (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:1773:23)
at HardhatNode.mineBlock (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:466:16)
at EthModule._sendTransactionAndReturnHash (node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:1504:18)
at HardhatNetworkProvider.request (node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:118:18)
at EthersProviderWrapper.send (node_modules\@nomiclabs\hardhat-ethers\src\internal\ethers-provider-wrapper.ts:13:20) Looks like function checkUpkeep(bytes memory /*checkData*/) public override returns(
bool upkeepNeeded, bytes memory /*performData*/)
{
bool isOpen=RaffleState.OPEN==s_raffleState;
bool timePassed=((block.timestamp-s_lastTimeStamp)>i_interval);
bool hasPlayers=(s_players.length>0);
bool hasBalance=address(this).balance>0;
bool upkeepNeeded=(isOpen && timePassed && hasPlayers && hasBalance);
}
function performUpkeep(bytes calldata /*performData*/) external override{
(bool upkeepNeeded,)=checkUpkeep("");
if(!upkeepNeeded){
revert Raffle__UpkeepNotNeeded(address(this).balance,s_players.length,uint256(s_raffleState));
}
s_raffleState=RaffleState.CALCULATING;
uint256 requestId=i_vrfCoordinator.requestRandomWords(
i_gasLane,
i_subscriptionId,
REQUEST_CONFIRMATIONS,
i_callbackGasLimit,
NUM_WORDS
);
emit RequestedRaffleWinner(requestId);
}
I modified the code to check await raffle.checkUpkeep([]); it("doesn't allow entrance when raffle is calculating", async function () {
await raffle.enterRaffle({ value: raffleEntranceFee });
await network.provider.send("evm_increaseTime", [interval.toNumber() + 1]);
await network.provider.send("evm_mine", []);
const test1 = await raffle.checkUpkeep([]);
console.log(test1);
console.log(test1[0]);
console.log(test1[1]);
// await raffle.performUpkeep([]);
// await expect(raffle.enterRaffle({ value: raffleEntranceFee })).to.be.revertedWith(
// "Raffle__NotOpen"
// );
}); it returns the following Raffle Unit Tests
enterRaffle
{
hash: '0x91a39444e8f1eb3bd011c47c3e2fb4674790f12516853863efffd08edbe0512c',
type: 2,
accessList: [],
blockHash: '0x50cffb80e879de261d9a5b7979d5e7f72b903831836931b715fa20ef26bdf4da',
blockNumber: 7,
transactionIndex: 0,
confirmations: 1,
from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
gasPrice: BigNumber { _hex: '0x53bbc66c', _isBigNumber: true },
maxPriorityFeePerGas: BigNumber { _hex: '0x3b9aca00', _isBigNumber: true },
maxFeePerGas: BigNumber { _hex: '0x6bdcc2d8', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x01bad598', _isBigNumber: true },
to: '0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
nonce: 5,
data: '0x6e04ff0d00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000',
r: '0x9d6a81075c88fadbb7ef18edd4cea1cba1d6203b5855b7fe261d07502ec44db4',
s: '0x20a5ca451269dc2c9c1b7fc754ad7e7af42ea34bbcb48fe79223f44ec3de02c1',
v: 1,
creates: null,
chainId: 31337,
wait: [Function (anonymous)]
}
undefined
undefined
✔ doesn't allow entrance when raffle is calculating (46ms)
1 passing (665ms) |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
May be something wrong with interval. Try temporary hardcoding like this: await network.provider.send("evm_increaseTime", [31]); |
Beta Was this translation helpful? Give feedback.
-
hey dude i have a problem can you solve that out same lesson 9 |
Beta Was this translation helpful? Give feedback.
-
error code here const VRF_SUB_FUND_AMOUNT = ethers.utils.parseEther("30"); module.exports = async function({getNamedAccounts, deployments}) {
} module.exports.tags = ["all", "raffle"] |
Beta Was this translation helpful? Give feedback.
-
Let's try another way. function checkUpkeepNeeded() public view returns (bool) {
(bool upkeepNeeded,) = checkUpkeep("");
return upkeepNeeded;
} and check results in raffle.test.js (raffle.test.ts) await contractRaffle.enterRuffle({ value: entranceFee })
await network.provider.send('evm_increaseTime', [parseInt(interval) + 1])
await network.provider.send('evm_mine', [])
// await contractRaffle.performUpkeep([])
const upkeepNeeded = await contractRaffle.checkUpkeepNeeded()
console.log('upkeepNeeded:',upkeepNeeded) Result should be like this
|
Beta Was this translation helpful? Give feedback.
-
I think to solve the problem you should replace bool isOpen=RaffleState.OPEN==s_raffleState; with bool isOpen = (s_ruffleState == RaffleState.OPEN); and bool hasBalance=address(this).balance>0; with bool hasBalance = (address(this).balance > 0); |
Beta Was this translation helpful? Give feedback.
-
I had the same issue. Solved it by adding:
As shown in the checkUpkeep function on the github repo. |
Beta Was this translation helpful? Give feedback.
I had the same issue. Solved it by adding:
upkeepNeeded = (timePassed && isOpen && hasBalance && hasPlayers); return (upkeepNeeded, "0x0");
in checkUpkeep functionAs shown in the checkUpkeep function on the github repo.