Skip to content

Commit e18ffc0

Browse files
committed
policy: add (broken, ignored) unit test showing a problem with asm
Turns out the asm fragment is basically unusable. Oops. The next commit will fix this, at the cost of some ugly API changes.
1 parent 7e5df30 commit e18ffc0

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/policy/satisfy.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,4 +714,60 @@ mod tests {
714714
}
715715
}
716716
}
717+
718+
// This test fails with an "InferenceContextMismatch". In fact, it is impossible to
719+
// combine asm with any other fragments in the current codebase, because the non-asm
720+
// fragments are satisfied using an ephemeral type inference context constructed in
721+
// `satisfy_internal`, which is inaccessible and impossible to use in the return
722+
// value of `lookup_asm_program`.
723+
//
724+
// This will be fixed in the next commit.
725+
#[test]
726+
#[ignore]
727+
fn satisfy_asm_and_older() {
728+
let env = ElementsEnv::dummy_with(
729+
elements::LockTime::ZERO,
730+
elements::Sequence::from_consensus(42),
731+
);
732+
let mut satisfier = get_satisfier(&env);
733+
734+
let mut assert_branch = |witness0: Value, witness1: Value| {
735+
let ctx = &types::Context::new();
736+
let asm_program = serialize::verify_bexp(
737+
&Arc::<ConstructNode<Elements>>::pair(
738+
&Arc::<ConstructNode<Elements>>::witness(ctx, Some(witness0.clone())),
739+
&Arc::<ConstructNode<Elements>>::witness(ctx, Some(witness1.clone())),
740+
)
741+
.expect("sound types"),
742+
&Arc::<ConstructNode<Elements>>::jet(ctx, Elements::Eq8),
743+
);
744+
let cmr = asm_program.cmr();
745+
satisfier.assembly.insert(cmr, asm_program);
746+
747+
let policy = Policy::And {
748+
left: Arc::new(Policy::Assembly(cmr)),
749+
right: Arc::new(Policy::Older(41)),
750+
};
751+
let result = policy.satisfy(&satisfier, &env);
752+
753+
if witness0 == witness1 {
754+
let program = result.expect("policy should be satisfiable");
755+
let witness = to_witness(&program);
756+
757+
assert_eq!(2, witness.len());
758+
assert_eq!(&witness0, witness[0]);
759+
assert_eq!(&witness1, witness[1]);
760+
761+
execute_successful(program, &env);
762+
} else {
763+
assert!(matches!(result, Err(SatisfierError::AssemblyFailed(..))));
764+
}
765+
};
766+
767+
for a in 0..2 {
768+
for b in 0..2 {
769+
assert_branch(Value::u8(a), Value::u8(b))
770+
}
771+
}
772+
}
717773
}

0 commit comments

Comments
 (0)