11use candid:: { decode_one, encode_args, encode_one, CandidType , Principal } ;
2- use pocket_ic:: { PocketIc , WasmResult } ;
2+ use pocket_ic:: { PocketIc , PocketIcBuilder , WasmResult } ;
33use 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