-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(server): add Methods::extensions/extensions_mut
#1440
Conversation
The RpcModule/Methods may need to inject extensions which could be injected by the implementation as Extensions. This PR adds additional API to be used for unit testing a RpcModule. For instance one may inject some arbitary data which can't be unit tested unless it's explictly injected by the RpcModule.
Methods::inject_extensions
Methods::with_extensions
Methods::with_extensions
Methods::extensions/extensions_mut
let params = Params::new(params.as_ref().map(|params| params.as_ref().get())); | ||
let max_response_size = usize::MAX; | ||
let conn_id = ConnectionId(0); | ||
extensions.insert(conn_id); | ||
let mut ext = self.extensions.clone(); | ||
ext.insert(conn_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could actually inject this dummy connection in the constructor but I don't want to add the overhead for stuff that isn't using it.
@@ -213,6 +213,7 @@ impl Debug for MethodCallback { | |||
#[derive(Default, Debug, Clone)] | |||
pub struct Methods { | |||
callbacks: Arc<FxHashMap<&'static str, MethodCallback>>, | |||
extensions: Extensions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cheap, the default is just Option::None,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks cleaner than before; like it!
The RpcModule/Methods may need to inject extensions which could be needed by the RPC implementations.
For example in substrate I have moved the
deny unsafe stuff
to an extension but the unit tests fails because it's needs be added by the RpcModule.Thus, this PR adds additional API to be used for unit testing a RpcModule. For instance one may inject some arbitary data which can't be unit tested unless it's explictly injected by the RpcModule.