/// This is a simple example (proof of concept) of how the Proptest framework
/// can be employed to fuzz test a canister API method.
///
/// What is tested here is not very interesting. The intention is that this can
/// serve as a basis to write more interesting fuzz tests for canisters using
/// the Proptest framework in the future.
///
/// Note that `TestRunner::run` cannot be used since that does not work for
/// `async` methods. Also, the `proptest!` macro cannot be used in this context
/// because it is intended for unit tests (i.e. with `#[test]` annotation)
This is a simple example (proof of concept) of how the Proptest framework
can be employed to fuzz test a canister API method.



Note that `TestRunner::run` cannot be used since that does not work for
`async` methods. Also, the `proptest!` macro cannot be used in this context
because it is intended for unit tests
This is a simple example ( proof of concept ) of how the Proptest framework can be employed to fuzz test a canister API method . Note that ` TestRunner :: run ` cannot be used since that does not work for ` async ` methods . Also the ` proptest! ` macro cannot be used in this context because it is intended for unit tests
pub fn test(handle: IcHandle, ctx: &ic_fondue::pot::Context) {
    ctx.install_nns_canisters(&handle, true);
    let mut rng = ctx.rng.clone();
    let endpoint = get_random_nns_node_endpoint(&handle, &mut rng);
    let rt = tokio::runtime::Runtime::new().expect("Could not create tokio runtime.");
    rt.block_on(async move {
        endpoint.assert_ready(ctx).await;
        let nns = runtime_from_url(endpoint.url.clone());
        let governance = Canister::new(&nns, GOVERNANCE_CANISTER_ID);
        let mut runner = TestRunner::default();
        for _ in 0..256 {
            let neuron_id = Box::new((0..u64::MAX).new_tree(&mut runner).unwrap());
            assert!(
                get_neuron_returns_not_found_error(&governance, ctx, neuron_id.current()).await
            );
            // If the assertion fails, it would be possible to apply 'shrinking'
            // to find the 'simplest' input that causes a failure. We could do
            // this at a later point.
            // See https://altsysrq.github.io/proptest-book/proptest/tutorial/shrinking-basics.html.
        }
    });
}
pub fn test ( handle : IcHandle , ctx : & ic_fondue :: pot :: Context ) { ctx . install_nns_canisters ( & handle , true ) ; let mut rng = ctx . rng . clone ( ) ; let endpoint = get_random_nns_node_endpoint ( & handle , & mut rng ) ; let rt = tokio :: runtime :: Runtime :: new ( ) . expect ( " " ) ; rt . block_on ( async move { endpoint . assert_ready ( ctx ) . await ; let nns = runtime_from_url ( endpoint . url . clone ( ) ) ; let governance = Canister :: new ( & nns , GOVERNANCE_CANISTER_ID ) ; let mut runner = TestRunner :: default ( ) ; for _ in 0 .. 256 { let neuron_id = Box :: new ( ( 0 .. u64 :: MAX ) . new_tree ( & mut runner ) . unwrap ( ) ) ; assert ! ( get_neuron_returns_not_found_error ( governance ctx neuron_id current ( ) ) await ) ; // If the assertion fails, it would be possible to apply 'shrinking' // to find the 'simplest' input that causes a failure. We could do // this at a later point. // See https://altsysrq.github.io/proptest-book/proptest/tutorial/shrinking-basics.html. } } ) ; }
This is a simple example (proof of concept) of how the Proptest framework
can be employed to fuzz test a canister API method.
This is a simple example ( proof of concept ) of how the Proptest framework can be employed to fuzz test a canister API method .
handle
IcHandle
ctx
&ic_fondue::pot::Context