Skip to content

Commit d1a862d

Browse files
committed
Merge branch 'ceyonur/acp-226-verify-min-delay-excess' into ceyonur/acp-226-min-block-delay-verify
2 parents e714170 + d7e9d59 commit d1a862d

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

plugin/evm/customheader/time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
ErrFutureTimestampAbuse = errors.New("future timestamp abuse detected")
3030
)
3131

32-
// GetNextTimestamp calculates the timestamp (in seconds and milliseconds) for the header based on the parent's timestamp and the current time.
32+
// GetNextTimestamp calculates the timestamp (in seconds and milliseconds) for the next child block based on the parent's timestamp and the current time.
3333
// First return value is the timestamp in seconds, second return value is the timestamp in milliseconds.
3434
func GetNextTimestamp(parent *types.Header, now time.Time) (uint64, uint64) {
3535
var (

plugin/evm/customheader/time_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,75 @@ func TestVerifyTime(t *testing.T) {
298298
})
299299
}
300300
}
301+
302+
func TestGetNextTimestamp(t *testing.T) {
303+
now := time.Unix(1714339200, 123_456_789) // Fixed timestamp for consistent testing
304+
nowSeconds := uint64(now.Unix())
305+
nowMillis := uint64(now.UnixMilli())
306+
307+
tests := []struct {
308+
name string
309+
parent *types.Header
310+
now time.Time
311+
expectedSec uint64
312+
expectedMillis uint64
313+
}{
314+
{
315+
name: "current_time_after_parent_time_no_milliseconds",
316+
parent: generateHeader(nowSeconds-10, nil),
317+
now: now,
318+
expectedSec: nowSeconds,
319+
expectedMillis: nowMillis,
320+
},
321+
{
322+
name: "current_time_after_parent_time_with_milliseconds",
323+
parent: generateHeader(nowSeconds-10, utils.NewUint64(nowMillis-500)),
324+
now: now,
325+
expectedSec: nowSeconds,
326+
expectedMillis: nowMillis,
327+
},
328+
{
329+
name: "current_time_equals_parent_time_no_milliseconds",
330+
parent: generateHeader(nowSeconds, nil),
331+
now: now,
332+
expectedSec: nowSeconds,
333+
expectedMillis: nowSeconds * 1000, // parent.Time * 1000
334+
},
335+
{
336+
name: "current_time_equals_parent_time_with_milliseconds",
337+
parent: generateHeader(nowSeconds, utils.NewUint64(nowMillis)),
338+
now: now,
339+
expectedSec: nowSeconds,
340+
expectedMillis: nowMillis, // parent's TimeMilliseconds
341+
},
342+
{
343+
name: "current_time_before_parent_time",
344+
parent: generateHeader(nowSeconds+10, nil),
345+
now: now,
346+
expectedSec: nowSeconds + 10,
347+
expectedMillis: (nowSeconds + 10) * 1000, // parent.Time * 1000
348+
},
349+
{
350+
name: "current_time_before_parent_time_with_milliseconds",
351+
parent: generateHeader(nowSeconds+10, utils.NewUint64(nowMillis)),
352+
now: now,
353+
expectedSec: nowSeconds + 10,
354+
expectedMillis: nowMillis, // parent's TimeMilliseconds
355+
},
356+
{
357+
name: "current_time_milliseconds_before_parent_time_milliseconds",
358+
parent: generateHeader(nowSeconds, utils.NewUint64(nowMillis+10)),
359+
now: now,
360+
expectedSec: nowSeconds,
361+
expectedMillis: nowMillis + 10, // parent's TimeMilliseconds
362+
},
363+
}
364+
365+
for _, test := range tests {
366+
t.Run(test.name, func(t *testing.T) {
367+
sec, millis := GetNextTimestamp(test.parent, test.now)
368+
require.Equal(t, test.expectedSec, sec)
369+
require.Equal(t, test.expectedMillis, millis)
370+
})
371+
}
372+
}

0 commit comments

Comments
 (0)