From d508816d16e57411b1e5d297e4fdefa154df02b1 Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Thu, 11 Jan 2024 12:09:38 +0200 Subject: [PATCH 1/2] Support milliseconds for time delta in Test.moveTime --- runtime/stdlib/test-framework.go | 2 +- runtime/stdlib/test_emulatorbackend.go | 2 +- runtime/stdlib/test_test.go | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/runtime/stdlib/test-framework.go b/runtime/stdlib/test-framework.go index 8fc3db0753..e3404f72f5 100644 --- a/runtime/stdlib/test-framework.go +++ b/runtime/stdlib/test-framework.go @@ -75,7 +75,7 @@ type Blockchain interface { Reset(uint64) - MoveTime(int64) + MoveTime(float64) CreateSnapshot(string) error diff --git a/runtime/stdlib/test_emulatorbackend.go b/runtime/stdlib/test_emulatorbackend.go index 1fa3d6eef6..7e31b8dfd3 100644 --- a/runtime/stdlib/test_emulatorbackend.go +++ b/runtime/stdlib/test_emulatorbackend.go @@ -726,7 +726,7 @@ func (t *testEmulatorBackendType) newMoveTimeFunction( if !ok { panic(errors.NewUnreachableError()) } - blockchain.MoveTime(int64(timeDelta.ToInt(invocation.LocationRange))) + blockchain.MoveTime(float64(timeDelta) / sema.Fix64Factor) return interpreter.Void }, ) diff --git a/runtime/stdlib/test_test.go b/runtime/stdlib/test_test.go index c390d0616d..bac4ebad9b 100644 --- a/runtime/stdlib/test_test.go +++ b/runtime/stdlib/test_test.go @@ -2366,18 +2366,18 @@ func TestBlockchain(t *testing.T) { // timeDelta is the representation of 35 days, // in the form of seconds. let timeDelta = Fix64(35 * 24 * 60 * 60) - Test.moveTime(by: timeDelta) + Test.moveTime(by: timeDelta + 0.5) } - ` + ` moveTimeInvoked := false testFramework := &mockedTestFramework{ emulatorBackend: func() Blockchain { return &mockedBlockchain{ - moveTime: func(timeDelta int64) { + moveTime: func(timeDelta float64) { moveTimeInvoked = true - assert.Equal(t, int64(3024000), timeDelta) + assert.Equal(t, 3024000.5, timeDelta) }, } }, @@ -2405,16 +2405,16 @@ func TestBlockchain(t *testing.T) { let timeDelta = Fix64(35 * 24 * 60 * 60) * -1.0 Test.moveTime(by: timeDelta) } - ` + ` moveTimeInvoked := false testFramework := &mockedTestFramework{ emulatorBackend: func() Blockchain { return &mockedBlockchain{ - moveTime: func(timeDelta int64) { + moveTime: func(timeDelta float64) { moveTimeInvoked = true - assert.Equal(t, int64(-3024000), timeDelta) + assert.Equal(t, -3024000.0, timeDelta) }, } }, @@ -2439,14 +2439,14 @@ func TestBlockchain(t *testing.T) { fun testMoveTime() { Test.moveTime(by: 3000) } - ` + ` moveTimeInvoked := false testFramework := &mockedTestFramework{ emulatorBackend: func() Blockchain { return &mockedBlockchain{ - moveTime: func(timeDelta int64) { + moveTime: func(timeDelta float64) { moveTimeInvoked = true }, } @@ -2876,7 +2876,7 @@ type mockedBlockchain struct { serviceAccount func() (*Account, error) events func(inter *interpreter.Interpreter, eventType interpreter.StaticType) interpreter.Value reset func(uint64) - moveTime func(int64) + moveTime func(float64) createSnapshot func(string) error loadSnapshot func(string) error } @@ -2989,7 +2989,7 @@ func (m mockedBlockchain) Reset(height uint64) { m.reset(height) } -func (m mockedBlockchain) MoveTime(timeDelta int64) { +func (m mockedBlockchain) MoveTime(timeDelta float64) { if m.moveTime == nil { panic("'SetTimestamp' is not implemented") } From 913cfcc46146d3e5171a38e7f488384ee89176cd Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Thu, 11 Jan 2024 19:15:29 +0200 Subject: [PATCH 2/2] Fix indentation changes --- runtime/stdlib/test_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/stdlib/test_test.go b/runtime/stdlib/test_test.go index bac4ebad9b..a3892e6e9b 100644 --- a/runtime/stdlib/test_test.go +++ b/runtime/stdlib/test_test.go @@ -2368,7 +2368,7 @@ func TestBlockchain(t *testing.T) { let timeDelta = Fix64(35 * 24 * 60 * 60) Test.moveTime(by: timeDelta + 0.5) } - ` + ` moveTimeInvoked := false @@ -2405,7 +2405,7 @@ func TestBlockchain(t *testing.T) { let timeDelta = Fix64(35 * 24 * 60 * 60) * -1.0 Test.moveTime(by: timeDelta) } - ` + ` moveTimeInvoked := false @@ -2439,7 +2439,7 @@ func TestBlockchain(t *testing.T) { fun testMoveTime() { Test.moveTime(by: 3000) } - ` + ` moveTimeInvoked := false