Skip to content

Commit

Permalink
Merge pull request #16 from Foundation-Devices/jeandudey/sft-2562-add…
Browse files Browse the repository at this point in the history
…-psbt-test-vectors

SFT-2562: Add BIP-174 test vectors.
  • Loading branch information
jeandudey authored Aug 14, 2023
2 parents 3de50cb + 7bf31de commit 464b424
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 0 deletions.
1 change: 1 addition & 0 deletions test-vectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ default = ["std"]
std = ["hex/std"]
bip32 = ["bs58", "hex/serde"]
nostr = ["hex/serde"]
psbt = ["hex/serde"]
seedqr = ["bip39/serde", "hex/serde"]
blockchain-commons = ["bitcoin/serde", "hex/serde"]

Expand Down
1 change: 1 addition & 0 deletions test-vectors/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn main() {
println!("cargo:rerun-if-changed=data/bcr-2020-008.json");
println!("cargo:rerun-if-changed=data/bcr-2020-009.json");
println!("cargo:rerun-if-changed=data/bip-0032.json");
println!("cargo:rerun-if-changed=data/bip-0174.json");
println!("cargo:rerun-if-changed=data/nip-19.json");
println!("cargo:rerun-if-changed=data/seedqr.json");
}
299 changes: 299 additions & 0 deletions test-vectors/data/bip-0174.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions test-vectors/data/bip-0174.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: © 2017 Andrew Chow <achow101@gmail.com>
SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
SPDX-License-Identifier: BSD-2-Clause
2 changes: 2 additions & 0 deletions test-vectors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ impl SeedQRVector {

#[cfg(feature = "bip32")]
pub mod bip32;
#[cfg(feature = "psbt")]
pub mod psbt;

#[cfg(feature = "blockchain-commons")]
mod blockchain_commons {
Expand Down
32 changes: 32 additions & 0 deletions test-vectors/src/psbt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
// SPDX-License-Identifier: GPL-3.0-or-later

#[derive(Debug, serde::Deserialize)]
pub struct TestVectors {
pub invalid: Vec<TestVector>,
pub valid: Vec<TestVector>,
}

impl TestVectors {
pub fn new() -> Self {
serde_json::from_slice(include_bytes!("../data/bip-0174.json"))
.expect("file should be valid JSON")
}
}

#[derive(Debug, serde::Deserialize)]
pub struct TestVector {
pub description: String,
#[serde(with = "hex", rename = "as-hex")]
pub data: Vec<u8>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_new() {
TestVectors::new();
}
}

0 comments on commit 464b424

Please sign in to comment.