Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ dfx command-line parameters for canister http requests integration:
This defaults to the following value in dfx.json:
.defaults.canister_http.enabled

=== fix: specifying ic provider with a trailing slash is recognised correctly

Specifying the network provider as `https://ic0.app/` instead of `https://ic0.app` is now recognised as the real IC network.

=== Binary cache

Added ic-canister-http-adapter to the binary cache.
Expand Down
1 change: 1 addition & 0 deletions src/dfx/src/config/dfinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct ConfigCanistersCanisterRemote {

const DEFAULT_LOCAL_BIND: &str = "127.0.0.1:8000";
pub const DEFAULT_IC_GATEWAY: &str = "https://ic0.app";
pub const DEFAULT_IC_GATEWAY_TRAILING_SLASH: &str = "https://ic0.app/";

/// A Canister configuration in the dfx.json config file.
/// It only contains a type; everything else should be infered using the
Expand Down
31 changes: 24 additions & 7 deletions src/dfx/src/lib/network/network_descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::dfinity::NetworkType;
use crate::config::dfinity::DEFAULT_IC_GATEWAY;
use crate::config::dfinity::{DEFAULT_IC_GATEWAY, DEFAULT_IC_GATEWAY_TRAILING_SLASH};

#[derive(Clone, Debug)]
pub struct NetworkDescriptor {
Expand All @@ -10,12 +10,20 @@ pub struct NetworkDescriptor {
}

impl NetworkDescriptor {
// Determines whether the provided connection is the official IC or not.
/// Determines whether the provided connection is the official IC or not.
#[allow(clippy::ptr_arg)]
pub fn is_ic(network_name: &str, providers: &Vec<String>) -> bool {
let name_match = network_name == "ic" || network_name == DEFAULT_IC_GATEWAY;
let provider_match =
{ providers.len() == 1 && providers.get(0).unwrap() == "https://ic0.app" };
let name_match = matches!(
network_name,
"ic" | DEFAULT_IC_GATEWAY | DEFAULT_IC_GATEWAY_TRAILING_SLASH
);
let provider_match = {
providers.len() == 1
&& matches!(
providers.get(0).unwrap().as_str(),
DEFAULT_IC_GATEWAY | DEFAULT_IC_GATEWAY_TRAILING_SLASH
)
};
name_match || provider_match
}
}
Expand All @@ -27,13 +35,22 @@ mod test {
#[test]
fn ic_by_netname() {
assert!(NetworkDescriptor::is_ic("ic", &vec![]));
assert!(NetworkDescriptor::is_ic(DEFAULT_IC_GATEWAY, &vec![]));
assert!(NetworkDescriptor::is_ic(
DEFAULT_IC_GATEWAY_TRAILING_SLASH,
&vec![]
));
}

#[test]
fn ic_by_provider() {
assert!(NetworkDescriptor::is_ic(
"not_ic",
&vec!["https://ic0.app".to_string()]
&vec![DEFAULT_IC_GATEWAY.to_string()]
));
assert!(NetworkDescriptor::is_ic(
"not_ic",
&vec![DEFAULT_IC_GATEWAY_TRAILING_SLASH.to_string()]
));
}

Expand All @@ -55,7 +72,7 @@ mod test {
assert!(!NetworkDescriptor::is_ic(
"not_ic",
&vec![
"https://ic0.app".to_string(),
DEFAULT_IC_GATEWAY.to_string(),
"some_other_provider".to_string()
]
));
Expand Down