Skip to content
Closed
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions e2e/bats/assetscanister.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ teardown() {
install_asset assetscanister

dfx_start
dfx canister create --all
dfx build
dfx canister install e2e_project_assets

Expand Down
2 changes: 2 additions & 0 deletions e2e/bats/base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ teardown() {
install_asset base

dfx_start
dfx canister create --all
dfx build
dfx canister install e2e_project

Expand All @@ -32,6 +33,7 @@ teardown() {
dfx config defaults/build/packtool "echo"

dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match 'import error, package "base" not defined'
}
4 changes: 4 additions & 0 deletions e2e/bats/basic-project.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ teardown() {
@test "build + install + call + request-status -- greet_mo" {
install_asset greet
dfx_start
dfx canister create --all
dfx build
INSTALL_REQUEST_ID=$(dfx canister install hello --async)
dfx canister request-status $INSTALL_REQUEST_ID
Expand All @@ -40,6 +41,7 @@ teardown() {
@test "build + install + call + request-status -- counter_mo" {
install_asset counter
dfx_start
dfx canister create --all
dfx build
dfx canister install hello

Expand Down Expand Up @@ -80,6 +82,7 @@ teardown() {
@test "build + install + call -- counter_idl_mo" {
install_asset counter_idl
dfx_start
dfx canister create --all
dfx build
dfx canister install --all

Expand All @@ -90,6 +93,7 @@ teardown() {
@test "build + install + call -- matrix_multiply_mo" {
install_asset matrix_multiply
dfx_start
dfx canister create --all
dfx build
dfx canister install --all

Expand Down
9 changes: 9 additions & 0 deletions e2e/bats/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ teardown() {
@test "build fails on invalid motoko" {
install_asset invalid
dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match "syntax error"
}

@test "build supports relative imports" {
install_asset import
dfx_start
dfx canister create --all
assert_command dfx build
dfx canister install --all
assert_command dfx canister call e2e_project greet World
Expand All @@ -32,13 +34,15 @@ teardown() {

@test "build succeeds on default project" {
dfx_start
dfx canister create --all
assert_command dfx build
}

# TODO: Before Tungsten, we need to update this test for code with inter-canister calls.
# Currently due to new canister ids, the wasm binary will be different for inter-canister calls.
@test "build twice produces the same wasm binary" {
dfx_start
dfx canister create --all
assert_command dfx build
cp canisters/e2e_project/main.wasm ./old.wasm
assert_command dfx build
Expand All @@ -47,34 +51,39 @@ teardown() {

@test "build outputs the canister manifest" {
dfx_start
dfx canister create --all
assert_command dfx build
[[ -f canisters/canister_manifest.json ]]
}

@test "build outputs warning" {
install_asset warning
dfx_start
dfx canister create --all
assert_command dfx build
assert_match "warning, this pattern consuming type"
}

@test "build fails on unknown imports" {
install_asset import_error
dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match 'import error, canister alias "random" not defined'
}

@test "build fails if canister type is not supported" {
dfx_start
dfx config canisters.e2e_project.type unknown_canister_type
dfx canister create --all
assert_command_fail dfx build
assert_match "CouldNotFindBuilderForCanister"
}

@test "can build a custom canister type" {
dfx_start
install_asset custom_canister
dfx canister create --all
assert_command dfx build
assert_match "CUSTOM_CANISTER_BUILD_DONE"

Expand Down
1 change: 1 addition & 0 deletions e2e/bats/call.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ teardown() {
@test "call subcommand accepts canister identifier as canister name" {
install_asset greet
dfx_start
dfx canister create --all
dfx build
dfx canister install hello
assert_command dfx canister call $(dfx canister id hello) greet '("Names are difficult")'
Expand Down
33 changes: 33 additions & 0 deletions e2e/bats/create.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bats

load utils/_

setup() {
# We want to work from a temporary directory, different for every test.
cd $(mktemp -d -t dfx-e2e-XXXXXXXX)
export RUST_BACKTRACE=1

dfx_new
}

teardown() {
dfx_stop
}

@test "create succeeds on default project" {
dfx_start
assert_command dfx canister create --all
}

@test "build fails without create" {
dfx_start
assert_command_fail dfx build
assert_match 'Failed to find canister manifest'
}

@test "build fails if all canisters in project are not created" {
dfx_start
assert_command dfx canister create e2e_project
assert_command_fail dfx build
assert_match 'Failed to find canister id for e2e_project_assets'
}
2 changes: 2 additions & 0 deletions e2e/bats/frontend.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ teardown() {

@test "dfx start serves a frontend" {
dfx_start
dfx canister create --all
dfx build --skip-frontend

sleep 1
Expand All @@ -26,6 +27,7 @@ teardown() {
[ "$USE_IC_REF" ] && skip "dfx start cannot serve frontent when using ic-ref"

dfx_start --host 127.0.0.1:12345
dfx canister --provider http://127.0.0.1:12345 create --all
dfx build --skip-frontend --provider http://127.0.0.1:12345

assert_command curl http://localhost:12345 # 8000 = default port.
Expand Down
1 change: 1 addition & 0 deletions e2e/bats/id.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ teardown() {
@test "id subcommand prints valid canister identifier" {
install_asset id
dfx_start
dfx canister create --all
dfx build
assert_command dfx canister id e2e_project
assert_match $(cat canisters/canister_manifest.json | jq -r .canisters.e2e_project.canister_id)
Expand Down
1 change: 1 addition & 0 deletions e2e/bats/identity.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ teardown() {
@test "calls and query receive the same principal from dfx" {
install_asset identity
dfx_start
dfx canister create --all
assert_command dfx build
assert_command dfx canister install --all

Expand Down
5 changes: 5 additions & 0 deletions e2e/bats/packtool.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ teardown() {
install_asset packtool

dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match 'import error, package "(rate|describe)" not defined'
}
Expand All @@ -26,6 +27,7 @@ teardown() {
source configure_packtool.bash

dfx_start
dfx canister create --all
dfx build
}

Expand All @@ -34,6 +36,7 @@ teardown() {
source configure_packtool.bash

dfx_start
dfx canister create --all
dfx build
dfx canister install e2e_project

Expand All @@ -49,6 +52,7 @@ teardown() {
dfx config defaults/build/packtool "./no-such-command that command cannot be invoked"

dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match 'Failed to invoke the package tool'
assert_match 'no-such-command.*that.*command.*cannot.*be.*invoked'
Expand All @@ -60,6 +64,7 @@ teardown() {
dfx config defaults/build/packtool "sh ./command-that-fails.bash"

dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match 'Package tool.*reported an error'
assert_match 'sh.*command-that-fails.bash'
Expand Down
1 change: 1 addition & 0 deletions e2e/bats/print.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ teardown() {

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
Expand Down
1 change: 1 addition & 0 deletions e2e/bats/usage.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ teardown() {
dfx new t --no-frontend
cd t
dfx_start
dfx canister create --all
assert_command dfx build
}
9 changes: 4 additions & 5 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@
"type": "git"
},
"dfinity": {
"ref": "v0.5.8",
"ref": "akhi3030-v0.5.8",
"repo": "ssh://git@github.com/dfinity-lab/dfinity",
"rev": "45c2b5022e1ae81677c5745e0f5d829228c3fb5a",
"rev": "3045e224d47aff317e265ac66e37834c31637011",
"type": "git"
},
"ic-ref": {
"branch": "legacy3",
"ref": "legacy3",
"ref": "0.8",
"repo": "ssh://git@github.com/dfinity-lab/ic-ref",
"rev": "6331356b20183bb9eda5589959ee18bf66becc06",
"rev": "d0166d45978b17e87f25a74f484ed872a897d8f9",
"type": "git"
},
"motoko": {
Expand Down
2 changes: 2 additions & 0 deletions src/agent/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ edition = "2018"
[dependencies]
async-trait = "0.1.35"
byteorder = "1.3.2"
candid = "0.3.1"
candid_derive = "0.2.2"
crc8 = "0.1.1"
delay = "0.1.1"
hex = "0.4.0"
Expand Down
19 changes: 18 additions & 1 deletion src/agent/rust/src/agent/agent_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Replied, RequestIdError};
use crate::{Replied, RequestIdError, TextualCanisterIdError};
use serde_cbor::error::Error as SerdeError;

#[derive(Debug)]
Expand Down Expand Up @@ -27,6 +27,11 @@ pub enum AgentError {
},

UnexpectedReply(Replied),

CandidError(candid::Error),
CanisterIdTextError(TextualCanisterIdError),

InstallModeError(String),
}

impl From<SerdeError> for AgentError {
Expand All @@ -41,6 +46,12 @@ impl From<reqwest::Error> for AgentError {
}
}

impl From<candid::Error> for AgentError {
fn from(err: candid::Error) -> Self {
Self::CandidError(err)
}
}

impl From<url::ParseError> for AgentError {
fn from(err: url::ParseError) -> Self {
Self::UrlParseError(err)
Expand All @@ -52,3 +63,9 @@ impl From<RequestIdError> for AgentError {
Self::CannotCalculateRequestId(err)
}
}

impl From<TextualCanisterIdError> for AgentError {
fn from(err: TextualCanisterIdError) -> Self {
Self::CanisterIdTextError(err)
}
}
41 changes: 0 additions & 41 deletions src/agent/rust/src/agent/agent_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,47 +210,6 @@ fn call_rejected() -> Result<(), AgentError> {
Ok(())
}

#[test]
fn install() -> Result<(), AgentError> {
let canister_id = CanisterId::from_bytes(&[5u8]);
let module = Blob::from(&[1, 2]);

let blob = Blob(Vec::from("Hello World"));
let response = QueryResponse::Replied {
reply: CallReply { arg: blob.clone() },
};

let submit_mock = mock("POST", "/api/v1/submit").with_status(200).create();
let status_mock = mock("POST", "/api/v1/read")
.with_status(200)
.with_header("content-type", "application/cbor")
.with_body(serde_cbor::to_vec(&response)?)
.create();

let agent = Agent::new(AgentConfig {
url: &mockito::server_url(),
..AgentConfig::default()
})?;

let mut runtime = tokio::runtime::Runtime::new().expect("Unable to create a runtime");
let result = runtime.block_on(async {
let request_id = agent.install(&canister_id, &module, &Blob::empty()).await?;
agent.request_status_raw(&request_id).await
});

submit_mock.assert();
status_mock.assert();

assert_eq!(
result?,
RequestStatusResponse::Replied {
reply: Replied::CallReplied(blob)
}
);

Ok(())
}

#[test]
fn ping() -> Result<(), AgentError> {
let response = serde_cbor::Value::Map(BTreeMap::new());
Expand Down
Loading