5555//! produces two tests: `some+some` and `none+none`. Each scenario becomes its own `#[test]`, suffixed by index
5656//! (`__0`, `__1`, …).
5757
58+ use crate::messages::delivery::OnchainDeliveryMode ;
59+ use crate::oracle::get_contract_instance::GetContractInstanceResult ;
5860use crate::protocol:: {
5961 abis::function_selector::FunctionSelector ,
6062 address ::{AztecAddress , EthAddress },
@@ -143,6 +145,26 @@ impl OracleTestValue<1> for EthAddress {
143145 [Scenario ::unnamed (EthAddress ::from_field (seed as Field ))]
144146 }
145147}
148+ impl OracleTestValue <1 > for OnchainDeliveryMode {
149+ fn oracle_test_value (seed : u32 ) -> [Scenario <Self >; 1 ] {
150+ // The seed alternates between the only two valid modes
151+ let mode = if (seed % 2 ) == 0 {
152+ OnchainDeliveryMode ::onchain_unconstrained ()
153+ } else {
154+ OnchainDeliveryMode ::onchain_constrained ()
155+ };
156+ [Scenario ::unnamed (mode )]
157+ }
158+ }
159+ impl OracleTestValue <1 > for GetContractInstanceResult {
160+ fn oracle_test_value (seed : u32 ) -> [Scenario <Self >; 1 ] {
161+ [
162+ Scenario ::unnamed (
163+ GetContractInstanceResult { exists : (seed % 2 ) != 0 , member : (seed + 1 ) as Field },
164+ ),
165+ ]
166+ }
167+ }
146168impl <T > OracleTestValue <2 > for Option <T >
147169where
148170 T : OracleTestValue <1 >,
@@ -390,8 +412,9 @@ pub(crate) unconstrained fn add_scenario_to_oracle_test(_name: BoundedVec<u8, MA
390412global TEST_COLLECTION_LEN : u32 = 3 ;
391413global TEST_BOUNDED_VEC_CAP : u32 = 5 ;
392414
393- /// Rewrites `typ`, replacing every array length with [`TEST_COLLECTION_LEN`] and every bounded-vec capacity with
394- /// [`TEST_BOUNDED_VEC_CAP`] (recursing through `Option` inners). Returns it as a `Quoted` type to splice into the test.
415+ /// Rewrites `typ`, replacing every generic array length with [`TEST_COLLECTION_LEN`] and every bounded-vec capacity
416+ /// with [`TEST_BOUNDED_VEC_CAP`] (recursing through `Option` inners). Returns it as a `Quoted` type to splice into the
417+ /// test.
395418///
396419/// This exists because the annotated oracles are *generic* over their lengths (e.g.
397420/// `get_hash_preimage_oracle<let N: u32>(...) -> [Field; N]`), but the generated test is not generic, so it has no `N`
@@ -401,9 +424,14 @@ global TEST_BOUNDED_VEC_CAP: u32 = 5;
401424comptime fn pinned_type (typ : Type ) -> Quoted {
402425 let array = typ .as_array ();
403426 if array .is_some () {
404- let (element_type , _generic_length ) = array .unwrap ();
427+ let (element_type , length_type ) = array .unwrap ();
405428 let pinned_element = pinned_type (element_type );
406- let len = f"{ TEST_COLLECTION_LEN} " .quoted_contents ();
429+ // A concrete length (e.g. `[T; 1]`) is part of the oracle's signature and must be kept; only a generic
430+ // length has no value to instantiate and gets pinned.
431+ let len = length_type
432+ .as_constant ()
433+ .map (|concrete_length | f"{ concrete_length} " .quoted_contents ())
434+ .unwrap_or_else (|| f"{ TEST_COLLECTION_LEN} " .quoted_contents ());
407435 quote { [$pinned_element ; $len ] }
408436 } else if is_data_type_named (typ , quote { BoundedVec }) {
409437 let element_type = typ .as_data_type ().unwrap ().1 [0 ];
0 commit comments