1
1
use candid:: { decode_one, encode_args, encode_one, CandidType , Principal } ;
2
- use pocket_ic:: { PocketIc , WasmResult } ;
2
+ use pocket_ic:: { PocketIc , PocketIcBuilder , WasmResult } ;
3
3
use schnorr_example_rust:: {
4
4
PublicKeyReply , SchnorrAlgorithm , SignatureReply , SignatureVerificationReply ,
5
5
} ;
@@ -11,7 +11,11 @@ fn signing_and_verification_should_work_correctly() {
11
11
const ALGORITHMS : [ SchnorrAlgorithm ; 2 ] =
12
12
[ SchnorrAlgorithm :: Bip340Secp256k1 , SchnorrAlgorithm :: Ed25519 ] ;
13
13
14
- let pic = PocketIc :: new ( ) ;
14
+ let pic = PocketIcBuilder :: new ( )
15
+ . with_application_subnet ( )
16
+ . with_ii_subnet ( )
17
+ . with_fiduciary_subnet ( )
18
+ . build ( ) ;
15
19
16
20
for algorithm in ALGORITHMS {
17
21
for _trial in 0 ..5 {
@@ -33,14 +37,19 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
33
37
// Make sure the canister is properly initialized
34
38
fast_forward ( & pic, 5 ) ;
35
39
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 ( ) ;
37
46
38
47
let sig_reply: Result < SignatureReply , String > = update (
39
48
& pic,
40
49
my_principal,
41
50
example_canister_id,
42
51
"sign" ,
43
- encode_args ( ( message_hex . clone ( ) , algorithm) ) . unwrap ( ) ,
52
+ encode_args ( ( message . clone ( ) , algorithm) ) . unwrap ( ) ,
44
53
) ;
45
54
46
55
let signature_hex = sig_reply. expect ( "failed to sign" ) . signature_hex ;
@@ -63,7 +72,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
63
72
"verify" ,
64
73
encode_args ( (
65
74
signature_hex. clone ( ) ,
66
- message_hex . clone ( ) ,
75
+ message . clone ( ) ,
67
76
public_key_hex. clone ( ) ,
68
77
algorithm,
69
78
) )
@@ -81,7 +90,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
81
90
"verify" ,
82
91
encode_args ( (
83
92
clone_and_reverse_chars ( & signature_hex) ,
84
- message_hex . clone ( ) ,
93
+ message . clone ( ) ,
85
94
public_key_hex. clone ( ) ,
86
95
algorithm,
87
96
) )
@@ -99,7 +108,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
99
108
"verify" ,
100
109
encode_args ( (
101
110
signature_hex. clone ( ) ,
102
- clone_and_reverse_chars ( & message_hex ) ,
111
+ clone_and_reverse_chars ( & message ) ,
103
112
public_key_hex. clone ( ) ,
104
113
algorithm,
105
114
) )
@@ -117,7 +126,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
117
126
"verify" ,
118
127
encode_args ( (
119
128
signature_hex. clone ( ) ,
120
- message_hex . clone ( ) ,
129
+ message . clone ( ) ,
121
130
clone_and_reverse_chars ( & public_key_hex) ,
122
131
algorithm,
123
132
) )
@@ -138,7 +147,7 @@ fn test_impl(pic: &PocketIc, algorithm: SchnorrAlgorithm) {
138
147
"verify" ,
139
148
encode_args ( (
140
149
signature_hex. clone ( ) ,
141
- message_hex . clone ( ) ,
150
+ message . clone ( ) ,
142
151
public_key_hex. clone ( ) ,
143
152
other_algorithm ( algorithm) ,
144
153
) )
0 commit comments