Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danhper committed Jul 12, 2024
1 parent 1d55fe5 commit 97167b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
25 changes: 15 additions & 10 deletions src/interpreter/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,22 @@ impl Type {

pub fn max(&self) -> Result<Value> {
let res = match self {
Type::Uint(256) => U256::MAX,
Type::Uint(size) => (U256::from(1) << U256::from(*size)) - U256::from(1),
Type::Int(size) => (U256::from(1) << U256::from(*size - 1)) - U256::from(1),
Type::Uint(256) => Value::Uint(U256::MAX, 256),
Type::Uint(size) => {
Value::Uint((U256::from(1) << U256::from(*size)) - U256::from(1), 256)
}
Type::Int(size) => Value::Int(
I256::from_raw((U256::from(1) << U256::from(*size - 1)) - U256::from(1)),
256,
),
_ => bail!("cannot get max value for type {}", self),
};
Ok(Value::Uint(res, 256))
Ok(res)
}

pub fn min(&self) -> Result<Value> {
match self {
Type::Uint(_) => Ok(0.into()),
Type::Uint(_) => Ok(0u64.into()),
Type::Int(256) => Ok(Value::Int(I256::MIN, 256)),
Type::Int(size) => {
let minus_one = -I256::from_raw(U256::from(1));
Expand Down Expand Up @@ -501,11 +506,11 @@ mod tests {
#[test]
fn uint_min() {
let cases = vec![
(Type::Uint(256), 0),
(Type::Uint(128), 0),
(Type::Uint(64), 0),
(Type::Uint(32), 0),
(Type::Uint(8), 0),
(Type::Uint(256), 0u64),
(Type::Uint(128), 0u64),
(Type::Uint(64), 0u64),
(Type::Uint(32), 0u64),
(Type::Uint(8), 0u64),
];
for (t, expected) in cases {
assert_eq!(t.min().unwrap(), Value::Uint(U256::from(expected), 256));
Expand Down
11 changes: 0 additions & 11 deletions src/vendor/ledger_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,6 @@ impl Signer for LedgerSigner {

impl LedgerSigner {
/// Instantiate the application by acquiring a lock on the ledger device.
///
/// # Examples
///
/// ```
/// # async fn foo() -> Result<(), Box<dyn std::error::Error>> {
/// use alloy_signer_ledger::{HDPath, LedgerSigner};
///
/// let ledger = LedgerSigner::new(HDPath::LedgerLive(0), Some(1)).await?;
/// # Ok(())
/// # }
/// ```
pub async fn new(
transport: Arc<Mutex<Ledger>>,
derivation: HDPath,
Expand Down

0 comments on commit 97167b9

Please sign in to comment.