Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion scripts/checkStorageLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,32 @@ function hasContract(output: { contracts?: Record<string, Record<string, unknown
return Boolean(output.contracts?.[fqName.slice(0, at)]?.[fqName.slice(at + 1)]);
}

/**
* Artifacts don't record `@custom:oz-renamed-from`, and OZ reports a rename whenever the current
* annotation differs from the deployed one, even if the label is unchanged. So once a rename ships, its
* annotation would fail every later run. Copying the annotation onto the deployed variable with the same
* slot, offset and label restores what OZ's own manifest would hold. A real rename has a different label,
* so it is still caught. The slot is matched too because labels like `__gap` repeat across inherited
* contracts.
*/
function restoreDeployedRenames(deployed: Layout, updated: Layout): void {
for (const old of deployed.storage) {
const same = updated.storage.find(
item => item.slot === old.slot && item.offset === old.offset && item.label === old.label,
);
if (same) old.renamedFrom = same.renamedFrom;
}
Comment thread
GitGuru7 marked this conversation as resolved.
Resolved
}

/** Compares one deployed layout against the current source, returning undefined when they are
* compatible. A contract missing from build-info is a failure rather than a skip, so a source
* that was renamed or deleted cannot drop out of the check unnoticed. */
function check(target: Target, current: Map<string, Layout>): string | undefined {
const updated = target.fqName ? current.get(target.fqName) : undefined;
if (!updated) return `${target.fqName} was not found in artifacts/build-info`;
const report = getStorageUpgradeReport(target.deployed as Layout, updated, withValidationDefaults({}));
const deployed = target.deployed as Layout;
restoreDeployedRenames(deployed, updated);
const report = getStorageUpgradeReport(deployed, updated, withValidationDefaults({}));
return report.ok ? undefined : report.explain(false);
}

Expand Down
Loading