Skip to content

Commit 07c59cc

Browse files
committed
node: add unit tests for commit/redeem string format
1 parent bf20b65 commit 07c59cc

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/node/commit.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,13 @@ mod tests {
296296
use crate::node::SimpleFinalizer;
297297
use crate::{BitMachine, Value};
298298

299+
#[cfg_attr(not(feature = "base64"), allow(unused_variables))]
299300
#[track_caller]
300301
fn assert_program_deserializable<J: Jet>(
301302
prog_str: &str,
302303
prog_bytes: &[u8],
303304
cmr_str: &str,
305+
b64_str: &str,
304306
) -> Arc<CommitNode<J>> {
305307
let forest = match Forest::<J>::parse(prog_str) {
306308
Ok(forest) => forest,
@@ -352,6 +354,12 @@ mod tests {
352354
reser_sink.as_hex(),
353355
);
354356

357+
#[cfg(feature = "base64")]
358+
{
359+
assert_eq!(prog.to_string(), b64_str);
360+
assert_eq!(prog.display().program().to_string(), b64_str);
361+
}
362+
355363
prog
356364
}
357365

@@ -451,6 +459,7 @@ mod tests {
451459
"main := witness",
452460
&[0x38],
453461
"a0fc8debd6796917c86b77aded82e6c61649889ae8f2ed65b57b41aa9d90e375",
462+
"OA==",
454463
);
455464

456465
#[rustfmt::skip]
@@ -494,6 +503,7 @@ mod tests {
494503
],
495504
// CMR not checked against C code, since C won't give us any data without witnesses
496505
"e9339a0d715c721bff752aedc02710cdf3399f3f8d86e64456e85a1bc06ecb7c",
506+
"3O4o5oxBCDgVxiKNtxBGAgA=",
497507
),
498508
// Same program but with each `witness` replaced by `comp iden witness`.
499509
(
@@ -515,12 +525,13 @@ mod tests {
515525
],
516526
// CMR not checked against C code, since C won't give us any data without witnesses
517527
"d03bf350f406aef3af0d48e6533b3325ff86f18a36e0e73895a5cd6d6692b860",
528+
"4ChwQ4MAq5oxBCDgVxiKNtxBGAg=",
518529
)
519530
];
520531

521-
for (prog_str, diff1, cmr) in diff1s {
532+
for (prog_str, diff1, cmr, b64) in diff1s {
522533
let diff1_prog = crate::node::commit::tests::assert_program_deserializable::<Core>(
523-
prog_str, &diff1, cmr,
534+
prog_str, &diff1, cmr, b64,
524535
);
525536

526537
// Attempt to finalize, providing 32-bit witnesses 0, 1, ..., and then

src/node/redeem.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,15 @@ mod tests {
569569
use std::collections::HashMap;
570570
use std::fmt;
571571

572+
#[cfg_attr(not(feature = "base64"), allow(unused_variables))]
573+
#[track_caller]
572574
fn assert_program_deserializable<J: Jet>(
573575
prog_bytes: &[u8],
574576
witness_bytes: &[u8],
575577
cmr_str: &str,
576578
amr_str: &str,
577579
ihr_str: &str,
580+
b64_str: &str,
578581
) -> Arc<RedeemNode<J>> {
579582
let prog_hex = prog_bytes.as_hex();
580583
let witness_hex = witness_bytes.as_hex();
@@ -628,9 +631,21 @@ mod tests {
628631
reser_witness.as_hex(),
629632
);
630633

634+
#[cfg(feature = "base64")]
635+
{
636+
let disp = prog.display();
637+
assert_eq!(prog.to_string(), b64_str);
638+
assert_eq!(disp.program().to_string(), b64_str);
639+
assert_eq!(
640+
disp.witness().to_string(),
641+
witness_bytes.as_hex().to_string()
642+
);
643+
}
644+
631645
prog
632646
}
633647

648+
#[track_caller]
634649
fn assert_program_not_deserializable<J: Jet>(
635650
prog_bytes: &[u8],
636651
witness_bytes: &[u8],
@@ -697,6 +712,7 @@ mod tests {
697712
"d7969920eff9a1ed0359aaa8545b239c69969e22c304c645a7b49bcc976a40a8",
698713
"f7acbb077e7661a08384818bc8e3a275ed42ad446252575a35a35f71689fef78",
699714
"3ce4a6390b4e4bda6330acda4800e66e5d2cae0f5a2888564c706f2b910146b8",
715+
"ycRtuIIwEA==",
700716
);
701717
}
702718

@@ -744,6 +760,7 @@ mod tests {
744760
"8a54101335ca2cf7e933d74cdb15f99becc4e540799ba5e2d19c00c9d7219e71",
745761
"74e868bd640c250bc45522085158a9723fc7e277bb16a8d582c4012ebbb1f6f1",
746762
"39b8f72bd1539de87d26673890603d6548cfc8b68571d996bdf9b1d8b557bd35",
763+
"wQAAAQA=",
747764
);
748765
}
749766

@@ -765,6 +782,7 @@ mod tests {
765782
"abdd773fc7a503908739b4a63198416fdd470948830cb5a6516b98fe0a3bfa85",
766783
"1362ee53ae75218ed51dc4bd46cdbfa585f934ac6c6c3ff787e27dce91ccd80b",
767784
"251c6778129e0f12da3f2388ab30184e815e9d9456b5931e54802a6715d9ca42",
785+
"zSQIS29W33fvVt9371bfd+9W33fvVt9371bfd+9W33fvVt93hgGA",
768786
);
769787

770788

@@ -783,6 +801,7 @@ mod tests {
783801
"f6c678dfb180b94567a9d524e05fbc893f6905e0e3db931ff01dc2701e783d4c",
784802
"212d4fa3dbe2b33db1e11bb6f4cc973be5de0896a3775387a06056483b8feb0f",
785803
"7a583edcc733b6bba66998110be403ac61fab2d93fc09ba3c84ab2509b538043",
804+
"zSUIberb7v3q2+796tvu/erb7v3q2+796tvu/erb7v3q2+70hgGA",
786805
);
787806
}
788807

@@ -800,6 +819,7 @@ mod tests {
800819
"afe8f5f8bd3f64bfa51d2f29ffa22523604d9654c0d9862dbf2dc67ba097cbb2",
801820
"15239708cb7b448cedc6a0b6401dce86ed74084056dd95831928860dd0c3ca67",
802821
"9cdacb48b16e108ccbd6bcbce459a64056df285c2dc6e02dca6d13c4b1530fb0",
822+
"xQIGJBA=",
803823
);
804824
}
805825

@@ -841,6 +861,7 @@ mod tests {
841861
"f3cd4537d7ebb201732203195b30b549b8dc0c2c6257b3a0d53bedb08ea02874",
842862
"107fa80454ed0f2d95d7c18d307912b1497505b98de47198fee23b5018efa544",
843863
"d52021c638ba742a90bead9b3055efd66091fb50bb131aa8b10eb7c13ef464d1",
864+
"02kAAAAAAAAAAAAAADt4zlY/iaDtlBT1qiitDZbWeV+cY0cHAsDijYgQ",
844865
);
845866
}
846867

@@ -863,6 +884,7 @@ mod tests {
863884
"b689bdee289c8dd4e2e283358d187813363d441776cf826dafc27cc8a81ec441",
864885
"3c68660a1afde7982ce4aa9d499ad382bc32f5f9ad894a5e915f76e66303a25b",
865886
"85313720ee43ae0ee03f88b05e6d9e4494308c6897bdeb3e93b94559c3317484",
887+
"yQkgdJBA",
866888
);
867889
}
868890

@@ -890,6 +912,7 @@ mod tests {
890912
"8a9e97676b24be7797d9ee0bf32dd76bcd78028e973025f785eae8dc91c8a0da",
891913
"ec97c8774cb6bfb381fdbbcc8d964380fb3a3b45779322624490d6231ae777a4",
892914
"ad7c38b16b9129646dc89b52cff144de94a80e383c4983b53de65e3575abcf38",
915+
"xtXyYRQDJLGGIJJonwvxOqRTamOQiwbfM2EMA+InecBt8gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4o2MBAA=",
893916
);
894917
}
895918

0 commit comments

Comments
 (0)