From 6e892a20fad2e0bc9d101e44bb64f24f811b23a9 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Mon, 11 Mar 2024 21:16:37 -0400 Subject: [PATCH] =?UTF-8?q?mock-consensus:=20=F0=9F=91=B7=20block=20data?= =?UTF-8?q?=20is=20implicitly=20empty,=20can=20be=20appended=20(#4004)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #3936. based upon #4002. see #3588. this changes the type of the block builder's `data`, allowing it to be implicitly kept empty. this is useful when e.g. fast forwarding a number of blocks _(see #4002)_. this spares us the need to call `with_data(vec![])`, and additionally means that the block builder is never in an uninitialized state _(making #4003 needless)._ * #3936 * #4002 * #3588 --- crates/test/mock-consensus/src/block.rs | 21 ++++++++++----------- crates/test/mock-consensus/src/lib.rs | 1 - 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/test/mock-consensus/src/block.rs b/crates/test/mock-consensus/src/block.rs index 279c07dd2d..dafa729f62 100644 --- a/crates/test/mock-consensus/src/block.rs +++ b/crates/test/mock-consensus/src/block.rs @@ -4,7 +4,6 @@ use { crate::TestNode, - anyhow::bail, tap::Tap, tendermint::{ account, @@ -25,7 +24,7 @@ pub struct Builder<'e, C> { test_node: &'e mut TestNode, /// Transaction data. - data: Option>>, + data: Vec>, /// Evidence of malfeasance. evidence: evidence::List, @@ -47,10 +46,13 @@ impl TestNode { impl<'e, C> Builder<'e, C> { /// Sets the data for this block. pub fn with_data(self, data: Vec>) -> Self { - Self { - data: Some(data), - ..self - } + Self { data, ..self } + } + + /// Appends the given tx to this block's data. + pub fn add_tx(mut self, tx: Vec) -> Self { + self.data.push(tx); + self } /// Sets the evidence [`List`][evidence::List] for this block. @@ -112,13 +114,10 @@ where fn finish(self) -> Result<(&'e mut TestNode, Block), anyhow::Error> { tracing::trace!("building block"); let Self { - data: Some(data), + data, evidence, test_node, - } = self - else { - bail!("builder was not fully initialized") - }; + } = self; let height = { let height = test_node.height.increment(); diff --git a/crates/test/mock-consensus/src/lib.rs b/crates/test/mock-consensus/src/lib.rs index 1160e566e8..d9de6b2dfc 100644 --- a/crates/test/mock-consensus/src/lib.rs +++ b/crates/test/mock-consensus/src/lib.rs @@ -69,7 +69,6 @@ where for i in 0..blocks { self.block() - .with_data(vec![]) .execute() .tap(|_| trace!(%i, "executing empty block")) .await