From 5f17d872d51870f3e07a49f7d8e8820786c7b2b1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 21 Jan 2025 12:52:01 +0100 Subject: [PATCH] fix: diff unequal mappings (#187) --- src/govv3/checks/state.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/govv3/checks/state.ts b/src/govv3/checks/state.ts index 6605b09..875a3d8 100644 --- a/src/govv3/checks/state.ts +++ b/src/govv3/checks/state.ts @@ -47,11 +47,14 @@ function getContractChanges(diffs: StateDiff[]) { // This is a complex type like a mapping, which may have multiple changes. The diff.original // and diff.dirty fields can be strings or objects, and for complex types they are objects, // so we cast them as such - const keys = Object.keys(diff.original); - const original = diff.original as Record; - const dirty = diff.dirty as Record; + const keys = Array.from( + new Set([...Object.keys(diff.original || {}), ...Object.keys(diff.dirty || {})]), + ); + const original = (diff.original || {}) as Record; + const dirty = (diff.dirty || {}) as Record; for (const k of keys as Hex[]) { - changes.push({before: original[k], after: dirty[k], name: k, type: diff.soltype?.name}); + if (original[k] || dirty[k]) + changes.push({before: original[k], after: dirty[k], name: k, type: diff.soltype?.name}); } } else { // TODO arrays and nested mapping are currently not well supported -- find a transaction