Skip to content
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

Merged
merged 5 commits into from
Aug 14, 2024
Merged

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Aug 12, 2024

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.

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.
@niklasad1 niklasad1 requested a review from a team as a code owner August 12, 2024 14:47
@niklasad1 niklasad1 changed the title feat(server): add Methods::inject_extensions feat(server): add Methods::with_extensions Aug 12, 2024
@niklasad1 niklasad1 changed the title feat(server): add Methods::with_extensions feat(server): add Methods::extensions/extensions_mut Aug 14, 2024
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);
Copy link
Member Author

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,
Copy link
Member Author

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,

Copy link
Collaborator

@jsdw jsdw left a 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!

@niklasad1 niklasad1 merged commit 8175fa8 into master Aug 14, 2024
11 checks passed
@niklasad1 niklasad1 deleted the na-inject-ext branch August 14, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants