Skip to content

Commit cd22301

Browse files
committed
chore: remove block height arg and add test
1 parent 3a1e296 commit cd22301

File tree

10 files changed

+59
-23
lines changed

10 files changed

+59
-23
lines changed

crates/block-processor/src/alias.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ impl AliasOracleFactory for Box<dyn StateProviderFactory> {
6262
type Oracle = Box<dyn StateProvider>;
6363

6464
fn create(&self) -> eyre::Result<Self::Oracle> {
65+
// NB: This becomes a problem if anyone ever birthday attacks a
66+
// contract/EOA pair (c.f. EIP-3607). In practice this is unlikely to
67+
// happen for the foreseeable future, and if it does we can revisit
68+
// this decision.
69+
// We considered taking the host height as an argument to this method,
70+
// but this would require all nodes to be archive nodes in order to
71+
// sync, which is less than ideal
6572
self.state_by_block_number_or_tag(alloy::eips::BlockNumberOrTag::Latest).map_err(Into::into)
6673
}
6774
}

crates/node-tests/src/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
HostBlockSpec, NotificationSpec, NotificationWithSidecars, RuBlockSpec,
3-
aliases::{CtxProvider, Log, TestCounterInstance, TestErc20Instance, TestLogInstance},
43
convert::ToRethPrimitive,
4+
types::{CtxProvider, Log, TestCounterInstance, TestErc20Instance, TestLogInstance},
55
utils::create_test_provider_factory_with_chain_spec,
66
};
77
use alloy::{
@@ -481,6 +481,7 @@ impl<'a> NonceChecks<'a> {
481481
}
482482

483483
/// Assert that the nonce of the address has increased.
484+
#[track_caller]
484485
pub fn assert_increase_by(&mut self, amount: u64) {
485486
let old_nonce = self.update_nonce();
486487
let expected = old_nonce + amount;
@@ -496,6 +497,7 @@ impl<'a> NonceChecks<'a> {
496497
}
497498

498499
/// Assert that the nonce of the address has increased by 1.
500+
#[track_caller]
499501
pub fn assert_incremented(&mut self) {
500502
self.assert_increase_by(1);
501503
}

crates/node-tests/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#![deny(unused_must_use, rust_2018_idioms)]
1212
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1313

14-
/// Test aliases and type definitions.
15-
pub mod aliases;
16-
1714
/// Test constants.
1815
pub mod constants;
1916

@@ -28,6 +25,9 @@ pub mod convert;
2825
pub mod rpc;
2926
pub use rpc::rpc_test;
3027

28+
/// Test aliases and type definitions.
29+
pub mod types;
30+
3131
/// Utility functions and test harnesses.
3232
pub mod utils;
3333
pub use utils::run_test;

crates/node-tests/src/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{aliases::TestCounterInstance, context::SignetTestContext, utils::run_test};
1+
use crate::{context::SignetTestContext, types::TestCounterInstance, utils::run_test};
22

33
/// A test helper that sets up a Signet test context, deploys the Counter
44
/// contract, and then runs the provided async function `f` with the context and
File renamed without changes.

crates/node-tests/tests/host_events.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ use serial_test::serial;
1414
use signet_db::{DbSignetEvent, SignetEvents};
1515
use signet_node_tests::{
1616
HostBlockSpec, SignetTestContext,
17-
aliases::{Counter, TestCounterInstance},
1817
constants::{DEFAULT_REWARD_ADDRESS, TEST_CONSTANTS},
1918
run_test,
19+
types::{Counter, TestCounterInstance},
2020
utils::{adjust_usd_decimals, adjust_usd_decimals_u256},
2121
};
2222
use signet_test_utils::{chain::USDC_RECORD, contracts::counter::COUNTER_BYTECODE};
23-
use signet_types::constants::{HostPermitted, RollupPermitted};
23+
use signet_types::{
24+
constants::{HostPermitted, RollupPermitted},
25+
unalias_address,
26+
};
2427
use signet_zenith::{MINTER_ADDRESS, Passage, Transactor, mintCall};
2528

2629
alloy::sol! {
@@ -207,31 +210,44 @@ async fn test_transact() {
207210
run_test(|ctx| async move {
208211
// set up user
209212
let user = ctx.addresses[0];
213+
214+
// Getting a little cute here. We ensure that the ALIASED version is
215+
// one of the standard test addresses, so we don't have to set up any
216+
// extra accounts.
217+
let aliased = ctx.addresses[1];
218+
let host_contract = unalias_address(aliased);
219+
220+
// Indicate to the block processor that this address should be aliased
221+
ctx.set_should_alias(host_contract, true);
222+
210223
let mut user_nonce = ctx.track_nonce(user, Some("user"));
211224
let mut user_bal = ctx.track_balance(user, Some("user"));
212225

226+
let mut aliased_nonce = ctx.track_nonce(aliased, Some("aliased"));
227+
let mut aliased_bal = ctx.track_balance(aliased, Some("aliased"));
228+
213229
// Deploy a contract to interact with
214-
let deployer = ctx.addresses[1];
230+
let deployer = ctx.addresses[2];
215231

216232
// Assert that the counter is zero
217233
let contract = ctx.deploy_counter(deployer).await;
218234
let contract_addr = *contract.address();
219235
assert_eq!(contract.count().call().await.unwrap(), U256::ZERO);
220236

221237
// Transact that calls the context and increments it.
222-
let block = HostBlockSpec::new(ctx.constants()).simple_transact(
223-
user,
224-
contract_addr,
225-
Counter::incrementCall::SELECTOR,
226-
0,
227-
);
238+
let block = HostBlockSpec::new(ctx.constants())
239+
.simple_transact(user, contract_addr, Counter::incrementCall::SELECTOR, 0)
240+
.simple_transact(host_contract, contract_addr, Counter::incrementCall::SELECTOR, 0);
228241

229242
ctx.process_block(block).await.unwrap();
230243

231244
user_nonce.assert_incremented();
232245
user_bal.assert_decrease();
233246

234-
assert_eq!(contract.count().call().await.unwrap(), U256::from(1));
247+
aliased_nonce.assert_incremented();
248+
aliased_bal.assert_decrease();
249+
250+
assert_eq!(contract.count().call().await.unwrap(), U256::from(2));
235251

236252
// check the RPC response
237253
let block = ctx
@@ -258,6 +274,20 @@ async fn test_transact() {
258274
assert_eq!(transact_tx.to().unwrap(), contract_addr);
259275
assert_eq!(transact_tx.value(), U256::ZERO);
260276
assert_eq!(transact_tx.input(), &Bytes::from(Counter::incrementCall::SELECTOR));
277+
278+
let aliased_transact_tx = &txns[1];
279+
assert_eq!(aliased_transact_tx.from(), aliased);
280+
assert_eq!(aliased_transact_tx.to().unwrap(), contract_addr);
281+
assert_eq!(aliased_transact_tx.value(), U256::ZERO);
282+
assert_eq!(aliased_transact_tx.input(), &Bytes::from(Counter::incrementCall::SELECTOR));
283+
284+
let aliased_tx_hash = aliased_transact_tx.tx_hash();
285+
let aliased_transact_tx =
286+
ctx.alloy_provider.get_transaction_by_hash(aliased_tx_hash).await.unwrap().unwrap();
287+
assert_eq!(aliased_transact_tx.from(), aliased);
288+
assert_eq!(aliased_transact_tx.to().unwrap(), contract_addr);
289+
assert_eq!(aliased_transact_tx.value(), U256::ZERO);
290+
assert_eq!(aliased_transact_tx.input(), &Bytes::from(Counter::incrementCall::SELECTOR));
261291
})
262292
.await;
263293
}

crates/node-tests/tests/orders.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use alloy::{
88
};
99
use serial_test::serial;
1010
use signet_node_tests::{
11-
HostBlockSpec, RuBlockSpec, SignetTestContext,
12-
aliases::{Erc20, TestErc20Instance},
13-
run_test,
11+
HostBlockSpec, RuBlockSpec, SignetTestContext, run_test,
12+
types::{Erc20, TestErc20Instance},
1413
};
1514
use signet_types::constants::HostPermitted;
1615
use signet_zenith::RollupOrders;

crates/node-tests/tests/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use reth::providers::{BlockNumReader, BlockReader, TransactionsProvider};
1717
use serial_test::serial;
1818
use signet_node_tests::{
1919
SignetTestContext,
20-
aliases::{Counter, TestCounterInstance},
2120
constants::TEST_CONSTANTS,
2221
rpc_test,
22+
types::{Counter, TestCounterInstance},
2323
};
2424
use signet_test_utils::contracts::counter::{COUNTER_BYTECODE, COUNTER_DEPLOY_CODE};
2525
use tokio::try_join;

crates/node-tests/tests/rpc_debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use reth::{
44
rpc::types::trace::geth::{CallConfig, GethDebugTracingOptions},
55
};
66
use serial_test::serial;
7-
use signet_node_tests::{aliases::Counter::incrementCall, rpc::rpc_test};
7+
use signet_node_tests::{rpc::rpc_test, types::Counter::incrementCall};
88
use signet_test_utils::specs::{HostBlockSpec, RuBlockSpec};
99

1010
#[serial]

crates/node-tests/tests/submit-tx.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use alloy::{
66
rpc::types::eth::TransactionRequest,
77
};
88
use serial_test::serial;
9-
use signet_node_tests::{
10-
HostBlockSpec, RuBlockSpec, aliases::TestCounterInstance, utils::run_test,
11-
};
9+
use signet_node_tests::{HostBlockSpec, RuBlockSpec, types::TestCounterInstance, utils::run_test};
1210
use signet_test_utils::contracts::counter::{COUNTER_BYTECODE, COUNTER_DEPLOY_CODE};
1311

1412
const USER_A: Address = Address::repeat_byte(0x39);

0 commit comments

Comments
 (0)