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

Add hardhat #6719

Merged
merged 48 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
51beb30
add hardhat
Jan 11, 2024
98bbd69
removing ganache pt 1
Jan 11, 2024
3e0829f
Merge branch '4.x' into add-hardhat
Jan 12, 2024
cc0b0d9
fix build
Jan 12, 2024
c08699e
fix build
Jan 12, 2024
f49127b
add hardhat plugin
Jan 12, 2024
d65338b
remove hardhat plugin from each package
Jan 12, 2024
e9d9e9a
update flow
Jan 12, 2024
8b59549
update hardhat command
Jan 12, 2024
c53cebe
add stop script
Jan 16, 2024
59bb595
Merge branch '4.x' into add-hardhat
Jan 16, 2024
2119e83
update build
Jan 16, 2024
e2b1df1
update flow
Jan 17, 2024
66b2501
update buiild
Jan 17, 2024
eb7e33d
update build
Jan 17, 2024
5c750af
update tests
Jan 17, 2024
f5f8588
update tests
Jan 18, 2024
db6f06e
add eslint-disable
Jan 18, 2024
9e7a379
add es-lint
Jan 18, 2024
adb756b
update web3-eth tests with hardhat
Jan 19, 2024
d0a7a55
fix lint
Jan 19, 2024
97efe98
update net
Jan 19, 2024
b2d4e73
fix build
Jan 19, 2024
834f98a
update
Jan 22, 2024
03e9cf8
update
Jan 22, 2024
9c66ba2
update
Jan 22, 2024
7004c61
update tests
Jan 22, 2024
0e06554
update pr
Jan 23, 2024
229f494
update build
Jan 24, 2024
954ee91
update workflow
Jan 24, 2024
1ac4f24
update package
Jan 24, 2024
5dfed6b
update
Jan 24, 2024
802009b
add comments
Jan 24, 2024
8684f10
Merge branch '4.x' into add-hardhat
Jan 24, 2024
86d1a10
update yml
Jan 24, 2024
9ab7d3f
fix yml
Jan 24, 2024
bcedcbe
add script
Jan 24, 2024
a235820
updae blackbox tests
Jan 24, 2024
80f92e9
add const for backend
Jan 29, 2024
36b3de8
Merge branch '4.x' into add-hardhat
Jan 29, 2024
bec4e0a
fix breakin tests
Jan 30, 2024
62ec640
update
Jan 30, 2024
d78f0be
remove ganache specific tests
Jan 30, 2024
edc26de
fix script
Jan 30, 2024
6081147
Merge branch '4.x' into add-hardhat
Jan 30, 2024
67ff9ec
update const
Jan 31, 2024
bdb9a82
Merge branch '4.x' into add-hardhat
Feb 2, 2024
38dabb2
remove unneccesary comments
Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,25 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
if: ${{ matrix.node == 18 }}

integration:
name: Integration (ganache) # (ganache with HTTP)
integration-hardhat:
name: Integration hardhat
needs: build
runs-on: ubuntu-latest
env:
INFURA_GOERLI_HTTP: ${{ secrets.INFURA_GOERLI_HTTP }}
INFURA_GOERLI_WS: ${{ secrets.INFURA_GOERLI_WS }}
strategy:
fail-fast: false
steps:
- uses: actions/setup-node@v4
with:
node-version: 18
- uses: actions/cache/restore@v3
with:
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: actions/cache/restore@v3
with:
path: ./
key: web3-18-${{github.event.pull_request.base.sha}}
- run: yarn test:e2e:ganache:http
shell: bash
- run: npx hardhat node &
- run: yarn test:e2e:hardhat:http
shell: bash

e2e:
e2e-geth:
name: Integration # (geth with HTTP, IPC & WS)
needs: build
runs-on: ubuntu-latest
Expand All @@ -172,31 +172,31 @@ jobs:
shell: bash

e2e-browsers:
name: End-to-End ganache:ws
name: End-to-End hardhat:ws
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
browser: ['electron', 'chrome', 'firefox']
fail-fast: false
matrix:
browser: ['electron', 'chrome', 'firefox']
steps:
- uses: actions/setup-node@v4
with:
node-version: 18
- uses: browser-actions/setup-firefox@latest
if: matrix.browser == 'firefox'
- uses: actions/cache/restore@v3
with:
path: ./
key: web3-18-${{github.event.pull_request.base.sha}}
- run: npm install --no-package-lock --no-save --force cypress
- run: npx ts-node scripts/init.ts
- name: Cypress run
uses: cypress-io/github-action@v4
with:
install: false
command: yarn test:e2e:ganache:ws:${{ matrix.browser }}
cache-key: node-v${{ matrix.node }}-on-${{ matrix.browser }}-hash-${{ hashFiles('yarn.lock') }}
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: browser-actions/setup-firefox@latest
if: matrix.browser == 'firefox'
- uses: actions/cache/restore@v3
with:
path: ./
key: web3-18-${{github.event.pull_request.base.sha}}
- run: npx hardhat node &
- run: npm install --no-package-lock --no-save --force cypress
- name: Cypress run
uses: cypress-io/github-action@v4
with:
install: false
command: yarn test:e2e:hardhat:ws:${{ matrix.browser }}
cache-key: node-v18-on-${{ matrix.browser }}-hash-${{ hashFiles('yarn.lock') }}

deploy-docs:
name: Docs CloudFlare Deploy
Expand Down
13 changes: 13 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type import('hardhat/config').HardhatUserConfig */

module.exports = {
solidity: "0.8.17",
networks: {
hardhat: {
chainId: 1337,
accounts: {

}
}
}
};
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@
"build:docs": "yarn generate:docs && cd docs && yarn install && yarn build",
"changelog": "ts-node -P scripts/changelog/tsconfig.json scripts/changelog/src/index.ts",
"clean": "lerna run clean --stream --parallel",
"ganache:start": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start",
"ganache:start:background": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start 1",
"ganache:stop": "./scripts/ganache.sh stop",
"geth:start": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth.sh start",
"geth:start:background": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth.sh start 1",
"geth:stop": "./scripts/geth.sh stop",
"geth-binary:start": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh start",
"geth-binary:start:background": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh start 1",
"geth-binary:stop": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh stop",
"hardhat:start": "WEB3_SYSTEM_TEST_BACKEND=hardhat && ./scripts/hardhat.sh start",
"hardhat:stop": "./scripts/hardhat.sh stop",
"geth-manual:start:background": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh manualStart 1",
"geth-manual:stop": "WEB3_SYSTEM_TEST_BACKEND=geth && ./scripts/geth_binary.sh stop",
"lint": "lerna run lint --stream --parallel",
Expand All @@ -65,14 +64,10 @@
"test:integration": "lerna run test:integration --stream",
"test:benchmark": "lerna run test:benchmark",
"test:integration:stress": "lerna run test:integration:stress --stream",
"test:e2e:ganache:http": "./scripts/test-runner.sh ganache http",
"test:e2e:ganache:ws": "./scripts/test-runner.sh ganache ws",
"test:e2e:geth:http": "./scripts/test-runner.sh geth http",
"test:e2e:geth:ws": "./scripts/test-runner.sh geth ws",
"test:e2e:geth:ipc": "./scripts/test-runner.sh geth ipc",
"test:e2e:ganache:ws:electron": "./scripts/test-runner.sh ganache ws electron",
"test:e2e:ganache:ws:chrome": "./scripts/test-runner.sh ganache ws chrome",
"test:e2e:ganache:ws:firefox": "./scripts/test-runner.sh ganache ws firefox",
"test:e2e:hardhat:http": "./scripts/test-runner.sh hardhat http",
"test:e2e:coverage": "./scripts/test-runner.sh coverage",
"test:e2e:mainnet:http": "./scripts/test-runner.sh mainnet http",
"test:e2e:mainnet:ws": "./scripts/test-runner.sh mainnet ws",
Expand All @@ -85,12 +80,15 @@
"generate:accounts": "node ./scripts/gen_accounts.js",
"pre-blackbox": "yarn config set registry http://localhost:4873 && git init && git config --global user.email \"ci@github.com\" && git config --global user.name \"CI\"",
"post-blackbox": "./scripts/verdaccio.sh stop",
"post-blackbox:ganache": "yarn ganache:stop && yarn post-blackbox",
"post-blackbox:geth": "yarn geth:stop && yarn post-blackbox",
"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",
"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",
"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",
"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",
"test:e2e:geth:ws:electron": "./scripts/test-runner.sh hardhat ws electron",
"test:e2e:geth:ws:chrome": "./scripts/test-runner.sh hardhat ws chrome",
"test:e2e:geth:ws:firefox": "./scripts/test-runner.sh hardhat ws firefox",
"test:e2e:hardhat:ws:electron": "./scripts/test-runner.sh hardhat http electron",
"test:e2e:hardhat:ws:chrome": "./scripts/test-runner.sh hardhat http chrome",
"test:e2e:hardhat:ws:firefox": "./scripts/test-runner.sh hardhat http firefox",
"test:blackbox:infura:http": "yarn pre-blackbox && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:infura:http --stream && yarn post-blackbox",
"test:blackbox:infura:ws": "yarn pre-blackbox && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:infura:ws --stream && yarn post-blackbox",
"test:manual:long-connection-ws": "node packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js",
Expand Down Expand Up @@ -138,6 +136,7 @@
"typedoc-plugin-merge-modules": "^5.1.0",
"typescript": "^4.7.4",
"utf-8-validate": "^5.0.9",
"web3-hardhat-plugin": "^1.0.0",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-core/src/web3_request_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ export class Web3RequestManager<
} else if ((response as unknown) instanceof Error) {
error = response as unknown as JsonRpcError;
}

// This message means that there was an error while executing the code of the smart contract
// However, more processing will happen at a higher level to decode the error data,
// according to the Error ABI, if it was available as of EIP-838.
// according to the Error ABI, if it was available as of EIP-838.
if (error?.message.includes('revert')) throw new ContractExecutionError(error);

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import {
createTempAccount,
describeIf,
getSystemTestBackend,
BACKEND
} from '../fixtures/system_test_utils';

describe('contract', () => {
describeIf(getSystemTestBackend() === 'geth')('createAccessList', () => {
describeIf(getSystemTestBackend() === BACKEND.GETH)('createAccessList', () => {
let contract: Contract<typeof GreeterAbi>;
let deployOptions: Record<string, unknown>;
let sendOptions: Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
signTxAndSendEIP1559,
sendFewSampleTxs,
closeOpenConnection,
getSystemTestBackend,
BACKEND
} from '../fixtures/system_test_utils';

describe('contract', () => {
Expand Down Expand Up @@ -254,9 +256,17 @@ describe('contract', () => {
});

it('should fail with errors on "intrinsic gas too low" OOG', async () => {
await expect(
contract.deploy(deployOptions).send({ ...sendOptions, gas: '100' }),
).rejects.toThrow('Returned error: intrinsic gas too low');
if (getSystemTestBackend() !== BACKEND.HARDHAT){
// eslint-disable-next-line jest/no-conditional-expect
await expect(
contract.deploy(deployOptions).send({ ...sendOptions, gas: '100' }),
).rejects.toThrow('Returned error: intrinsic gas too low');
} else {
// eslint-disable-next-line jest/no-conditional-expect
await expect(
contract.deploy(deployOptions).send({ ...sendOptions, gas: '100' }),
).rejects.toThrow('Returned error: Transaction requires at least 109656 gas but got 100');
}
});

it('should fail with errors deploying a zero length bytecode', () => {
Expand All @@ -273,14 +283,25 @@ describe('contract', () => {
it('should fail with errors on revert', async () => {
const revert = new Contract(DeployRevertAbi);
revert.provider = getSystemTestProvider();
// eslint-disable-next-line jest/no-standalone-expect
if (getSystemTestBackend() !== BACKEND.HARDHAT){
// eslint-disable-next-line jest/no-conditional-expect
await expect(
revert
.deploy({
data: DeployRevertBytecode,
})
.send(sendOptions),
).rejects.toThrow("code couldn't be stored");
} else {
// eslint-disable-next-line jest/no-conditional-expect
await expect(
revert
.deploy({
data: DeployRevertBytecode,
})
.send(sendOptions),
).rejects.toThrow("code couldn't be stored");
).rejects.toThrow("Error happened while trying to execute a function inside a smart contract");
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { ContractExecutionError } from 'web3-errors';
import { Contract } from '../../src';
import { BasicAbi, BasicBytecode } from '../shared_fixtures/build/Basic';
import { getSystemTestProvider, createTempAccount } from '../fixtures/system_test_utils';
import { getSystemTestProvider, createTempAccount, getSystemTestBackend, BACKEND} from '../fixtures/system_test_utils';

describe('contract', () => {
let contract: Contract<typeof BasicAbi>;
Expand Down Expand Up @@ -135,9 +135,9 @@ describe('contract', () => {
it('should run send method of the contract if data is provided at initiation', async () => {
const tempContract = new Contract(BasicAbi, {
provider: getSystemTestProvider(),
input: BasicBytecode,
from: acc.address,
gas: '1000000',
data: BasicBytecode,
});
const deployedTempContract = await tempContract
.deploy({ arguments: [10, 'string init value'] })
Expand All @@ -148,23 +148,35 @@ describe('contract', () => {
});

it('should returns errors on reverts', async () => {
await expect(
contractDeployed.methods.reverts().send(sendOptions),
).rejects.toMatchObject({
name: 'TransactionRevertedWithoutReasonError',
receipt: {
cumulativeGasUsed: BigInt(21543),
from: acc.address,
gasUsed: BigInt(21543),
logs: [],
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: BigInt(0),
to: contractDeployed.options.address?.toLowerCase(),
transactionIndex: BigInt(0),
type: BigInt(2),
},
});
// TODO hardhat reverts but sends an undefined receipt, needs investigation
if (getSystemTestBackend() === BACKEND.HARDHAT) {
// eslint-disable-next-line jest/no-conditional-expect
await expect(
contractDeployed.methods.reverts().send(sendOptions),
).rejects.toMatchObject({
"name": "ContractExecutionError",
"receipt": undefined,
});
} else {
// eslint-disable-next-line jest/no-conditional-expect
await expect(
contractDeployed.methods.reverts().send(sendOptions),
).rejects.toMatchObject({
name: 'TransactionRevertedWithoutReasonError',
receipt: {
cumulativeGasUsed: BigInt(21543),
from: acc.address,
gasUsed: BigInt(21543),
logs: [],
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: BigInt(0),
to: contractDeployed.options.address?.toLowerCase(),
transactionIndex: BigInt(0),
type: BigInt(2),
},
});
}
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
createTempAccount,
getSystemTestBackend,
describeIf,
BACKEND,
} from '../fixtures/system_test_utils';

describe('contract errors', () => {
Expand Down Expand Up @@ -50,7 +51,7 @@ describe('contract errors', () => {
contract.setProvider(getSystemTestProvider());
});

describeIf(getSystemTestBackend() === 'geth')('Test EIP-838 Error Codes', () => {
describeIf(getSystemTestBackend() === BACKEND.GETH)('Test EIP-838 Error Codes', () => {
it('Unauthorized', async () => {
let error: ContractExecutionError | undefined;
try {
Expand Down
Loading
Loading