<divclass="link title"><ahref="/v5/">Documentation</a></div><divclass="base show link depth-1"><ahref="/v5/getting-started/">Getting Started</a></div><divclass="base show link depth-1"><ahref="/v5/concepts/">Ethereum Basics</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/events/">Events</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/gas/">Gas</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/security/">Security</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/best-practices/">Best Practices</a></div><divclass="base show link depth-1"><ahref="/v5/api-keys/">Provider API Keys</a></div><divclass="base show link depth-1"><ahref="/v5/api/">Application Programming Interface</a></div><divclass="hide link depth-2"><ahref="/v5/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/provider/">Provider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/other/">Other Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/types/">Types</a></div><divclass="hide link depth-2"><ahref="/v5/api/signer/">Signers</a></div><divclass="hide link depth-2"><ahref="/v5/api/contract/">Contract Interaction</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract/">Contract</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract-factory/">ContractFactory</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><divclass="hide link depth-2"><ahref="/v5/api/utils/">Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/abi/">Application Binary Interface</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/coder/">AbiCoder</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/formats/">ABI Formats</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/fragments/">Fragments</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/interface/">Interface</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/address/">Addresses</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/bignumber/">BigNumber</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/bytes/">Byte Manipulation</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/constants/">Constants</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/display-logic/">Display Logic and Input</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/encoding/">Encoding Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/fixednumber/">FixedNumber</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/hashing/">Hashing Algorithms</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/hdnode/">HD Wallet</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/logger/">Logging</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/properties/">Property Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/signing-key/">Signing Key</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/strings/">Strings</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/transactions/">Transactions</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/web/">Web Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/wordlists/">Wordlists</a></div><divclass="hide link depth-2"><ahref="/v5/api/other/">Other Libraries</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/assembly/">Assembly</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/api/">Utilities</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/ast/
<aname="testing"></a><h1class="show-anchors"><div>Testing<divclass="anchors"><aclass="self"href="/v5/testing/#testing"></a></div></div></h1><p>Testing is a critical part of any library which wishes to remain secure, safe and reliable.</p>
<p>Ethers currently has <b>over 23k tests</b> among its test suites, which are all made available for other projects to use as simple exported GZIP-JSON files.</p>
<p>The tests are run on every check-in and the results can been seen on the <ahref="https://github.com/ethers-io/ethers.js/actions/runs/158006903">GitHub CI Action</a>.</p>
<p>We also strive to constantly add new test cases, especially when issues arise to ensure the issue is present prior to the fix, corrected after the fix and included to prevent future changes from causing a regression.</p>
<p>A large number of the test cases were created procedurally by using known correct implementations from various sources (such as Geth) and written in different languages and verified with multiple libraries.</p>
<p>For example, the ABI test suites were generated by procedurally generating a list of types, for each type choosing a random (valid) value, which then was converted into a Solidity source file, compiled using <codeclass="inline">solc</code> and deployed to a running Parity node and executed, with its outputs being captured. Similar to the how many of the hashing, event and selector test cases were created.</p>
<aname="testing-supported"></a><aname="testing--testing-supported"></a><h2class="show-anchors"><div>Supported Platforms<divclass="anchors"><aclass="self"href="/v5/testing/#testing-supported"></a></div></div></h2><p>While web technologies move quite fast, especially in the Web3 universe, we try to keep ethers as accessible as possible.</p>
<p>Currently ethers should work on almost any ES3 or better environment and tests are run against:</p>
<p>If there is an environment you feel has been overlooked or have suggestions, please feel free to reach out by opening an <ahref="https://github.com/ethers-io/ethers.js/issues">issue on Github</a>.</p>
<p>We would like to add a test build for Expo and React as those developers often seem to encounter pain points when using ethers, so if you have experience or ideas on this, <ahref="https://github.com/ethers-io/ethers.js/issues">bug us</a>.</p>
<p>The next Major version (probably summer 2021) will likely drop support for node 8.x and will require ES2015 for <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy">Proxy</a>.</p>
<p>Certain features in JavaScript are also avoided, such as look-behind tokens in regular expressions, since these have caused conflicts (at import time) with certain JavaScript environments such as <ahref="https://github.com/robertkrimen/otto">Otto</a>.</p>
<aname="testing-suites"></a><aname="testing--testing-suites"></a><h2class="show-anchors"><div>Test Suites<divclass="anchors"><aclass="self"href="/v5/testing/#testing-suites"></a></div></div></h2><p>The test suites are available as gzipped JSON files in the <codeclass="inline">@ethersproject/testcases</code>, which makes it easy to install and import (both GZIP and JSON are quite easy to consume from most languages). Each test suite also has its schema available in this package.</p>
<tableclass="table full"><tr><tdalign="center"width="34%"><b>Filename</b></td><tdalign="center"colspan="2"width="66%"><b>Test Cases</b></td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">accounts.json.gz</td><tdalign="left"colspan="2"width="66%">Private Keys and addresses in checksum and ICAP formats</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">contract-events.json.gz</td><tdalign="left"colspan="2"width="66%">Compiled Solidity, ABI interfaces, input types/values with the output types/values for emitted events; all tests were executed against real Ethereum nodes</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">contract-interface.json.gz</td><tdalign="left"colspan="2"width="66%">Compiled Solidity, ABI interfaces, input types/values with the output types/values, encoded and decoded binary data and normalized values for function calls executed against real Ethereum nodes.</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">contract-interface-abi2.json.gz</td><tdalign="left"colspan="2"width="66%">Identical to <codeclass="inline">contract-interface</code>, except with emphasis on the ABIv2 coder which supports nested dynami types and structured data</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">contract-signatures.json.gz</td><tdalign="left"colspan="2"width="66%">Contract signatures and matching selectors</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">hashes.json.gz</td><tdalign="left"colspan="2"width="66%">Data and respective hashes against a variety of hash functions</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">hdnode.json.gz</td><tdalign="left"colspan="2"width="66%">HDNodes (BIP-32) with mnemonics, entropy, seed and computed nodes with pathes and addresses</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">namehash.json.gz</td><tdalign="left"colspan="2"width="66%">ENS names along with computed [namehashes](link-namehash</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">nameprep.json.gz</td><tdalign="left"colspan="2"width="66%">IDNA and Nameprep representations including official vectors</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">rlp-coder.json.gz</td><tdalign="left"colspan="2"width="66%">Recursive-Length Prefix (RLP) data and encodings</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">solidity-hashes.json.gz</td><tdalign="left"colspan="2"width="66%">Hashes based on the Solidity non-standard packed form</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">transactions.json.gz</td><tdalign="left"colspan="2"width="66%">Signed and unsigned transactions with their serialized formats including both with and without EIP-155 replay protection</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">units.json.gz</td><tdalign="left"colspan="2"width="66%">Values converted between various units</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">wallets.json.gz</td><tdalign="left"colspan="2"width="66%">Keystore JSON format wallets, passwords and decrypted values</td><tdclass="fix"> </td></tr><tr><tdalign="left"width="34%">wordlists.json.gz</td><tdalign="left"colspan="2"width="66%">Fully decompressed BIP-39 official wordlists</td><tdclass="fix"> </td></tr><tr><tdclass="table-title"colspan="3">Test Suites</td><tdclass="fix"> </td></tr></table><aname="testing-api"></a><aname="testing--testing-api"></a><h2class="show-anchors"><div>Test Suite API<divclass="anchors"><aclass="self"href="/v5/testing/#testing-api"></a></div></div></h2><p>There are also convenience functions for those developing directly in TypeScript.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">testcases</span><spanclass="symbol">.</span><spanclass="method">loadTests</span><spanclass="symbol">(</span><spanclass="param">tag</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">Array< TestCase ></span><divclass="anchors"></div></div><divclass="body"><p>Load all the given testcases for the <i>tag</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">testcases</span><spanclass="symbol">.</span><spanclass="path">TestCase</span><spanclass="symbol">.</span><spanclass="method">TEST_NAME</span><divclass="anchors"></div></div><divclass="body"><p>Most testcases have its schema available as a TypeScript type to make testing each property easier.</p>
</div></div><aname="testing--testing-api--deterministic-random-numbers-drng"></a><h3class="show-anchors"><div>Deterministic Random Numbers (DRNG)<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-api--deterministic-random-numbers-drng"></a></div></div></h3><p>When creating test cases, often we want want random data from the perspective we do not case what values are used, however we want the values to be consistent across runs. Otherwise it becomes difficult to reproduce an issue.</p>
<p>In each of the following the seed is used to control the random value returned. Be sure to tweak the seed properly, for example on each iteration change the value and in recursive functions, concatenate to the seed.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">testcases</span><spanclass="symbol">.</span><spanclass="method">randomBytes</span><spanclass="symbol">(</span><spanclass="param">seed</span><spanclass="symbol">,</span><spanclass="param">lower</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">upper</span><spanclass="symbol">]</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span><divclass="anchors"></div></div><divclass="body"><p>Return at least <i>lower</i> random bytes, up to <i>upper</i> (exclusive) if specified, given <i>seed</i>. If <i>upper</i> is omitted, exactly <i>/lower</i> bytes are returned.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">testcases</span><spanclass="symbol">.</span><spanclass="method">randomHexString</span><spanclass="symbol">(</span><spanclass="param">seed</span><spanclass="symbol">,</span><spanclass="param">lower</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">upper</span><spanclass="symbol">]</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>></span><divclass="anchors"></div></div><divclass="body"><p>Identical to randomBytes, except returns the value as a <ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a> instead of a Uint8Array.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">testcases</span><spanclass="symbol">.</span><spanclass="method">randomNumber</span><spanclass="symbol">(</span><spanclass="param">seed</span><spanclass="symbol">,</span><spanclass="param">lower</span><spanclass="symbol">,</span><spanclass="param">upper</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">number</span><divclass="anchors"></div></div><divclass="body"><p>Returns a random number of at least <i>lower</i> and less than <i>upper</i> given <i>seed</i>.</p>
</div></div><aname="testing-schemas"></a><aname="testing--testing-schemas"></a><h2class="show-anchors"><div>Schemas<divclass="anchors"><aclass="self"href="/v5/testing/#testing-schemas"></a></div></div></h2><p>This section is still a work in progress, but will outline some of the more nuanced aspects of the test cases and their values.</p>
<p>There will likely be an overhaul of the test cases in the next major version, to make code coverage testing more straight forward and to collapse some of the redundancy.</p>
<p>For example, there is no longer a need to separate the ABI and ABIv2 test case and the accounts and transactions suites can be merged into one large collection.</p>
<aname="testing--testing-schemas--accounts"></a><h3class="show-anchors"><div>Accounts<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-schemas--accounts"></a></div></div></h3><p>Basic account information using a private key and computing various address forms.</p>
<p>Tests were verified against [EthereumJS](https://github.com/ethereumjs) and custom scripts created to directly interact with Geth and cpp implementations.</p>
</div><aname="testing--testing-schemas--contract-interface"></a><h3class="show-anchors"><div>Contract Interface<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-schemas--contract-interface"></a></div></div></h3><p>Procedurally generated test cases to test ABI coding.</p>
</div><aname="testing--testing-schemas--contract-signatures"></a><h3class="show-anchors"><div>Contract Signatures<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-schemas--contract-signatures"></a></div></div></h3><p>Computed ABI signatures and the selector hash.</p>
</div><aname="testing--testing-schemas--hierarchal-deterministic-node-bip-32"></a><h3class="show-anchors"><div>Hierarchal Deterministic Node (BIP-32)<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-schemas--hierarchal-deterministic-node-bip-32"></a></div></div></h3><p>Tests for <ahref="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki">BIP-32</a> HD Wallets.</p>
"mnemonic": "void come effort suffer camp survey warrior heavy shoot primary clutch crush open amazing screen patrol group space point ten exist slush involve unfold",
</div><aname="testing--testing-schemas--ens-namehash"></a><h3class="show-anchors"><div>ENS Namehash<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-schemas--ens-namehash"></a></div></div></h3><p>Test cases for the <ahref="https://docs.ens.domains/contract-api-reference/name-processing#hashing-names">ENS Namehash Algorithm</a>.</p>
</div><aname="testing--testing-schemas--solidity-hashes"></a><h3class="show-anchors"><div>Solidity Hashes<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-schemas--solidity-hashes"></a></div></div></h3><p>Tests for the non-standard packed form of the Solidity hash functions.</p>
<p>These tests were created by procedurally generating random signatures and values that match those signatures, constructing the equivalent Soldity, compiling it and deploying it to a Parity node then evaluating the response.</p>
</div><aname="testing--testing-schemas--transactions"></a><h3class="show-anchors"><div>Transactions<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-schemas--transactions"></a></div></div></h3><p>Serialized signed and unsigned transactions with both EIP-155 enabled and disabled.</p>
</div><aname="testing--testing-schemas--wallets"></a><h3class="show-anchors"><div>Wallets<divclass="anchors"><aclass="self"href="/v5/testing/#testing--testing-schemas--wallets"></a></div></div></h3><p>Tests for the JSON keystore format.</p>
<divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on February 8, 2021, 3:25pm.</div>