Skip to content

Commit 1905f12

Browse files
committed
fix(scaffold): correct entity ID format in generated tests
When generating test files with --index-events, the entity ID format was using the old string concatenation format ('-1') instead of the format produced by concatI32() ('01000000'). This caused all generated tests to fail out-of-the-box. Changes: - Update entity ID in test assertions from '-1' to '01000000' format - Improve comment to explain concatI32() encoding with little-endian bytes - Correct terminology from "default address" to "default transaction hash" This fixes a bug introduced in commit 34aee49 (Oct 2022) when Bytes as ID with @immutable was implemented. The mapping and schema templates were updated but the test template was missed.
1 parent 8455ab9 commit 1905f12

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

packages/cli/src/scaffold/__snapshots__/ethereum.test.ts.snap

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,34 +315,36 @@ describe("Describe entity assertions", () => {
315315
test("ExampleEvent created and stored", () => {
316316
assert.entityCount("ExampleEvent", 1)
317317
318-
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function
318+
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default transaction hash used in newMockEvent() function
319+
// When indexEvents is true, entity ID uses concatI32() which appends log index as little-endian bytes
320+
// Default log index 1 becomes: 01000000 (4 bytes: 0x01 0x00 0x00 0x00)
319321
assert.fieldEquals(
320322
"ExampleEvent",
321-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
323+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
322324
"a",
323325
"234"
324326
)
325327
assert.fieldEquals(
326328
"ExampleEvent",
327-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
329+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
328330
"b",
329331
"[1234567890]"
330332
)
331333
assert.fieldEquals(
332334
"ExampleEvent",
333-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
335+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
334336
"param2",
335337
"Example string value"
336338
)
337339
assert.fieldEquals(
338340
"ExampleEvent",
339-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
341+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
340342
"c",
341343
"ethereum.Tuple Not implemented"
342344
)
343345
assert.fieldEquals(
344346
"ExampleEvent",
345-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
347+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
346348
"d",
347349
"Example string value"
348350
)
@@ -482,34 +484,36 @@ describe("Describe entity assertions", () => {
482484
test("ExampleEvent created and stored", () => {
483485
assert.entityCount("ExampleEvent", 1)
484486
485-
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function
487+
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default transaction hash used in newMockEvent() function
488+
// When indexEvents is true, entity ID uses concatI32() which appends log index as little-endian bytes
489+
// Default log index 1 becomes: 01000000 (4 bytes: 0x01 0x00 0x00 0x00)
486490
assert.fieldEquals(
487491
"ExampleEvent",
488-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
492+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
489493
"a",
490494
"234"
491495
)
492496
assert.fieldEquals(
493497
"ExampleEvent",
494-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
498+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
495499
"b",
496500
"[1234567890]"
497501
)
498502
assert.fieldEquals(
499503
"ExampleEvent",
500-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
504+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
501505
"param2",
502506
"Example string value"
503507
)
504508
assert.fieldEquals(
505509
"ExampleEvent",
506-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
510+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
507511
"c",
508512
"ethereum.Tuple Not implemented"
509513
)
510514
assert.fieldEquals(
511515
"ExampleEvent",
512-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
516+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
513517
"d",
514518
"Example string value"
515519
)

packages/cli/src/scaffold/tests.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const generateFieldsAssertions = (entity: string, eventInputs: any[], indexEvent
9191
(input, index) =>
9292
`assert.fieldEquals(
9393
"${entity}",
94-
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a${indexEvents ? '-1' : ''}",
94+
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a${indexEvents ? '01000000' : ''}",
9595
"${input.name || `param${index}`}",
9696
"${expectedValue(ascTypeForEthereum(input.type))}"
9797
)`,
@@ -171,7 +171,9 @@ const generateExampleTest = (
171171
test("${entity} created and stored", () => {
172172
assert.entityCount('${entity}', 1)
173173
174-
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function
174+
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default transaction hash used in newMockEvent() function
175+
// When indexEvents is true, entity ID uses concatI32() which appends log index as little-endian bytes
176+
// Default log index 1 becomes: 01000000 (4 bytes: 0x01 0x00 0x00 0x00)
175177
${generateFieldsAssertions(entity, eventInputs, indexEvents)}
176178
177179
// More assert options:

0 commit comments

Comments
 (0)