Skip to content

Commit

Permalink
Add unit tests for all canisters
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Oct 23, 2024
1 parent a25dff9 commit e20342f
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 53 deletions.
86 changes: 65 additions & 21 deletions Cargo.lock

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

31 changes: 19 additions & 12 deletions src/dns_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,31 @@ mod test {
use super::*;
use candid::{decode_one, encode_args, encode_one, Encode, Principal};
use ic_cdk::api::call::RejectionCode;
use ic_cdk::api::management_canister::http_request::{
http_request, CanisterHttpRequestArgument, HttpHeader, HttpMethod, HttpResponse,
TransformArgs, TransformContext,
};
use pocket_ic::{
common::rest::{
BlobCompression, CanisterHttpReply, CanisterHttpResponse, MockCanisterHttpResponse,
RawEffectivePrincipal, SubnetKind, CanisterHttpHeader
BlobCompression, CanisterHttpHeader, CanisterHttpReply, CanisterHttpResponse,
MockCanisterHttpResponse, RawEffectivePrincipal, SubnetKind,
},
update_candid, PocketIc, WasmResult,
};
use ic_cdk::api::management_canister::http_request::{
http_request, CanisterHttpRequestArgument, HttpHeader, HttpMethod, HttpResponse, TransformArgs,
TransformContext
update_candid, PocketIc, PocketIcBuilder, WasmResult,
};

#[test]
fn test_dns_client_gmail() {
let pic = PocketIc::new();
let pic = PocketIcBuilder::new()
.with_nns_subnet()
.with_ii_subnet() // this subnet has ECDSA keys
.with_application_subnet()
.build();

let topology = pic.topology();
let app_subnet = topology.get_app_subnets()[0];

// Create an empty canister as the anonymous principal and add cycles.
let canister_id = pic.create_canister();
let canister_id = pic.create_canister_on_subnet(None, None, app_subnet);
pic.add_cycles(canister_id, 2_000_000_000_000);
let wasm_bytes =
include_bytes!("../../../target/wasm32-unknown-unknown/release/dns_client.wasm")
Expand Down Expand Up @@ -256,7 +264,7 @@ mod test {
response: CanisterHttpResponse::CanisterHttpReply(CanisterHttpReply {
status: 200,
headers: vec![],
body: body.as_bytes().to_vec()
body: body.as_bytes().to_vec(),
}),
additional_responses: vec![],
};
Expand All @@ -268,8 +276,7 @@ mod test {
println!("{:?}", reply);
match reply {
WasmResult::Reply(data) => {
let http_response: Result<String, String> =
decode_one(&data).unwrap();
let http_response: Result<String, String> = decode_one(&data).unwrap();
assert_eq!(http_response.unwrap(), "0x9edbd2293d6192a84a7b4c5c699d31f906e8b83b09b817dbcbf4bcda3c6ca02fd2a1d99f995b360f52801f79a2d40a9d31d535da1d957c44de389920198ab996377df7a009eee7764b238b42696168d1c7ecbc7e31d69bf3fcc337549dc4f0110e070cec0b111021f0435e51db415a2940011aee0d4db4767c32a76308aae634320642d63fe2e018e81f505e13e0765bd8f6366d0b443fa41ea8eb5c5b8aebb07db82fb5e10fe1d265bd61b22b6b13454f6e1273c43c08e0917cd795cc9d25636606145cff02c48d58d0538d96ab50620b28ad9f5aa685b528f41ef1bad24a546c8bdb1707fb6ee7a2e61bbb440cd9ab6795d4c106145000c13aeeedd678b05f");
}
WasmResult::Reject(msg) => panic!("Unexpected reject {}", msg),
Expand Down
4 changes: 3 additions & 1 deletion src/ic_dns_oracle_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ serde = { version = "1.0.152", default-features = false }
hex = { version = "0.4.3", default-features = false }
rsa = { version = "0.9.6", default-features = false }
# sha2 = { version = "0.10.6", default-features = false }
ic-evm-sign = { version = "0.1.6", git = "https://github.com/SoraSuegami/ic-evm-sign.git" }
ic-evm-sign = { version = "0.1.7", git = "https://github.com/SoraSuegami/ic-evm-sign.git" }
ic-stable-structures = "0.6.5"
# ic-storage = { version = "0.16.0", git = "https://github.com/bitfinity-network/canister-sdk.git" }
# ic-exports = { version = "0.16.0", git = "https://github.com/bitfinity-network/canister-sdk.git" }
Expand All @@ -30,3 +30,5 @@ ic-stable-structures = "0.6.5"
ethers-core = "2.0.10"
easy-hasher = "2.2.1"
poseidon = { path = "../poseidon" }
pocket-ic = "5.0.0"
libsecp256k1 = { version = "0.7.1", package = "libsecp256k1" }
3 changes: 2 additions & 1 deletion src/ic_dns_oracle_backend/ic_dns_oracle_backend.did
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type SignedRevocation = record {
};
service : (opt Environment, text, text) -> {
get_dns_client_canister_id : () -> (text) query;
get_ethereum_address : () -> (text) query;
get_poseidon_canister_id : () -> (text) query;
get_signer_ethereum_address : () -> (text) query;
init_signer_ethereum_address : () -> (text);
read_log_from_first : (nat64) -> (vec text) query;
read_log_from_last : (nat64) -> (vec text) query;
revoke_dkim_public_key : (text, text, text) -> (Result);
Expand Down
Loading

0 comments on commit e20342f

Please sign in to comment.