From ccdf1e23425f6d04e34ac95750d6001a1a444b80 Mon Sep 17 00:00:00 2001 From: Samarth Patel Date: Sat, 21 Nov 2026 17:36:39 +0530 Subject: [PATCH] Test repeated EVM prefixes and document merge checks --- CONTRIBUTING.md | 33 +++++++++++++++++++++++++++++++++ tests/evm-prefix.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 CONTRIBUTING.md create mode 100644 tests/evm-prefix.test.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9b911c4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing to validator0x + +## Local setup + +Use Node.js 22.13 or later on the Node 22 line, or a newer supported LTS. From the repository root, install the locked dependencies with `npm ci`. The packed-browser test uses Google Chrome stable. If Chrome is missing, run `npx playwright-core install chrome`. + +## Changing a validator + +Keep validation synchronous and offline with zero runtime dependencies. Put family-specific rules in `src/validators/` and shared encoding or hashing logic in `src/utils/`. Route address input through `AddressValidator.validate` to apply the shared input limit and network policy. + +For a bug fix, add a regression test using a public API and confirm that it fails on the affected revision. Include a valid control when changing which inputs are accepted. For chain or checksum changes, use published protocol vectors and cover malformed inputs, network options and ambiguous detection where applicable. Compare changes to cryptographic primitives against the independent reference implementations used by the differential suite. + +Document changes to public behavior in the README and changelog. For a new entrypoint, follow the export, declaration and packed-consumer requirements in [AGENTS.md](./AGENTS.md). + +## Before opening a pull request + +Run these commands from the repository root. + +```sh +npm run check +npm run test:coverage +npm audit +``` + +`npm run check` runs lint, type checking, unit tests, the production build, differential comparisons and installation tests against the actual npm tarball. The coverage command enforces the repository thresholds. Use `npm test -- tests/evm-prefix.test.ts` for a focused run while developing. + +Open the PR against `main`. Link the issue, describe the user-visible change and include your test results. For a performance change, give the Node version and compare the same inputs on both revisions. Keep generated coverage, build output and package archives out of the diff. + +## Merge checks + +GitHub requires all seven CI jobs before merging into `main`. Six package jobs run on Ubuntu and Windows with Node 22, 24 and 26. Each installs the locked dependencies, runs the full check and audits dependencies. The seventh job checks coverage on Ubuntu with Node 24. If GitHub marks the branch out of date, update it with the latest `main` and let CI run on the new revision. + +For release preparation and publishing permissions, see [RELEASING.md](./RELEASING.md). diff --git a/tests/evm-prefix.test.ts b/tests/evm-prefix.test.ts new file mode 100644 index 0000000..c8699a6 --- /dev/null +++ b/tests/evm-prefix.test.ts @@ -0,0 +1,23 @@ +import { detectBlockchain, EVM_CHAINS, validateAddress, validateBatch } from '../src'; + +describe('EVM address prefixes', () => { + // After stripping one prefix, the remaining 40 characters still contain an x. + const repeatedPrefix = '0x0x' + '1'.repeat(38); + const checksummed = '0x52908400098527886E0F7030069857D2E4169EE7'; + + test.each(EVM_CHAINS)('%s rejects a repeated prefix with default options', chain => { + expect(validateAddress(repeatedPrefix, chain).valid).toBe(false); + }); + + test('detection finds no candidate for the repeated prefix', () => { + expect(detectBlockchain(repeatedPrefix)).toBeNull(); + }); + + test('batch validation accepts either supported spelling and rejects a repeated prefix', () => { + const inputs = [checksummed, repeatedPrefix, checksummed.slice(2)]; + for (const options of [undefined, { strict: true }]) { + expect(validateBatch(inputs, 'ethereum', options).map(result => result.valid)) + .toEqual([true, false, true]); + } + }); +});