Skip to content
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
65 changes: 56 additions & 9 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
members = [
"src/dfx",
]

[patch.crates-io]
ic-types = { git = "ssh://git@github.com/dfinity-lab/agent-rust.git", branch = "next", version = "0.1.1" }
1 change: 0 additions & 1 deletion assets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pkgs.runCommandNoCCLocal "assets" {} ''
cp ${pkgs.dfinity.ic-replica}/bin/replica $out
cp ${pkgs.dfinity.ic-starter}/bin/ic-starter $out
cp -R ${pkgs.motoko.base-src} $out/base
cp ${pkgs.motoko.didc}/bin/didc $out
cp ${pkgs.motoko.mo-doc}/bin/mo-doc $out
cp ${pkgs.motoko.mo-ide}/bin/mo-ide $out
cp ${pkgs.motoko.moc}/bin/moc $out
Expand Down
2 changes: 1 addition & 1 deletion distributed-canisters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let

in
pkgs.runCommandNoCCLocal "distributed-canisters" {
inherit (pkgs.motoko) didc rts;
inherit (pkgs.motoko) rts;
moc = pkgs.motoko.moc;
base = pkgs.motoko.base-src;
} ''
Expand Down
14 changes: 7 additions & 7 deletions e2e/bats/assetscanister.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ teardown() {
dfx build
dfx canister install e2e_project_assets

assert_command dfx canister call --query e2e_project_assets retrieve '("binary/noise.txt")'
assert_eq '(vec { 184; 1; 32; 128; 10; 119; 49; 50; 32; 0; 120; 121; 10; 75; 76; 11; 10; 106; 107; })'
assert_command dfx canister call --query e2e_project_assets retrieve '("binary/noise.txt")' --output idl
assert_eq '(vec { 184; 1; 32; 128; 10; 119; 49; 50; 32; 0; 120; 121; 10; 75; 76; 11; 10; 106; 107 })'

assert_command dfx canister call --query e2e_project_assets retrieve '("text-with-newlines.txt")'
assert_eq '(vec { 99; 104; 101; 114; 114; 105; 101; 115; 10; 105; 116; 39; 115; 32; 99; 104; 101; 114; 114; 121; 32; 115; 101; 97; 115; 111; 110; 10; 67; 72; 69; 82; 82; 73; 69; 83; })'
assert_command dfx canister call --query e2e_project_assets retrieve '("text-with-newlines.txt")' --output idl
assert_eq '(vec { 99; 104; 101; 114; 114; 105; 101; 115; 10; 105; 116; 39; 115; 32; 99; 104; 101; 114; 114; 121; 32; 115; 101; 97; 115; 111; 110; 10; 67; 72; 69; 82; 82; 73; 69; 83 })'

assert_command dfx canister call --update e2e_project_assets store '("AA", vec { 100; 107; 62; 9; })'
assert_eq '()'
assert_command dfx canister call --update e2e_project_assets store '("B", vec { 88; 87; 86; })'
assert_eq '()'

assert_command dfx canister call --query e2e_project_assets retrieve '("B")'
assert_eq '(vec { 88; 87; 86; })'
assert_eq '(vec { 88; 87; 86 })'

assert_command dfx canister call --query e2e_project_assets retrieve '("AA")'
assert_eq '(vec { 100; 107; 62; 9; })'
assert_eq '(vec { 100; 107; 62; 9 })'

assert_command dfx canister call --query e2e_project_assets retrieve '("B")'
assert_eq '(vec { 88; 87; 86; })'
assert_eq '(vec { 88; 87; 86 })'

assert_command_fail dfx canister call --query e2e_project_assets retrieve '("C")'

Expand Down
6 changes: 3 additions & 3 deletions e2e/bats/basic-project.bash
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ teardown() {
dfx build
dfx canister install --all

assert_command dfx canister call hello inc '(42,false,"testzZ",vec{1;2;3},opt record{head=42; tail=opt record{head=+43; tail=null}}, variant { cons=record{ 42; variant { cons=record{43; variant { nil }} } } })'
assert_eq "(43, true, \"uftu{[\", vec { 2; 3; 4; }, opt record { head = 43; tail = opt record { head = 44; tail = null; }; }, variant { cons = record { 0 = 43; 1 = variant { cons = record { 0 = 44; 1 = variant { nil = null }; } }; } })"
assert_command dfx canister call hello inc '(42,false,"testzZ",vec{1;2;3},opt record{head=42; tail=opt record{head=+43; tail=null}}, variant { cons=record{ 42; variant { cons=record{43; variant { nil }} } } })' --output idl
assert_eq "(43, true, \"uftu{[\", vec { 2; 3; 4 }, opt record { head = 43; tail = opt record { head = 44; tail = null } }, variant { cons = record { 43; variant { cons = record { 44; variant { nil } } } } })"
}

@test "build + install + call -- matrix_multiply_mo" {
Expand All @@ -102,5 +102,5 @@ teardown() {
dfx canister install --all

assert_command dfx canister call hello multiply '(vec{vec{1;2};vec{3;4};vec{5;6}},vec{vec{1;2;3};vec{4;5;6}})'
assert_eq "(vec { vec { 9; 12; 15; }; vec { 19; 26; 33; }; vec { 29; 40; 51; }; })"
assert_eq "(vec { vec { 9; 12; 15 }; vec { 19; 26; 33 }; vec { 29; 40; 51 } })"
}
8 changes: 4 additions & 4 deletions e2e/bats/build_granular.bash
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ teardown() {
dfx build e2e_project_assets
dfx canister install e2e_project_assets

assert_command dfx canister call --query e2e_project_assets retrieve '("binary/noise.txt")'
assert_eq '(vec { 184; 1; 32; 128; 10; 119; 49; 50; 32; 0; 120; 121; 10; 75; 76; 11; 10; 106; 107; })'
assert_command dfx canister call --query e2e_project_assets retrieve '("binary/noise.txt")' --output idl
assert_eq '(vec { 184; 1; 32; 128; 10; 119; 49; 50; 32; 0; 120; 121; 10; 75; 76; 11; 10; 106; 107 })'

assert_command dfx canister call --query e2e_project_assets retrieve '("text-with-newlines.txt")'
assert_eq '(vec { 99; 104; 101; 114; 114; 105; 101; 115; 10; 105; 116; 39; 115; 32; 99; 104; 101; 114; 114; 121; 32; 115; 101; 97; 115; 111; 110; 10; 67; 72; 69; 82; 82; 73; 69; 83; })'
assert_command dfx canister call --query e2e_project_assets retrieve '("text-with-newlines.txt")' --output idl
assert_eq '(vec { 99; 104; 101; 114; 114; 105; 101; 115; 10; 105; 116; 39; 115; 32; 99; 104; 101; 114; 114; 121; 32; 115; 101; 97; 115; 111; 110; 10; 67; 72; 69; 82; 82; 73; 69; 83 })'

}

Expand Down
14 changes: 7 additions & 7 deletions e2e/bats/identity.bash
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ teardown() {
assert_eq '(false)'

# these all fail (other identities are not initializer; cannot store assets):
assert_command_fail dfx --identity bob canister call e2e_project_assets store '("B", vec { 88; 87; 86; })'
assert_command_fail dfx --identity default canister call e2e_project_assets store '("B", vec { 88; 87; 86; })'
assert_command_fail dfx canister call e2e_project_assets store '("B", vec { 88; 87; 86; })'
assert_command_fail dfx --identity bob canister call e2e_project_assets store '("B", vec { 88; 87; 86 })'
assert_command_fail dfx --identity default canister call e2e_project_assets store '("B", vec { 88; 87; 86 })'
assert_command_fail dfx canister call e2e_project_assets store '("B", vec { 88; 87; 86 })'
assert_command_fail dfx canister call e2e_project_assets retrieve '("B")'

# but alice, the initializer, can store assets:
assert_command dfx --identity alice canister call e2e_project_assets store '("B", vec { 88; 87; 86; })'
assert_command dfx --identity alice canister call e2e_project_assets store '("B", vec { 88; 87; 86 })'
assert_eq '()'
assert_command dfx canister call e2e_project_assets retrieve '("B")'
assert_eq '(vec { 88; 87; 86; })'
assert_eq '(vec { 88; 87; 86 })'
}

@test "after renaming an identity, the renamed identity is still initializer" {
Expand All @@ -102,8 +102,8 @@ teardown() {
assert_command dfx --identity bob canister call e2e_project amInitializer
assert_eq '(true)'

assert_command dfx --identity bob canister call e2e_project_assets store '("B", vec { 40; 67; })'
assert_command dfx --identity bob canister call e2e_project_assets store '("B", vec { 40; 67 })'
assert_eq '()'
assert_command dfx canister call e2e_project_assets retrieve '("B")'
assert_eq '(vec { 40; 67; })'
assert_eq '(vec { 40; 67 })'
}
9 changes: 4 additions & 5 deletions src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ actix-server = "0.6.1"
actix-web = { version = "1.0.8", features = [ "default", "openssl", "ssl" ] }
atty = "0.2.13"
base64 = "0.11.0"
candid = "0.5.2"
candid = "0.6.0"
chrono = "0.4.9"
clap = "2.33.0"
console = "0.7.7"
Expand Down Expand Up @@ -69,14 +69,13 @@ wasmparser = "0.45.0"
version = "0.1.0"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "e61e646c7a810c13c1b3d898d1d2ed7366b67a0a"
rev = "35a0f9851cf8cceea34acf405ba50c84ab5fbc5e"

[dependencies.ic-types]
version = "0.1.0"
version = "0.1.1"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "e61e646c7a810c13c1b3d898d1d2ed7366b67a0a"

rev = "35a0f9851cf8cceea34acf405ba50c84ab5fbc5e"

[dev-dependencies]
env_logger = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn construct() -> App<'static, 'static> {
.long("output")
.takes_value(true)
.conflicts_with("async")
.possible_values(&["idl", "raw"]),
.possible_values(&["idl", "raw", "pp"]),
)
.arg(
Arg::with_name("argument")
Expand Down
35 changes: 6 additions & 29 deletions src/dfx/src/lib/models/canister.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::config::cache::Cache;
use crate::config::dfinity::Config;
use crate::lib::builders::{
BuildConfig, BuildOutput, BuilderPool, CanisterBuilder, IdlBuildOutput, WasmBuildOutput,
Expand All @@ -7,7 +6,7 @@ use crate::lib::canister_info::CanisterInfo;
use crate::lib::environment::Environment;
use crate::lib::error::{BuildErrorKind, DfxError, DfxResult};
use crate::lib::models::canister_id_store::CanisterIdStore;
use crate::util::assets;
use crate::util::{assets, check_candid_file};
use ic_types::principal::Principal as CanisterId;
use petgraph::graph::{DiGraph, NodeIndex};
use rand::{thread_rng, Rng, RngCore};
Expand Down Expand Up @@ -89,7 +88,6 @@ impl Canister {
pub struct CanisterPool {
canisters: Vec<Arc<Canister>>,
logger: Logger,
cache: Arc<dyn Cache>,
}

struct PoolConstructHelper<'a> {
Expand Down Expand Up @@ -195,7 +193,6 @@ impl CanisterPool {
Ok(CanisterPool {
canisters: canisters_map,
logger,
cache: env.get_cache().clone(),
})
}

Expand Down Expand Up @@ -331,7 +328,7 @@ impl CanisterPool {
.map(|_| {})
.map_err(DfxError::from)?;

build_canister_js(self.cache.clone(), &canister.canister_id(), &canister.info)?;
build_canister_js(&canister.canister_id(), &canister.info)?;

canister.postbuild(self, build_config)
}
Expand Down Expand Up @@ -440,35 +437,15 @@ fn decode_path_to_str(path: &Path) -> DfxResult<&str> {
}

/// Create a canister JavaScript DID and Actor Factory.
fn build_canister_js(
cache: Arc<dyn Cache>,
canister_id: &CanisterId,
canister_info: &CanisterInfo,
) -> DfxResult {
fn build_canister_js(canister_id: &CanisterId, canister_info: &CanisterInfo) -> DfxResult {
let output_did_js_path = canister_info.get_build_idl_path().with_extension("did.js");
let output_canister_js_path = canister_info.get_build_idl_path().with_extension("js");

let mut cmd = cache.get_binary_command("didc")?;
let cmd = cmd
.arg("--js")
.arg(&canister_info.get_build_idl_path())
.arg("-o")
.arg(&output_did_js_path);

let output = cmd.output()?;
if !output.status.success() {
return Err(DfxError::BuildError(BuildErrorKind::CompilerError(
format!("{:?}", cmd),
String::from_utf8_lossy(&output.stdout).to_string(),
String::from_utf8_lossy(&output.stderr).to_string(),
)));
} else if !output.stderr.is_empty() {
// Cannot use eprintln, because it would interfere with the progress bar.
println!("{}", String::from_utf8_lossy(&output.stderr));
}
let (env, ty) = check_candid_file(&canister_info.get_build_idl_path())?;
let content = candid::bindings::javascript::compile(&env, &ty);
std::fs::write(output_did_js_path, content)?;

let mut language_bindings = assets::language_bindings()?;

for f in language_bindings.entries()? {
let mut file = f?;
let mut file_contents = String::new();
Expand Down
Loading