Skip to content

Commit

Permalink
Add codes to make sure block 0 and 1 are tested in TestSmokeRPCCompat…
Browse files Browse the repository at this point in the history
…ibilities
  • Loading branch information
Kourin1996 committed Dec 17, 2024
1 parent 48e967e commit b2a968c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions compat_test/smoke_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func TestSmokeRPCCompatibilities(t *testing.T) {
if opGethRpcURL == "" {
t.Fatal("op-geth rpc url not set example usage:\n go test -v ./compat_test -tags compat_test -run TestSmokeRPCCompatibilities -celo-url ws://localhost:8546 -op-geth-url ws://localhost:9994")
}
if blockInterval == 0 {
t.Fatal("block interval must be positive integer:\n go test -v ./compat_test -tags compat_test -run TestSmokeRPCCompatibilities -celo-url ws://localhost:8546 -op-geth-url ws://localhost:9994 -block-interval 1000000")
}

// Setup RPC clients for Celo L1 and Celo L2 server
celoClient, err := rpc.DialOptions(context.Background(), celoRpcURL, clientOpts...)
Expand Down Expand Up @@ -92,7 +95,11 @@ func TestSmokeRPCCompatibilities(t *testing.T) {
opClient: opClient,
}

// Fetch some random blocks between 0 to lastCeloL1BlockHeight
// Fetch data of the first 2 blocks
asyncFetchRpcData(t, jobCtx, fetchingEg, 0, clients, resultChan)
asyncFetchRpcData(t, jobCtx, fetchingEg, 1, clients, resultChan)

// Fetch some random blocks between blockInterval to lastCeloL1BlockHeight
for currentBlockNumber := uint64(0); currentBlockNumber < lastCeloL1BlockHeight; currentBlockNumber += blockInterval {
// exit loop if context is canceled
if isContextCanceled(jobCtx) {
Expand All @@ -112,11 +119,21 @@ func TestSmokeRPCCompatibilities(t *testing.T) {
offset = uint64(rand.Int63n(int64(randomUpperBound)))
}

targetHeight := currentBlockNumber + offset
if targetHeight < 2 {
// ignore block at 0 and 1 because they're already fetched
if blockInterval == 1 {
continue
}

targetHeight = 2
}

// Fetch data at the point of current range
asyncFetchRpcData(t, jobCtx, fetchingEg, currentBlockNumber+offset, clients, resultChan)
asyncFetchRpcData(t, jobCtx, fetchingEg, targetHeight, clients, resultChan)
}

// Fetch data at the last block
// Fetch data at the last height
asyncFetchRpcData(t, jobCtx, fetchingEg, lastCeloL1BlockHeight, clients, resultChan)

return nil
Expand Down

0 comments on commit b2a968c

Please sign in to comment.