-
Notifications
You must be signed in to change notification settings - Fork 4
Streaming join tests #1490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leoyvens
wants to merge
4
commits into
main
Choose a base branch
from
yaml-anvil-steps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Streaming join tests #1490
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Streaming join test using Anvil | ||
| # | ||
| # This test validates that streaming queries with JOINs correctly deliver | ||
| # incremental results as new blocks are mined on Anvil. | ||
|
|
||
| - anvil: {} | ||
|
|
||
| # Mine initial blocks (anvil starts with block 0) | ||
| - name: mine_initial | ||
| mine: 3 | ||
|
|
||
| # Dump to make data available (must happen before registering stream) | ||
| - name: dump_initial | ||
| dataset: _/anvil_rpc@0.0.0 | ||
| end: 3 | ||
|
|
||
| # Register the streaming join query (self-join on blocks via parent_hash) | ||
| - name: register_streaming_join | ||
| stream: | | ||
| SELECT child.block_num, parent.block_num as parent_num | ||
| FROM anvil_rpc.blocks child | ||
| JOIN anvil_rpc.blocks parent ON child.parent_hash = parent.hash | ||
| SETTINGS stream = true | ||
|
|
||
| # Take initial join results - blocks 1,2,3 each joined with their parent | ||
| - name: take_initial_join | ||
| stream: register_streaming_join | ||
| take: 3 | ||
| results: | | ||
| [ | ||
| {"block_num": 1, "parent_num": 0}, | ||
| {"block_num": 2, "parent_num": 1}, | ||
| {"block_num": 3, "parent_num": 2} | ||
| ] | ||
|
|
||
| # Mine more blocks | ||
| - name: mine_more | ||
| mine: 2 | ||
|
|
||
| # Dump new blocks | ||
| - name: dump_more | ||
| dataset: _/anvil_rpc@0.0.0 | ||
| end: 5 | ||
|
|
||
| # Take incremental join results - blocks 4,5 joined with their parents | ||
| - name: take_incremental_join | ||
| stream: register_streaming_join | ||
| take: 2 | ||
| results: | | ||
| [ | ||
| {"block_num": 4, "parent_num": 3}, | ||
| {"block_num": 5, "parent_num": 4} | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Streaming cross-table join test using Anvil | ||
| # | ||
| # This test validates that streaming queries with JOINs across different | ||
| # tables (blocks and transactions) correctly deliver incremental results. | ||
| # | ||
| # Uses INNER JOIN between blocks and transactions - returns rows only when | ||
| # blocks have transactions. With empty anvil blocks, we need to verify | ||
| # the join mechanism works even if no rows are returned initially. | ||
|
|
||
| - anvil: {} | ||
|
|
||
| # Mine initial blocks | ||
| - name: mine_initial | ||
| mine: 3 | ||
|
|
||
| # Dump to make data available | ||
| - name: dump_initial | ||
| dataset: _/anvil_rpc@0.0.0 | ||
| end: 3 | ||
|
|
||
| # Register streaming cross-table join query (blocks INNER JOIN transactions) | ||
| # This joins blocks with their transactions on block_num | ||
| - name: register_cross_table_join | ||
| stream: | | ||
| SELECT b.block_num, t.tx_hash, t.tx_index | ||
| FROM anvil_rpc.blocks b | ||
| INNER JOIN anvil_rpc.transactions t ON b.block_num = t.block_num | ||
| SETTINGS stream = true | ||
|
|
||
| # Take initial join results - empty blocks have no transactions, so 0 rows | ||
| - name: take_initial_join | ||
| stream: register_cross_table_join | ||
| take: 0 | ||
| results: | | ||
| [] | ||
|
|
||
| # Mine more blocks | ||
| - name: mine_more | ||
| mine: 2 | ||
|
|
||
| # Dump new blocks | ||
| - name: dump_more | ||
| dataset: _/anvil_rpc@0.0.0 | ||
| end: 5 | ||
|
|
||
| # Take incremental join results - still no transactions in empty blocks | ||
| - name: take_incremental_join | ||
| stream: register_cross_table_join | ||
| take: 0 | ||
| results: | | ||
| [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Streaming join test with blockchain reorganization | ||
| # | ||
| # This test validates that streaming queries with JOINs correctly handle | ||
| # blockchain reorganizations, delivering updated results after reorg. | ||
| # | ||
| # Flow: | ||
| # 1. Mine initial blocks and register streaming join | ||
| # 2. Take initial join results | ||
| # 3. Trigger reorg (removes some blocks) | ||
| # 4. Mine new blocks on the new fork | ||
| # 5. Verify join results reflect the reorganized chain | ||
|
|
||
| - anvil: {} | ||
|
|
||
| # Mine initial blocks (anvil starts with block 0) | ||
| - name: mine_initial | ||
| mine: 5 | ||
|
|
||
| # Dump to make data available | ||
| - name: dump_initial | ||
| dataset: _/anvil_rpc@0.0.0 | ||
| end: 5 | ||
|
|
||
| # Register the streaming join query (self-join on blocks via parent_hash) | ||
| - name: register_streaming_join | ||
| stream: | | ||
| SELECT child.block_num, parent.block_num as parent_num | ||
| FROM anvil_rpc.blocks child | ||
| JOIN anvil_rpc.blocks parent ON child.parent_hash = parent.hash | ||
| SETTINGS stream = true | ||
|
|
||
| # Take initial join results - blocks 1-5 each joined with their parent | ||
| - name: take_initial_join | ||
| stream: register_streaming_join | ||
| take: 5 | ||
| results: | | ||
| [ | ||
| {"block_num": 1, "parent_num": 0}, | ||
| {"block_num": 2, "parent_num": 1}, | ||
| {"block_num": 3, "parent_num": 2}, | ||
| {"block_num": 4, "parent_num": 3}, | ||
| {"block_num": 5, "parent_num": 4} | ||
| ] | ||
|
|
||
| # Trigger reorg - removes last 2 blocks (4 and 5) | ||
| - name: trigger_reorg | ||
| reorg: 2 | ||
|
|
||
| # Mine new blocks on the reorganized chain | ||
| - name: mine_after_reorg | ||
| mine: 3 | ||
|
|
||
| # Dump the reorganized chain state | ||
| - name: dump_after_reorg | ||
| dataset: _/anvil_rpc@0.0.0 | ||
| end: 6 | ||
|
|
||
| # Take incremental join results after reorg | ||
| # Should see blocks 4, 5, 6 with their new parent relationships | ||
| - name: take_after_reorg | ||
| stream: register_streaming_join | ||
| take: 3 | ||
| results: | | ||
| [ | ||
| {"block_num": 4, "parent_num": 3}, | ||
| {"block_num": 5, "parent_num": 4}, | ||
| {"block_num": 6, "parent_num": 5} | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //! Test step for initializing Anvil blockchain fixture. | ||
|
|
||
| use common::BoxError; | ||
|
|
||
| use crate::testlib::ctx::TestCtx; | ||
|
|
||
| /// Test step that validates Anvil is available for the test. | ||
| /// | ||
| /// This step serves as a marker that the test requires Anvil and validates | ||
| /// that the test context was configured with Anvil support. It should appear | ||
| /// before any `mine` or `reorg` steps in the YAML spec. | ||
| /// | ||
| /// Note: The actual Anvil instance must be configured via `TestCtxBuilder::with_anvil_ipc()` | ||
| /// or `with_anvil_http()` in the test harness. This step validates that configuration. | ||
| #[derive(Debug, serde::Deserialize)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct Step { | ||
| /// Anvil configuration options. | ||
| pub anvil: AnvilConfig, | ||
| } | ||
|
|
||
| /// Configuration options for the Anvil step. | ||
| #[derive(Debug, Default, serde::Deserialize)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct AnvilConfig { | ||
| /// Connection mode: "ipc" (default) or "http". | ||
| #[serde(default)] | ||
| pub mode: Option<String>, | ||
| } | ||
|
|
||
| impl Step { | ||
| /// Validates that Anvil is available in the test context. | ||
| /// | ||
| /// This method checks that the test context was configured with Anvil support. | ||
| /// If Anvil is not available, it returns an error with guidance on how to fix it. | ||
| pub async fn run(&self, ctx: &TestCtx) -> Result<(), BoxError> { | ||
| tracing::debug!("Validating Anvil fixture is available"); | ||
|
|
||
| // This will panic if Anvil is not configured, which is the expected behavior | ||
| // to fail fast with a clear error message | ||
| let _anvil = ctx.anvil(); | ||
|
|
||
| tracing::info!("Anvil fixture validated successfully"); | ||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //! Test step for mining blocks on Anvil. | ||
|
|
||
| use common::BoxError; | ||
|
|
||
| use crate::testlib::ctx::TestCtx; | ||
|
|
||
| /// Test step that mines blocks on the Anvil blockchain. | ||
| /// | ||
| /// This step instructs Anvil to mine a specified number of blocks, advancing | ||
| /// the blockchain state. This is useful for generating test data and simulating | ||
| /// blockchain progression. | ||
| #[derive(Debug, serde::Deserialize)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct Step { | ||
| /// The name of this test step. | ||
| pub name: String, | ||
| /// The number of blocks to mine. | ||
| pub mine: u64, | ||
| } | ||
|
|
||
| impl Step { | ||
| /// Mines the specified number of blocks on Anvil. | ||
| /// | ||
| /// Uses the Anvil fixture from the test context to mine blocks. | ||
| /// Requires that the test context was configured with Anvil support. | ||
| pub async fn run(&self, ctx: &TestCtx) -> Result<(), BoxError> { | ||
| tracing::debug!("Mining {} blocks", self.mine); | ||
|
|
||
| ctx.anvil().mine(self.mine).await?; | ||
|
|
||
| tracing::info!("Successfully mined {} blocks", self.mine); | ||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //! Test step for triggering blockchain reorganizations on Anvil. | ||
|
|
||
| use common::BoxError; | ||
|
|
||
| use crate::testlib::ctx::TestCtx; | ||
|
|
||
| /// Test step that triggers a blockchain reorganization on Anvil. | ||
| /// | ||
| /// This step simulates a chain reorganization by replacing the last N blocks | ||
| /// with alternative blocks. This is useful for testing reorg handling in | ||
| /// streaming queries and data synchronization. | ||
| #[derive(Debug, serde::Deserialize)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct Step { | ||
| /// The name of this test step. | ||
| pub name: String, | ||
| /// The depth of the reorganization (number of blocks to replace). | ||
| pub reorg: u64, | ||
| } | ||
|
|
||
| impl Step { | ||
| /// Triggers a blockchain reorganization with the specified depth. | ||
| /// | ||
| /// Uses the Anvil fixture from the test context to trigger a reorg. | ||
| /// Requires that the test context was configured with Anvil support. | ||
| pub async fn run(&self, ctx: &TestCtx) -> Result<(), BoxError> { | ||
| tracing::debug!("Triggering reorg with depth {}", self.reorg); | ||
|
|
||
| ctx.anvil().reorg(self.reorg).await?; | ||
|
|
||
| tracing::info!("Successfully triggered reorg with depth {}", self.reorg); | ||
| Ok(()) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
mineandreorgare anvil-dependent steps, I would suggest renaming themanvil_mineandanvil_reorg.