code.vegaprotocol.io/vega@v0.79.0/core/events/bus_test.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package events_test
    17  
    18  import (
    19  	"context"
    20  	"testing"
    21  	"time"
    22  
    23  	"code.vegaprotocol.io/vega/core/events"
    24  	vgcontext "code.vegaprotocol.io/vega/libs/context"
    25  
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  func TestTimeEvent(t *testing.T) {
    30  	now := time.Now()
    31  	ctx := context.Background()
    32  	e := events.NewTime(ctx, now)
    33  	assert.Equal(t, e.Time(), now)
    34  	assert.Equal(t, events.TimeUpdate, e.Type())
    35  	assert.NotEmpty(t, e.TraceID())
    36  	_, trace := vgcontext.TraceIDFromContext(e.Context())
    37  	assert.NotNil(t, trace)
    38  	assert.Equal(t, trace, e.TraceID())
    39  	assert.Zero(t, e.Sequence())
    40  }
    41  
    42  func TestContextReplace(t *testing.T) {
    43  	now := time.Now()
    44  	ctx := vgcontext.WithBlockHeight(context.Background(), 100)
    45  	e := events.NewTime(ctx, now)
    46  	assert.Equal(t, int64(100), e.BlockNr())
    47  
    48  	ctx = vgcontext.WithBlockHeight(context.Background(), 200)
    49  	e.Replace(ctx)
    50  	assert.Equal(t, int64(200), e.BlockNr())
    51  }