Skip to content

Commit

Permalink
Merge branch 'tiago/router-no-pat-match' (#2739)
Browse files Browse the repository at this point in the history
* origin/tiago/router-no-pat-match:
  Changelog for #2739
  Add router regression test
  Avoid looping indefinitely when sub-router doesn't match
  • Loading branch information
tzemanovic committed Feb 27, 2024
2 parents f96503b + 23901a3 commit 401eac6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/2739-router-no-pat-match.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Bail from router if a nester router segment is not matched.
([\#2739](https://github.com/anoma/namada/pull/2739))
23 changes: 23 additions & 0 deletions crates/sdk/src/queries/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ macro_rules! try_match_segments {
);
}
)*

return Err(
$crate::queries::router::Error::WrongPath($request.path.clone()))
.into_storage_result();
};

// Terminal tail call, invoked after when all the args in the current
Expand Down Expand Up @@ -1040,6 +1044,25 @@ mod test {
let result = TEST_RPC.handle(ctx, &request);
assert!(result.is_err());

// Test request with another invalid path.
// The key difference here is that we are testing
// an invalid path in a nested segment.
let request = RequestQuery {
path: "/b/4".to_owned(),
data: Default::default(),
height: block::Height::from(0_u32),
prove: Default::default(),
};
let ctx = RequestCtx {
event_log: &client.event_log,
state: &client.state,
vp_wasm_cache: (),
tx_wasm_cache: (),
storage_read_past_height_limit: None,
};
let result = TEST_RPC.handle(ctx, &request);
assert!(result.is_err());

// Test request with a non-ascii path
let request = RequestQuery {
path: "ÀÁõö÷øùúûüýþÿ".to_owned(),
Expand Down
18 changes: 18 additions & 0 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,15 @@ fn check_shielded_balances_after_back(
// Check the balance on Chain B
std::env::set_var(ENV_VAR_CHAIN_ID, test_b.net.chain_id.to_string());
let rpc_b = get_actor_rpc(test_b, Who::Validator(0));
let tx_args = vec![
"shielded-sync",
"--viewing-keys",
AB_VIEWING_KEY,
"--node",
&rpc_b,
];
let mut client = run!(test_b, Bin::Client, tx_args, Some(120))?;
client.assert_success();
let ibc_denom = format!("{src_port_id}/{src_channel_id}/btc");
let query_args = vec![
"balance",
Expand All @@ -2081,6 +2090,15 @@ fn check_shielded_balances_after_back(
// Check the balance on Chain A
std::env::set_var(ENV_VAR_CHAIN_ID, test_a.net.chain_id.to_string());
let rpc_a = get_actor_rpc(test_a, Who::Validator(0));
let tx_args = vec![
"shielded-sync",
"--viewing-keys",
AA_VIEWING_KEY,
"--node",
&rpc_a,
];
let mut client = run!(test_a, Bin::Client, tx_args, Some(120))?;
client.assert_success();
let query_args = vec![
"balance",
"--owner",
Expand Down

0 comments on commit 401eac6

Please sign in to comment.