• protolambda's avatar
    op-node: sequencing better encapsulated, now with events (#10991) · 89f75545
    protolambda authored
    * op-node: sequencer / engine events refactor
    
    incl sequencer events fixes
    
    * op-node: distinguish block sealing error kinds
    
    * op-node: review fixes, stashed tweaks
    
    * op-node: events based sequencer chaos test
    
    * op-node: fix missing DerivedFrom data in attributes test
    
    * op-node: drop old wip debugging work log
    
    * op-node: sequencer move OnEvent function
    
    * op-node: update stale todo comment
    
    * op-node: detect derivation block-building as sequencer, and avoid conflict
    
    * op-node: clarify comments and rename PayloadSealTemporaryErrorEvent to PayloadSealExpiredErrorEvent to describe applicability better
    
    * op-node: prevent temporary engine error from influencing inactive sequencer
    89f75545
simple_test.go 953 Bytes
package clock

import (
	"testing"
	"time"

	"github.com/stretchr/testify/require"
)

func TestSimpleClock_Now(t *testing.T) {
	c := NewSimpleClock()
	require.Equal(t, time.Unix(0, 0), c.Now())
	expectedTime := time.Now()
	c.v.Store(&expectedTime)
	require.Equal(t, expectedTime, c.Now())
}

func TestSimpleClock_SetTime(t *testing.T) {
	tests := []struct {
		name         string
		expectedTime int64
	}{
		{
			name:         "SetZeroTime",
			expectedTime: 0,
		},
		{
			name:         "SetZeroUnixTime",
			expectedTime: time.Unix(0, 0).Unix(),
		},

		{
			name:         "SetCurrentTime",
			expectedTime: time.Now().Unix(),
		},
		{
			name:         "SetFutureTime",
			expectedTime: time.Now().Add(time.Hour).Unix(),
		},
	}

	for _, test := range tests {
		test := test
		t.Run(test.name, func(t *testing.T) {
			c := NewSimpleClock()
			c.SetTime(uint64(test.expectedTime))
			require.Equal(t, time.Unix(test.expectedTime, 0), c.Now())
		})
	}
}