Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return block in callbackified blockchain #986

Merged
merged 2 commits into from
Nov 9, 2020
Merged

Conversation

fvictorio
Copy link
Member

This fix is literally one line, but I also modified a bunch of typescript stuff to make typescript detect the previous issue. I'm not sure at all about those changes.

I also added some minimal tests for the callbackified version of the Blockchain class. One of them is skipped for reasons I will explain in the comments.

@@ -1,2 +1 @@
export type Callback<T = void> = ((error: NonNullable<any>) => void) &
((error: null | undefined, value: T) => void);
export type Callback<T = void> = (error: any, value: T) => void;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the type change that triggers all the other typescript changes. This makes sense to me, but I have no idea what I'm doing.

const genesis = createBlock(0);
const one = createBlock(1);
await promisify<Block>(callbackifiedBlockchain.putBlock)(genesis);
await promisify<Block>(callbackifiedBlockchain.putBlock)(one);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ugly, I'd rather have a promisifiedCallbackifiedBlockchain (without that name, I swear) and just duplicate the previous test as is.

@@ -146,6 +176,34 @@ describe("HardhatBlockchain", () => {
assert.equal(await blockchain.getBlock(blockThree.hash()), undefined);
});

it.skip("removes the block and all subsequent ones (callbackified)", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a duplicated version of the previous one, like the other added tests. But this one fails because of this line:

https://github.com/nomiclabs/hardhat/blob/7b606216090859ac0edbca105d6cbd49113c209a/packages/hardhat-core/src/internal/hardhat-network/provider/types/PBlockchain.ts#L34

I don't know if that line is fine, and so this tests needs to be different, or if that undefined check should be removed

@alcuadrado alcuadrado merged commit 6e60bc4 into master Nov 9, 2020
@alcuadrado alcuadrado deleted the blockhash-issue branch November 9, 2020 15:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants