-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing
blockHeaderSchema
properties (#6243)
* Add missing blockHeaderSchema properties * Update CHANGELOGs * Update BlockHeaderOutput * Refactor subscript new heads integration test * Add try/catch to new heads sub test for faster failing * Init e2e new heads subscription test * Debug failing tests * Debugging failing tests for cypress
- Loading branch information
1 parent
1361787
commit 7d0a91d
Showing
11 changed files
with
357 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../scripts/accounts.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @NOTE This Util method is kept seperate from shared system_test_utils.ts file because | ||
* of it's import of .secrets.json. For this method to exist in shared system_test_utils.ts | ||
* file, the import path would be ../.secrets.json which doesn't resolve when the file is | ||
* copied over to each package's test directory. Because web3 package is the only package | ||
* running these E2E tests that use Sepolia and Mainnet, this util exists here for now. | ||
*/ | ||
|
||
import { getSystemTestBackend } from '../fixtures/system_test_utils'; | ||
// eslint-disable-next-line import/no-relative-packages | ||
import secrets from '../../../../.secrets.json'; | ||
|
||
export const getSystemE2ETestProvider = (): string => { | ||
if (process.env.WEB3_SYTEM_TEST_MODE === 'http') { | ||
return getSystemTestBackend() === 'sepolia' | ||
? process.env.INFURA_SEPOLIA_HTTP ?? secrets.SEPOLIA.HTTP | ||
: process.env.INFURA_MAINNET_HTTP ?? secrets.MAINNET.HTTP; | ||
} | ||
return getSystemTestBackend() === 'sepolia' | ||
? process.env.INFURA_SEPOLIA_WS ?? secrets.SEPOLIA.WS | ||
: process.env.INFURA_MAINNET_WS ?? secrets.MAINNET.WS; | ||
}; | ||
|
||
export const getE2ETestAccountAddress = (): string => { | ||
if (process.env.TEST_ACCOUNT_ADDRESS !== undefined) { | ||
return process.env.TEST_ACCOUNT_ADDRESS; | ||
// eslint-disable-next-line no-else-return | ||
} else if (getSystemTestBackend() === 'sepolia' || getSystemTestBackend() === 'mainnet') { | ||
return secrets[getSystemTestBackend().toUpperCase() as 'SEPOLIA' | 'MAINNET'].ACCOUNT | ||
.address; | ||
} | ||
|
||
throw new Error('Unable to get test account address'); | ||
}; | ||
|
||
export const getE2ETestContractAddress = () => | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
secrets[getSystemTestBackend().toUpperCase() as 'SEPOLIA' | 'MAINNET'] | ||
.DEPLOYED_TEST_CONTRACT_ADDRESS as string; | ||
|
||
export const getAllowedSendTransaction = (): boolean => { | ||
if (process.env.ALLOWED_SEND_TRANSACTION !== undefined) { | ||
// https://github.com/actions/runner/issues/1483 | ||
if (process.env.ALLOWED_SEND_TRANSACTION === 'false') { | ||
return false; | ||
} | ||
|
||
return Boolean(process.env.ALLOWED_SEND_TRANSACTION); | ||
// eslint-disable-next-line no-else-return | ||
} else if (getSystemTestBackend() === 'sepolia' || getSystemTestBackend() === 'mainnet') { | ||
return secrets[getSystemTestBackend().toUpperCase() as 'SEPOLIA' | 'MAINNET'] | ||
.ALLOWED_SEND_TRANSACTION; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
export const getE2ETestAccountPrivateKey = (): string => { | ||
if (process.env.TEST_ACCOUNT_PRIVATE_KEY !== undefined) { | ||
return process.env.TEST_ACCOUNT_PRIVATE_KEY; | ||
// eslint-disable-next-line no-else-return | ||
} else if (getSystemTestBackend() === 'sepolia' || getSystemTestBackend() === 'mainnet') { | ||
return secrets[getSystemTestBackend().toUpperCase() as 'SEPOLIA' | 'MAINNET'].ACCOUNT | ||
.privateKey; | ||
} | ||
|
||
throw new Error('Unable to get test account private key'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const base = require('../config/jest.config'); | ||
|
||
module.exports = { | ||
...base, | ||
setupFilesAfterEnv: ['<rootDir>/test/e2e/setup.js'], | ||
testMatch: [ | ||
`<rootDir>/test/e2e/*.(spec|test).(js|ts)`, | ||
`<rootDir>/test/e2e/${process.env.WEB3_SYSTEM_TEST_BACKEND}/**/*.(spec|test).(js|ts)`, | ||
], | ||
/** | ||
* restoreMocks [boolean] | ||
* | ||
* Default: false | ||
* | ||
* Automatically restore mock state between every test. | ||
* Equivalent to calling jest.restoreAllMocks() between each test. | ||
* This will lead to any mocks having their fake implementations removed | ||
* and restores their initial implementation. | ||
*/ | ||
restoreMocks: true, | ||
|
||
/** | ||
* resetModules [boolean] | ||
* | ||
* Default: false | ||
* | ||
* By default, each test file gets its own independent module registry. | ||
* Enabling resetModules goes a step further and resets the module registry before running each individual test. | ||
* This is useful to isolate modules for every test so that local module state doesn't conflict between tests. | ||
* This can be done programmatically using jest.resetModules(). | ||
*/ | ||
resetModules: true, | ||
coverageDirectory: `.coverage/e2e/${process.env.WEB3_SYSTEM_TEST_BACKEND}`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// Have to use `require` because of Jest issue https://jestjs.io/docs/ecmascript-modules | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
require('../config/setup'); | ||
|
||
const jestTimeout = 30000; // Sometimes `in3` takes long time because of its decentralized nature. | ||
|
||
jest.setTimeout(jestTimeout); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import Web3, { BlockHeaderOutput } from 'web3'; | ||
|
||
import { | ||
closeOpenConnection, | ||
getSystemTestBackend, | ||
itIf, | ||
waitForOpenConnection, | ||
} from '../fixtures/system_test_utils'; | ||
import { getSystemE2ETestProvider } from './e2e_utils'; | ||
|
||
describe(`${getSystemTestBackend()} tests - subscription newHeads`, () => { | ||
const provider = getSystemE2ETestProvider(); | ||
const expectedNumberOfNewHeads = 1; | ||
|
||
let web3: Web3; | ||
|
||
beforeAll(() => { | ||
web3 = new Web3(provider); | ||
}); | ||
|
||
afterAll(async () => { | ||
await closeOpenConnection(web3); | ||
}); | ||
|
||
itIf(provider.startsWith('ws'))( | ||
`should subscribe to newHeads and receive ${expectedNumberOfNewHeads}`, | ||
async () => { | ||
const newHeadsSubscription = await web3.eth.subscribe('newHeads'); | ||
|
||
let numberOfNewHeadsReceived = 0; | ||
|
||
await waitForOpenConnection(web3.eth); | ||
const assertionPromise = new Promise((resolve, reject) => { | ||
newHeadsSubscription.on('data', (data: BlockHeaderOutput) => { | ||
try { | ||
expect(data).toMatchObject<BlockHeaderOutput>({ | ||
hash: expect.any(String), | ||
parentHash: expect.any(String), | ||
receiptsRoot: expect.any(String), | ||
miner: expect.any(String), | ||
stateRoot: expect.any(String), | ||
transactionsRoot: expect.any(String), | ||
logsBloom: expect.any(String), | ||
difficulty: expect.any(BigInt), | ||
number: expect.any(BigInt), | ||
gasLimit: expect.any(BigInt), | ||
gasUsed: expect.any(BigInt), | ||
timestamp: expect.any(BigInt), | ||
extraData: expect.any(String), | ||
nonce: expect.any(BigInt), | ||
sha3Uncles: expect.any(String), | ||
baseFeePerGas: expect.any(BigInt), | ||
mixHash: expect.any(String), | ||
withdrawalsRoot: expect.any(String), | ||
}); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
|
||
numberOfNewHeadsReceived += 1; | ||
if (numberOfNewHeadsReceived === expectedNumberOfNewHeads) resolve(undefined); | ||
}); | ||
|
||
newHeadsSubscription.on('error', error => reject(error)); | ||
}); | ||
|
||
await assertionPromise; | ||
await web3.eth.subscriptionManager?.removeSubscription(newHeadsSubscription); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7d0a91d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks