Skip to content

Commit 52956f0

Browse files
committed
fix: failing script test & cover plutus list serialization cases
1 parent 1c4e89e commit 52956f0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

rust/src/plutus.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ impl Deserialize for Strings {
11681168
#[cfg(test)]
11691169
mod tests {
11701170
use super::*;
1171+
use hex::*;
11711172

11721173
#[test]
11731174
pub fn plutus_constr_data() {
@@ -1184,4 +1185,30 @@ mod tests {
11841185
let constr_1854_roundtrip = PlutusData::from_bytes(constr_1854.to_bytes()).unwrap();
11851186
assert_eq!(constr_1854, constr_1854_roundtrip);
11861187
}
1187-
}
1188+
1189+
#[test]
1190+
pub fn plutus_list_serialization_cli_compatibility() {
1191+
// mimic cardano-cli array encoding, see https://github.com/Emurgo/cardano-serialization-lib/issues/227
1192+
let datum_cli = "d8799f4100d8799fd8799fd8799f581cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd8799fd8799fd8799f581cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd87a80ff1a002625a0d8799fd879801a000f4240d87a80ffff";
1193+
let datum = PlutusData::from_bytes(Vec::from_hex(datum_cli).unwrap()).unwrap();
1194+
assert_eq!(datum_cli, hex::encode(datum.to_bytes()));
1195+
1196+
// encode empty arrays as fixed
1197+
assert_eq!("80", hex::encode(PlutusList::from_bytes(Vec::from_hex("9fff").unwrap()).unwrap().to_bytes()));
1198+
1199+
// encode arrays as indefinite length array
1200+
let mut list = PlutusList::new();
1201+
list.add(&PlutusData::new_integer(&BigInt::from_str("1").unwrap()));
1202+
assert_eq!("9f01ff", hex::encode(list.to_bytes()));
1203+
1204+
// witness_set should have fixed length array
1205+
let mut witness_set = TransactionWitnessSet::new();
1206+
witness_set.set_plutus_data(&list);
1207+
assert_eq!("a1048101", hex::encode(witness_set.to_bytes()));
1208+
1209+
list = PlutusList::new();
1210+
list.add(&datum);
1211+
witness_set.set_plutus_data(&list);
1212+
assert_eq!(format!("a10481{}", datum_cli), hex::encode(witness_set.to_bytes()));
1213+
}
1214+
}

rust/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ mod tests {
21612161

21622162
assert_eq!(
21632163
hex::encode(script_data_hash.to_bytes()),
2164-
"57240d358f8ab6128c4a66340271e4fec39b4971232add308f01a5809313adcf"
2164+
"4415e6667e6d6bbd992af5092d48e3c2ba9825200d0234d2470068f7f0f178b3"
21652165
);
21662166
}
21672167

0 commit comments

Comments
 (0)