Skip to content

Commit df96bf4

Browse files
committed
adding new testcase for plutus data hashing
1 parent 69039e3 commit df96bf4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

rust/src/plutus.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,17 @@ impl Costmdls {
385385
}
386386
serializer.finalize()
387387
}
388+
389+
pub(crate) fn retain_language_versions(&self, languages: Vec<Language>) -> Costmdls {
390+
let mut result = Costmdls::new();
391+
for lang in languages {
392+
match self.get(&lang) {
393+
Some(costmodel) => { result.insert(&lang, &costmodel); },
394+
_ => {}
395+
}
396+
}
397+
result
398+
}
388399
}
389400

390401
#[wasm_bindgen]
@@ -2317,4 +2328,42 @@ mod tests {
23172328
);
23182329
assert_eq!(hex::encode(hash.to_bytes()), "ac71f2adcaecd7576fa658098b12001dec03ce5c27dbb890e16966e3e135b3e2");
23192330
}
2331+
2332+
#[test]
2333+
fn test_known_plutus_data_hash_2() {
2334+
let datums = PlutusList::from(vec![
2335+
PlutusData::new_constr_plutus_data(
2336+
&ConstrPlutusData::new(
2337+
&BigNum::zero(),
2338+
&PlutusList::from(vec![
2339+
PlutusData::new_bytes(
2340+
hex::decode("45F6A506A49A38263C4A8BBB2E1E369DD8732FB1F9A281F3E8838387").unwrap(),
2341+
),
2342+
PlutusData::new_integer(&BigInt::from_str("60000000").unwrap()),
2343+
PlutusData::new_bytes(
2344+
hex::decode("EE8E37676F6EBB8E031DFF493F88FF711D24AA68666A09D61F1D3FB3").unwrap(),
2345+
),
2346+
PlutusData::new_bytes(
2347+
hex::decode("43727970746F44696E6F3036333039").unwrap(),
2348+
),
2349+
]),
2350+
)
2351+
)
2352+
]);
2353+
let redeemers = Redeemers(vec![
2354+
Redeemer::new(
2355+
&RedeemerTag::new_spend(),
2356+
&BigNum::one(),
2357+
&PlutusData::new_empty_constr_plutus_data(&BigNum::one()),
2358+
&ExUnits::new(&to_bignum(61300), &to_bignum(18221176)),
2359+
),
2360+
]);
2361+
let hash = hash_script_data(
2362+
&redeemers,
2363+
&TxBuilderConstants::plutus_vasil_cost_models()
2364+
.retain_language_versions(vec![Language::new_plutus_v1()]),
2365+
Some(datums),
2366+
);
2367+
assert_eq!(hex::encode(hash.to_bytes()), "e6129f50a866d19d95bc9c95ee87b57a9e695c05d92ba2746141b03c15cf5f70");
2368+
}
23202369
}

0 commit comments

Comments
 (0)