Skip to content

Commit b0bf41b

Browse files
feat: dfx info default-effective-canister-id (#4172)
1 parent 593624a commit b0bf41b

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

docs/cli-reference/dfx-info.mdx

+12-11
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ dfx info [type] [flag]
1414

1515
These are the types of information that the `dfx info` command can display.
1616

17-
| Information | Description |
18-
|----------------------|----------------------------------------------------------------------------------------------------------------------|
19-
| candid-ui-url | The URL of the Candid UI canister. |
20-
| config-json-path | Path to DFX configuration `config.json`. |
21-
| networks-json-path | Path to network definition file `networks.json`. |
22-
| replica-port | The listening port of the replica. |
23-
| pocketic-config-port | The listening port of PocketIC. |
24-
| replica-rev | The revision of the bundled replica. |
25-
| security-policy | Show the headers that gets applied to assets in `.ic-assets.json5` if "security_policy" is "standard" or "hardened". |
26-
| telemetry-log-path | Show the path to the telemetry log. |
27-
| webserver-port | The local webserver port. |
17+
| Information | Description |
18+
|-------------------------------|----------------------------------------------------------------------------------------------------------------------|
19+
| candid-ui-url | The URL of the Candid UI canister. |
20+
| config-json-path | Path to DFX configuration `config.json`. |
21+
| networks-json-path | Path to network definition file `networks.json`. |
22+
| default-effective-canister-id | The effective canister ID that dfx will use for management canister calls that don't imply one. |
23+
| replica-port | The listening port of the replica. |
24+
| pocketic-config-port | The listening port of PocketIC. |
25+
| replica-rev | The revision of the bundled replica. |
26+
| security-policy | Show the headers that gets applied to assets in `.ic-assets.json5` if "security_policy" is "standard" or "hardened". |
27+
| telemetry-log-path | Show the path to the telemetry log. |
28+
| webserver-port | The local webserver port. |
2829

2930
## Options
3031

e2e/tests-dfx/info.bash

+16
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,19 @@ teardown() {
123123
assert_command test -f "$cfg"
124124
assert_command jq . "$cfg"
125125
}
126+
127+
@test "prints the pocket-ic default effective canister id" {
128+
dfx_start
129+
if [[ $USE_REPLICA ]]; then
130+
assert_command dfx info default-effective-canister-id
131+
assert_eq "$stdout" rwlgt-iiaaa-aaaaa-aaaaa-cai
132+
else
133+
local topology expected_id64 expected_id
134+
topology=$(curl "http://localhost:$(get_webserver_port)/_/topology")
135+
expected_id64=$(jq -r .default_effective_canister_id.canister_id <<<"$topology")
136+
expected_id=$(cat <(crc32 <(base64 -d <<<"$expected_id64") | xxd -r -p) <(base64 -d <<<"$expected_id64") | base32 \
137+
| tr -d = | tr '[:upper:]' '[:lower:]' | fold -w5 | paste -sd- -)
138+
assert_command dfx info default-effective-canister-id
139+
assert_eq "$stdout" "$expected_id"
140+
fi
141+
}

scripts/workflows/provision-linux.sh

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ if [ "$E2E_TEST" = "tests-dfx/identity_encryption.bash" ] \
3939
then
4040
sudo apt-get install --yes expect
4141
fi
42+
if [ "$E2E_TEST" = "tests-dfx/info.bash" ]; then
43+
sudo apt-get install --yes libarchive-zip-perl
44+
fi
4245

4346
# Set environment variables.
4447
echo "$HOME/bin" >> "$GITHUB_PATH"

src/dfx/src/commands/info/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ enum InfoType {
3535
PocketicConfigPort,
3636
/// Show the path to the telemetry log file
3737
TelemetryLogPath,
38+
/// Show the effective canister ID that dfx will use for management canister calls that don't imply one
39+
DefaultEffectiveCanisterId,
3840
}
3941

4042
#[derive(Parser)]
@@ -60,6 +62,10 @@ pub fn exec(env: &dyn Environment, opts: InfoOpts) -> DfxResult {
6062
),
6163
}
6264
}
65+
InfoType::DefaultEffectiveCanisterId => {
66+
let env = create_anonymous_agent_environment(env, opts.network.to_network_name())?;
67+
env.get_effective_canister_id().to_text()
68+
}
6369
InfoType::SecurityPolicy => {
6470
ic_asset::security_policy::SecurityPolicy::Standard.to_json5_str()
6571
}

0 commit comments

Comments
 (0)