Skip to content

Commit

Permalink
Merge branch 'master' into lwshang/SDK-1876
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang committed Nov 8, 2024
2 parents 807bbe3 + 72cb257 commit 7d9e840
Show file tree
Hide file tree
Showing 28 changed files with 176 additions and 71 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ jobs:
matrix:
# We build a dynamic-linked linux binary because otherwise HSM support fails with:
# Error: IO: Dynamic loading not supported
os: [macos-12, ubuntu-20.04, ubuntu-22.04, windows-2022]
os: [macos-13-large, ubuntu-20.04, ubuntu-22.04, windows-2022]
include:
- os: macos-12
- os: macos-13-large
target: x86_64-apple-darwin
binary_path: target/x86_64-apple-darwin/release/dfx
- os: ubuntu-20.04
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-12, ubuntu-20.04, ubuntu-22.04]
os: [macos-13-large, ubuntu-20.04, ubuntu-22.04]
steps:
- uses: actions/checkout@v4
- name: Download dfx binary
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-12, ubuntu-20.04, ubuntu-22.04]
os: [macos-13-large, ubuntu-20.04, ubuntu-22.04]
steps:
- name: Checking out repo
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-12, windows-latest ]
os: [ ubuntu-latest, macos-13-large, windows-latest ]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prepare-dfx-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-12 ]
os: [ ubuntu-latest, macos-13-large ]
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# Error: IO: Dynamic loading not supported
target: [ x86_64-apple-darwin, x86_64-unknown-linux-gnu ]
include:
- os: macos-12
- os: macos-13-large
target: x86_64-apple-darwin
binary_path: target/x86_64-apple-darwin/release
name: x86_64-darwin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-12 ]
os: [ ubuntu-latest, macos-13-large ]
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

# UNRELEASED

### chore: update agent version in frontend templates, and include `resolve.dedupe` in Vite config

### chore: improve error message when trying to use the local replica when it is not running

### Frontend canister

Allow setting permissions lists in init arguments just like in upgrade arguments.

- Module hash: 2c24b5e1584890a7965011d5d1d827aca68c489c9a6308475730420fa53372e8
- https://github.com/dfinity/sdk/pull/3965

### Candid UI

- Module hash: f45db224b40fac516c877e3108dc809d4b22fa42d05ee8dfa5002536a3a3daed
- Bump agent-js to fix error code

# 0.24.2

### feat: Support canister log allowed viewer list
Expand Down
2 changes: 1 addition & 1 deletion docs/cli-reference/dfx-identity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ dfx identity export alice >generated-id.pem

## dfx identity import

Use the `dfx identity import` command to create a user identity by importing the user’s key information or security certificate from a PEM file.
Use the `dfx identity import` command to create a user identity by importing the user’s key information or security certificate from a PEM file or seed phrase file.

*Password policy*: If an identity is imported using `--storage-mode password-protected`, the following requirements apply to the password:
- The password needs to be longer than 8 characters.
Expand Down
10 changes: 10 additions & 0 deletions e2e/tests-dfx/error_context.bash
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,13 @@ teardown() {
assert_contains "it did not contain a function that dfx was looking for"
assert_contains "dfx identity set-wallet <PRINCIPAL> --identity <IDENTITY>"
}

@test "Local replica not running has nice error messages" {
dfx_new
assert_command_fail dfx ping local
assert_contains "You are trying to connect to the local replica but dfx cannot connect to it."
assert_command_fail dfx deploy
assert_contains "You are trying to connect to the local replica but dfx cannot connect to it."
assert_command_fail dfx canister call um5iw-rqaaa-aaaaq-qaaba-cai some_method
assert_contains "You are trying to connect to the local replica but dfx cannot connect to it."
}
52 changes: 11 additions & 41 deletions scripts/test-uis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,21 @@
("Error", "/index.js"),
("Invalid asm.js: Unexpected token", "/index.js"),
("Expected to find result for path [object Object], but instead found nothing.", "/index.js"),
("If you want to use Internet Identity, please provide a URL to your local Internet Identity service using the `ii` query parameter", "/index.js"),
(
"""
Error: Server returned an error:
Code: 404 (Not Found)
Body: Custom section name not found.
at j.readState (http://localhost:4943/index.js:2:11709)
at async http://localhost:4943/index.js:2:97683
at async Promise.all (index 0)
at async Module.UA (http://localhost:4943/index.js:2:98732)
at async Object.getNames (http://localhost:4943/index.js:2:266156)
at async http://localhost:4943/index.js:2:275479""".strip(),
AgentError: Call failed:
Canister: aaaaa-aa
Method: fetch_canister_logs (query)
"Status": "rejected"
"Code": "CanisterReject"
"Message": "IC0406: Caller 2vxsx-fae is not allowed to query ic00 method fetch_canister_logs"
""".strip(),
"/index.js",
),
(
"""
Error: Server returned an error:
Code: 404 (Not Found)
Body: Custom section name not found.""".strip(),
"/index.js",
),
)
]
_CANDID_UI_ERRORS_TO_IGNORE = [
("Error", "/index.js"),
("Failed to load resource: the server responded with a status of 404 (Not Found)", "/read_state"),
(
"Error: Please provide a URL to your local Internet Identity service using the `ii` query parameter",
"/index.js",
),
(
"""
Error: Please provide a URL to your local Internet Identity service using the `ii` query parameter
at http://localhost:4943/index.js:2:300040
at t.renderAuth (http://localhost:4943/index.js:2:301237)
at async http://localhost:4943/index.js:2:314291""".strip(),
"/index.js",
),
(
"""
Error: Please provide a URL to your local Internet Identity service using the `ii` query parameter
at http://127.0.0.1:4943/index.js:2:300040
at t.renderAuth (http://127.0.0.1:4943/index.js:2:301237)
at async http://127.0.0.1:4943/index.js:2:314291""".strip(),
"/index.js",
),
("Error", "/index.js")
]
# `page.route` does not support additional function parameters
_FRONTEND_URL = None
Expand Down Expand Up @@ -161,7 +131,7 @@ def _check_console_logs(console_logs):
for actual_text, endpoint in (
_CANDID_UI_ERRORS_TO_IGNORE if log.type == "error" else _CANDID_UI_WARNINGS_TO_IGNORE
):
if actual_text == log.text.strip() and endpoint in url:
if log.text.strip().startswith(actual_text) and endpoint in url:
logging.warning(
f'Found {log.type}, but it was expected (log.type="{actual_text}", endpoint="{endpoint}")'
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/workflows/e2e-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_scripts(prefix):
matrix = {
"test": test,
"backend": ["pocketic", "replica"],
"os": ["macos-12", "ubuntu-20.04"],
"os": ["macos-13-large", "ubuntu-20.04"],
"exclude": [
{
"backend": "pocketic",
Expand Down
2 changes: 1 addition & 1 deletion scripts/workflows/provision-darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ "$E2E_TEST" = "tests-dfx/bitcoin.bash" ]; then
brew fetch --retry bitcoin
brew install bitcoin
fi
if [ "$E2E_TEST" = "tests-dfx/build_rust.bash" ]; then
if [ "$E2E_TEST" = "tests-dfx/build_rust.bash" ] && command -v cargo-audit &>/dev/null; then
cargo uninstall cargo-audit
fi
if [ "$E2E_TEST" = "tests-dfx/certificate.bash" ]; then
Expand Down
19 changes: 17 additions & 2 deletions src/dfx-core/src/config/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
use crate::config::directories::project_dirs;
use crate::error::cache::{
DeleteCacheError, EnsureCacheVersionsDirError, GetBinaryCommandPathError, GetCacheRootError,
IsCacheInstalledError, ListCacheVersionsError,
GetVersionFromCachePathError, IsCacheInstalledError, ListCacheVersionsError,
};
#[cfg(not(windows))]
use crate::foundation::get_user_home;
use crate::fs::composite::ensure_dir_exists;
use semver::Version;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

pub trait Cache {
fn version_str(&self) -> String;
Expand Down Expand Up @@ -50,6 +50,21 @@ pub fn get_cache_path_for_version(v: &str) -> Result<PathBuf, GetCacheRootError>
Ok(p)
}

pub fn get_version_from_cache_path(
cache_path: &Path,
) -> Result<Version, GetVersionFromCachePathError> {
let version = cache_path
.file_name()
.ok_or(GetVersionFromCachePathError::NoCachePathFilename(
cache_path.to_path_buf(),
))?
.to_str()
.ok_or(GetVersionFromCachePathError::CachePathFilenameNotUtf8(
cache_path.to_path_buf(),
))?;
Ok(Version::parse(version)?)
}

/// Return the binary cache root. It constructs it if not present
/// already.
pub fn ensure_cache_versions_dir() -> Result<PathBuf, EnsureCacheVersionsDirError> {
Expand Down
13 changes: 13 additions & 0 deletions src/dfx-core/src/error/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::error::fs::{
};
use crate::error::get_current_exe::GetCurrentExeError;
use crate::error::get_user_home::GetUserHomeError;
use std::path::PathBuf;
use thiserror::Error;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -34,6 +35,18 @@ pub enum EnsureCacheVersionsDirError {
GetCacheRoot(#[from] GetCacheRootError),
}

#[derive(Error, Debug)]
pub enum GetVersionFromCachePathError {
#[error("no filename in cache path '{0}'")]
NoCachePathFilename(PathBuf),

#[error("filename in cache path '{0}' is not valid UTF-8")]
CachePathFilenameNotUtf8(PathBuf),

#[error("cannot parse version from cache path filename")]
ParseVersion(#[from] semver::Error),
}

#[derive(Error, Debug)]
pub enum GetCacheRootError {
#[error(transparent)]
Expand Down
12 changes: 12 additions & 0 deletions src/dfx-core/src/error/interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::error::cache::GetVersionFromCachePathError;
use crate::error::extension::NewExtensionManagerError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum NewExtensionManagerFromCachePathError {
#[error(transparent)]
GetVersionFromCachePath(#[from] GetVersionFromCachePathError),

#[error(transparent)]
NewExtensionManager(#[from] NewExtensionManagerError),
}
1 change: 1 addition & 0 deletions src/dfx-core/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod fs;
pub mod get_current_exe;
pub mod get_user_home;
pub mod identity;
pub mod interface;
pub mod keyring;
pub mod load_dfx_config;
pub mod load_networks_config;
Expand Down
33 changes: 31 additions & 2 deletions src/dfx-core/src/interface/builder.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use crate::{
config::cache::get_version_from_cache_path,
config::model::{
dfinity::{Config, NetworksConfig},
network_descriptor::NetworkDescriptor,
},
error::{
builder::{BuildAgentError, BuildDfxInterfaceError, BuildIdentityError},
extension::NewExtensionManagerError,
interface::NewExtensionManagerFromCachePathError,
network_config::NetworkConfigError,
},
extension::manager::ExtensionManager,
identity::{identity_manager::InitializeIdentity, IdentityManager},
network::{
provider::{create_network_descriptor, LocalBindDetermination},
Expand All @@ -16,6 +20,8 @@ use crate::{
};
use ic_agent::{agent::route_provider::RoundRobinRouteProvider, Agent, Identity};
use reqwest::Client;
use semver::Version;
use std::path::Path;
use std::sync::Arc;

#[derive(PartialEq)]
Expand All @@ -42,14 +48,17 @@ pub struct DfxInterfaceBuilder {
/// There is no need to set this for the local network, where the root key is fetched by default.
/// This would typically be set for a testnet, or an alias for the local network.
force_fetch_root_key_insecure_non_mainnet_only: bool,

extension_manager: Option<ExtensionManager>,
}

impl DfxInterfaceBuilder {
pub(crate) fn new() -> Self {
pub fn new() -> Self {
Self {
identity: IdentityPicker::Selected,
network: NetworkPicker::Local,
force_fetch_root_key_insecure_non_mainnet_only: false,
extension_manager: None,
}
}

Expand Down Expand Up @@ -77,6 +86,26 @@ impl DfxInterfaceBuilder {
self.with_network(NetworkPicker::Named(name.to_string()))
}

pub fn with_extension_manager(
self,
version: Version,
) -> Result<Self, NewExtensionManagerError> {
let extension_manager = Some(ExtensionManager::new(&version)?);
Ok(Self {
extension_manager,
..self
})
}

pub fn with_extension_manager_from_cache_path(
self,
cache_path: &Path,
) -> Result<Self, NewExtensionManagerFromCachePathError> {
let version = get_version_from_cache_path(cache_path)?;

Ok(self.with_extension_manager(version)?)
}

pub fn with_force_fetch_root_key_insecure_non_mainnet_only(self) -> Self {
Self {
force_fetch_root_key_insecure_non_mainnet_only: true,
Expand All @@ -88,7 +117,7 @@ impl DfxInterfaceBuilder {
let fetch_root_key = self.network == NetworkPicker::Local
|| self.force_fetch_root_key_insecure_non_mainnet_only;
let networks_config = NetworksConfig::new()?;
let config = Config::from_current_dir(None)?.map(Arc::new);
let config = Config::from_current_dir(self.extension_manager.as_ref())?.map(Arc::new);
let network_descriptor = self.build_network_descriptor(config.clone(), &networks_config)?;
let identity = self.build_identity()?;
let agent = self.build_agent(identity.clone(), &network_descriptor)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@dfinity/agent": "^1.4.0",
"@dfinity/candid": "^1.4.0",
"@dfinity/principal": "^1.4.0"
"@dfinity/agent": "^2.1.3",
"@dfinity/candid": "^2.1.3",
"@dfinity/principal": "^2.1.3"
},
"devDependencies": {
"@types/react": "^18.2.14",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export default defineConfig({
),
},
],
dedupe: ['@dfinity/agent'],
},
});
Loading

0 comments on commit 7d9e840

Please sign in to comment.