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

OG-588 Hardhat migration #683

Merged
merged 28 commits into from
Aug 24, 2021
Merged

OG-588 Hardhat migration #683

merged 28 commits into from
Aug 24, 2021

Conversation

shahafn
Copy link
Member

@shahafn shahafn commented Aug 23, 2021

Truffle patch file note:

On eth_call, ganache returns error object that has message, code, data fields. Truffle reads the revert reason from res.error.data in this case. But hardhat returns error object only with message and code, so to return the revert reason, I needed to parse res.error.message.

In general, when eth_call returns an error, the spec doesn't specify a data field containing the revert reason, so truffle is tailored specifically for ganache here

@shahafn shahafn changed the title Hardhat migration OG-588 Hardhat migration Aug 23, 2021
package.json Outdated Show resolved Hide resolved
packages/cli/src/GsnTestEnvironment.ts Show resolved Hide resolved
packages/common/src/Utils.ts Show resolved Hide resolved
packages/dev/package.json Outdated Show resolved Hide resolved
packages/dev/test/provider/RelayClient.test.ts Outdated Show resolved Hide resolved
packages/dev/test/provider/RelayProvider.test.ts Outdated Show resolved Hide resolved
packages/dev/truffle.js Show resolved Hide resolved
Comment on lines +21 to +27
+ const isHardHat =
+ res && typeof res === "object" && res.error && res.error.message && !res.error.data;
+
+ if (isHardHat) {
+ if (res.error.message.includes('Transaction reverted without a reason string')) return 'revert'
+ return res.error.message.match('VM Exception while processing transaction: reverted with reason string \'(.*)\'')[1]
+ }
Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate and write a very descriptive comment in this patchfile?
I was hoping we can get rid of patchfiles one day...

Copy link
Member Author

Choose a reason for hiding this comment

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

On eth_call, ganache returns error object that has message, code, data fields. Truffle reads the revert reason from res.error.data in this case. But hardhat returns error object only with message and code, so to return the revert reason, I needed to parse res.error.message.

In general, when eth_call returns an error, the spec doesn't specify a data field containing the revert reason, so truffle is tailored specifically for ganache here

Copy link
Member

Choose a reason for hiding this comment

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

can you please write this comment in the patch itself, maybe? it will be impossible to remember few months later

scripts/hardhat-node Show resolved Hide resolved
Copy link
Member

@drortirosh drortirosh left a comment

Choose a reason for hiding this comment

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

overall, looks good.
just few small things.

import '@nomiclabs/hardhat-web3'

module.exports = {
solidity: '0.7.3',
Copy link
Member

Choose a reason for hiding this comment

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

I know we don't use it yet to compile, but better to write here 0.8.7 anyways..

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that was הכנה למזגן קצת

networks: {
hardhat: { chainId: 1337 },
npmtest: { // used from "npm test". see package.json
verbose: process.env.VERBOSE,
Copy link
Member

Choose a reason for hiding this comment

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

verbose is not a hardhat parameter (I use .ts config, and it complains on unknown extra params)

Copy link
Member Author

Choose a reason for hiding this comment

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

Weird, for me it doesn't complain. I can remove though

npmtest: { // used from "npm test". see package.json
verbose: process.env.VERBOSE,
url: 'http://127.0.0.1:8544',
network_id: '*'
Copy link
Member

Choose a reason for hiding this comment

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

network_id is also not defined (hh always reads from the provider the net/chain id)

Copy link
Member Author

Choose a reason for hiding this comment

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

I know, forgot to remove after copy pasta from truffle.js

packages/cli/src/GsnTestEnvironment.ts Show resolved Hide resolved
packages/common/src/Utils.ts Show resolved Hide resolved

misbehavingPaymaster = await TestPaymasterConfigurableMisbehavior.new()
await misbehavingPaymaster.setRevertPreRelayCallOnEvenBlocks(true)
await misbehavingPaymaster.setTrustedForwarder(forwarderInstance.address)
await misbehavingPaymaster.setRelayHub(relayHub.address)
await misbehavingPaymaster.deposit({ value: web3.utils.toWei('1', 'ether') })

const relayProvider = await RelayProvider.newProvider({
relayProvider = await RelayProvider.newProvider({
Copy link
Member

Choose a reason for hiding this comment

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

why removed const?

Copy link
Member Author

Choose a reason for hiding this comment

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

to have access to relayProvider in the test, to stub validateRelayCall

@@ -145,6 +144,7 @@ export class ServerTestEnvironment {
config: mergedConfig
})
await this.relayClient.init()
this.gasLess = toChecksumAddress(this.relayClient.newAccount().address)
Copy link
Member

Choose a reason for hiding this comment

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

better move the toChecksumAddress INTO our newAccount method..

Copy link
Member Author

Choose a reason for hiding this comment

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

You might be onto something 😆

@@ -21,7 +21,7 @@ contract('AccountManager', function (accounts) {
const address = '0x982a8CbE734cb8c29A6a7E02a3B0e4512148F6F9'
const privateKey = '0xd353907ab062133759f149a3afcb951f0f746a65a60f351ba05a3ebf26b67f5c'
const config = configureGSN({
methodSuffix: '',
methodSuffix: '_v4',
Copy link
Member

Choose a reason for hiding this comment

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

yes, but you changed the default in the provider to "_v4"

@@ -61,7 +61,7 @@ export async function prepareTransaction (testRecipient: TestRecipientInstance,
relayData: {
pctRelayFee: '1',
baseRelayFee: '1',
gasPrice: '1',
gasPrice: '4494095',
Copy link
Member

Choose a reason for hiding this comment

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

why this number? I undetstand "500000" or "1", but this seems to be explicit number (or random...)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's just the baseFee hardhat had, but it can be 1e9 like the rest. That's the first test I changed so...

packages/dev/truffle.js Show resolved Hide resolved
@shahafn shahafn mentioned this pull request Aug 24, 2021
@forshtat
Copy link
Member

trufflesuite/ganache#939

@shahafn shahafn merged commit 2cbb0ff into master Aug 24, 2021
@shahafn shahafn deleted the hardhat-migration branch August 24, 2021 20:15
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