Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: default to PocketIC #4130

Merged
merged 7 commits into from
Mar 5, 2025
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: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ jobs:
echo "archive=$(pwd)/e2e/archive" >> "$GITHUB_ENV"
echo "assets=$(pwd)/e2e/assets" >> "$GITHUB_ENV"
echo "utils=$(pwd)/e2e/utils" >> "$GITHUB_ENV"
if [ "${{ matrix.backend == 'pocketic' || '' }}" ]; then
echo "USE_POCKETIC=1" >> "$GITHUB_ENV"
if [ "${{ matrix.backend == 'replica' || '' }}" ]; then
echo "USE_REPLICA=1" >> "$GITHUB_ENV"
fi
export
- name: Download bats-support as a git submodule
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# UNRELEASED

### feat!: `dfx start` uses `--pocketic` by default

As [announced](https://forum.dfinity.org/t/dfx-replacing-the-local-replica-with-pocketic/40167) `dfx start` now runs PocketIC by default.
Running a local replica is still possible with `--replica`, but this option will be removed in the near future.

# 0.25.1

### feat: `skip_cargo_audit` flag in dfx.json to skip `cargo audit` build step
Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ If there is already an entry in the 'Unreleased' section, change it; if not, add

#### Running End-to-End Tests

This runs the end-to-end tests against the
[PocketIC emulator](https://github.com/dfinity/pocketic).

``` bash
sdk $ bats e2e/tests-dfx/*.bash
sdk $ bats e2e/tests-replica/*.bash
```

#### Running End-to-End Tests Against Reference IC

This runs the end-to-end tests against the
[PocketIC emulator](https://github.com/dfinity/pocketic).
#### Running End-to-End Tests Against Local Replica

``` bash
sdk $ USE_POCKETIC=1 bats e2e/tests-dfx/*.bash
sdk $ USE_POCKETIC=1 bats e2e/tests-replica/*.bash
sdk $ USE_REPLICA=1 bats e2e/tests-dfx/*.bash
sdk $ USE_REPLICA=1 bats e2e/tests-replica/*.bash
```

## Conventional Commits
Expand Down
4 changes: 2 additions & 2 deletions e2e/assets/expect_scripts/ctrl_c_right_after_dfx_start.exp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set timeout 330

spawn dfx cache install
expect "Installed dfx"
if [info exists env(USE_POCKETIC)] {
spawn dfx start --pocketic --clean
if [info exists env(USE_REPLICA)] {
spawn dfx start --replica --clean
} else {
spawn dfx start --clean
}
Expand Down
14 changes: 7 additions & 7 deletions e2e/tests-dfx/bitcoin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ set_local_network_bitcoin_enabled() {
}

@test "dfx restarts replica when ic-btc-adapter restarts" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
[[ ! "$USE_REPLICA" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
dfx_new_assets hello
dfx_start --enable-bitcoin

Expand Down Expand Up @@ -87,15 +87,15 @@ set_local_network_bitcoin_enabled() {
}

@test "dfx start --bitcoin-node <node> implies --enable-bitcoin" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
[[ ! "$USE_REPLICA" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
dfx_new hello
dfx_start "--bitcoin-node" "127.0.0.1:18444"

assert_file_not_empty "$E2E_SHARED_LOCAL_NETWORK_DATA_DIRECTORY/ic-btc-adapter-pid"
}

@test "dfx start --enable-bitcoin with no other configuration succeeds" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
[[ ! "$USE_REPLICA" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
dfx_new hello

dfx_start --enable-bitcoin
Expand All @@ -114,7 +114,7 @@ set_local_network_bitcoin_enabled() {
}

@test "can enable bitcoin through default configuration - dfx start" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
[[ ! "$USE_REPLICA" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
dfx_new hello
define_project_network
set_project_default_bitcoin_enabled
Expand All @@ -125,7 +125,7 @@ set_local_network_bitcoin_enabled() {
}

@test "can enable bitcoin through shared local network - dfx start" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
[[ ! "$USE_REPLICA" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
dfx_new hello
set_shared_local_network_bitcoin_enabled

Expand All @@ -135,7 +135,7 @@ set_local_network_bitcoin_enabled() {
}

@test "can enable bitcoin through local network configuration - dfx start" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
[[ ! "$USE_REPLICA" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
dfx_new hello
set_local_network_bitcoin_enabled

Expand All @@ -145,7 +145,7 @@ set_local_network_bitcoin_enabled() {
}

@test "dfx start with both bitcoin and canister http enabled" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
[[ ! "$USE_REPLICA" ]] && skip "skipped for pocketic: bitcoin adapter is a replica implementation detail"
dfx_new hello

dfx_start --enable-bitcoin --enable-canister-http
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests-dfx/call.bash
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ teardown() {
dfx canister create --all
dfx build
dfx canister install hello_backend
[[ "$USE_POCKETIC" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_backend
[[ ! "$USE_REPLICA" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_backend
assert_command dfx canister call hello_backend recurse 100
}

Expand Down Expand Up @@ -369,13 +369,13 @@ function impersonate_sender() {
}

@test "impersonate management canister as sender" {
[[ ! "$USE_POCKETIC" ]] && skip "skipped for replica: impersonating sender is only supported for PocketIC"
[[ "$USE_REPLICA" ]] && skip "skipped for replica: impersonating sender is only supported for PocketIC"

impersonate_sender "aaaaa-aa"
}

@test "impersonate new random identity as sender" {
[[ ! "$USE_POCKETIC" ]] && skip "skipped for replica: impersonating sender is only supported for PocketIC"
[[ "$USE_REPLICA" ]] && skip "skipped for replica: impersonating sender is only supported for PocketIC"

dfx identity new impersonated_identity --storage-mode plaintext
IDENTITY_PRINCIPAL="$(dfx --identity impersonated_identity identity get-principal)"
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests-dfx/create.bash
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ teardown() {
}

@test "create succeeds when specify large canister ID" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: nonexistent subnet ranges are unsupported"
[[ ! "$USE_REPLICA" ]] && skip "skipped for pocketic: nonexistent subnet ranges are unsupported"
dfx_start
# hhn2s-5l777-77777-7777q-cai is the canister ID of (u64::MAX / 2)
assert_command dfx canister create e2e_project_backend --specified-id hhn2s-5l777-77777-7777q-cai
Expand All @@ -56,7 +56,7 @@ teardown() {
# nojwb-ieaaa-aaaaa-aaaaa-cai is the canister ID of (u64::MAX / 2 + 1)
assert_command_fail dfx canister create e2e_project_backend --specified-id nojwb-ieaaa-aaaaa-aaaaa-cai

if [[ "$USE_POCKETIC" ]]; then
if [[ ! "$USE_REPLICA" ]]; then
assert_match "The effective canister ID nojwb-ieaaa-aaaaa-aaaaa-cai does not belong to an existing subnet and it is not a mainnet canister ID."
else
assert_match "Specified CanisterId nojwb-ieaaa-aaaaa-aaaaa-cai is not hosted by subnet"
Expand Down Expand Up @@ -407,7 +407,7 @@ function textual_decode() {
}

@test "create targets application subnet in PocketIC" {
[[ ! "$USE_POCKETIC" ]] && skip "skipped for replica: no support for multiple subnets"
[[ "$USE_REPLICA" ]] && skip "skipped for replica: no support for multiple subnets"
dfx_start
# create the backend canister without a wallet canister so that the backend canister is the only canister ever created
assert_command dfx canister create e2e_project_backend --no-wallet
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests-dfx/info.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ teardown() {
}

@test "displays the replica port" {
if [[ "$USE_POCKETIC" ]]
if [[ ! "$USE_REPLICA" ]]
then
assert_command_fail dfx info pocketic-config-port
assert_contains "No PocketIC port found"
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests-dfx/ledger.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load ../utils/_
install_nns() {
dfx_start_for_nns_install

dfx extension install nns --version 0.4.3
dfx extension install nns --version 0.5.0
dfx nns install --ledger-accounts 345f723e9e619934daac6ae0f4be13a7b0ba57d6a608e511a00fd0ded5866752 22ca7edac648b814e81d7946e8bacea99280e07c5f51a04ba7a38009d8ad8e89 5a94fe181e9d411c58726cb87cbf2d016241b6c350bc3330e4869ca76e54ecbc
}

Expand Down Expand Up @@ -158,10 +158,10 @@ tc_to_num() {
balance=$(tc_to_num "$(dfx wallet balance)")

assert_command dfx ledger top-up "$wallet" --icp 5
assert_match "Canister was topped up with 617283500000000 cycles"
assert_match "Canister was topped up with 500000000000000 cycles"
balance_now=$(tc_to_num "$(dfx wallet balance)")

(( balance_now - balance > 600000000000000 ))
(( balance_now - balance > 400000000000000 ))

# Transaction Deduplication
t=$(current_time_nanoseconds)
Expand Down Expand Up @@ -204,7 +204,7 @@ tc_to_num() {
dfx_new
assert_command dfx canister create e2e_project_backend
assert_command dfx ledger top-up e2e_project_backend --amount 5
assert_contains "Canister was topped up with 617283500000000 cycles"
assert_contains "Canister was topped up with 500000000000000 cycles"
}

@test "ledger create-canister" {
Expand Down
18 changes: 9 additions & 9 deletions e2e/tests-dfx/playground.bash
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ setup_playground() {

@test "canister lifecycle" {
assert_command dfx canister create --all --playground
[[ "$USE_POCKETIC" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground
[[ "$USE_POCKETIC" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground
[[ ! "$USE_REPLICA" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground
[[ ! "$USE_REPLICA" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground

assert_command dfx deploy --playground
assert_command dfx canister --playground call hello_backend greet '("player")'
Expand Down Expand Up @@ -81,9 +81,9 @@ setup_playground() {
rm -rf hello
dfx_new_frontend hello

[[ "$USE_POCKETIC" ]] && assert_command dfx canister create --all --playground
[[ "$USE_POCKETIC" ]] && assert_command dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground
[[ "$USE_POCKETIC" ]] && assert_command dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground
[[ ! "$USE_REPLICA" ]] && assert_command dfx canister create --all --playground
[[ ! "$USE_REPLICA" ]] && assert_command dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground
[[ ! "$USE_REPLICA" ]] && assert_command dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground

assert_command dfx deploy --playground
assert_command dfx canister --playground call hello_backend greet '("player")'
Expand All @@ -107,8 +107,8 @@ setup_playground() {
# instrument the asset canister during upload which would run into execution limits.
@test "playground-installed asset canister is same wasm as normal asset canister" {
assert_command dfx canister create --all --playground
[[ "$USE_POCKETIC" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground
[[ "$USE_POCKETIC" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground
[[ ! "$USE_REPLICA" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground
[[ ! "$USE_REPLICA" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground

assert_command dfx deploy --playground
PLAYGROUND_HASH=$(dfx canister --playground info hello_frontend | grep hash)
Expand All @@ -120,8 +120,8 @@ setup_playground() {

@test "playground canister upgrades work with Motoko Enhanced Orthogonal Persistence" {
assert_command dfx canister create --all --playground
[[ "$USE_POCKETIC" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground
[[ "$USE_POCKETIC" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground
[[ ! "$USE_REPLICA" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground
[[ ! "$USE_REPLICA" ]] && dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground

# enable EOP
jq '.canisters.hello_backend.args="--enhanced-orthogonal-persistence"' dfx.json | sponge dfx.json
Expand Down
Loading