Skip to content

Commit

Permalink
chore: Add unit test for native script hash (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Apr 28, 2022
1 parent c998d9a commit 0946c83
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pallas-primitives/src/alonzo/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ impl TransactionBody {

#[cfg(test)]
mod tests {
use crate::alonzo::BlockWrapper;
use std::str::FromStr;

use pallas_codec::utils::MaybeIndefArray;
use pallas_crypto::hash::Hash;

use crate::alonzo::{BlockWrapper, NativeScript};
use crate::Fragment;

#[test]
Expand All @@ -66,4 +71,24 @@ mod tests {
assert_eq!(hex::encode(computed_hash), known_hash)
}
}

#[test]
fn native_script_hashes_cardano_cli() {
// construct an arbitrary script to use as example
let ns = NativeScript::ScriptAll(MaybeIndefArray::Def(vec![
NativeScript::ScriptPubkey(
Hash::<28>::from_str("4d04380dcb9fbad5aff8e2f4e19394ef4e5e11b37932838f01984a12")
.unwrap(),
),
NativeScript::InvalidBefore(112500819),
]));

// hash that we assume correct since it was generated through the cardano-cli
let cardano_cli_output = "d6a8ced01ecdfbb26c90850010a06fbc20a7c23632fc92f531667f36";

assert_eq!(
ns.to_hash(),
Hash::<28>::from_str(cardano_cli_output).unwrap()
)
}
}

0 comments on commit 0946c83

Please sign in to comment.