From 06bd3ee7c705edcc054f722cd1a550861f53b286 Mon Sep 17 00:00:00 2001 From: Eric Woolsey Date: Fri, 27 Sep 2024 16:27:08 -0700 Subject: [PATCH] more tests --- world-chain-builder/src/pool/validator.rs | 70 ++++++++++++++++++++--- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/world-chain-builder/src/pool/validator.rs b/world-chain-builder/src/pool/validator.rs index b5cf7874..4ad3285a 100644 --- a/world-chain-builder/src/pool/validator.rs +++ b/world-chain-builder/src/pool/validator.rs @@ -281,7 +281,7 @@ mod tests { blobstore::InMemoryBlobStore, validate::EthTransactionValidatorBuilder, EthPooledTransaction, TransactionOrigin, TransactionValidationOutcome, }; - use reth_transaction_pool::{Pool, PoolTransaction as _, TransactionPool as _}; + use reth_transaction_pool::{Pool, PoolTransaction as _, TransactionPool}; use revm_primitives::hex; use semaphore::identity::Identity; use semaphore::poseidon_tree::LazyPoseidonTree; @@ -307,6 +307,14 @@ mod tests { tx.try_into_ecrecovered().unwrap().into() } + fn get_non_pbh_transaction() -> WorldChainPooledTransaction { + let eth_tx = get_eth_transaction(); + WorldChainPooledTransaction { + inner: eth_tx, + semaphore_proof: None, + } + } + fn get_pbh_transaction() -> WorldChainPooledTransaction { let eth_tx = get_eth_transaction(); let semaphore_proof = valid_proof( @@ -384,18 +392,14 @@ mod tests { #[tokio::test] async fn validate_non_pbh_transaction() { let validator = world_chain_validator(); - let transaction = get_eth_transaction(); + let transaction = get_non_pbh_transaction(); + validator.inner.client().add_account( transaction.sender(), ExtendedAccount::new(transaction.nonce(), alloy_primitives::U256::MAX), ); - let transaction = WorldChainPooledTransaction { - inner: transaction, - semaphore_proof: None, - }; let outcome = validator.validate_one(TransactionOrigin::External, transaction.clone()); - assert!(outcome.is_valid()); let ordering = WorldChainOrdering::new(validator.database_env.clone()); @@ -438,6 +442,58 @@ mod tests { assert!(tx.is_some()); } + #[tokio::test] + async fn invalid_external_nullifier_hash() { + let validator = world_chain_validator(); + let mut transaction = get_pbh_transaction(); + transaction + .semaphore_proof + .as_mut() + .unwrap() + .external_nullifier_hash = Field::from(0); + + validator.inner.client().add_account( + transaction.sender(), + ExtendedAccount::new(transaction.nonce(), alloy_primitives::U256::MAX), + ); + + let ordering = WorldChainOrdering::new(validator.database_env.clone()); + + let pool = Pool::new( + validator, + ordering, + InMemoryBlobStore::default(), + Default::default(), + ); + + let res = pool.add_external_transaction(transaction.clone()).await; + assert!(res.is_err()); + } + + #[tokio::test] + async fn invalid_signal_hash() { + let validator = world_chain_validator(); + let mut transaction = get_pbh_transaction(); + transaction.semaphore_proof.as_mut().unwrap().signal_hash = Field::from(0); + + validator.inner.client().add_account( + transaction.sender(), + ExtendedAccount::new(transaction.nonce(), alloy_primitives::U256::MAX), + ); + + let ordering = WorldChainOrdering::new(validator.database_env.clone()); + + let pool = Pool::new( + validator, + ordering, + InMemoryBlobStore::default(), + Default::default(), + ); + + let res = pool.add_external_transaction(transaction.clone()).await; + assert!(res.is_err()); + } + #[test] fn test_format_date() { let date = chrono::Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap();