Skip to content

Commit 71ff300

Browse files
committed
tests
1 parent 70fd854 commit 71ff300

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cardano-serialization-lib",
3-
"version": "11.0.0-rc.6",
3+
"version": "11.0.0-rc.8",
44
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
55
"scripts": {
66
"rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; wasm-pack pack) && npm run js:flowgen",

rust/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cardano-serialization-lib"
3-
version = "11.0.0-rc.6"
3+
version = "11.0.0-rc.8"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"

rust/src/plutus.rs

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,9 @@ impl Costmdls {
283283
if l.kind() == LanguageKind::PlutusV1 {
284284
let mut serializer = Serializer::new_vec();
285285
serializer.write_bytes(l.to_bytes()).unwrap();
286-
serializer.finalize().len()
287-
} else {
288-
l.to_bytes().len()
286+
return serializer.finalize().len();
289287
}
288+
l.to_bytes().len()
290289
}
291290
let mut keys: Vec<Language> = self.0.iter().map(|(k, _v)| k.clone()).collect();
292291
// keys must be in canonical ordering first
@@ -313,9 +312,7 @@ impl Costmdls {
313312
serializer.serialize(self.0.get(&key).unwrap()).unwrap();
314313
}
315314
}
316-
let out = serializer.finalize();
317-
println!("language_views = {}", hex::encode(out.clone()));
318-
out
315+
serializer.finalize()
319316
}
320317
}
321318

@@ -1596,4 +1593,55 @@ mod tests {
15961593
let costmodels = TxBuilderConstants::plutus_vasil_cost_models();
15971594
assert_eq!(costmodels, Costmdls::from_bytes(costmodels.to_bytes()).unwrap());
15981595
}
1596+
1597+
#[test]
1598+
fn test_known_plutus_data_hash() {
1599+
use crate::tx_builder_constants::TxBuilderConstants;
1600+
let pdata = PlutusList::from(vec![
1601+
PlutusData::new_constr_plutus_data(
1602+
&ConstrPlutusData::new(
1603+
&BigNum::zero(),
1604+
&PlutusList::from(vec![
1605+
PlutusData::new_constr_plutus_data(
1606+
&ConstrPlutusData::new(
1607+
&BigNum::zero(),
1608+
&PlutusList::from(vec![
1609+
PlutusData::new_bytes(hex::decode("A183BF86925F66C579A3745C9517744399679B090927B8F6E2F2E1BB").unwrap()),
1610+
PlutusData::new_bytes(hex::decode("6164617065416D616E734576616E73").unwrap())
1611+
]),
1612+
),
1613+
),
1614+
PlutusData::new_constr_plutus_data(
1615+
&ConstrPlutusData::new(
1616+
&BigNum::zero(),
1617+
&PlutusList::from(vec![
1618+
PlutusData::new_bytes(hex::decode("9A4E855293A0B9AF5E50935A331D83E7982AB5B738EA0E6FC0F9E656").unwrap()),
1619+
PlutusData::new_bytes(hex::decode("4652414D455F38333030325F4C30").unwrap())
1620+
]),
1621+
),
1622+
),
1623+
PlutusData::new_bytes(hex::decode("BEA1C521DF58F4EEEF60C647E5EBD88C6039915409F9FD6454A476B9").unwrap()),
1624+
]),
1625+
),
1626+
),
1627+
]);
1628+
let redeemers = Redeemers(vec![
1629+
Redeemer::new(
1630+
&RedeemerTag::new_spend(),
1631+
&BigNum::one(),
1632+
&PlutusData::new_empty_constr_plutus_data(&BigNum::zero()),
1633+
&ExUnits::new(&to_bignum(7000000), &to_bignum(3000000000)),
1634+
),
1635+
]);
1636+
let lang = Language::new_plutus_v1();
1637+
let lang_costmodel = TxBuilderConstants::plutus_vasil_cost_models().get(&lang).unwrap();
1638+
let mut retained_cost_models = Costmdls::new();
1639+
retained_cost_models.insert(&lang, &lang_costmodel);
1640+
let hash = hash_script_data(
1641+
&redeemers,
1642+
&retained_cost_models,
1643+
Some(pdata),
1644+
);
1645+
assert_eq!(hex::encode(hash.to_bytes()), "357041b88b914670a3b5e3b0861d47f2ac05ed4935ea73886434d8944aa6dfe0");
1646+
}
15991647
}

0 commit comments

Comments
 (0)