Skip to content

Commit 89ca125

Browse files
authored
Merge pull request #1015 from dfinity/alex/reenable-tests-in-rust-tschnorr
reenable tests and adjust cycles in rust threshold Schnorr
2 parents de5c69a + adfc19c commit 89ca125

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

.github/workflows/motoko-threshold-schnorr-example.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
run: bash .github/workflows/provision-darwin.sh
2222
- name: Motoko Threshold Schnorr Darwin
2323
run: |
24-
dfxvm default 0.22.0-beta.0
2524
dfx start --background
2625
npm install @noble/curves
2726
pushd motoko/threshold-schnorr
@@ -34,7 +33,6 @@ jobs:
3433
run: bash .github/workflows/provision-linux.sh
3534
- name: Motoko Threshold Schnorr Linux
3635
run: |
37-
dfxvm default 0.22.0-beta.0
3836
dfx start --background
3937
npm install @noble/curves
4038
pushd motoko/threshold-schnorr

rust/threshold-schnorr/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
.PHONY: all
22
all: build
33

4+
.PHONY: build
5+
.SILENT: build
6+
build:
7+
dfx build --check
8+
49
.PHONY: deploy
510
.SILENT: deploy
611
deploy:
712
dfx deploy
813

914
.PHONY: test
1015
.SILENT: test
11-
test:
16+
test: build
1217
cargo test
1318

1419
.PHONY: clean

rust/threshold-schnorr/src/schnorr_example_rust/src/wasm_only.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async fn public_key(algorithm: SchnorrAlgorithm) -> Result<PublicKeyReply, Strin
4242
let request = ManagementCanisterSchnorrPublicKeyRequest {
4343
canister_id: None,
4444
derivation_path: vec![ic_cdk::api::caller().as_slice().to_vec()],
45-
key_id: SchnorrKeyIds::TestKeyLocalDevelopment.to_key_id(algorithm),
45+
key_id: SchnorrKeyIds::TestKey1.to_key_id(algorithm),
4646
};
4747

4848
let (res,): (ManagementCanisterSchnorrPublicKeyReply,) = ic_cdk::call(
@@ -63,15 +63,15 @@ async fn sign(message: String, algorithm: SchnorrAlgorithm) -> Result<SignatureR
6363
let internal_request = ManagementCanisterSignatureRequest {
6464
message: message.as_bytes().to_vec(),
6565
derivation_path: vec![ic_cdk::api::caller().as_slice().to_vec()],
66-
key_id: SchnorrKeyIds::TestKeyLocalDevelopment.to_key_id(algorithm),
66+
key_id: SchnorrKeyIds::TestKey1.to_key_id(algorithm),
6767
};
6868

6969
let (internal_reply,): (ManagementCanisterSignatureReply,) =
7070
ic_cdk::api::call::call_with_payment(
7171
Principal::management_canister(),
7272
"sign_with_schnorr",
7373
(internal_request,),
74-
25_000_000_000,
74+
26_153_846_153,
7575
)
7676
.await
7777
.map_err(|e| format!("sign_with_schnorr failed {e:?}"))?;

rust/threshold-schnorr/src/schnorr_example_rust/tests/tests.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use candid::{decode_one, encode_args, encode_one, CandidType, Principal};
2-
use pocket_ic::{PocketIc, WasmResult};
2+
use pocket_ic::{PocketIc, PocketIcBuilder, WasmResult};
33
use schnorr_example_rust::{
44
PublicKeyReply, SchnorrAlgorithm, SignatureReply, SignatureVerificationReply,
55
};
@@ -11,7 +11,11 @@ fn signing_and_verification_should_work_correctly() {
1111
const ALGORITHMS: [SchnorrAlgorithm; 2] =
1212
[SchnorrAlgorithm::Bip340Secp256k1, SchnorrAlgorithm::Ed25519];
1313

14-
let pic = PocketIc::new();
14+
let pic = PocketIcBuilder::new()
15+
.with_application_subnet()
16+
.with_ii_subnet()
17+
.with_fiduciary_subnet()
18+
.build();
1519

1620
for algorithm in ALGORITHMS {
1721
for _trial in 0..5 {
@@ -33,14 +37,19 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
3337
// Make sure the canister is properly initialized
3438
fast_forward(&pic, 5);
3539

36-
let message_hex = hex::encode("Test message");
40+
// a message we can reverse to break the signature
41+
// currently pocket IC only supports 32B messages for BIP340
42+
let message: String = std::iter::repeat('a')
43+
.take(16)
44+
.chain(std::iter::repeat('b').take(16))
45+
.collect();
3746

3847
let sig_reply: Result<SignatureReply, String> = update(
3948
&pic,
4049
my_principal,
4150
example_canister_id,
4251
"sign",
43-
encode_args((message_hex.clone(), algorithm)).unwrap(),
52+
encode_args((message.clone(), algorithm)).unwrap(),
4453
);
4554

4655
let signature_hex = sig_reply.expect("failed to sign").signature_hex;
@@ -63,7 +72,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
6372
"verify",
6473
encode_args((
6574
signature_hex.clone(),
66-
message_hex.clone(),
75+
message.clone(),
6776
public_key_hex.clone(),
6877
algorithm,
6978
))
@@ -81,7 +90,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
8190
"verify",
8291
encode_args((
8392
clone_and_reverse_chars(&signature_hex),
84-
message_hex.clone(),
93+
message.clone(),
8594
public_key_hex.clone(),
8695
algorithm,
8796
))
@@ -99,7 +108,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
99108
"verify",
100109
encode_args((
101110
signature_hex.clone(),
102-
clone_and_reverse_chars(&message_hex),
111+
clone_and_reverse_chars(&message),
103112
public_key_hex.clone(),
104113
algorithm,
105114
))
@@ -117,7 +126,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
117126
"verify",
118127
encode_args((
119128
signature_hex.clone(),
120-
message_hex.clone(),
129+
message.clone(),
121130
clone_and_reverse_chars(&public_key_hex),
122131
algorithm,
123132
))
@@ -138,7 +147,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
138147
"verify",
139148
encode_args((
140149
signature_hex.clone(),
141-
message_hex.clone(),
150+
message.clone(),
142151
public_key_hex.clone(),
143152
other_algorithm(algorithm),
144153
))

0 commit comments

Comments
 (0)