Skip to content

Commit

Permalink
feat(btc): Minor changes in tw_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Sep 19, 2024
1 parent e91dde3 commit b9c1a79
Show file tree
Hide file tree
Showing 30 changed files with 53 additions and 48 deletions.
2 changes: 0 additions & 2 deletions rust/tw_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

pub mod common;
6 changes: 3 additions & 3 deletions rust/tw_tests/tests/chains/bitcoin/bitcoin_compile/brc20.rs
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
8 changes: 4 additions & 4 deletions rust/tw_tests/tests/chains/bitcoin/bitcoin_compile/p2pkh.rs
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
6 changes: 3 additions & 3 deletions rust/tw_tests/tests/chains/bitcoin/bitcoin_plan/plan_psbt.rs
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
6 changes: 3 additions & 3 deletions rust/tw_tests/tests/chains/bitcoin/bitcoin_sign/brc20.rs
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
8 changes: 4 additions & 4 deletions rust/tw_tests/tests/chains/bitcoin/bitcoin_sign/p2pkh.rs
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
8 changes: 4 additions & 4 deletions rust/tw_tests/tests/chains/bitcoin/bitcoin_sign/p2sh.rs
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,9 +1,11 @@
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
4 changes: 3 additions & 1 deletion rust/tw_tests/tests/chains/bitcoin/bitcoin_sign/p2wpkh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
//
// 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
8 changes: 4 additions & 4 deletions rust/tw_tests/tests/chains/bitcoin/bitcoin_sign/p2wsh.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
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 @@ -6,10 +10,6 @@ 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
2 changes: 1 addition & 1 deletion rust/tw_tests/tests/chains/bitcoin/bitcoin_sign/psbt.rs
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::psbt_sign::{BitcoinPsbtSignHelper, Expected};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
use tw_proto::BitcoinV2::Proto;
use tw_tests::common::bitcoin::psbt_sign::{BitcoinPsbtSignHelper, Expected};

#[test]
fn test_bitcoin_sign_psbt_thorchain_swap_witness() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::chains::common::bitcoin::{
btc_info, dust_threshold, input, output, sign, DUST, SIGHASH_ALL,
};
use std::str::FromStr;
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};
use tw_utxo::address::legacy::LegacyAddress;
use tw_utxo::address::segwit::SegwitAddress;
use tw_utxo::script::standard_script::conditions;
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, sign, DUST, SIGHASH_SINGLE,
};
use tw_coin_registry::coin_type::CoinType;
use tw_encoding::hex::DecodeHex;
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, DUST, SIGHASH_SINGLE,
};

/// In this test we check not only SIGHASH_SINGLE, but also multiple private keys,
/// also legacy and witness UTXOs at the same time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//
// Copyright © 2017 Trust Wallet.

use crate::common::bitcoin::sign;
use crate::chains::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::common::bitcoin::sign::Expected;
pub use crate::chains::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.
1 change: 1 addition & 0 deletions rust/tw_tests/tests/chains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
mod aptos;
mod binance;
mod bitcoin;
mod common;
mod cosmos;
mod dydx;
mod ethereum;
Expand Down

0 comments on commit b9c1a79

Please sign in to comment.