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

Commit 159cd79

Browse files
authored
Merge branch '1.x' into issue/3513
2 parents 5fe8ead + a434ce1 commit 159cd79

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ Fixes #(issue)
2929
- [ ] I ran `npm run build-all` and tested the resulting files from `dist` folder in a browser.
3030
- [ ] I have updated the `CHANGELOG.md` file in the root folder.
3131
- [ ] I have tested my code on the live network.
32+
- [ ] The browser visual inspection check looks ok: [sudden-playground.surge.sh][1]
33+
34+
[1]: http://sudden-playground.surge.sh/

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ Released with 1.0.0-beta.37 code base.
207207

208208
### Added
209209

210+
- Documentation about testing & ci resources for Web3.js development (#3528)
211+
210212
### Changed
211213

212214
### Fixed

TESTING.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Guide to Web3's tests and CI
2+
3+
Web3 is used in Node.js and browser contexts to interact with a wide variety of clients. Its tests
4+
try to cover as much of this domain as possible.
5+
6+
If you're looking for a fixture, test pattern or common execution context to validate a change, you should be able find it in the existing test suite. (Caveats include Parity / Quorum clients and MetaMask specific tests.)
7+
8+
## Required Tests
9+
10+
These should pass for PRs to merge:
11+
12+
| Test type | npm command | Example | Description | CI Only |
13+
| --------- | --------------- | ------ | ----------- | ----- |
14+
| unit | test | [eth.accounts.sign.js][1] | For discrete pieces of logic |
15+
| integration | test:e2e:clients | [e2e.contract.events.js][2] | Tests using geth and ganache-cli, (insta-mining and interval mining.) Easy to write and good for modeling complex use-cases |
16+
| browser | test:e2e:browsers | | The integration tests run in a headless browser using web3.min.js (browserified, vs. ganache-cli) |
17+
| typescript | dtslint | -- | TS type definitions tests |
18+
| dependencies | depcheck | -- | Verifies every dependency is listed correctly in the module package |
19+
| bundle | test:e2e:min | [e2e.minified.js][3] | Verifies minified bundle loads in a headless browser *without* being webpacked / browserified | :white_check_mark: |
20+
| cdn | test:e2e:cdn | [e2e.cdn.sh][4]| Visual inspection check: publishes an (un-webpacked) site that uses web3.min.js at http://sudden-playground.surge.sh/ | :white_check_mark: |
21+
| windows | -- | [e2e.windows.sh][5] | Verifies Web3 installs on Windows OS / Node 12 and can connect to Infura over wss and https | :white_check_mark: |
22+
23+
24+
## Optional Tests
25+
26+
CI also has tests that install Web3's state at an arbitrary commit in an external real-world project and run *their* unit tests with it. This strategy is borrowed from ethereum/solidity which checks latest Solidity against OpenZeppelin and others to keep abreast of how local changes might affect critical projects downstream from them.
27+
28+
Examples include:
29+
+ [e2e.mosaic.sh][8]: ~300 unit tests for [a Solidity project built with Buidler & @truffle/contract][9]
30+
+ [e2e.ganache.core.sh][9]: ~600 unit tests for [a widely used JS testrpc][11]
31+
32+
These tests are "allowed failures". They're:
33+
+ a pre-publication sanity check that discovers how Web3 performs in the wild
34+
+ useful for catching problems which are difficult to anticipate
35+
+ exposed to failure for reasons outside of Web3's control, ex: when fixes here surface bugs in the target.
36+
37+
## Implementation Details
38+
39+
**Code coverage**
40+
41+
Coverage is measured by aggregating the results of tests run in the `unit_and_e2e_clients`
42+
CI job.
43+
44+
**Tests which use an Ethereum client**
45+
46+
The npm script `test:e2e:clients` greps all tests with an `[ @E2E ]` tag
47+
in their mocha test description and runs them against:
48+
+ ganache-cli
49+
+ geth 1.9.13 (POA, single instance, instamining)
50+
+ geth 1.9.13 (POA, single instance, mining at 2s intervals)
51+
52+
These tests are grouped in files prefixed by "e2e", ex: `test/e2e.method.call.js`.
53+
54+
Additionally, there are conventional unit tests postfixed `.ganache.js` which spin up a ganache
55+
server programatically within mocha. This pattern is useful if you want to
56+
control client configuration for a specific case, test against multiple independent providers, etc.
57+
58+
**"Real world" tests**
59+
60+
The tests which install Web3's current state in an external real-world project and
61+
run their unit tests accomplish this by publishing the monorepo to an ephemeral private
62+
npm registry which is spun up in CI using [verdaccio][14]. (Implementation details can
63+
be seen in [scripts/e2e.npm.publish.sh][15])
64+
65+
The real world target is then cloned and npm or yarn are used to replace its existing
66+
Web3 version with the version published to the the private registry. A simple example can be seen at
67+
[scripts/e2e.ganache.core.sh][10].
68+
69+
In practice, complex projects can have many versions of Web3 nested in their dependency tree.
70+
It's important to coerce all of them to the virtually published package's version for the test to be valid.
71+
This can be done with [scripts/js/resolutions.js][18] which modifies the target's
72+
`package.json` to take advantage of Yarn's [selective dependency resolutions][17].
73+
An example of its use can be seen at [scripts/e2e.mosaic.sh][8].
74+
75+
[14]: https://verdaccio.org/docs/en/installation
76+
[15]: https://github.com/ethereum/web3.js/blob/1.x/scripts/e2e.npm.publish.sh
77+
[17]: https://classic.yarnpkg.com/en/docs/selective-version-resolutions/
78+
[18]: https://github.com/ethereum/web3.js/blob/1.x/scripts/js/resolutions.js
79+
80+
[8]: https://github.com/ethereum/web3.js/blob/1.x/scripts/e2e.mosaic.sh
81+
[9]: https://github.com/cgewecke/mosaic-1
82+
[10]: https://github.com/ethereum/web3.js/blob/1.x/scripts/e2e.ganache.core.sh
83+
[11]: https://github.com/trufflesuite/ganache-core
84+
85+
[1]: https://github.com/ethereum/web3.js/blob/1.x/test/eth.accounts.sign.js
86+
[2]: https://github.com/ethereum/web3.js/blob/1.x/test/e2e.contract.events.js
87+
[3]: https://github.com/ethereum/web3.js/blob/1.x/test/e2e.minified.js
88+
[4]: https://github.com/ethereum/web3.js/blob/1.x/scripts/e2e.cdn.sh
89+
[5]: https://github.com/ethereum/web3.js/blob/1.x/scripts/e2e.windows.sh

scripts/html/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ <h2> Latest Block </h2>
1111
<p id="blockNumber"></p>
1212
<p id="timestamp"></p>
1313
<p id="gasLimit"></p>
14+
15+
<h4> Important: this test site is shared by all pull requests & is overwritten by the most recent run. </h4>
16+
<h4> It's only informative when the PR ref number listed below matches your PR. </h4>
17+
1418
<p id="commitHash"></p>
1519
<p id="branch"></p>
1620

@@ -22,11 +26,10 @@ <h2> Latest Block </h2>
2226
document.getElementById("timestamp").innerHTML = "block.timestamp: " + block.timestamp;
2327
document.getElementById("gasLimit").innerHTML = "block.gasLimit: " + block.gasLimit;
2428
document.getElementById("today").innerHTML = "Today is " + Date(block.timestamp);
25-
document.getElementById("commitHash").innerHTML = "Commit: " + "__COMMIT_HASH__";
29+
document.getElementById("commitHash").innerHTML = "Merge commit hash: " + "__COMMIT_HASH__";
2630
document.getElementById("branch").innerHTML = "Branch: " + "__BRANCH__";
2731
}
2832
writeBlock();
2933
</script>
3034
</body>
3135
</html>
32-

0 commit comments

Comments
 (0)