Skip to content

Commit

Permalink
Merge branch 'master' into ens/changelog-0.24.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswanson-dfinity authored Nov 14, 2024
2 parents 1a6ca1c + 87a27ec commit 69c0bd0
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 36 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

# UNRELEASED


# 0.24.3

### feat: Bitcoin support in PocketIC

`dfx start --pocketic` is now compatible with `--bitcoin-node` and `--enable-bitcoin`.

### feat: facade pull ICP, ckBTC, ckETH ledger canisters

The ledger canisters can be pulled even though they are not really "pullable".
Expand Down
7 changes: 7 additions & 0 deletions e2e/tests-dfx/bitcoin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set_local_network_bitcoin_enabled() {
}

@test "dfx restarts replica when ic-btc-adapter restarts" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: PocketIC does not expose bitcoin adapter"
dfx_new_assets hello
dfx_start --enable-bitcoin

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

@test "dfx start --bitcoin-node <node> implies --enable-bitcoin" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: PocketIC does not expose bitcoin adapter"
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: PocketIC does not expose bitcoin adapter"
dfx_new hello

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

@test "can enable bitcoin through default configuration - dfx start" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: PocketIC does not expose bitcoin adapter"
dfx_new hello
define_project_network
set_project_default_bitcoin_enabled
Expand All @@ -121,6 +125,7 @@ set_local_network_bitcoin_enabled() {
}

@test "can enable bitcoin through shared local network - dfx start" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: PocketIC does not expose bitcoin adapter"
dfx_new hello
set_shared_local_network_bitcoin_enabled

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

@test "can enable bitcoin through local network configuration - dfx start" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: PocketIC does not expose bitcoin adapter"
dfx_new hello
set_local_network_bitcoin_enabled

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

@test "dfx start with both bitcoin and canister http enabled" {
[[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: PocketIC does not expose bitcoin adapter"
dfx_new hello

dfx_start --enable-bitcoin --enable-canister-http
Expand Down
27 changes: 0 additions & 27 deletions e2e/tests-dfx/print.bash

This file was deleted.

12 changes: 12 additions & 0 deletions e2e/tests-dfx/usage.bash
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ teardown() {
assert_match "$(dfx identity get-principal --identity alice)"
}

@test "print_mo" {
dfx_new
install_asset print
dfx_start 2>stderr.txt
dfx canister create --all
dfx build
dfx canister install e2e_project
dfx canister call e2e_project hello
sleep 2
run tail -2 stderr.txt
assert_match "Hello, World! from DFINITY"
}
4 changes: 0 additions & 4 deletions scripts/workflows/e2e-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ def test_scripts(prefix):
"backend": ["pocketic", "replica"],
"os": ["macos-13-large", "ubuntu-20.04"],
"exclude": [
{
"backend": "pocketic",
"test": "dfx/bitcoin"
},
{
"backend": "pocketic",
"test": "dfx/canister_http_adapter"
Expand Down
9 changes: 9 additions & 0 deletions src/dfx/src/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,19 @@ pub fn start_pocketic_actor(
)
})?;

let bitcoin_integration_config = if local_server_descriptor.bitcoin.enabled {
Some(BitcoinIntegrationConfig {
canister_init_arg: local_server_descriptor.bitcoin.canister_init_arg.clone(),
})
} else {
None
};
let actor_config = pocketic::Config {
pocketic_path,
effective_config_path: local_server_descriptor.effective_config_path(),
replica_config,
bitcoind_addr: local_server_descriptor.bitcoin.nodes.clone(),
bitcoin_integration_config,
port: local_server_descriptor.replica.port,
port_file: pocketic_port_path,
pid_file: local_server_descriptor.pocketic_pid_path(),
Expand Down
36 changes: 33 additions & 3 deletions src/dfx/src/actors/pocketic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ use crate::actors::shutdown::{wait_for_child_or_receiver, ChildOrReceiver};
use crate::actors::shutdown_controller::signals::outbound::Shutdown;
use crate::actors::shutdown_controller::signals::ShutdownSubscribe;
use crate::actors::shutdown_controller::ShutdownController;
use crate::actors::BitcoinIntegrationConfig;
use crate::lib::error::{DfxError, DfxResult};
#[cfg(unix)]
use crate::lib::info::replica_rev;
#[cfg(unix)]
use crate::lib::integrations::bitcoin::initialize_bitcoin_canister;
#[cfg(unix)]
use crate::lib::integrations::create_integrations_agent;
use actix::{
Actor, ActorContext, ActorFutureExt, Addr, AsyncContext, Context, Handler, Recipient,
ResponseActFuture, Running, WrapFuture,
Expand All @@ -20,6 +25,7 @@ use dfx_core::config::model::replica_config::ReplicaConfig;
#[cfg(unix)]
use dfx_core::json::save_json_file;
use slog::{debug, error, info, warn, Logger};
use std::net::SocketAddr;
use std::ops::ControlFlow::{self, *};
use std::path::{Path, PathBuf};
use std::thread::JoinHandle;
Expand All @@ -43,6 +49,8 @@ pub struct Config {
pub pocketic_path: PathBuf,
pub effective_config_path: PathBuf,
pub replica_config: ReplicaConfig,
pub bitcoind_addr: Option<Vec<SocketAddr>>,
pub bitcoin_integration_config: Option<BitcoinIntegrationConfig>,
pub port: Option<u16>,
pub port_file: PathBuf,
pub pid_file: PathBuf,
Expand Down Expand Up @@ -265,6 +273,8 @@ fn pocketic_start_thread(
let instance = match initialize_pocketic(
port,
&config.effective_config_path,
&config.bitcoind_addr,
&config.bitcoin_integration_config,
&config.replica_config,
logger.clone(),
) {
Expand Down Expand Up @@ -322,6 +332,8 @@ fn pocketic_start_thread(
async fn initialize_pocketic(
port: u16,
effective_config_path: &Path,
bitcoind_addr: &Option<Vec<SocketAddr>>,
bitcoin_integration_config: &Option<BitcoinIntegrationConfig>,
replica_config: &ReplicaConfig,
logger: Logger,
) -> DfxResult<usize> {
Expand All @@ -339,7 +351,7 @@ async fn initialize_pocketic(
sns: Some(SubnetSpec::default()),
ii: Some(SubnetSpec::default()),
fiduciary: None,
bitcoin: None,
bitcoin: Some(SubnetSpec::default()),
system: vec![],
verified_application: vec![],
application: vec![],
Expand All @@ -358,7 +370,7 @@ async fn initialize_pocketic(
state_dir: Some(replica_config.state_manager.state_root.clone()),
nonmainnet_features: true,
log_level: Some(replica_config.log_level.to_ic_starter_string()),
bitcoind_addr: None,
bitcoind_addr: bitcoind_addr.clone(),
})
.send()
.await?
Expand Down Expand Up @@ -420,12 +432,30 @@ async fn initialize_pocketic(
.send()
.await?
.error_for_status()?;

let agent_url = format!("http://localhost:{port}/instances/{instance}/");

debug!(logger, "Waiting for replica to report healthy status");
crate::lib::replica::status::ping_and_wait(&agent_url).await?;

if let Some(bitcoin_integration_config) = bitcoin_integration_config {
let agent = create_integrations_agent(&agent_url, &logger).await?;
initialize_bitcoin_canister(&agent, &logger, bitcoin_integration_config.clone()).await?;
}

info!(logger, "Initialized PocketIC.");
Ok(instance)
}

#[cfg(not(unix))]
fn initialize_pocketic(_: u16, _: &Path, _: &ReplicaConfig, _: Logger) -> DfxResult<usize> {
fn initialize_pocketic(
_: u16,
_: &Path,
_: &Option<Vec<SocketAddr>>,
_: &Option<BitcoinIntegrationConfig>,
_: &ReplicaConfig,
_: Logger,
) -> DfxResult<usize> {
bail!("PocketIC not supported on this platform")
}

Expand Down
4 changes: 2 additions & 2 deletions src/dfx/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ pub struct StartOpts {
clean: bool,

/// Address of bitcoind node. Implies --enable-bitcoin.
#[arg(long, action = ArgAction::Append, conflicts_with = "pocketic")]
#[arg(long, action = ArgAction::Append)]
bitcoin_node: Vec<SocketAddr>,

/// enable bitcoin integration
#[arg(long, conflicts_with = "pocketic")]
#[arg(long)]
enable_bitcoin: bool,

/// enable canister http requests (on by default for --pocketic)
Expand Down

0 comments on commit 69c0bd0

Please sign in to comment.