Skip to content

Commit 4c5ffd5

Browse files
committed
fix: prevent duplicate keys in MetadatumMap arbitrary generator
The property-based test generator for MetadatumMap was creating invalid metadata by allowing duplicate keys (e.g., two empty strings). When duplicate keys were added to the Map, the second insertion would overwrite the first, causing a mismatch between the expected array length and actual Map size. This caused flaky test failures in AuxiliaryData.CML.test.ts when comparing Evolution SDK CBOR output with CML CBOR output. Fixed by using FastCheck.uniqueArray with a selector function that ensures unique keys based on their string values. Fixes intermittent CI failures in test/AuxiliaryData.CML.test.ts
1 parent 44b1b6c commit 4c5ffd5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/evolution/src/core/TransactionMetadatum.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,15 @@ export const arbitrary: FastCheck.Arbitrary<TransactionMetadatum> = FastCheck.on
258258
),
259259
{ maxLength: 3 }
260260
).map((value) => new ArrayMetadatum({ value })),
261-
FastCheck.array(
261+
FastCheck.uniqueArray(
262262
FastCheck.tuple(
263263
FastCheck.string().map((value) => new TextMetadatum({ value })),
264264
int64Arbitrary.map((value) => new IntMetadatum({ value }))
265265
),
266-
{ maxLength: 3 }
266+
{
267+
maxLength: 3,
268+
selector: ([key]) => key.value // Ensure unique keys by their string value
269+
}
267270
).map((entries) => {
268271
const map = new Map()
269272
for (const [key, value] of entries) {

0 commit comments

Comments
 (0)