Skip to content

Commit

Permalink
feat(btc): Move all tests from tw_any_coin to tw_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Sep 19, 2024
1 parent f0b72d1 commit e91dde3
Show file tree
Hide file tree
Showing 112 changed files with 99 additions and 73 deletions.
30 changes: 23 additions & 7 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ members = [
"tw_misc",
"tw_number",
"tw_proto",
"tw_tests",
"wallet_core_bin",
"wallet_core_rs",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl StandardScript {
match self {
StandardScript::P2PK(pubkey) => {
// Display P2PK input as P2PKH.
LegacyAddress::p2pkh_with_public_key(chain_info.p2pkh_prefix, &pubkey)
LegacyAddress::p2pkh_with_public_key(chain_info.p2pkh_prefix, pubkey)
.map(StandardBitcoinAddress::Legacy)
.map(Some)
},
Expand Down
12 changes: 0 additions & 12 deletions rust/tw_any_coin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,3 @@ test-utils = [
"tw_misc/test-utils",
"tw_proto"
]

[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tw_any_coin = { path = "./", features = ["test-utils"] }
tw_cosmos_sdk = { path = "../tw_cosmos_sdk", features = ["test-utils"] }
tw_keypair = { path = "../tw_keypair", features = ["test-utils"] }
tw_memory = { path = "../tw_memory", features = ["test-utils"] }
tw_misc = { path = "../tw_misc", features = ["test-utils"] }
tw_number = { path = "../tw_number" }
tw_ton_sdk = { path = "../frameworks/tw_ton_sdk" }
tw_utxo = { path = "../frameworks/tw_utxo" }
23 changes: 23 additions & 0 deletions rust/tw_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "tw_tests"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tw_any_coin = { path = "../tw_any_coin", features = ["test-utils"] }
tw_coin_entry = { path = "../tw_coin_entry", features = ["test-utils"] }
tw_coin_registry = { path = "../tw_coin_registry" }
tw_encoding = { path = "../tw_encoding" }
tw_hash = { path = "../tw_hash" }
tw_keypair = { path = "../tw_keypair", features = ["test-utils"] }
tw_memory = { path = "../tw_memory" }
tw_misc = { path = "../tw_misc" }
tw_number = { path = "../tw_number" }
tw_proto = { path = "../tw_proto" }
wallet-core-rs = { path = "../wallet_core_rs" }
# Chain specific:
tw_cosmos_sdk = { path = "../tw_cosmos_sdk", features = ["test-utils"] }
tw_ton_sdk = { path = "../frameworks/tw_ton_sdk" }
tw_utxo = { path = "../frameworks/tw_utxo" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::sign;
use crate::common::bitcoin::sign;
use tw_any_coin::test_utils::sign_utils::CompilerHelper;
use tw_coin_registry::coin_type::CoinType;
use tw_memory::Data;
use tw_proto::BitcoinV2::Proto;

pub use crate::chains::common::bitcoin::sign::Expected;
pub use crate::common::bitcoin::sign::Expected;

pub struct BitcoinCompileHelper<'a> {
input: &'a Proto::SigningInput<'a>,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions rust/tw_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

pub mod common;
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{
btc_info, compile, dust_threshold, input, output, preimage, DUST, SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::ToHex;
use tw_hash::H256;
use tw_keypair::traits::SigningKeyTrait;
use tw_keypair::{ecdsa, schnorr};
use tw_misc::traits::ToBytesVec;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{
btc_info, compile, dust_threshold, input, output, preimage, DUST, SIGHASH_ALL,
};

const BRC20_COMMIT_TX_ID: &str = "797d17d47ae66e598341f9dfdea020b04d4017dcf9cc33f0e51f7a6082171fb1";
const BRC20_REVEAL_TX_ID: &str = "7046dc2689a27e143ea2ad1039710885147e9485ab6453fa7e87464aa7dd3eca";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, DUST, MINER_FEE, ONE_BTC, SIGHASH_ALL,
};
use tw_any_coin::test_utils::sign_utils::CompilerHelper;
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_proto::BitcoinV2::Proto;
use tw_proto::Common::Proto::SigningError;
use tw_tests::common::bitcoin::{
btc_info, dust_threshold, input, output, DUST, MINER_FEE, ONE_BTC, SIGHASH_ALL,
};

#[test]
fn test_bitcoin_compile_p2pkh_error() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{
btc_info, compile, dust_threshold, input, output, preimage, DUST, MINER_FEE, ONE_BTC,
SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::{DecodeHex, ToHex};
use tw_keypair::ecdsa;
use tw_keypair::traits::SigningKeyTrait;
use tw_misc::traits::ToBytesVec;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{
btc_info, compile, dust_threshold, input, output, preimage, DUST, MINER_FEE, ONE_BTC,
SIGHASH_ALL,
};

/// Note this test contains a sample transaction that has never been broadcasted.
#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{plan, Amount, DUST};
use tw_coin_registry::coin_type::CoinType;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{plan, Amount, DUST};

#[test]
fn test_exact_selector_with_change_1() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{plan, Amount, DUST};
use tw_any_coin::test_utils::plan_utils::AnyPlannerHelper;
use tw_coin_registry::coin_type::CoinType;
use tw_proto::BitcoinV2::Proto;
use tw_proto::Common::Proto as CommonProto;
use tw_tests::common::bitcoin::{plan, Amount, DUST};

#[test]
fn test_exact_selector_insufficient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{plan, Amount, DUST};
use tw_coin_registry::coin_type::CoinType;
use tw_tests::common::bitcoin::{plan, Amount, DUST};

#[test]
fn test_max_selector_1() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{plan, Amount, DUST};
use tw_any_coin::test_utils::plan_utils::AnyPlannerHelper;
use tw_coin_registry::coin_type::CoinType;
use tw_proto::BitcoinV2::Proto;
use tw_proto::Common::Proto as CommonProto;
use tw_tests::common::bitcoin::{plan, Amount, DUST};

#[test]
fn test_max_selector_insufficient_to_cover_fee() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::input::out_point;
use crate::chains::common::bitcoin::psbt_plan::BitcoinPsbtPlanHelper;
use crate::chains::common::bitcoin::{btc_info, input, output, RecipientType};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_keypair::ecdsa;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::input::out_point;
use tw_tests::common::bitcoin::psbt_plan::BitcoinPsbtPlanHelper;
use tw_tests::common::bitcoin::{btc_info, input, output, RecipientType};

#[test]
fn test_bitcoin_plan_psbt_thorchain_swap_witness() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, plan, sign, DUST, SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_keypair::{ecdsa, schnorr};
use tw_misc::traits::ToBytesVec;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{
btc_info, dust_threshold, input, output, plan, sign, DUST, SIGHASH_ALL,
};

const ALICE_PRIVATE_KEY: &str = "e253373989199da27c48680e3a3fc0f648d50f9a727ef17a7fe6a4dc3b159129";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{dust_threshold, input, output, sign, DUST, SIGHASH_ALL};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{dust_threshold, input, output, sign, DUST, SIGHASH_ALL};

/// Deposit 0.0001 BTC from bc1q2sphzvc2uqmxqte2w9dd4gzy4sy9vvfv0me9ke to 0xa8491D40d4F71A752cA41DA0516AEd80c33a1B56 on ZETA mainnet.
/// https://www.zetachain.com/docs/developers/omnichain/bitcoin/#example-1-deposit-btc-into-an-account-in-zevm
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, plan, sign, BITCOIN_P2PKH_PREFIX, DUST, MINER_FEE,
ONE_BTC, SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_hash::hasher::sha256_ripemd;
use tw_keypair::ecdsa;
use tw_misc::traits::ToBytesVec;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{
btc_info, dust_threshold, input, output, plan, sign, BITCOIN_P2PKH_PREFIX, DUST, MINER_FEE,
ONE_BTC, SIGHASH_ALL,
};
use tw_utxo::address::legacy::LegacyAddress;

enum P2PKHClaimingScriptType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, BITCOIN_P2SH_PREFIX, DUST, MINER_FEE, ONE_BTC,
SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_hash::hasher::sha256_ripemd;
use tw_hash::H160;
use tw_keypair::ecdsa;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, BITCOIN_P2SH_PREFIX, DUST, MINER_FEE, ONE_BTC,
SIGHASH_ALL,
};
use tw_utxo::address::legacy::LegacyAddress;
use tw_utxo::script::standard_script::conditions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, BITCOIN_HRP, DUST, MINER_FEE, ONE_BTC,
SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_keypair::{ecdsa, schnorr};
use tw_misc::traits::ToBytesVec;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, BITCOIN_HRP, DUST, MINER_FEE, ONE_BTC,
SIGHASH_ALL,
};
use tw_utxo::address::taproot::TaprootAddress;
use tw_utxo::script::standard_script::conditions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, DUST, SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_keypair::schnorr;
use tw_misc::traits::ToBytesVec;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{btc_info, dust_threshold, input, output, sign, DUST, SIGHASH_ALL};
use tw_utxo::transaction::asset::brc20::{BRC20TransferInscription, Brc20Ticker};

const ALICE_PRIVATE_KEY: &str = "e253373989199da27c48680e3a3fc0f648d50f9a727ef17a7fe6a4dc3b159129";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
//
// Copyright © 2017 Trust Wallet.

use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, DUST, SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_keypair::ecdsa;
use tw_misc::traits::{ToBytesVec, ToBytesZeroizing};
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{btc_info, dust_threshold, input, output, sign, DUST, SIGHASH_ALL};

#[test]
fn test_bitcoin_sign_p2wpkh_input_different_builders() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, BITCOIN_HRP, DUST, MINER_FEE, ONE_BTC,
SIGHASH_ALL,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_hash::hasher::sha256_ripemd;
Expand All @@ -10,6 +6,10 @@ use tw_hash::H160;
use tw_keypair::ecdsa;
use tw_misc::traits::ToBytesVec;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, BITCOIN_HRP, DUST, MINER_FEE, ONE_BTC,
SIGHASH_ALL,
};
use tw_utxo::address::segwit::SegwitAddress;
use tw_utxo::script::standard_script::conditions;
use tw_utxo::script::Script;
Expand Down
Loading

0 comments on commit e91dde3

Please sign in to comment.