Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit e5673ca

Browse files
author
Alex
authored
Add hardhat (#6719)
* add hardhat * removing ganache pt 1 * fix build * fix build * add hardhat plugin * remove hardhat plugin from each package * update flow * update hardhat command * add stop script * update build * update flow * update buiild * update build * update tests * update tests * add eslint-disable * add es-lint * update web3-eth tests with hardhat * fix lint * update net * fix build * update * update * update * update tests * update pr * update build * update workflow * update package * update * add comments * update yml * fix yml * add script * updae blackbox tests * add const for backend * fix breakin tests * update * remove ganache specific tests * fix script * update const * remove unneccesary comments
1 parent 42ec398 commit e5673ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+432
-389
lines changed

Diff for: .github/workflows/build.yml

+34-34
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,25 @@ jobs:
131131
token: ${{ secrets.CODECOV_TOKEN }}
132132
if: ${{ matrix.node == 18 }}
133133

134-
integration:
135-
name: Integration (ganache) # (ganache with HTTP)
134+
integration-hardhat:
135+
name: Integration hardhat
136136
needs: build
137137
runs-on: ubuntu-latest
138-
env:
139-
INFURA_GOERLI_HTTP: ${{ secrets.INFURA_GOERLI_HTTP }}
140-
INFURA_GOERLI_WS: ${{ secrets.INFURA_GOERLI_WS }}
138+
strategy:
139+
fail-fast: false
141140
steps:
142-
- uses: actions/setup-node@v4
143-
with:
144-
node-version: 18
145-
- uses: actions/cache/restore@v3
146-
with:
141+
- uses: actions/setup-node@v3
142+
with:
143+
node-version: 18
144+
- uses: actions/cache/restore@v3
145+
with:
147146
path: ./
148147
key: web3-18-${{github.event.pull_request.base.sha}}
149-
- run: yarn test:e2e:ganache:http
150-
shell: bash
148+
- run: npx hardhat node &
149+
- run: yarn test:e2e:hardhat:http
150+
shell: bash
151151

152-
e2e:
152+
e2e-geth:
153153
name: Integration # (geth with HTTP, IPC & WS)
154154
needs: build
155155
runs-on: ubuntu-latest
@@ -172,31 +172,31 @@ jobs:
172172
shell: bash
173173

174174
e2e-browsers:
175-
name: End-to-End ganache:ws
175+
name: End-to-End hardhat:ws
176176
needs: build
177177
runs-on: ubuntu-latest
178178
strategy:
179-
fail-fast: false
180-
matrix:
181-
browser: ['electron', 'chrome', 'firefox']
179+
fail-fast: false
180+
matrix:
181+
browser: ['electron', 'chrome', 'firefox']
182182
steps:
183-
- uses: actions/setup-node@v4
184-
with:
185-
node-version: 18
186-
- uses: browser-actions/setup-firefox@latest
187-
if: matrix.browser == 'firefox'
188-
- uses: actions/cache/restore@v3
189-
with:
190-
path: ./
191-
key: web3-18-${{github.event.pull_request.base.sha}}
192-
- run: npm install --no-package-lock --no-save --force cypress
193-
- run: npx ts-node scripts/init.ts
194-
- name: Cypress run
195-
uses: cypress-io/github-action@v4
196-
with:
197-
install: false
198-
command: yarn test:e2e:ganache:ws:${{ matrix.browser }}
199-
cache-key: node-v${{ matrix.node }}-on-${{ matrix.browser }}-hash-${{ hashFiles('yarn.lock') }}
183+
- uses: actions/setup-node@v3
184+
with:
185+
node-version: 18
186+
- uses: browser-actions/setup-firefox@latest
187+
if: matrix.browser == 'firefox'
188+
- uses: actions/cache/restore@v3
189+
with:
190+
path: ./
191+
key: web3-18-${{github.event.pull_request.base.sha}}
192+
- run: npx hardhat node &
193+
- run: npm install --no-package-lock --no-save --force cypress
194+
- name: Cypress run
195+
uses: cypress-io/github-action@v4
196+
with:
197+
install: false
198+
command: yarn test:e2e:hardhat:ws:${{ matrix.browser }}
199+
cache-key: node-v18-on-${{ matrix.browser }}-hash-${{ hashFiles('yarn.lock') }}
200200

201201
deploy-docs:
202202
name: Docs CloudFlare Deploy

Diff for: hardhat.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** @type import('hardhat/config').HardhatUserConfig */
2+
3+
module.exports = {
4+
solidity: "0.8.17",
5+
networks: {
6+
hardhat: {
7+
chainId: 1337,
8+
accounts: {
9+
10+
}
11+
}
12+
}
13+
};

Diff for: package.json

+10-11
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@
4444
"build:docs": "yarn generate:docs && cd docs && yarn install && yarn build",
4545
"changelog": "ts-node -P scripts/changelog/tsconfig.json scripts/changelog/src/index.ts",
4646
"clean": "lerna run clean --stream --parallel",
47-
"ganache:start": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start",
48-
"ganache:start:background": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start 1",
49-
"ganache:stop": "./scripts/ganache.sh stop",
5047
"geth:start": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth.sh start",
5148
"geth:start:background": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth.sh start 1",
5249
"geth:stop": "./scripts/geth.sh stop",
5350
"geth-binary:start": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh start",
5451
"geth-binary:start:background": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh start 1",
5552
"geth-binary:stop": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh stop",
53+
"hardhat:start": "WEB3_SYSTEM_TEST_BACKEND=hardhat && ./scripts/hardhat.sh start",
54+
"hardhat:stop": "./scripts/hardhat.sh stop",
5655
"geth-manual:start:background": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh manualStart 1",
5756
"geth-manual:stop": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh stop",
5857
"lint": "lerna run lint --stream --parallel",
@@ -65,14 +64,10 @@
6564
"test:integration": "lerna run test:integration --stream",
6665
"test:benchmark": "lerna run test:benchmark",
6766
"test:integration:stress": "lerna run test:integration:stress --stream",
68-
"test:e2e:ganache:http": "./scripts/test-runner.sh ganache http",
69-
"test:e2e:ganache:ws": "./scripts/test-runner.sh ganache ws",
7067
"test:e2e:geth:http": "./scripts/test-runner.sh geth http",
7168
"test:e2e:geth:ws": "./scripts/test-runner.sh geth ws",
7269
"test:e2e:geth:ipc": "./scripts/test-runner.sh geth ipc",
73-
"test:e2e:ganache:ws:electron": "./scripts/test-runner.sh ganache ws electron",
74-
"test:e2e:ganache:ws:chrome": "./scripts/test-runner.sh ganache ws chrome",
75-
"test:e2e:ganache:ws:firefox": "./scripts/test-runner.sh ganache ws firefox",
70+
"test:e2e:hardhat:http": "./scripts/test-runner.sh hardhat http",
7671
"test:e2e:coverage": "./scripts/test-runner.sh coverage",
7772
"test:e2e:mainnet:http": "./scripts/test-runner.sh mainnet http",
7873
"test:e2e:mainnet:ws": "./scripts/test-runner.sh mainnet ws",
@@ -85,12 +80,15 @@
8580
"generate:accounts": "node ./scripts/gen_accounts.js",
8681
"pre-blackbox": "yarn config set registry http://localhost:4873 && git init && git config --global user.email \"[email protected]\" && git config --global user.name \"CI\"",
8782
"post-blackbox": "./scripts/verdaccio.sh stop",
88-
"post-blackbox:ganache": "yarn ganache:stop && yarn post-blackbox",
8983
"post-blackbox:geth": "yarn geth:stop && yarn post-blackbox",
90-
"test:blackbox:ganache:http": "yarn pre-blackbox && yarn ganache:start:background && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:ganache:http --stream && yarn post-blackbox:ganache",
91-
"test:blackbox:ganache:ws": "yarn pre-blackbox && yarn ganache:start:background && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:ganache:ws --stream && yarn post-blackbox:ganache",
9284
"test:blackbox:geth:http": "yarn pre-blackbox && yarn geth:start:background && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:geth:http --stream && yarn post-blackbox:geth",
9385
"test:blackbox:geth:ws": "yarn pre-blackbox && yarn geth:start:background && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:geth:ws --stream && yarn post-blackbox:geth",
86+
"test:e2e:geth:ws:electron": "./scripts/test-runner.sh hardhat ws electron",
87+
"test:e2e:geth:ws:chrome": "./scripts/test-runner.sh hardhat ws chrome",
88+
"test:e2e:geth:ws:firefox": "./scripts/test-runner.sh hardhat ws firefox",
89+
"test:e2e:hardhat:ws:electron": "./scripts/test-runner.sh hardhat http electron",
90+
"test:e2e:hardhat:ws:chrome": "./scripts/test-runner.sh hardhat http chrome",
91+
"test:e2e:hardhat:ws:firefox": "./scripts/test-runner.sh hardhat http firefox",
9492
"test:blackbox:infura:http": "yarn pre-blackbox && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:infura:http --stream && yarn post-blackbox",
9593
"test:blackbox:infura:ws": "yarn pre-blackbox && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:infura:ws --stream && yarn post-blackbox",
9694
"test:manual:long-connection-ws": "node packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js",
@@ -138,6 +136,7 @@
138136
"typedoc-plugin-merge-modules": "^5.1.0",
139137
"typescript": "^4.7.4",
140138
"utf-8-validate": "^5.0.9",
139+
"web3-hardhat-plugin": "^1.0.0",
141140
"webpack": "^5.73.0",
142141
"webpack-cli": "^4.10.0"
143142
},

Diff for: packages/web3-core/src/web3_request_manager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,10 @@ export class Web3RequestManager<
425425
} else if ((response as unknown) instanceof Error) {
426426
error = response as unknown as JsonRpcError;
427427
}
428-
428+
429429
// This message means that there was an error while executing the code of the smart contract
430430
// However, more processing will happen at a higher level to decode the error data,
431-
// according to the Error ABI, if it was available as of EIP-838.
431+
// according to the Error ABI, if it was available as of EIP-838.
432432
if (error?.message.includes('revert')) throw new ContractExecutionError(error);
433433

434434
return false;

Diff for: packages/web3-eth-contract/test/integration/contract_accesslist.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import {
2222
createTempAccount,
2323
describeIf,
2424
getSystemTestBackend,
25+
BACKEND
2526
} from '../fixtures/system_test_utils';
2627

2728
describe('contract', () => {
28-
describeIf(getSystemTestBackend() === 'geth')('createAccessList', () => {
29+
describeIf(getSystemTestBackend() === BACKEND.GETH)('createAccessList', () => {
2930
let contract: Contract<typeof GreeterAbi>;
3031
let deployOptions: Record<string, unknown>;
3132
let sendOptions: Record<string, unknown>;

Diff for: packages/web3-eth-contract/test/integration/contract_deploy.test.ts

+26-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import {
2929
signTxAndSendEIP1559,
3030
sendFewSampleTxs,
3131
closeOpenConnection,
32+
getSystemTestBackend,
33+
BACKEND
3234
} from '../fixtures/system_test_utils';
3335

3436
describe('contract', () => {
@@ -254,9 +256,17 @@ describe('contract', () => {
254256
});
255257

256258
it('should fail with errors on "intrinsic gas too low" OOG', async () => {
257-
await expect(
258-
contract.deploy(deployOptions).send({ ...sendOptions, gas: '100' }),
259-
).rejects.toThrow('Returned error: intrinsic gas too low');
259+
if (getSystemTestBackend() !== BACKEND.HARDHAT){
260+
// eslint-disable-next-line jest/no-conditional-expect
261+
await expect(
262+
contract.deploy(deployOptions).send({ ...sendOptions, gas: '100' }),
263+
).rejects.toThrow('Returned error: intrinsic gas too low');
264+
} else {
265+
// eslint-disable-next-line jest/no-conditional-expect
266+
await expect(
267+
contract.deploy(deployOptions).send({ ...sendOptions, gas: '100' }),
268+
).rejects.toThrow('Returned error: Transaction requires at least 109656 gas but got 100');
269+
}
260270
});
261271

262272
it('should fail with errors deploying a zero length bytecode', () => {
@@ -273,14 +283,25 @@ describe('contract', () => {
273283
it('should fail with errors on revert', async () => {
274284
const revert = new Contract(DeployRevertAbi);
275285
revert.provider = getSystemTestProvider();
276-
// eslint-disable-next-line jest/no-standalone-expect
286+
if (getSystemTestBackend() !== BACKEND.HARDHAT){
287+
// eslint-disable-next-line jest/no-conditional-expect
288+
await expect(
289+
revert
290+
.deploy({
291+
data: DeployRevertBytecode,
292+
})
293+
.send(sendOptions),
294+
).rejects.toThrow("code couldn't be stored");
295+
} else {
296+
// eslint-disable-next-line jest/no-conditional-expect
277297
await expect(
278298
revert
279299
.deploy({
280300
data: DeployRevertBytecode,
281301
})
282302
.send(sendOptions),
283-
).rejects.toThrow("code couldn't be stored");
303+
).rejects.toThrow("Error happened while trying to execute a function inside a smart contract");
304+
}
284305
});
285306
});
286307
});

Diff for: packages/web3-eth-contract/test/integration/contract_methods.test.ts

+31-19
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1717
import { ContractExecutionError } from 'web3-errors';
1818
import { Contract } from '../../src';
1919
import { BasicAbi, BasicBytecode } from '../shared_fixtures/build/Basic';
20-
import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils';
20+
import { getSystemTestProvider, createTempAccount, getSystemTestBackend, BACKEND} from '../fixtures/system_test_utils';
2121

2222
describe('contract', () => {
2323
let contract: Contract<typeof BasicAbi>;
@@ -135,9 +135,9 @@ describe('contract', () => {
135135
it('should run send method of the contract if data is provided at initiation', async () => {
136136
const tempContract = new Contract(BasicAbi, {
137137
provider: getSystemTestProvider(),
138-
input: BasicBytecode,
139138
from: acc.address,
140139
gas: '1000000',
140+
data: BasicBytecode,
141141
});
142142
const deployedTempContract = await tempContract
143143
.deploy({ arguments: [10, 'string init value'] })
@@ -148,23 +148,35 @@ describe('contract', () => {
148148
});
149149

150150
it('should returns errors on reverts', async () => {
151-
await expect(
152-
contractDeployed.methods.reverts().send(sendOptions),
153-
).rejects.toMatchObject({
154-
name: 'TransactionRevertedWithoutReasonError',
155-
receipt: {
156-
cumulativeGasUsed: BigInt(21543),
157-
from: acc.address,
158-
gasUsed: BigInt(21543),
159-
logs: [],
160-
logsBloom:
161-
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
162-
status: BigInt(0),
163-
to: contractDeployed.options.address?.toLowerCase(),
164-
transactionIndex: BigInt(0),
165-
type: BigInt(2),
166-
},
167-
});
151+
// TODO hardhat reverts but sends an undefined receipt, needs investigation
152+
if (getSystemTestBackend() === BACKEND.HARDHAT) {
153+
// eslint-disable-next-line jest/no-conditional-expect
154+
await expect(
155+
contractDeployed.methods.reverts().send(sendOptions),
156+
).rejects.toMatchObject({
157+
"name": "ContractExecutionError",
158+
"receipt": undefined,
159+
});
160+
} else {
161+
// eslint-disable-next-line jest/no-conditional-expect
162+
await expect(
163+
contractDeployed.methods.reverts().send(sendOptions),
164+
).rejects.toMatchObject({
165+
name: 'TransactionRevertedWithoutReasonError',
166+
receipt: {
167+
cumulativeGasUsed: BigInt(21543),
168+
from: acc.address,
169+
gasUsed: BigInt(21543),
170+
logs: [],
171+
logsBloom:
172+
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
173+
status: BigInt(0),
174+
to: contractDeployed.options.address?.toLowerCase(),
175+
transactionIndex: BigInt(0),
176+
type: BigInt(2),
177+
},
178+
});
179+
}
168180
});
169181
});
170182
});

Diff for: packages/web3-eth-contract/test/integration/contract_methods_errors.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
createTempAccount,
2424
getSystemTestBackend,
2525
describeIf,
26+
BACKEND,
2627
} from '../fixtures/system_test_utils';
2728

2829
describe('contract errors', () => {
@@ -50,7 +51,7 @@ describe('contract errors', () => {
5051
contract.setProvider(getSystemTestProvider());
5152
});
5253

53-
describeIf(getSystemTestBackend() === 'geth')('Test EIP-838 Error Codes', () => {
54+
describeIf(getSystemTestBackend() === BACKEND.GETH)('Test EIP-838 Error Codes', () => {
5455
it('Unauthorized', async () => {
5556
let error: ContractExecutionError | undefined;
5657
try {

0 commit comments

Comments
 (0)