Skip to content

Commit

Permalink
test: basic tx validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Oct 12, 2024
1 parent f966654 commit 2ed1d5b
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion crates/wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub trait OdysseyWalletApi {
}

/// Errors returned by the wallet API.
#[derive(Debug, thiserror::Error)]
#[derive(Debug, Eq, PartialEq, thiserror::Error)]
pub enum OdysseyWalletError {
/// The transaction value is not 0.
///
Expand Down Expand Up @@ -386,4 +386,45 @@ mod tests {
);
}
}

mod validation {
use alloy_network::TransactionBuilder;
use alloy_primitives::{Address, U256};
use alloy_rpc_types::TransactionRequest;

use crate::{validate_tx_request, OdysseyWalletError};

#[test]
fn no_value_allowed() {
assert_eq!(
validate_tx_request(&TransactionRequest::default().with_value(U256::from(1))),
Err(OdysseyWalletError::ValueNotZero)
);

assert_eq!(
validate_tx_request(&TransactionRequest::default().with_value(U256::from(0))),
Ok(())
);
}

#[test]
fn no_from_allowed() {
assert_eq!(
validate_tx_request(&TransactionRequest::default().with_from(Address::ZERO)),
Err(OdysseyWalletError::FromSet)
);

assert_eq!(validate_tx_request(&TransactionRequest::default()), Ok(()));
}

#[test]
fn no_nonce_allowed() {
assert_eq!(
validate_tx_request(&TransactionRequest::default().with_nonce(1)),
Err(OdysseyWalletError::FromSet)
);

assert_eq!(validate_tx_request(&TransactionRequest::default()), Ok(()));
}
}
}

0 comments on commit 2ed1d5b

Please sign in to comment.