fix: use correct prefix when hashing plutus v2 script (#182)

* fix: use correct prefix when hashing plutus v2 script

* chore: remove debug print
This commit is contained in:
Harper 2022-09-04 12:42:25 +01:00 committed by GitHub
parent 9100884270
commit 4b2de75f69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -96,7 +96,7 @@ impl ToHash<32> for babbage::Header {
impl ToHash<28> for babbage::PlutusV2Script { impl ToHash<28> for babbage::PlutusV2Script {
fn to_hash(&self) -> Hash<28> { fn to_hash(&self) -> Hash<28> {
Hasher::<224>::hash_tagged_cbor(self, 1) Hasher::<224>::hash_tagged_cbor(self, 2)
} }
} }
@ -260,7 +260,7 @@ mod tests {
} }
#[test] #[test]
fn plutus_script_hashes_as_cardano_cli() { fn plutus_v1_script_hashes_as_cardano_cli() {
let bytecode_hex = include_str!("../../test_data/jpgstore.plutus"); let bytecode_hex = include_str!("../../test_data/jpgstore.plutus");
let bytecode = hex::decode(bytecode_hex).unwrap(); let bytecode = hex::decode(bytecode_hex).unwrap();
let script: alonzo::PlutusScript = pallas_codec::minicbor::decode(&bytecode).unwrap(); let script: alonzo::PlutusScript = pallas_codec::minicbor::decode(&bytecode).unwrap();
@ -274,4 +274,20 @@ mod tests {
"4a59ebd93ea53d1bbf7f82232c7b012700a0cf4bb78d879dabb1a20a" "4a59ebd93ea53d1bbf7f82232c7b012700a0cf4bb78d879dabb1a20a"
); );
} }
#[test]
fn plutus_v2_script_hashes_as_cardano_cli() {
let bytecode_hex = include_str!("../../test_data/v2script.plutus");
let bytecode = hex::decode(bytecode_hex).unwrap();
let script: babbage::PlutusV2Script = pallas_codec::minicbor::decode(&bytecode).unwrap();
let generated = script.to_hash().to_string();
assert_eq!(
generated,
// script bytes and script hash from
// https://preview.cexplorer.io/script/2616f3e9edb51f98ef04dbaefd042b5c731e86616e8e9172c63c39be
"2616f3e9edb51f98ef04dbaefd042b5c731e86616e8e9172c63c39be"
);
}
} }

File diff suppressed because one or more lines are too long