|
| 1 | +import { expect } from "chai"; |
| 2 | +import { isPackageNotRegisteredError } from "../../src/utils/isPackageNotRegisteredError.js"; |
| 3 | + |
| 4 | +describe("isPackageNotRegisteredError", () => { |
| 5 | + // Each string is what an APM lookup for an unpublished package actually |
| 6 | + // produced, so the first publish must keep working across ethers versions. |
| 7 | + const notRegistered: { name: string; message: string }[] = [ |
| 8 | + { |
| 9 | + name: "toolkit reports no repository", |
| 10 | + message: "Could not resolve name foo.dnp.dappnode.eth: NOREPO" |
| 11 | + }, |
| 12 | + { |
| 13 | + name: "ethers v6 before the custom-error decoding", |
| 14 | + message: "Could not resolve name foo.dnp.dappnode.eth" |
| 15 | + }, |
| 16 | + { |
| 17 | + name: "current ethers decodes the ENS custom error", |
| 18 | + message: "execution reverted: ResolverNotFound(bytes)" |
| 19 | + } |
| 20 | + ]; |
| 21 | + |
| 22 | + for (const { name, message } of notRegistered) { |
| 23 | + it(`detects an unregistered package: ${name}`, () => { |
| 24 | + expect(isPackageNotRegisteredError(new Error(message))).to.equal(true); |
| 25 | + }); |
| 26 | + } |
| 27 | + |
| 28 | + // A registry problem must never be mistaken for an unpublished package, or |
| 29 | + // publish would silently restart versioning from the manifest. |
| 30 | + const realFailures: { name: string; message: string }[] = [ |
| 31 | + { name: "unrelated revert", message: "execution reverted: Unauthorized()" }, |
| 32 | + { name: "network failure", message: "could not detect network" }, |
| 33 | + { name: "bad response", message: "missing response for request" } |
| 34 | + ]; |
| 35 | + |
| 36 | + for (const { name, message } of realFailures) { |
| 37 | + it(`does not swallow a real failure: ${name}`, () => { |
| 38 | + expect(isPackageNotRegisteredError(new Error(message))).to.equal(false); |
| 39 | + }); |
| 40 | + } |
| 41 | + |
| 42 | + it("tolerates a non-Error value", () => { |
| 43 | + expect(isPackageNotRegisteredError(undefined)).to.equal(false); |
| 44 | + expect(isPackageNotRegisteredError("execution reverted: ResolverNotFound(bytes)")).to.equal(true); |
| 45 | + }); |
| 46 | +}); |
0 commit comments