Skip to content

Commit

Permalink
fixed head broadcaster test
Browse files Browse the repository at this point in the history
  • Loading branch information
yongkangc committed Jun 23, 2023
1 parent 50c96cc commit 5d3b2b8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pkg/solana/headtracker/head_broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@ import (
"github.com/stretchr/testify/require"

commonhtrk "github.com/smartcontractkit/chainlink-relay/pkg/headtracker"
commontypes "github.com/smartcontractkit/chainlink-relay/pkg/types"
commonmocks "github.com/smartcontractkit/chainlink-relay/pkg/types/mocks"

"github.com/smartcontractkit/chainlink-solana/pkg/solana/headtracker"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/headtracker/types"

// configtest "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest/v2"
"github.com/smartcontractkit/chainlink-solana/pkg/internal/testutils"
// "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink-relay/pkg/logger"
// "github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
// "github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink-relay/pkg/services"
commontypes "github.com/smartcontractkit/chainlink-relay/pkg/types"
commonmocks "github.com/smartcontractkit/chainlink-relay/pkg/types/mocks"
"github.com/smartcontractkit/chainlink-relay/pkg/utils"
"github.com/smartcontractkit/chainlink-solana/pkg/internal/cltest"
"github.com/smartcontractkit/chainlink-solana/pkg/internal/testutils"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/headtracker"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/headtracker/types"
)

func waitHeadBroadcasterToStart(t *testing.T, hb commontypes.HeadBroadcaster[*types.Head, types.Hash]) {
Expand All @@ -43,6 +37,7 @@ func waitHeadBroadcasterToStart(t *testing.T, hb commontypes.HeadBroadcaster[*ty
func TestHeadBroadcaster_Subscribe(t *testing.T) {
t.Parallel()
g := gomega.NewWithT(t)
g.SetDefaultEventuallyTimeout(1 * time.Second)

lggr, _ := logger.New()
sub := commonmocks.NewSubscription(t)
Expand Down Expand Up @@ -87,14 +82,17 @@ func TestHeadBroadcaster_Subscribe(t *testing.T) {
g.Eventually(checker1.OnNewLongestChainCount).Should(gomega.Equal(int32(1)))

latest2, _ := hb.Subscribe(checker2)

// "latest head" is set here to the most recent head received
assert.NotNil(t, latest2)
assert.Equal(t, firstHead.BlockNumber(), latest2.BlockNumber())

unsubscribe1()

headers <- secondHead
g.Eventually(checker2.OnNewLongestChainCount).Should(gomega.Equal(int32(1)))
// sleep for 3 seconds
time.Sleep(3 * time.Second)
g.Eventually(checker2.OnNewLongestChainCount).Should(gomega.Equal(int32(1))) // TODO: Fix this test
}

func TestHeadBroadcaster_BroadcastNewLongestChain(t *testing.T) {
Expand Down

0 comments on commit 5d3b2b8

Please sign in to comment.