-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bitcoin-move] Add more ord tests (#2466)
* [bitcoin-move] Ord tests * fixup
- Loading branch information
Showing
10 changed files
with
9,810 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...tests/blocks/bitcoin/4b8111663106c242da8580ba38c36f261287b9c35b1aa5974f4c14306905e720.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
020000000001013aa223b77dccee5af627b1895ce5b2a352e482ae131b664ff0f2685d01e618df0700000000fffffffd012202000000000000160014eb501bd60d2d1dc04a30a75d0ccd1e5ca42a758f0340dc173f55f63045cdc9f36ca578a16b8a712d2ed4cae1eb1ad813d1aa8ef2fb1b2f4776af686c5c7caa835f401a224709e55a4f15c105909ffb5dceaab99d3e718020c8a3d49a332c37d564d94b93d23f7df03eff030e8e2ac03912d963ad0bbf76c9ac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d38003a7b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a2273617473222c22616d74223a22313030303030303030227d6821c0c8a3d49a332c37d564d94b93d23f7df03eff030e8e2ac03912d963ad0bbf76c900000000 |
1 change: 1 addition & 0 deletions
1
...tests/blocks/bitcoin/69d52ccb5eb80372b7fc6c4fc3feb17038dd2f58313c5d16302d70f7ef0fff7f.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
02000000000101c5d8fc62b7512401b6fc31911dbb763a473d6e1cfd63966f348d617c2f7b721c0100000000fffffffd02260100000000000016001480f177474e4e9caba5eb4d58f6d071264401d072ab6919020000000022512074a7bcc1ed5fc5b28680a838ccf8e745fd8afdcb171a95e4e1bcf0100792c3e103408160d443c29618f76a7498f952c8b42309489566f482cd9564796720056d948b86b84bcf44c1068ca6146a611a592f3f6799b55dd4682859b992d6a11d48d28d452088225c0158a85208c9f0a93d3b724953f164a056121b81a87f88ab0a666cbff1ac0063036f726401010a746578742f706c61696e000d3832303936302e6269746d61706821c188225c0158a85208c9f0a93d3b724953f164a056121b81a87f88ab0a666cbff100000000 |
9,533 changes: 9,533 additions & 0 deletions
9,533
...ests/blocks/bitcoin/e5efc3b2bbf3d738d253e62ffde36b51abb5d12a748abf89d06fca456345fe48.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use bitcoin::{ | ||
absolute::LockTime, consensus::deserialize, hex::FromHex, transaction::Version, Amount, Block, | ||
Sequence, Transaction, Txid, Witness, | ||
}; | ||
use include_dir::{include_dir, Dir}; | ||
use rooch_types::bitcoin::network::Network; | ||
use serde::{Deserialize, Serialize}; | ||
use std::path::PathBuf; | ||
|
||
// Download the bitcoin block via the following command: | ||
// curl -sSL "https://mempool.space/api/block/00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f/raw" > crates/rooch-framework-tests/blocks/bitcoin/91812.blob | ||
// curl -sSL "https://mempool.space/api/block/00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec/raw" > crates/rooch-framework-tests/blocks/bitcoin/91842.blob | ||
// curl -sSL "https://mempool.space/api/block/000000000000000000020750f322f4e72e99c2f0b9738fb4f46607860bd18c13/raw" > crates/rooch-framework-tests/blocks/bitcoin/818677.blob | ||
// curl -sSL "https://mempool.space/testnet/api/block/0000000016412abe1778a347da773ff8bc087ad1a91ae5daad349bc268285c2d/raw" > crates/rooch-framework-tests/blocks/testnet/2821527.blob | ||
pub(crate) const STATIC_BLOCK_DIR: Dir = include_dir!("blocks"); | ||
|
||
pub(crate) fn load_block(network: Network, height: u64) -> Block { | ||
let block_file = PathBuf::from(network.to_string()).join(format!("{}.blob", height)); | ||
let btc_block_bytes = STATIC_BLOCK_DIR | ||
.get_file(block_file.as_path()) | ||
.unwrap() | ||
.contents(); | ||
let block: Block = deserialize(btc_block_bytes).unwrap(); | ||
block | ||
} | ||
|
||
pub(crate) fn load_tx(network: Network, txid: &str) -> Transaction { | ||
let tx_file = PathBuf::from(network.to_string()).join(format!("{}.txt", txid)); | ||
let btc_tx_hex = STATIC_BLOCK_DIR | ||
.get_file(tx_file.as_path()) | ||
.unwrap() | ||
.contents_utf8() | ||
.unwrap(); | ||
let tx: Transaction = bitcoin_tx_from_hex(btc_tx_hex); | ||
tx | ||
} | ||
|
||
pub(crate) fn load_tx_info(network: Network, txid: &str) -> TxInfo { | ||
let tx_file = PathBuf::from(network.to_string()).join(format!("{}.json", txid)); | ||
let btc_tx_json = STATIC_BLOCK_DIR | ||
.get_file(tx_file.as_path()) | ||
.unwrap() | ||
.contents_utf8() | ||
.unwrap(); | ||
let tx: TxInfo = serde_json::from_str(btc_tx_json).unwrap(); | ||
tx | ||
} | ||
|
||
pub(crate) fn bitcoin_tx_from_hex(hex: &str) -> Transaction { | ||
let btc_tx_bytes = Vec::from_hex(hex).unwrap(); | ||
let btc_tx: Transaction = deserialize(btc_tx_bytes.as_slice()).unwrap(); | ||
btc_tx | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct OutputInfo { | ||
pub scriptpubkey: String, | ||
pub scriptpubkey_asm: String, | ||
pub scriptpubkey_type: String, | ||
pub scriptpubkey_address: String, | ||
pub value: Amount, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct TxInputInfo { | ||
pub txid: Txid, | ||
pub vout: u32, | ||
pub prevout: OutputInfo, | ||
pub scriptsig: String, | ||
pub scriptsig_asm: String, | ||
pub witness: Vec<String>, | ||
pub is_coinbase: bool, | ||
pub sequence: u32, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct TxInfo { | ||
pub txid: Txid, | ||
pub version: i32, | ||
pub locktime: u32, | ||
pub vin: Vec<TxInputInfo>, | ||
pub vout: Vec<OutputInfo>, | ||
} | ||
|
||
impl From<TxInfo> for Transaction { | ||
fn from(tx_info: TxInfo) -> Self { | ||
let mut tx = Transaction { | ||
version: Version::non_standard(tx_info.version), | ||
lock_time: LockTime::from_consensus(tx_info.locktime), | ||
input: vec![], | ||
output: vec![], | ||
}; | ||
for input in tx_info.vin { | ||
let txid = input.txid; | ||
let vout = input.vout; | ||
|
||
let script_sig = input.scriptsig; | ||
let sequence = input.sequence; | ||
let witness = input | ||
.witness | ||
.into_iter() | ||
.map(|w| Vec::from_hex(&w).unwrap()) | ||
.collect::<Vec<Vec<u8>>>(); | ||
let tx_input = bitcoin::TxIn { | ||
previous_output: bitcoin::OutPoint { txid, vout }, | ||
script_sig: bitcoin::ScriptBuf::from_hex(&script_sig).unwrap(), | ||
sequence: Sequence::from_consensus(sequence), | ||
witness: Witness::from_slice(&witness), | ||
}; | ||
tx.input.push(tx_input); | ||
} | ||
for output in tx_info.vout { | ||
let script_pubkey = output.scriptpubkey; | ||
let value = output.value; | ||
let tx_output = bitcoin::TxOut { | ||
script_pubkey: bitcoin::ScriptBuf::from_hex(&script_pubkey).unwrap(), | ||
value, | ||
}; | ||
tx.output.push(tx_output); | ||
} | ||
tx | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.