use jsonrpsee::core::RpcResult; use sov_modules_api::default_context::ZkDefaultContext; use sov_modules_api::macros::rpc_gen; use sov_modules_api::{Context, ModuleInfo, WorkingSet}; use sov_state::ZkStorage; #[derive(ModuleInfo)] pub struct TestStruct { #[address] pub(crate) address: C::Address, } #[rpc_gen(client, server, namespace = "test")] impl TestStruct { #[rpc_method(name = "firstMethod")] pub fn first_method(&self, _working_set: &mut WorkingSet) -> RpcResult { Ok(11) } #[rpc_method(name = "secondMethod")] pub fn second_method( &self, result: u32, _working_set: &mut WorkingSet, ) -> RpcResult { Ok(result) } #[rpc_method(name = "thirdMethod")] pub fn third_method(&self, result: u32) -> RpcResult { Ok(result) } #[rpc_method(name = "fourthMethod")] pub fn fourth_method( &self, _working_set: &mut WorkingSet, result: u32, ) -> RpcResult { Ok(result) } } pub struct TestRuntime { test_struct: TestStruct, } // This is generated by a macro annotating the state transition runner, // but we do not have that in scope here so generating the struct manually. struct RpcStorage { pub storage: C::Storage, } impl TestStructRpcImpl for RpcStorage { fn get_working_set( &self, ) -> ::sov_modules_api::WorkingSet { ::sov_modules_api::WorkingSet::new(self.storage.clone()) } } fn main() { let storage = ZkStorage::new(); let r: RpcStorage = RpcStorage { storage: storage.clone(), }; { let result = as TestStructRpcServer>::first_method( &r, ) .unwrap(); assert_eq!(result, 11); } { let result = as TestStructRpcServer>::second_method( &r, 22, ) .unwrap(); assert_eq!(result, 22); } { let result = as TestStructRpcServer>::third_method( &r, 33, ) .unwrap(); assert_eq!(result, 33); } { let result = as TestStructRpcServer>::fourth_method( &r, 44, ) .unwrap(); assert_eq!(result, 44); } { let result = as TestStructRpcServer>::health(&r) .unwrap(); assert_eq!(result, ()); } { let result = as TestStructRpcServer>::module_address(&r) .unwrap(); assert_eq!( result, "sov1y34qkrqwffa3hmpdzvj0fqc0ahmlgrjf5ltfan9ugt82v5ej6lkshg9ypu" ); } println!("All tests passed!"); }