Skip to content

v0.2.0

Choose a tag to compare

@github-actions github-actions released this 08 Nov 20:19
· 104 commits to main since this release
Immutable release. Only release title and notes can be modified.
dcbf328

This release tightens how the mock checks what a test gives it. A value the mock can't use is refused where it's given, with a message that names the call and field (e.g. mock.addTransaction()'s gasUsed must be a non-negative bigint; got -1n.), instead of being ignored or turned into a plausible-looking answer. An explicit undefined now always means the same as leaving the key out, so spreading a partial fixture behaves as expected.

⚠️ Breaking Changes

  • MockEventLog is renamed MockLogContent. It's the type for any log's content, testLog()'s included, not only an event's.
  • A revert spec takes one form: data, panic, or errorName with args. A spec with fields of two forms is a type error, and is refused at runtime.
  • A defaults: entry set to undefined registers no mock. Before, read, simulate and write answered zero for it.
  • Newly refused at registration:
    • a count past Number.MAX_SAFE_INTEGER in times(), failRequests()' times, historyLimit, historyOnFailure or chain.blockTime;
    • a matcher (match.any() and the rest) anywhere a value goes, such as a revert spec's args. Matchers go in a mock's args, params and pins;
    • a failRequests() method that isn't a method name or a list of them, e.g. a regex;
    • a receipt's status that isn't "success" or "reverted", e.g. "0x1" copied from a node;
    • a field that isn't a fee in createMockRpc({ fees }) or mock.setFees(), e.g. the maxFeePerGas of a client.estimateFeesPerGas() result;
    • a receipt mock with logs over a transaction that reverted.
  • Error classes: a negative balance, gas price, fee or fee history value is the mock's MockSetupError, not viem's IntegerOutOfRangeError.
  • Messages: most setup errors are reworded. Assert on the error class (toThrow(MockSetupError)) or its code, not its text.

Bug Fixes

  • An undefined field is left out everywhere: fees, revert specs, a mock's answer fields, and an unknown key holding undefined.
  • A pending transaction can null only some of its block fields.
  • An ABI function named after an Object.prototype member (toString, valueOf) can be mocked.
  • A bigint request param after a fault no longer crashes the request.
  • Errors and warnings use the package's current name. The hint for an estimate or send nothing answers also mentions .reverts().

👉 Changelog

compare changes

🩹 Fixes

  • ⚠️ Refuse a revert spec with fields of two forms (4a53ae7)
  • Point the reverted-receipt refusal at the record (19e25ed)
  • ⚠️ Register no default for a defaults entry that's undefined (5b2dc8f)
  • Refuse a receipt mock with logs over a reverted transaction (caa0b0c)
  • Treat an explicit undefined in a mock's fields as left out (d2c90c1)
  • Treat an undefined panic or data in a revert spec as left out (5aa21ed)
  • Accept a pending transaction that nulls only some of its block fields (06257b8)
  • Treat an undefined fee as left out in createMockRpc and setFees (2304007)
  • Don't crash on bigint request params after a fault (3cc82c8)
  • Mock ABI functions named after Object.prototype members (c98f109)
  • Update package name in errors and warnings; add .reverts() to the estimate and send hint (22ce5c5)

💅 Refactors

  • Refuse placed logs in the log content check, and name each log's call (0fbd443)
  • Hint at fixes for revert-arg matchers, left-out estimates and estimate-shaped fees, and let checkFields take a plain hint (ddb0fb0)
  • ⚠️ Rename MockEventLog to MockLogContent (f6bdc32)
  • Check hex, lists, and objects with helper functions (1d94337)
  • Check fee history fields one-by-one with checkAmount, and word answer object checks alike (b8ca1e6)
  • Note MockInternalError can also come from a value its types don't allow (e78c7a6)
  • Drop typeof checks that isHex and isHash already make, and a dead branch (706da38)
  • Refuse matchers in revert specs and failRequests' method, naming each place (dc28e7a)
  • Check transaction status with one shared checkStatus (aef5e57)
  • Check objects of known fields with one shared checkFields (f2d1853)
  • Check counts with one shared checkCount, and word both helpers alike (b5b5860)
  • Move mock.buildLog()'s placement out of logs/events.ts (e45b449)
  • ⚠️ Check bigint setup values with one shared checkAmount (bdfb78a)
  • Name setup checks check*, keeping assert* for public checks (23cbdb8)

📖 Documentation

  • Name the test command, where domain checks go, multi-call subjects, and how tests pin errors (c031105)
  • Add setup check rules to AGENTS.md and match architecture and notes (9b373c0)
  • Clarify leftOut's comment, notes.md's undefined wording and a test name (3d935b8)
  • Treat an explicit undefined as a key left out (2006149)
  • Only fix and review bugs that real use plausibly hits (9dc6b03)
  • Assert on MockSetupError's class or code, not message text (c489764)
  • Clarify that addTransaction mines a new block by default (96dc5cf)

✅ Tests

  • Set no-isolate on test script (c8c000f)
  • Cover fee history's list checks and failRequests' method lists (b56e23d)

❤️ Contributors