Skip to content

Commit 1fc9247

Browse files
authored
chore(crypto): CRP-2664 remove mock canister from basic_bitcoin examples (#1103)
1 parent de85e56 commit 1fc9247

File tree

8 files changed

+15
-50
lines changed

8 files changed

+15
-50
lines changed

motoko/basic_bitcoin/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ This example is extensively documented in the following tutorials:
195195
* [Deploying your first Bitcoin dapp](https://internetcomputer.org/docs/current/samples/deploying-your-first-bitcoin-dapp).
196196
* [Developing Bitcoin dapps locally](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/local-development).
197197

198+
Note that for *testing* on mainnet, the [chain-key testing
199+
canister](https://github.com/dfinity/chainkey-testing-canister) can be used to
200+
save on costs for calling the threshold signing APIs for signing the BTC
201+
transactions.
202+
198203
## Security considerations and best practices
199204

200205
If you base your application on this example, we recommend you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/current/references/security/) for developing on the Internet Computer. This example may not implement all the best practices.

motoko/basic_bitcoin/dfx.json

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
"basic_bitcoin": {
55
"main": "src/basic_bitcoin/src/Main.mo",
66
"type": "motoko"
7-
},
8-
"chainkey_testing_canister": {
9-
"type": "custom",
10-
"candid": "https://github.com/dfinity/chainkey-testing-canister/releases/download/v0.1.0/chainkey_testing_canister.did",
11-
"wasm": "https://github.com/dfinity/chainkey-testing-canister/releases/download/v0.1.0/chainkey_testing_canister.wasm.gz"
127
}
138
},
149
"defaults": {

motoko/basic_bitcoin/src/basic_bitcoin/src/Main.mo

+3-6
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,16 @@ actor class BasicBitcoin(network : Types.Network) {
3636
// The ECDSA key name.
3737
let KEY_NAME : Text = switch NETWORK {
3838
// For local development, we use a special test key with dfx.
39-
case (#regtest) "insecure_test_key_1";
39+
case (#regtest) "dfx_test_key";
4040
// On the IC we're using a test ECDSA key.
4141
case _ "test_key_1";
4242
};
4343

44+
// Threshold signing APIs instantiated with the management canister ID. Can be
45+
// replaced for cheaper testing.
4446
var ecdsa_canister_actor : EcdsaCanisterActor = actor ("aaaaa-aa");
4547
var schnorr_canister_actor : SchnorrCanisterActor = actor ("aaaaa-aa");
4648

47-
public func for_test_only_change_management_canister_id(p : Principal) {
48-
ecdsa_canister_actor := actor (Principal.toText(p));
49-
schnorr_canister_actor := actor (Principal.toText(p));
50-
};
51-
5249
/// Returns the balance of the given Bitcoin address.
5350
public func get_balance(address : BitcoinAddress) : async Satoshi {
5451
await BitcoinApi.get_balance(NETWORK, address);

rust/basic_bitcoin/Makefile

-10
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,8 @@ all: deploy
44
.PHONY: deploy
55
.SILENT: deploy
66
deploy:
7-
dfx deploy chainkey_testing_canister
87
dfx deploy basic_bitcoin --argument '(variant { regtest })'
98

10-
.PHONY: mock
11-
.SILENT: mock
12-
mock: deploy
13-
SCHNORR_MOCK_CANISTER_ID=$(shell dfx canister id chainkey_testing_canister); \
14-
BASIC_BITCOIN_CANISTER_ID=$(shell dfx canister id basic_bitcoin); \
15-
echo "Changing to using mock canister instead of management canister"; \
16-
CMD="dfx canister call "$${BASIC_BITCOIN_CANISTER_ID}" for_test_only_change_management_canister_id '("\"$${SCHNORR_MOCK_CANISTER_ID}\"")'"; \
17-
eval "$${CMD}"
18-
199
.PHONY: regtest_topup
2010
.SILENT: regtest_topup
2111
regtest_topup:

rust/basic_bitcoin/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ This example is extensively documented in the following tutorials:
227227
* [Deploying your first Bitcoin dapp](https://internetcomputer.org/docs/current/samples/deploying-your-first-bitcoin-dapp).
228228
* [Developing Bitcoin dapps locally](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/local-development).
229229

230+
Note that for *testing* on mainnet, the [chain-key testing
231+
canister](https://github.com/dfinity/chainkey-testing-canister) can be used to
232+
save on costs for calling the threshold signing APIs for signing the BTC
233+
transactions.
234+
230235
## Security considerations and best practices
231236

232237
If you base your application on this example, we recommend you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/current/references/security/) for developing on the Internet Computer. This example may not implement all the best practices.

rust/basic_bitcoin/dfx.json

-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"name": "candid:service"
1313
}
1414
]
15-
},
16-
"chainkey_testing_canister": {
17-
"type": "custom",
18-
"candid": "https://github.com/dfinity/chainkey-testing-canister/releases/download/v0.1.0/chainkey_testing_canister.did",
19-
"wasm": "https://github.com/dfinity/chainkey-testing-canister/releases/download/v0.1.0/chainkey_testing_canister.wasm.gz"
2015
}
2116
},
2217
"defaults": {

rust/basic_bitcoin/src/basic_bitcoin/basic_bitcoin.did

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ type get_block_headers_response = record {
4141
};
4242

4343
service : (network) -> {
44-
"for_test_only_change_management_canister_id" : (text) -> (variant { Ok: null; Err: text });
45-
4644
"get_p2pkh_address" : () -> (bitcoin_address);
4745

4846
"get_p2tr_address" : () -> (bitcoin_address);

rust/basic_bitcoin/src/basic_bitcoin/src/lib.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ thread_local! {
2828

2929
// The ECDSA key name.
3030
static KEY_NAME: RefCell<String> = RefCell::new(String::from(""));
31-
32-
// Management canister ID. Can be replaced for testing.
33-
static MGMT_CANISTER_ID: RefCell<String> = RefCell::new("aaaaa-aa".to_string());
3431
}
3532

3633
#[init]
@@ -81,19 +78,6 @@ pub struct GetBlockHeadersResponse {
8178
pub block_headers: Vec<BlockHeader>,
8279
}
8380

84-
#[update]
85-
async fn for_test_only_change_management_canister_id(id: String) -> Result<(), String> {
86-
let _ = CanisterId::from_text(&id).map_err(|e| panic!("invalid canister id: {}: {}", id, e));
87-
MGMT_CANISTER_ID.with_borrow_mut(move |current_id| {
88-
println!(
89-
"Changing management canister id from {} to {id}",
90-
*current_id
91-
);
92-
*current_id = id;
93-
});
94-
Ok(())
95-
}
96-
9781
/// Returns the block headers in the given height range.
9882
#[update]
9983
pub async fn get_block_headers(
@@ -237,11 +221,7 @@ pub struct SendRequest {
237221
pub amount_in_satoshi: u64,
238222
}
239223

240-
/// The current management canister Schnorr API in Pocket IC / `dfx` is not yet
241-
/// fully supported. Therefore, we install the `chainkey_testing_canister` via
242-
/// `dfx` and use that instead of the management canister for local testing.
243224
fn mgmt_canister_id() -> CanisterId {
244-
MGMT_CANISTER_ID
245-
.with_borrow(|id| CanisterId::from_text(id))
246-
.expect("invalid management canister principal string")
225+
// Management canister ID. Can be replaced for cheaper testing.
226+
candid::Principal::management_canister()
247227
}

0 commit comments

Comments
 (0)