From df4ec7df34ac5364b14a1558b0671095f0e09d71 Mon Sep 17 00:00:00 2001 From: aya015757881 <2581015450@qq.com> Date: Thu, 26 Dec 2024 10:40:56 +0800 Subject: [PATCH 1/2] fix: cancel max coin of 21000000 for dogecoin --- Cargo.lock | 2 +- crates/anychain-bitcoin/Cargo.toml | 2 +- crates/anychain-bitcoin/src/amount.rs | 13 +------------ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82dd7be..13441fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ dependencies = [ [[package]] name = "anychain-bitcoin" -version = "0.1.11" +version = "0.1.12" dependencies = [ "anychain-core", "base58", diff --git a/crates/anychain-bitcoin/Cargo.toml b/crates/anychain-bitcoin/Cargo.toml index 2c7864f..e423111 100644 --- a/crates/anychain-bitcoin/Cargo.toml +++ b/crates/anychain-bitcoin/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "anychain-bitcoin" description = "A Rust library for Bitcoin-focused cryptocurrency wallets, enabling seamless transactions on the Bitcoin blockchain" -version = "0.1.11" +version = "0.1.12" keywords = ["bitcoin", "blockchain", "wallet", "transactions"] categories = ["cryptography::cryptocurrencies"] diff --git a/crates/anychain-bitcoin/src/amount.rs b/crates/anychain-bitcoin/src/amount.rs index 17882de..3f319e1 100644 --- a/crates/anychain-bitcoin/src/amount.rs +++ b/crates/anychain-bitcoin/src/amount.rs @@ -1,4 +1,3 @@ -use anychain_core::no_std::*; use anychain_core::{Amount, AmountError}; use core::fmt; @@ -8,9 +7,6 @@ use std::ops::{Add, Sub}; // Number of satoshis (base unit) per BTC const COIN: i64 = 1_0000_0000; -// Maximum number of satoshis -const MAX_COINS: i64 = 21_000_000 * COIN; - /// Represents the amount of Bitcoin in satoshis #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] pub struct BitcoinAmount(pub i64); @@ -72,14 +68,7 @@ impl BitcoinAmount { pub const ONE_BTC: BitcoinAmount = BitcoinAmount(COIN); pub fn from_satoshi(satoshis: i64) -> Result { - if (-MAX_COINS..=MAX_COINS).contains(&satoshis) { - Ok(Self(satoshis)) - } else { - Err(AmountError::AmountOutOfBounds( - satoshis.to_string(), - MAX_COINS.to_string(), - )) - } + Ok(Self(satoshis)) } pub fn from_ubtc(ubtc_value: i64) -> Result { From 68d3383e4429d1be8a4724951dab57e17ab0f01b Mon Sep 17 00:00:00 2001 From: aya015757881 <2581015450@qq.com> Date: Thu, 26 Dec 2024 10:47:07 +0800 Subject: [PATCH 2/2] fix: remove out-of-bounds tests --- crates/anychain-bitcoin/src/amount.rs | 87 --------------------------- 1 file changed, 87 deletions(-) diff --git a/crates/anychain-bitcoin/src/amount.rs b/crates/anychain-bitcoin/src/amount.rs index 3f319e1..0d327e2 100644 --- a/crates/anychain-bitcoin/src/amount.rs +++ b/crates/anychain-bitcoin/src/amount.rs @@ -301,93 +301,6 @@ mod tests { mod test_invalid { use super::*; - mod test_out_of_bounds { - use super::*; - - const INVALID_TEST_AMOUNTS: [AmountDenominationTestCase; 4] = [ - AmountDenominationTestCase { - satoshi: 2100000100000000, - micro_bit: 21000001000000, - milli_bit: 21000001000, - centi_bit: 2100000100, - deci_bit: 210000010, - bitcoin: 21000001, - }, - AmountDenominationTestCase { - satoshi: -2100000100000000, - micro_bit: -21000001000000, - milli_bit: -21000001000, - centi_bit: -2100000100, - deci_bit: -210000010, - bitcoin: -21000001, - }, - AmountDenominationTestCase { - satoshi: 1000000000000000000, - micro_bit: 10000000000000000, - milli_bit: 10000000000000, - centi_bit: 1000000000000, - deci_bit: 100000000000, - bitcoin: 10000000000, - }, - AmountDenominationTestCase { - satoshi: -1000000000000000000, - micro_bit: -10000000000000000, - milli_bit: -10000000000000, - centi_bit: -1000000000000, - deci_bit: -100000000000, - bitcoin: -10000000000, - }, - ]; - - #[should_panic(expected = "AmountOutOfBounds")] - #[test] - fn test_invalid_satoshi_conversion() { - INVALID_TEST_AMOUNTS.iter().for_each(|amounts| { - test_from_satoshi(amounts.satoshi, BitcoinAmount(amounts.satoshi)) - }); - } - - #[should_panic(expected = "AmountOutOfBounds")] - #[test] - fn test_invalid_ubtc_conversion() { - INVALID_TEST_AMOUNTS.iter().for_each(|amounts| { - test_from_ubtc(amounts.micro_bit, BitcoinAmount(amounts.satoshi)) - }); - } - - #[should_panic(expected = "AmountOutOfBounds")] - #[test] - fn test_invalid_mbtc_conversion() { - INVALID_TEST_AMOUNTS.iter().for_each(|amounts| { - test_from_mbtc(amounts.milli_bit, BitcoinAmount(amounts.satoshi)) - }); - } - - #[should_panic(expected = "AmountOutOfBounds")] - #[test] - fn test_invalid_cbtc_conversion() { - INVALID_TEST_AMOUNTS.iter().for_each(|amounts| { - test_from_cbtc(amounts.centi_bit, BitcoinAmount(amounts.satoshi)) - }); - } - - #[should_panic(expected = "AmountOutOfBounds")] - #[test] - fn test_invalid_dbtc_conversion() { - INVALID_TEST_AMOUNTS.iter().for_each(|amounts| { - test_from_dbtc(amounts.deci_bit, BitcoinAmount(amounts.satoshi)) - }); - } - - #[should_panic(expected = "AmountOutOfBounds")] - #[test] - fn test_invalid_btc_conversion() { - INVALID_TEST_AMOUNTS.iter().for_each(|amounts| { - test_from_btc(amounts.bitcoin, BitcoinAmount(amounts.satoshi)) - }); - } - } - mod test_invalid_conversion { use super::*;