Skip to content

Commit

Permalink
Add test_runtime_transaction_type()
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Oct 15, 2024
1 parent 2852925 commit f7e2ae5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/pallet-bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ sp-runtime = { workspace = true, default-features = false }
sp-std = { workspace = true, default-features = false }
subcoin-runtime-primitives = { workspace = true, default-features = false }

[dev-dependencies]
hex = { package = "hex-conservative", version = "0.2.0", features = ["alloc"] }

[features]
default = ["std"]
std = [
Expand Down
19 changes: 18 additions & 1 deletion crates/pallet-bitcoin/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bitcoin::consensus::Encodable;
use bitcoin::consensus::{deserialize, Encodable};
use hex::test_hex_unwrap as hex;
use sp_core::Encode;

#[test]
Expand All @@ -15,3 +16,19 @@ fn test_runtime_txid_type() {
d.reverse();
assert_eq!(d, runtime_txid.encode());
}

#[test]
fn test_runtime_transaction_type() {
let tx_bytes = hex!(
"02000000000101595895ea20179de87052b4046dfe6fd515860505d6511a9004cf12a1f93cac7c01000000\
00ffffffff01deb807000000000017a9140f3444e271620c736808aa7b33e370bd87cb5a078702483045022\
100fb60dad8df4af2841adc0346638c16d0b8035f5e3f3753b88db122e70c79f9370220756e6633b17fd271\
0e626347d28d60b0a2d6cbb41de51740644b9fb3ba7751040121028fa937ca8cba2197a37c007176ed89410\
55d3bcb8627d085e94553e62f057dcc00000000"
);
let tx: bitcoin::Transaction = deserialize(&tx_bytes).unwrap();

let runtime_tx: crate::types::Transaction = tx.clone().into();

assert_eq!(tx, bitcoin::Transaction::from(runtime_tx));
}

0 comments on commit f7e2ae5

Please sign in to comment.