Skip to content

Commit

Permalink
fix unitests and fetcher init with endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
omerlavanet committed Dec 12, 2024
1 parent 6945503 commit ae2633f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion protocol/chainlib/chain_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ type ChainFetcher struct {
}

func (cf *ChainFetcher) FetchEndpoint() lavasession.RPCProviderEndpoint {
return *cf.endpoint
endpoint := cf.endpoint
if endpoint == nil {
return lavasession.RPCProviderEndpoint{}
}
return *endpoint
}

func (cf *ChainFetcher) Validate(ctx context.Context) error {
Expand Down
15 changes: 8 additions & 7 deletions protocol/integration/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"os"
"strconv"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -1434,14 +1433,12 @@ func TestSameProviderConflictReport(t *testing.T) {
lavaChainID: lavaChainID,
}
rpcConsumerOut := createRpcConsumer(t, ctx, rpcConsumerOptions)

conflict := make(chan bool)
conflictSent := false
wg := sync.WaitGroup{}
wg.Add(1)
txConflictDetectionMock := func(ctx context.Context, finalizationConflict *conflicttypes.FinalizationConflict, responseConflict *conflicttypes.ResponseConflict, conflictHandler common.ConflictHandlerInterface) error {
if finalizationConflict == nil {
wg.Done()
require.FailNow(t, "Finalization conflict should not be nil")
conflict <- true
return nil
}
utils.LavaFormatDebug("@@@@@@@@@@@@@@@ Called conflict mock tx", utils.LogAttr("provider0", finalizationConflict.RelayFinalization_0.RelaySession.Provider), utils.LogAttr("provider0", finalizationConflict.RelayFinalization_1.RelaySession.Provider))
Expand All @@ -1453,8 +1450,8 @@ func TestSameProviderConflictReport(t *testing.T) {
if finalizationConflict.RelayFinalization_0.RelaySession.Provider != providers[0].account.Addr.String() {
require.FailNow(t, "Finalization conflict provider address is not the provider address")
}
wg.Done()
conflictSent = true
conflict <- false
return nil
}
rpcConsumerOut.mockConsumerStateTracker.SetTxConflictDetectionWrapper(txConflictDetectionMock)
Expand Down Expand Up @@ -1484,7 +1481,11 @@ func TestSameProviderConflictReport(t *testing.T) {
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
// conflict calls happen concurrently, therefore we need to wait the call.
wg.Wait()
select {
case <-time.After(3 * time.Minute):
require.FailNow(t, "timeout waiting for conflict")
case <-conflict:
}
require.True(t, conflictSent)
})

Expand Down
5 changes: 4 additions & 1 deletion protocol/rpcconsumer/rpcconsumer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1667,10 +1667,13 @@ func (rpccs *RPCConsumerServer) ExtensionsSupported(internalPath string, extensi

// this function sends relays to the provider and according to the results enhances capabilities of the consumer such as parsing of data and errors
func (rpccs *RPCConsumerServer) ExtractNodeData(ctx context.Context) {
endpoint := &lavasession.RPCProviderEndpoint{ChainID: rpccs.listenEndpoint.ChainID, ApiInterface: rpccs.listenEndpoint.ApiInterface, NodeUrls: []common.NodeUrl{{
Url: "Internal",
}}}
chainFetcher := chainlib.NewChainFetcher(ctx, &chainlib.ChainFetcherOptions{
ChainRouter: rpccs,
ChainParser: rpccs.chainParser,
Endpoint: nil,
Endpoint: endpoint,
Cache: nil,
})
// we want a block that will surely fail
Expand Down

0 comments on commit ae2633f

Please sign in to comment.