Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
#122 fixed final check
Browse files Browse the repository at this point in the history
  • Loading branch information
ShravanSunder committed Jan 21, 2022
1 parent d58e02f commit 75e06f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/helpers/test-utils/eth/hardhatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const mineBlockUntil = async (
): Promise<[success: boolean, currentBlockNumber: number]> => {
let currentBlockNumber = await mockProvider.getBlockNumber();
const initialBlockNumber = currentBlockNumber;
while (!(await untilCondition(currentBlockNumber)) && maxNumberOfBlocks > currentBlockNumber - initialBlockNumber) {
console.log('update', currentBlockNumber, initialBlockNumber, maxNumberOfBlocks);
while (!(await untilCondition(currentBlockNumber)) && maxNumberOfBlocks >= currentBlockNumber - initialBlockNumber) {
await mineBlock(mockProvider);
currentBlockNumber = await mockProvider.getBlockNumber();
console.log('update', currentBlockNumber, initialBlockNumber, maxNumberOfBlocks);
}

console.log('after', await mockProvider.getBlockNumber());
Expand Down
9 changes: 6 additions & 3 deletions test/useContractReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('useContractReader', function () {

it.only('When given options of block number interval to update; then the hook does not update until that amount of blocks has passed', async () => {
// Given
const finalPurpose = 'purpose 1';
const finalPurpose = 'final purpose';
const blockIntervalToUpdate = 5;

const updateOptions = { blockNumberInterval: blockIntervalToUpdate };
Expand All @@ -179,15 +179,18 @@ describe('useContractReader', function () {
);

await yourContract?.setPurpose(finalPurpose);
// check if the hardhat has final vlaue
await mochaWaitFor(
async () => (await yourContract?.purpose()) === finalPurpose,
defaultBlockWaitOptions.timeout
);

console.log(await yourContract?.purpose());

// -- mine blocks up to block when update should occur
const [success, updateBlockNumber] = await mineBlockUntil(
wrapper.mockProvider,
blockIntervalToUpdate + 5,
blockIntervalToUpdate,
async (currentBlockNumber): Promise<boolean> => {
wrapper.mockProvider.blockNumber;
if (currentBlockNumber === blockIntervalToUpdate + testStartBockNumber) {
Expand All @@ -198,7 +201,7 @@ describe('useContractReader', function () {
);

expect(success).to.be.true;
expect(updateBlockNumber).to.be.equal(testStartBockNumber + blockIntervalToUpdate);
expect(updateBlockNumber).to.be.equal(testStartBockNumber + 1 + blockIntervalToUpdate);
});

it('When given option for refetchInterval; then ensures result is not returned before refetchInterval', async () => {
Expand Down

0 comments on commit 75e06f2

Please sign in to comment.