Skip to content

Commit

Permalink
feat: replace icx-proxy with PocketIC HTTP gateway (#3843)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity authored Aug 5, 2024
1 parent b2109b2 commit 31d5c0b
Show file tree
Hide file tree
Showing 25 changed files with 617 additions and 484 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

# UNRELEASED

### feat: PocketIC HTTP gateway

icx-proxy's HTTP gateway has been replaced with PocketIC's. (This does not impact the meaning of `--pocketic` in `dfx start`.)

### feat: Enable threshold schnorr signatures for Ed25519

Schnorr signature signing for `Ed25519` is now enabled.
A test key id `Ed25519:dfx_test_key` is ready to be used by locally created canisters.


# 0.22.1

## Dependencies
Expand Down
45 changes: 18 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions docs/cli-reference/dfx-info.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ dfx info [type] [flag]

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

| Information | Description |
|---------------------|--------------------------------------------------------------------------------------------------------------------|
| candid-ui-url | The URL of the Candid UI canister. |
| networks-json-path | Path to network definition file networks.json. |
| replica-port | The listening port of the replica. |
| replica-rev | The revision of the bundled replica. |
| security-policy | Show the headers that gets applied to assets in .ic-assets.json5 if "security_policy" is "standard" or "hardened". |
| webserver-port | The local webserver (icx-proxy) port. |
| Information | Description |
|--------------------|--------------------------------------------------------------------------------------------------------------------|
| candid-ui-url | The URL of the Candid UI canister. |
| networks-json-path | Path to network definition file networks.json. |
| replica-port | The listening port of the replica. |
| replica-rev | The revision of the bundled replica. |
| security-policy | Show the headers that gets applied to assets in .ic-assets.json5 if "security_policy" is "standard" or "hardened". |
| webserver-port | The local webserver port. |

## Options

You can use the following options with the `dfx info` command.

| Option | Description |
|------------------------------------|--------------------------------------------------------------------------------------------------------|
| `--network <network>` | Overrides the environment to connect to. By default, the local canister execution environment is used. |
| Option | Description |
|-----------------------|--------------------------------------------------------------------------------------------------------|
| `--network <network>` | Overrides the environment to connect to. By default, the local canister execution environment is used. |

## Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/dfx-json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
}
},
"ConfigDefaultsProxy": {
"description": "Configuration for icx-proxy.",
"description": "Configuration for the HTTP gateway.",
"type": "object",
"required": [
"domain"
Expand Down
2 changes: 1 addition & 1 deletion docs/networks-json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
}
},
"ConfigDefaultsProxy": {
"description": "Configuration for icx-proxy.",
"description": "Configuration for the HTTP gateway.",
"type": "object",
"required": [
"domain"
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests-dfx/bitcoin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ set_local_network_bitcoin_enabled() {
ID=$(dfx canister id hello_frontend)

timeout 15s sh -c \
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/webserver-port\")/sample-asset.txt?canisterId=$ID; do echo waiting for icx-proxy to restart; sleep 1; done" \
|| (echo "icx-proxy did not restart" && ps aux && exit 1)
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/webserver-port\")/sample-asset.txt?canisterId=$ID; do echo waiting for pocket-ic proxy to restart; sleep 1; done" \
|| (echo "pocket-ic proxy did not restart" && ps aux && exit 1)

assert_command curl --fail http://localhost:"$(get_webserver_port)"/sample-asset.txt?canisterId="$ID"
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests-dfx/canister_http.bash
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ set_shared_local_network_canister_http_empty() {
ID=$(dfx canister id hello_frontend)

timeout 15s sh -c \
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/webserver-port\")/sample-asset.txt?canisterId=$ID; do echo waiting for icx-proxy to restart; sleep 1; done" \
|| (echo "icx-proxy did not restart" && ps aux && exit 1)
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/webserver-port\")/sample-asset.txt?canisterId=$ID; do echo waiting for pocket-ic proxy to restart; sleep 1; done" \
|| (echo "pocket-ic proxy did not restart" && ps aux && exit 1)

assert_command curl --fail http://localhost:"$(get_webserver_port)"/sample-asset.txt?canisterId="$ID"
}
Expand Down
76 changes: 40 additions & 36 deletions e2e/tests-dfx/start.bash
Original file line number Diff line number Diff line change
Expand Up @@ -87,47 +87,51 @@ teardown() {
assert_contains "Module hash: None"
}


@test "icx-proxy domain configuration in string form" {
@test "pocket-ic proxy domain configuration in string form" {
create_networks_json
jq '.local.proxy.domain="xyz.domain"' "$E2E_NETWORKS_JSON" | sponge "$E2E_NETWORKS_JSON"

dfx_start

assert_command ps aux
assert_match "icx-proxy.*--domain xyz.domain"
domains="$(curl "http://localhost:$(get_pocketic_proxy_config_port)/http_gateway" \
| jq -c ".[] | select(.port == $(get_webserver_port)) | .domains | sort")"

assert_eq '["xyz.domain"]' "$domains"
}

@test "icx-proxy domain configuration in vector form" {
@test "pocket-ic proxy domain configuration in vector form" {
create_networks_json
jq '.local.proxy.domain=["xyz.domain", "abc.something"]' "$E2E_NETWORKS_JSON" | sponge "$E2E_NETWORKS_JSON"

dfx_start

assert_command ps aux
assert_match "icx-proxy.*--domain xyz.domain"
assert_match "icx-proxy.*--domain abc.something"
domains="$(curl "http://localhost:$(get_pocketic_proxy_config_port)/http_gateway" \
| jq -c ".[] | select(.port == $(get_webserver_port)) | .domains | sort")"

assert_eq '["abc.something","xyz.domain"]' "$domains"
}

@test "icx-proxy domain configuration from project defaults" {
@test "pocket-ic proxy domain configuration from project defaults" {
dfx_new
define_project_network

jq '.defaults.proxy.domain=["xyz.domain", "abc.something"]' dfx.json | sponge dfx.json

dfx_start

assert_command ps aux
assert_match "icx-proxy.*--domain xyz.domain"
assert_match "icx-proxy.*--domain abc.something"
domains="$(curl "http://localhost:$(get_pocketic_proxy_config_port)/http_gateway" \
| jq -c ".[] | select(.port == $(get_webserver_port)) | .domains | sort")"

assert_eq '["abc.something","xyz.domain"]' "$domains"
}

@test "icx-proxy domain configuration from command-line" {
@test "pocket-ic proxy domain configuration from command-line" {
dfx_start --domain xyz.domain --domain def.somewhere

assert_command ps aux
assert_match "icx-proxy.*--domain xyz.domain"
assert_match "icx-proxy.*--domain def.somewhere"
domains="$(curl "http://localhost:$(get_pocketic_proxy_config_port)/http_gateway" \
| jq -c ".[] | select(.port == $(get_webserver_port)) | .domains | sort")"

assert_eq '["def.somewhere","xyz.domain"]' "$domains"
}

@test "dfx restarts the replica" {
Expand Down Expand Up @@ -183,7 +187,7 @@ teardown() {
assert_command wait_until_replica_healthy
}

@test "dfx restarts icx-proxy" {
@test "dfx restarts pocketic proxy" {
dfx_new_assets hello
dfx_start

Expand All @@ -192,23 +196,23 @@ teardown() {
assert_command dfx canister call hello_backend greet '("Alpha")'
assert_eq '("Hello, Alpha!")'

ICX_PROXY_PID=$(get_icx_proxy_pid)
POCKETIC_PROXY_PID=$(get_pocketic_proxy_pid)

echo "icx-proxy pid is $ICX_PROXY_PID"
echo "pocket-ic proxy pid is $POCKETIC_PROXY_PID"

kill -KILL "$ICX_PROXY_PID"
assert_process_exits "$ICX_PROXY_PID" 15s
kill -KILL "$POCKETIC_PROXY_PID"
assert_process_exits "$POCKETIC_PROXY_PID" 15s

ID=$(dfx canister id hello_frontend)

timeout 15s sh -c \
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY\"/webserver-port)/sample-asset.txt?canisterId=$ID; do echo waiting for icx-proxy to restart; sleep 1; done" \
|| (echo "icx-proxy did not restart" && ps aux && exit 1)
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY\"/webserver-port)/sample-asset.txt?canisterId=$ID; do echo waiting for pocket-ic proxy to restart; sleep 1; done" \
|| (echo "pocket-ic proxy did not restart" && ps aux && exit 1)

assert_command curl --fail http://localhost:"$(get_webserver_port)"/sample-asset.txt?canisterId="$ID"
}

@test "dfx restarts icx-proxy when the replica restarts" {
@test "dfx restarts pocketic proxy when the replica restarts" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: state persistence"
dfx_new_assets hello
dfx_start
Expand All @@ -219,14 +223,14 @@ teardown() {
assert_eq '("Hello, Alpha!")'

REPLICA_PID=$(get_replica_pid)
ICX_PROXY_PID=$(get_icx_proxy_pid)
POCKETIC_PROXY_PID=$(get_pocketic_proxy_pid)

echo "replica pid is $REPLICA_PID"
echo "icx-proxy pid is $ICX_PROXY_PID"
echo "pocket-ic proxy pid is $POCKETIC_PROXY_PID"

kill -KILL "$REPLICA_PID"
assert_process_exits "$REPLICA_PID" 15s
assert_process_exits "$ICX_PROXY_PID" 15s
assert_process_exits "$POCKETIC_PROXY_PID" 15s

timeout 15s sh -c \
'until dfx ping; do echo waiting for replica to restart; sleep 1; done' \
Expand All @@ -252,23 +256,23 @@ teardown() {
ID=$(dfx canister id hello_frontend)

timeout 15s sh -c \
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/webserver-port\")/sample-asset.txt?canisterId=$ID; do echo waiting for icx-proxy to restart; sleep 1; done" \
|| (echo "icx-proxy did not restart" && ps aux && exit 1)
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/webserver-port\")/sample-asset.txt?canisterId=$ID; do echo waiting for pocket-ic proxy to restart; sleep 1; done" \
|| (echo "pocket-ic proxy did not restart" && ps aux && exit 1)

assert_command curl --fail http://localhost:"$(get_webserver_port)"/sample-asset.txt?canisterId="$ID"
}

@test "dfx restarts icx-proxy when pocketic restarts" {
@test "dfx restarts pocketic proxy when pocketic restarts" {
[[ "$USE_POCKETIC" ]] || skip "skipped for replica"
dfx_start
POCKETIC_PID=$(get_pocketic_pid)
ICX_PROXY_PID=$(get_icx_proxy_pid)
POCKETIC_PROXY_PID=$(get_pocketic_proxy_pid)
echo "pocketic pid is $POCKETIC_PID"
echo "icx-proxy pid is $ICX_PROXY_PID"
echo "pocketic proxy pid is $POCKETIC_PROXY_PID"

kill -KILL "$POCKETIC_PID"
assert_process_exits "$POCKETIC_PID" 15s
assert_process_exits "$ICX_PROXY_PID" 15s
assert_process_exits "$POCKETIC_PROXY_PID" 15s

timeout 15s sh -c \
'until dfx ping; do echo waiting for replica to restart; sleep 1; done' \
Expand All @@ -280,8 +284,8 @@ teardown() {
ID=$(dfx canister id hello_frontend --network "$POCKETIC_NETWORK")

timeout 15s sh -c \
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/webserver-port\")/sample-asset.txt?canisterId=$ID; do echo waiting for icx-proxy to restart; sleep 1; done" \
|| (echo "icx-proxy did not restart" && ps aux && exit 1)
"until curl --fail http://localhost:\$(cat \"$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/webserver-port\")/sample-asset.txt?canisterId=$ID; do echo waiting for pocket-ic proxy to restart; sleep 1; done" \
|| (echo "pocket-ic proxy did not restart" && ps aux && exit 1)

assert_command curl --fail http://localhost:"$(get_webserver_port)"/sample-asset.txt?canisterId="$ID"
}
Expand Down Expand Up @@ -540,5 +544,5 @@ teardown() {
@test "dfx-started processes can be killed with dfx killall" {
dfx_start
dfx killall
assert_command_fail pgrep dfx replica icx-proxy
assert_command_fail pgrep dfx replica pocket-ic
}
2 changes: 1 addition & 1 deletion e2e/tests-icx-asset/icx-asset.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load ../utils/_

setup() {
# when running e2e tests not in GitHub CI (so e.g. locally), build icx-proxy and set environment variable
# when running e2e tests not in GitHub CI (so e.g. locally), build icx-asset and set environment variable
if [ -z "$ICX_ASSET" ]; then
cargo build -p icx-asset
ICX_ASSET="$(pwd)/target/debug/icx-asset"
Expand Down
Loading

0 comments on commit 31d5c0b

Please sign in to comment.