Skip to content

Conversation

@tim-barry
Copy link
Contributor

@tim-barry tim-barry commented Sep 5, 2025

Allow testing on different spork versions, and fix a test that didn't verify what it claimed to.

Summary by CodeRabbit

  • Tests
    • Refactored verification tests to use template-driven network configurations with per-version subtests.
    • Added reusable helpers to verify blocks and execution results over explicit height ranges.
    • Improved header-based hash verification and strengthened assertions for seals, events, and computed results.
    • Replaced legacy helpers with unified templates to reduce duplication and improve error reporting and coverage.

Add configuration for multiple distinct sporks for testing
Remove unused createSpork() function and associated data.
The data was moved to variable `Mainnet24_SporkVersion6`.
The test was not actually verifying anything, due to only checking resultIDs
for current blocks against sealed results of previous blocks.
@coderabbitai
Copy link

coderabbitai bot commented Sep 5, 2025

Walkthrough

Refactors tests in state/convert_test.go: adds a sporkTemplate fixture and two exported templates, converts tests to per-spork subtests, and introduces helpers to verify blocks and execution results over explicit height ranges.

Changes

Cohort / File(s) Summary of changes
Spork templates & fixtures
state/convert_test.go
Added non-exported sporkTemplate type, builder method create(ctx) *config.Spork, and exported fixtures Mainnet24_SporkVersion6 and Mainnet26_SporkVersion7.
Block verification helpers & tests
state/convert_test.go
Introduced VerifyBlocksForSpork that fetches BlockByHeight and BlockHeaderByHeight over explicit height ranges; rewrote TestVerifyBlockHash to use per-spork subtests and the new helper.
Execution result verification helpers & tests
state/convert_test.go
Added VerifyExecutionResultsForSpork using maps keyed by flow.Identifier, computing convertExecutionResult / deriveExecutionResult, tracking seals/computed results, and updated TestVerifyExecutionResultHash to use per-spork subtests.
Event/hash consistency tests
state/convert_test.go
Updated TestDeriveEventsHash and TestExecutionResultConsistency_ChunkServiceEventCountField to run per-spork subtests and to use template-based Spork construction.
Cleanup
state/convert_test.go
Removed legacy createSpork helper and replaced hard-coded height loops with explicit start/end heights passed to helpers.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant TR as Test Runner
  participant ST as sporkTemplate
  participant S as *config.Spork
  participant BS as BlockSource
  participant ERS as ExecResultSource

  rect rgb(235,245,255)
  note right of TR: Per-spork subtest setup
  TR->>ST: build sporkTemplate
  ST-->>TR: S (Spork)
  end

  rect rgb(240,255,240)
  note right of TR: VerifyBlocksForSpork
  TR->>BS: Fetch BlockByHeight / BlockHeaderByHeight [start..end] using S
  BS-->>TR: Blocks & Headers
  TR->>TR: verifyBlockHash per block (compare header/block hash)
  end

  rect rgb(255,250,235)
  note right of TR: VerifyExecutionResultsForSpork
  TR->>ERS: Fetch seals and execution payloads using S
  ERS-->>TR: Seals & payloads
  TR->>TR: convertExecutionResult / deriveExecutionResult -> map by flow.Identifier
  TR->>TR: Compare sealed vs computed results (ensure at least one match)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • jordanschalm
  • peterargue
  • UlyanaAndrukhiv

Poem

I twitch my whiskers at templated light,
Two sporks align for tests tonight.
Blocks and seals in tidy rows,
Hashes checked where river flows.
Old helpers slept — new gardens spring; carrot cheers we bring. 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tim/update-convert-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
state/convert_test.go (5)

41-54: Enable TLS for real access nodes (avoid insecure dials and fatal dial failures)

These are production mainnet endpoints; dialing without TLS will use insecure creds in access.New and likely fail. Set TLS: true (or provide PublicKey) for each NodeConfig.

Apply:

 var Mainnet24_SporkVersion6 = sporkTemplate{
-	AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet24.nodes.onflow.org:9000"}},
+	AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet24.nodes.onflow.org:9000", TLS: true}},
 	Chain:       config.Chain{Network: "mainnet"},
 	RootBlock:   65264619,
 	Version:     6,
 }

 var Mainnet26_SporkVersion7 = sporkTemplate{
-	AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet26.nodes.onflow.org:9000"}},
+	AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet26.nodes.onflow.org:9000", TLS: true}},
 	Chain:       config.Chain{Network: "mainnet"},
 	RootBlock:   125_000_000,
 	Version:     7,
 }

If TLS is not accepted by these hosts in your env, please confirm the expected setting for NodeConfig (TLS vs PublicKey).


55-66: Bound network calls with timeouts in subtests

Guard against hangs by using context.WithTimeout in each subtest.

 t.Run("mainnet24 spork version 6", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
 	spork := Mainnet24_SporkVersion6.create(ctx)
 	VerifyBlocksForSpork(t, ctx, spork, 65264620, 65264630)
 })
 t.Run("mainnet26 spork version 7", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
 	spork := Mainnet26_SporkVersion7.create(ctx)
 	VerifyBlocksForSpork(t, ctx, spork, 125_000_001, 125_000_011)
 })
 t.Run("mainnet24 spork version 6", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
 	spork := Mainnet24_SporkVersion6.create(ctx)
 	VerifyExecutionResultsForSpork(t, ctx, spork, 65264620, 65264630)
 })
 t.Run("mainnet26 spork version 7", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
 	spork := Mainnet26_SporkVersion7.create(ctx)
 	VerifyExecutionResultsForSpork(t, ctx, spork, 125_000_001, 125_000_011)
 })
 t.Run("mainnet24 / spork version 6", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
 	spork := Mainnet24_SporkVersion6.create(ctx)
 	VerifyEventsHashForSpork(t, ctx, spork, 65264620, 65264630)
 })
 t.Run("mainnet26 / spork version 7", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
 	spork := Mainnet26_SporkVersion7.create(ctx)
 	VerifyEventsHashForSpork(t, ctx, spork, 125_000_001, 125_000_011)
 })

Add import:

 import (
 	"bytes"
 	"context"
 	"testing"
+	"time"

Also applies to: 84-96, 128-139


68-82: Use require.NoError instead of require.Fail for RPC errors

This provides better test output and avoids nil-pointer risk on subsequent uses.

-	block, err := client.BlockByHeight(ctx, blockHeight)
-	if err != nil {
-		require.Fail(t, err.Error())
-	}
+	block, err := client.BlockByHeight(ctx, blockHeight)
+	require.NoError(t, err)

-	blockHeader, err := client.BlockHeaderByHeight(ctx, blockHeight)
-	if err != nil {
-		require.Fail(t, err.Error())
-	}
+	blockHeader, err := client.BlockHeaderByHeight(ctx, blockHeight)
+	require.NoError(t, err)

68-82: Mark helpers with t.Helper() for accurate failure locations

Improves error reporting by attributing failures to caller sites.

 func VerifyBlocksForSpork(t *testing.T, ctx context.Context, spork *config.Spork, startHeight uint64, endHeight uint64) {
+	t.Helper()
 	client := spork.AccessNodes.Client()
 func VerifyExecutionResultsForSpork(t *testing.T, ctx context.Context, spork *config.Spork, startHeight uint64, endHeight uint64) {
+	t.Helper()
 	client := spork.AccessNodes.Client()
 func VerifyEventsHashForSpork(t *testing.T, ctx context.Context, spork *config.Spork, startHeight uint64, endHeight uint64) {
+	t.Helper()
 	client := spork.AccessNodes.Client()

Also applies to: 97-126, 141-196


97-126: Sanity-check: ensure the chosen height window contains at least one seal

The test requires at least one sealed vs computed comparison; if not, it'll fail with NotZero. If flakiness shows up, consider widening the window slightly.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3c53a74 and 7e3083e.

📒 Files selected for processing (1)
  • state/convert_test.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
state/convert_test.go (2)
access/access.go (3)
  • NodeConfig (515-523)
  • New (574-620)
  • Client (66-69)
config/config.go (2)
  • Chain (23-42)
  • Spork (107-119)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (1)
state/convert_test.go (1)

19-39: Centralized spork construction looks good

Encapsulating Spork creation behind a template improves consistency and reduces duplication.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

♻️ Duplicate comments (1)
state/convert_test.go (1)

97-126: Great fix on []byte→flow.Identifier conversions; compare identifiers directly.

Using toFlowIdentifier resolves the compile-time bug flagged earlier. Also, compare identifiers directly to avoid extra allocations.

 func VerifyExecutionResultsForSpork(t *testing.T, ctx context.Context, spork *config.Spork, startHeight uint64, endHeight uint64) {
+	t.Helper()
@@
-			require.Equal(t, sealedResult.String(), computedResults[blockID].String(), "mismatched result ID")
+			require.Equal(t, sealedResult, computedResults[blockID], "mismatched result ID")

Additionally, clarify that endHeight is exclusive in the function comment or switch loop to <= and pass inclusive end.

🧹 Nitpick comments (3)
state/convert_test.go (3)

19-30: Polish versioning comment grammar.

Minor doc tweak for clarity.

-	// This version number is incremented each time there is a Flow network upgrades which includes a breaking change for Rosetta.
+	// This version number is incremented each time there is a Flow network upgrade that includes a breaking change for Rosetta.

141-196: Helper ergonomics + richer assertions for easier triage.

  • Mark as helper.
  • Include height/chunk index in assertion messages.
 func VerifyEventsHashForSpork(t *testing.T, ctx context.Context, spork *config.Spork, startHeight uint64, endHeight uint64) {
+	t.Helper()
@@
-		require.Equal(t, len(eventHashes), len(execResult.Chunks))
+		require.Equalf(t, len(eventHashes), len(execResult.Chunks), "height=%d", blockHeight)
 		for idx, eventHash := range eventHashes {
 			chunk := execResult.Chunks[idx]
-			require.Equal(t, eventHash[:], chunk.EventCollection)
+			require.Equalf(t, eventHash[:], chunk.EventCollection, "height=%d chunk=%d", blockHeight, idx)
 		}

68-82: Mark VerifyBlocksForSpork as a test helper and improve error reporting
Add t.Helper() and replace require.Fail with require.NoErrorf (including the height) to retain stack traces and provide clearer context.

 func VerifyBlocksForSpork(t *testing.T, ctx context.Context, spork *config.Spork, startHeight uint64, endHeight uint64) {
+   t.Helper()
    client := spork.AccessNodes.Client()
    for blockHeight := startHeight; blockHeight < endHeight; blockHeight++ {
-       block, err := client.BlockByHeight(ctx, blockHeight)
-       if err != nil {
-           require.Fail(t, err.Error())
-       }
+       block, err := client.BlockByHeight(ctx, blockHeight)
+       require.NoErrorf(t, err, "BlockByHeight(%d)", blockHeight)
        blockHeader, err := client.BlockHeaderByHeight(ctx, blockHeight)
-       if err != nil {
-           require.Fail(t, err.Error())
-       }
+       require.NoErrorf(t, err, "BlockHeaderByHeight(%d)", blockHeight)
        require.True(t, verifyBlockHash(spork, block.Id, blockHeight, blockHeader, block))
    }
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7e3083e and 0efbd8f.

📒 Files selected for processing (1)
  • state/convert_test.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
state/convert_test.go (2)
access/access.go (3)
  • NodeConfig (515-523)
  • New (574-620)
  • Client (66-69)
config/config.go (2)
  • Chain (23-42)
  • Spork (107-119)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (1)
state/convert_test.go (1)

32-39: Spork factory looks good.

Helper cleanly constructs a config.Spork; no issues spotted.

Comment on lines +41 to +47
var Mainnet24_SporkVersion6 = sporkTemplate{
AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet24.nodes.onflow.org:9000"}},
Chain: config.Chain{Network: "mainnet"},
RootBlock: 65264619,
Version: 6,
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Likely broken connectivity: set TLS for public mainnet Access nodes.

The onflow public endpoints generally require TLS. With TLS omitted, grpc.DialContext will use insecure creds and calls will fail at runtime.

Apply:

 var Mainnet24_SporkVersion6 = sporkTemplate{
-	AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet24.nodes.onflow.org:9000"}},
+	AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet24.nodes.onflow.org:9000", TLS: true}},
 	Chain:       config.Chain{Network: "mainnet"},
 	RootBlock:   65264619,
 	Version:     6,
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var Mainnet24_SporkVersion6 = sporkTemplate{
AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet24.nodes.onflow.org:9000"}},
Chain: config.Chain{Network: "mainnet"},
RootBlock: 65264619,
Version: 6,
}
var Mainnet24_SporkVersion6 = sporkTemplate{
AccessNodes: []access.NodeConfig{{
Address: "access-001.mainnet24.nodes.onflow.org:9000",
TLS: true,
}},
Chain: config.Chain{Network: "mainnet"},
RootBlock: 65264619,
Version: 6,
}
🤖 Prompt for AI Agents
In state/convert_test.go around lines 41 to 47, the public mainnet Access node
is configured without TLS which will cause grpc.DialContext to use insecure
credentials and fail; update the NodeConfig to enable TLS and use the TLS port
(for example set Address to "access-001.mainnet24.nodes.onflow.org:443" and set
the NodeConfig's TLS/UseTLS field to true or equivalent so gRPC connects with
secure transport).

Comment on lines +48 to +53
var Mainnet26_SporkVersion7 = sporkTemplate{
AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet26.nodes.onflow.org:9000"}},
Chain: config.Chain{Network: "mainnet"},
RootBlock: 125_000_000,
Version: 7,
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Set TLS on mainnet26 node as well.

 var Mainnet26_SporkVersion7 = sporkTemplate{
-	AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet26.nodes.onflow.org:9000"}},
+	AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet26.nodes.onflow.org:9000", TLS: true}},
 	Chain:       config.Chain{Network: "mainnet"},
 	RootBlock:   125_000_000,
 	Version:     7,
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var Mainnet26_SporkVersion7 = sporkTemplate{
AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet26.nodes.onflow.org:9000"}},
Chain: config.Chain{Network: "mainnet"},
RootBlock: 125_000_000,
Version: 7,
}
var Mainnet26_SporkVersion7 = sporkTemplate{
AccessNodes: []access.NodeConfig{{Address: "access-001.mainnet26.nodes.onflow.org:9000", TLS: true}},
Chain: config.Chain{Network: "mainnet"},
RootBlock: 125_000_000,
Version: 7,
}
🤖 Prompt for AI Agents
In state/convert_test.go around lines 48 to 53, the Mainnet26_SporkVersion7
AccessNodes entry misses enabling TLS; update the access.NodeConfig for
"access-001.mainnet26.nodes.onflow.org:9000" to set TLS: true (i.e., add the TLS
field to the struct initialization) so the mainnet26 node is configured to use
TLS.

Comment on lines +55 to +66
func TestVerifyBlockHash(t *testing.T) {
t.Run("mainnet24 spork version 6", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet24_SporkVersion6.create(ctx)
VerifyBlocksForSpork(t, ctx, spork, 65264620, 65264630)
})
t.Run("mainnet26 spork version 7", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet26_SporkVersion7.create(ctx)
VerifyBlocksForSpork(t, ctx, spork, 125_000_001, 125_000_011)
})
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Bound network calls with timeouts to avoid hanging tests.

Use context.WithTimeout and t.Cleanup(cancel) in each subtest.

 t.Run("mainnet24 spork version 6", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	t.Cleanup(cancel)
 	spork := Mainnet24_SporkVersion6.create(ctx)
 	VerifyBlocksForSpork(t, ctx, spork, 65264620, 65264630)
 })
 t.Run("mainnet26 spork version 7", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	t.Cleanup(cancel)
 	spork := Mainnet26_SporkVersion7.create(ctx)
 	VerifyBlocksForSpork(t, ctx, spork, 125_000_001, 125_000_011)
 })

Add import:

// add to imports
"time"

Also consider documenting that endHeight is exclusive to avoid off-by-one confusion.

🤖 Prompt for AI Agents
In state/convert_test.go around lines 55 to 66 the subtests create background
contexts that allow network calls to hang indefinitely; update each subtest to
use context.WithTimeout (e.g., ctx, cancel :=
context.WithTimeout(context.Background(), time.Minute)) and call
t.Cleanup(cancel) so the timeout is enforced and cleaned up. Add the "time"
import to the file imports. Also add a short comment on the VerifyBlocksForSpork
call noting that endHeight is exclusive to prevent off-by-one confusion.

Comment on lines 84 to +96
func TestVerifyExecutionResultHash(t *testing.T) {
ctx := context.Background()
spork, err := createSpork(ctx)
if err != nil {
require.Fail(t, err.Error())
}
t.Run("mainnet24 spork version 6", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet24_SporkVersion6.create(ctx)
VerifyExecutionResultsForSpork(t, ctx, spork, 65264620, 65264630)
})
t.Run("mainnet26 spork version 7", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet26_SporkVersion7.create(ctx)
VerifyExecutionResultsForSpork(t, ctx, spork, 125_000_001, 125_000_011)
})
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add timeouts to execution-result subtests.

 t.Run("mainnet24 spork version 6", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	t.Cleanup(cancel)
 	spork := Mainnet24_SporkVersion6.create(ctx)
 	VerifyExecutionResultsForSpork(t, ctx, spork, 65264620, 65264630)
 })
 t.Run("mainnet26 spork version 7", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	t.Cleanup(cancel)
 	spork := Mainnet26_SporkVersion7.create(ctx)
 	VerifyExecutionResultsForSpork(t, ctx, spork, 125_000_001, 125_000_011)
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestVerifyExecutionResultHash(t *testing.T) {
ctx := context.Background()
spork, err := createSpork(ctx)
if err != nil {
require.Fail(t, err.Error())
}
t.Run("mainnet24 spork version 6", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet24_SporkVersion6.create(ctx)
VerifyExecutionResultsForSpork(t, ctx, spork, 65264620, 65264630)
})
t.Run("mainnet26 spork version 7", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet26_SporkVersion7.create(ctx)
VerifyExecutionResultsForSpork(t, ctx, spork, 125_000_001, 125_000_011)
})
}
func TestVerifyExecutionResultHash(t *testing.T) {
t.Run("mainnet24 spork version 6", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
t.Cleanup(cancel)
spork := Mainnet24_SporkVersion6.create(ctx)
VerifyExecutionResultsForSpork(t, ctx, spork, 65264620, 65264630)
})
t.Run("mainnet26 spork version 7", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
t.Cleanup(cancel)
spork := Mainnet26_SporkVersion7.create(ctx)
VerifyExecutionResultsForSpork(t, ctx, spork, 125_000_001, 125_000_011)
})
}
🤖 Prompt for AI Agents
In state/convert_test.go around lines 84 to 96, the two subtests lack timeouts
for their contexts; wrap each ctx := context.Background() with a cancellable
timeout (e.g., ctx, cancel := context.WithTimeout(context.Background(),
10*time.Second)) and defer cancel() immediately after creating it, then pass
that ctx into VerifyExecutionResultsForSpork so the test will be bounded and
will fail if it hangs.

Comment on lines 128 to +139
func TestDeriveEventsHash(t *testing.T) {
ctx := context.Background()
spork, err := createSpork(ctx)
if err != nil {
assert.Fail(t, err.Error())
}
t.Run("mainnet24 / spork version 6", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet24_SporkVersion6.create(ctx)
VerifyEventsHashForSpork(t, ctx, spork, 65264620, 65264630)
})
t.Run("mainnet26 / spork version 7", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet26_SporkVersion7.create(ctx)
VerifyEventsHashForSpork(t, ctx, spork, 125_000_001, 125_000_011)
})
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add timeouts to events-hash subtests.

 t.Run("mainnet24 / spork version 6", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	t.Cleanup(cancel)
 	spork := Mainnet24_SporkVersion6.create(ctx)
 	VerifyEventsHashForSpork(t, ctx, spork, 65264620, 65264630)
 })
 t.Run("mainnet26 / spork version 7", func(t *testing.T) {
-	ctx := context.Background()
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	t.Cleanup(cancel)
 	spork := Mainnet26_SporkVersion7.create(ctx)
 	VerifyEventsHashForSpork(t, ctx, spork, 125_000_001, 125_000_011)
 })

Optionally gate these network tests behind an env var (e.g., FLOW_INTEGRATION=1) to reduce CI flakiness.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestDeriveEventsHash(t *testing.T) {
ctx := context.Background()
spork, err := createSpork(ctx)
if err != nil {
assert.Fail(t, err.Error())
}
t.Run("mainnet24 / spork version 6", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet24_SporkVersion6.create(ctx)
VerifyEventsHashForSpork(t, ctx, spork, 65264620, 65264630)
})
t.Run("mainnet26 / spork version 7", func(t *testing.T) {
ctx := context.Background()
spork := Mainnet26_SporkVersion7.create(ctx)
VerifyEventsHashForSpork(t, ctx, spork, 125_000_001, 125_000_011)
})
}
func TestDeriveEventsHash(t *testing.T) {
t.Run("mainnet24 / spork version 6", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
t.Cleanup(cancel)
spork := Mainnet24_SporkVersion6.create(ctx)
VerifyEventsHashForSpork(t, ctx, spork, 65264620, 65264630)
})
t.Run("mainnet26 / spork version 7", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
t.Cleanup(cancel)
spork := Mainnet26_SporkVersion7.create(ctx)
VerifyEventsHashForSpork(t, ctx, spork, 125_000_001, 125_000_011)
})
}
🤖 Prompt for AI Agents
In state/convert_test.go around lines 128 to 139, the two subtests run
network-dependent verification without timeouts (and currently always run in
CI); add per-subtest timeouts by creating a context.WithTimeout inside each
t.Run and using that ctx for spork creation and VerifyEventsHashForSpork so the
test fails fast on hangs, and optionally gate these network tests behind an env
var (e.g., skip the subtest unless os.Getenv("FLOW_INTEGRATION") == "1") to
avoid running them in regular CI.

@tim-barry
Copy link
Contributor Author

Included as part of PR #90.

@tim-barry tim-barry closed this Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants