Skip to content

Conversation

@zemse
Copy link
Contributor

@zemse zemse commented May 24, 2022

Before:

const balanceOfOwner = await dai.balanceOf(await someContract.owner())

After:

const balanceOfOwner = await dai.balanceOf(someContract.owner())

@changeset-bot
Copy link

changeset-bot bot commented May 24, 2022

🦋 Changeset detected

Latest commit: f619c59

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@typechain/ethers-v5 Minor
@typechain/hardhat Major
test-e2e Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@zemse zemse marked this pull request as draft May 24, 2022 10:08
@zemse zemse marked this pull request as ready for review May 25, 2022 07:02
@krzkaczor
Copy link
Member

krzkaczor commented May 26, 2022

huh, i am somehow surprised that ethers.js supports promises instead of values :O We will need runtime tests for: a mocha test case where you would pass value and then pass promise of that value etc to test if this is really a case in runtime and to prevent regressions.

it('promise works', async function () {
const { contract } = chain

typedAssert(await chain.contract.input_uint8(getPromise('42')), 42)
Copy link
Contributor Author

@zemse zemse May 29, 2022

Choose a reason for hiding this comment

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

@krzkaczor would typedAssert also execute the code here and compare runtime values? (I assumed that, but any way pls lmk if we need more tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw yeah its a very underrated/underused thing in ethers that it resolves promise of values passed. Once I just passed a promise while in REPL, when I hit return I realised ahh this is going to fail, and the next second saw that it worked ✨

Copy link
Member

@krzkaczor krzkaczor May 30, 2022

Choose a reason for hiding this comment

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

is this documented somewhere? I would rather avoid us relaying on an undocumented feature which might break in the future because it's not part of the official spec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I discussed this with Richard, and he mentioned though the feature is in ethers since v4, it's not much mentioned, and at least for v5 this behavior not gonna be changed.

But I understand your point. You may consider this if you think it adds value. I've made the PR just because when one has await inside await inside await, it looks crazy and the code can look better without them.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah if @ricmoo says it's officially supported, then its fine. Thank you for clarifying that.

Copy link

Choose a reason for hiding this comment

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

It is used quite extensively internal to ethers too.

I guess I only ever talked about it during presentations? I didn’t realize it was so secret. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants