Skip to content

Commit c5cf5a6

Browse files
authored
chore(crypto): CRP-2664 remove mock canister from threshold-schnorr examples (#1105)
1 parent 2e13456 commit c5cf5a6

File tree

13 files changed

+105
-156
lines changed

13 files changed

+105
-156
lines changed

.github/workflows/rust-threshold-schnorr-example.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ jobs:
2929
run: |
3030
dfx start --background
3131
pushd rust/threshold-schnorr
32-
make deploy
33-
# This should be re-enabled when Pocket IC supports threshold Schnorr
34-
# sleep 10
35-
# make test
32+
make test
3633
rust-threshold-schnorr-linux:
3734
runs-on: ubuntu-22.04
3835
steps:
@@ -45,7 +42,4 @@ jobs:
4542
run: |
4643
dfx start --background
4744
pushd rust/threshold-schnorr
48-
make deploy
49-
# This should be re-enabled when Pocket IC supports threshold Schnorr
50-
# sleep 10
51-
# make test
45+
make test

motoko/threshold-schnorr/Makefile

+1-10
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@ all: deploy
66
deploy:
77
dfx deploy
88

9-
.PHONY: mock
10-
.SILENT: mock
11-
mock: deploy
12-
SCHNORR_MOCK_CANISTER_ID=$(shell dfx canister id chainkey_testing_canister); \
13-
SCHNORR_EXAMPLE_CANISTER_ID=$(shell dfx canister id schnorr_example_motoko); \
14-
echo "Changing to using mock canister instead of management canister for signing"; \
15-
CMD="dfx canister call "$${SCHNORR_EXAMPLE_CANISTER_ID}" for_test_only_change_management_canister_id '("\"$${SCHNORR_MOCK_CANISTER_ID}\"")'"; \
16-
eval "$${CMD}"
17-
189
.PHONY: test
1910
.SILENT: test
20-
test: mock
11+
test: deploy
2112
bash test.sh hellohellohellohellohellohello12
2213

2314
.PHONY: clean

motoko/threshold-schnorr/README.md

+1-18
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ make test
7676

7777
- `npm install` installs test javascript dependencies
7878
- `make test` deploys and tests the canister code on the local version of the
79-
IC, and also makes the canister call a mock canister for Schnorr API instead
80-
of the management canister
79+
IC
8180

8281

8382
## Deploying the canister on the mainnet
@@ -93,22 +92,6 @@ Deploying to the Internet Computer requires
9392
[cycles](https://internetcomputer.org/docs/current/developer-docs/getting-started/tokens-and-cycles)
9493
(the equivalent of "gas" on other blockchains).
9594

96-
#### Update management canister ID reference for testing
97-
98-
The latest version of `dfx`, `v0.24.3`, does not yet support BIP341
99-
`opt_merkle_tree_root_hex` that is not `None`. Therefore, for local tests, [the
100-
chain-key testing canister](https://github.com/dfinity/chainkey-testing-canister)
101-
can be installed and used instead of the management canister. Note also that the
102-
chain-key testing canister is deployed on the mainnet and can be used for mainnet
103-
testing to reduce the costs, see the linked repo for more details.
104-
105-
This sample canister allows the caller to change the management canister address
106-
for Schnorr by calling the `for_test_only_change_management_canister_id`
107-
endpoint with the target canister principal. With `dfx`, this can be done
108-
automatically with `make mock`, which will install the chain-key testing canister
109-
and use it instead of the management canister. Note that `dfx` should be running
110-
to successfully run `make mock`.
111-
11295
### Update source code with the right key ID
11396

11497
To deploy the sample code, the canister needs the right key ID for the right environment. Specifically, one needs to replace the value of the `key_id` in the `src/schnorr_example_motoko/src/lib.rs` file of the sample code. Before deploying to mainnet, one should modify the code to use the right name of the `key_id`.

motoko/threshold-schnorr/dfx.json

-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
"package": "schnorr_example_motoko",
66
"main": "src/schnorr_example_motoko/main.mo",
77
"type": "motoko"
8-
},
9-
"chainkey_testing_canister": {
10-
"type": "custom",
11-
"candid": "https://github.com/dfinity/chainkey-testing-canister/releases/download/v0.1.0/chainkey_testing_canister.did",
12-
"wasm": "https://github.com/dfinity/chainkey-testing-canister/releases/download/v0.1.0/chainkey_testing_canister.wasm.gz"
138
}
149
}
1510
}

motoko/threshold-schnorr/src/schnorr_example_motoko/main.mo

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ actor {
3737

3838
var ic : IC = actor ("aaaaa-aa");
3939

40-
public func for_test_only_change_management_canister_id(mock_id : Text) {
41-
ic := actor (mock_id);
42-
};
43-
4440
public shared ({ caller }) func public_key(algorithm : SchnorrAlgorithm) : async {
4541
#Ok : { public_key_hex : Text };
4642
#Err : Text;
@@ -49,7 +45,7 @@ actor {
4945
let { public_key } = await ic.schnorr_public_key({
5046
canister_id = null;
5147
derivation_path = [Principal.toBlob(caller)];
52-
key_id = { algorithm; name = "insecure_test_key_1" };
48+
key_id = { algorithm; name = "dfx_test_key" };
5349
});
5450
#Ok({ public_key_hex = Hex.encode(Blob.toArray(public_key)) });
5551
} catch (err) {
@@ -72,7 +68,7 @@ actor {
7268
let signArgs = {
7369
message = Text.encodeUtf8(message_arg);
7470
derivation_path = [Principal.toBlob(caller)];
75-
key_id = { algorithm; name = "insecure_test_key_1" };
71+
key_id = { algorithm; name = "dfx_test_key" };
7672
aux;
7773
};
7874
let { signature } = await ic.sign_with_schnorr(signArgs);

0 commit comments

Comments
 (0)