Lesson 9: Events are not firing in unit test for localhost. #719
Answered
by
sanjayojha
sanjayojha
asked this question in
Q&A
-
while testing the following. I get error. it("updates the raffle state and emits a requestId", async () => {
await raffle.enterRaffle({ value: raffleEntranceFee });
await network.provider.send("evm_increaseTime", [interval + 1]);
await network.provider.request({ method: "evm_mine", params: [] });
const transactipnResop = await raffle.performUpkeep("0x");
const transactipnReceipt = await transactipnResop.wait();
const raffleState = await raffle.getRaffleState();
const reqstId = transactipnReceipt!.events![1].args!.requestId;
//^ this is type undefined if I assert the test. Its because `events` is missing.
console.log(`----events----`);
console.log(transactipnReceipt.logs);
console.log(`----eventsends----`);
//assert(reqstId.toNumber() > 0);
//assert.equal(raffleState.toString(), "1");
}); the console log output: [
{
transactionIndex: 0,
blockNumber: 11,
transactionHash: '0x7f523e37a0f7361628dc3c24e502dbcd87d30f6bc12d4a2800647bb61779fba9',
address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
topics: [
'0x63373d1c4696214b898952999c9aaec57dac1ee2723cec59bea6888f489a9772',
'0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc',
'0x0000000000000000000000000000000000000000000000000000000000000001',
'0x000000000000000000000000a513e6e4b8f2a923d98304ec87f64353c4d5c853'
],
data: '0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000007a1200000000000000000000000000000000000000000000000000000000000000001',
logIndex: 0,
blockHash: '0x46d52529c48ce58eb59b5cab84f84ea52566ac993aa3cdb2733e69090763183a'
},
{
transactionIndex: 0,
blockNumber: 11,
transactionHash: '0x7f523e37a0f7361628dc3c24e502dbcd87d30f6bc12d4a2800647bb61779fba9',
address: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
topics: [
'0xfa36921ea69d24c57c089b83d394ff1c818677ced29369749bbcf5e1b74a5e6e',
'0x0000000000000000000000000000000000000000000000000000000000000001'
],
data: '0x',
logIndex: 1,
blockHash: '0x46d52529c48ce58eb59b5cab84f84ea52566ac993aa3cdb2733e69090763183a'
}
] As we can see there is no event is fired in above log. My event RequestRafflewinner(uint256 indexed requesetId);
//To pick a winner, used by chainlink keeper automatically.
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_CONFIRMATION,
i_callbackGasLimit,
NUM_WORDS
);
emit RequestRafflewinner(requestId);
}
|
Beta Was this translation helpful? Give feedback.
Answered by
sanjayojha
Jul 3, 2022
Replies: 1 comment
-
Never mind. I did a spelling error. Instead of Note the spelling of |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sanjayojha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Never mind. I did a spelling error.
Instead of
event RequestRafflewinner(uint256 indexed requesetId);
I should have
event RequestRafflewinner(uint256 indexed requestId);
Note the spelling of
requestId
.