Skip to content

Commit

Permalink
Merge pull request #1282 from eqlabs/chris/register-v04
Browse files Browse the repository at this point in the history
feat: register v0.4 rpc api
  • Loading branch information
Mirko-von-Leipzig authored Jul 27, 2023
2 parents 57f1ccf + 6732835 commit 847ece3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Hint: If you are looking to run two instances of pathfinder, you must configure

let module = crate::module::Module::new(self.context);
let module = v03::register_methods(module)?;
let module = v04::register_methods(module)?;
let module = pathfinder::register_methods(module)?;
let module = match &self.ws_senders {
Some(ws_senders) => websocket::register_subscriptions(module, ws_senders.clone())?,
Expand Down
13 changes: 11 additions & 2 deletions crates/rpc/src/middleware/versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ mod response {

pub mod test_utils {
pub mod method_names {
pub const COMMON_FOR_V03: [&str; 23] = [
pub const COMMON_FOR_V03_V04: [&str; 23] = [
"starknet_addDeclareTransaction",
"starknet_addDeployAccountTransaction",
"starknet_addInvokeTransaction",
Expand Down Expand Up @@ -279,11 +279,13 @@ pub mod test_utils {
pub const COMMON_FOR_ALL: [&str; 2] =
["pathfinder_getProof", "pathfinder_getTransactionStatus"];
pub const V03_ONLY: [&str; 1] = ["starknet_simulateTransaction"];
pub const V04_ONLY: [&str; 1] = ["starknet_simulateTransactions"];
pub const PATHFINDER_ONLY: [&str; 1] = ["pathfinder_version"];
}

pub mod paths {
pub const V03: &[&str] = &["", "/", "/rpc/v0.3", "/rpc/v0.3/"];
pub const V04: &[&str] = &["/rpc/v0.4", "/rpc/v0.4/"];
pub const PATHFINDER: &[&str] = &["/rpc/pathfinder/v0.1", "/rpc/pathfinder/v0.1/"];
}
}
Expand Down Expand Up @@ -312,14 +314,21 @@ mod tests {

let not_in_v03 = method_names::PATHFINDER_ONLY
.into_iter()
.chain(method_names::V04_ONLY.into_iter())
.collect::<Vec<_>>();
let not_in_pathfinder = method_names::COMMON_FOR_V03
let not_in_v04 = method_names::PATHFINDER_ONLY
.into_iter()
.chain(method_names::V03_ONLY.into_iter())
.collect::<Vec<_>>();
let not_in_pathfinder = method_names::COMMON_FOR_V03_V04
.into_iter()
.chain(method_names::V03_ONLY.into_iter())
.chain(method_names::V04_ONLY.into_iter())
.collect::<Vec<_>>();

for (paths, methods) in vec![
(paths::V03, not_in_v03),
(paths::V04, not_in_v04),
(paths::PATHFINDER, not_in_pathfinder),
]
.into_iter()
Expand Down
7 changes: 6 additions & 1 deletion crates/rpc/tests/versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ async fn api_versions_are_routed_correctly_for_all_methods() {
.await
.unwrap();

let v03_methods = method_names::COMMON_FOR_V03
let v03_methods = method_names::COMMON_FOR_V03_V04
.into_iter()
.chain(method_names::V03_ONLY.into_iter())
.collect::<Vec<_>>();
let v04_methods = method_names::COMMON_FOR_V03_V04
.into_iter()
.chain(method_names::V04_ONLY.into_iter())
.collect::<Vec<_>>();
let pathfinder_methods = method_names::COMMON_FOR_ALL
.into_iter()
.chain(method_names::PATHFINDER_ONLY.into_iter())
.collect();

for (paths, version, methods) in vec![
(paths::V03, "v0.3", v03_methods),
(paths::V04, "v0.4", v04_methods),
(paths::PATHFINDER, "v0.1", pathfinder_methods),
]
.into_iter()
Expand Down

0 comments on commit 847ece3

Please sign in to comment.