inkdevhub / drink

De-chained Ready-to-play ink! playground
Apache License 2.0
69 stars 15 forks source link

Expose the `fn execute_with` #81

Closed kvinwang closed 11 months ago

kvinwang commented 11 months ago

Phala's ink contract needs some extra setup. Like below code:

        #[drink::test]
        fn deploy_and_call_http_get() -> Result<(), Box<dyn std::error::Error>> {
            use drink_pink_runtime::PinkRuntime;
            let checker_bundle = BundleProvider::local()?;
            let mut session = Session::<PinkRuntime>::new()?;
            session.execute_with(|| {
                PinkRuntime::setup_cluster().expect("Failed to setup cluster");
            });
            let checker =
                session.deploy_bundle(checker_bundle, "default", NO_ARGS, vec![], None)?;
            let (status, _body): (u16, String) = session.call_with_address(
                checker.clone(),
                "http_get",
                &["\"https://httpbin.org/get\""],
                None,
            )??;
            assert_eq!(status, 200);
     }

So, is it OK to export the function execute_with?

kvinwang commented 11 months ago

however, please forgive me nitpicking, but I'd rather move this to ChainApi so that you can access this functionality from a Session object indirectly through chain_api() method

Sounds good. I've moved it to ChainApi.