Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Apr 25, 2024
1 parent 9334f55 commit 3039431
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
9 changes: 9 additions & 0 deletions e2e/assets/allocate_memory/src/e2e_project_backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[ic_cdk::query]
fn greet(s: String) -> String {
format!("Hello, {s}!")
}

#[ic_cdk::update]
fn greet_update(s: String) -> String {
format!("Hello, {s}!")
}
14 changes: 14 additions & 0 deletions e2e/tests-dfx/update_settings.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ teardown() {
assert_match "Freezing threshold: 100_000_000_000"
}

@test "set wasm memory limit" {
dfx_new_rust
install_asset allocate_memory
dfx_start
assert_command dfx deploy e2e_project_backend
assert_command dfx canister update-settings e2e_project_backend --wasm-memory-limit 8b
assert_command dfx canister status e2e_project_backend
assert_contains "WASM Memory Limit: 8 Bytes"
assert_command dfx canister call e2e_project_backend greet '("alice")' --query
assert_command dfx canister call e2e_project_backend greet '("alice")' --update
assert_command_fail dfx canister call e2e_project_backend greet_update '("alice")'
assert_contains "Canister exceeded its current Wasm memory limit of 8 bytes"
}

@test "set controller" {
# Create two identities
assert_command dfx identity new --storage-mode plaintext alice
Expand Down
36 changes: 20 additions & 16 deletions src/dfx/src/commands/canister/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,26 @@ async fn canister_status(
"Not Set".to_string()
};

println!("Canister status call result for {}.\nStatus: {}\nControllers: {}\nMemory allocation: {}\nCompute allocation: {}\nFreezing threshold: {}\nMemory Size: {:?}\nBalance: {} Cycles\nReserved: {} Cycles\nReserved Cycles Limit: {}\nModule hash: {}\nNumber of queries: {}\nInstructions spent in queries: {}\nTotal query request paylod size (bytes): {}\nTotal query response payload size (bytes): {}",
canister,
status.status,
controllers.join(" "),
status.settings.memory_allocation,
status.settings.compute_allocation,
status.settings.freezing_threshold,
status.memory_size,
status.cycles,
status.reserved_cycles,
reserved_cycles_limit,
status.module_hash.map_or_else(|| "None".to_string(), |v| format!("0x{}", hex::encode(v))),
status.query_stats.num_calls_total,
status.query_stats.num_instructions_total,
status.query_stats.request_payload_bytes_total,
status.query_stats.response_payload_bytes_total,
let wasm_memory_limit = if let Some(limit) = status.settings.wasm_memory_limit {
format!("{} Bytes", limit)
} else {
"Not Set".to_string()
};

println!("Canister status call result for {canister}.\nStatus: {status}\nControllers: {controllers}\nMemory allocation: {memory_allocation}\nCompute allocation: {compute_allocation}\nFreezing threshold: {freezing_threshold}\nMemory Size: {memory_size:?}\nBalance: {balance} Cycles\nReserved: {reserved} Cycles\nReserved Cycles Limit: {reserved_cycles_limit}\nWASM Memory Limit: {wasm_memory_limit}\nModule hash: {module_hash}\nNumber of queries: {queries_total}\nInstructions spent in queries: {query_instructions_total}\nTotal query request payload size (bytes): {query_req_payload_total}\nTotal query response payload size (bytes): {query_resp_payload_total}",
status = status.status,
controllers = controllers.join(" "),
memory_allocation = status.settings.memory_allocation,
compute_allocation = status.settings.compute_allocation,
freezing_threshold = status.settings.freezing_threshold,
memory_size = status.memory_size,
balance = status.cycles,
reserved = status.reserved_cycles,
module_hash = status.module_hash.map_or_else(|| "None".to_string(), |v| format!("0x{}", hex::encode(v))),
queries_total = status.query_stats.num_calls_total,
query_instructions_total = status.query_stats.num_instructions_total,
query_req_payload_total = status.query_stats.request_payload_bytes_total,
query_resp_payload_total = status.query_stats.response_payload_bytes_total,
);
Ok(())
}
Expand Down

0 comments on commit 3039431

Please sign in to comment.