-
Notifications
You must be signed in to change notification settings - Fork 45
/
test_unit_signatures.py
237 lines (203 loc) · 6.54 KB
/
test_unit_signatures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import pytest
from eth_tester.exceptions import TransactionFailed
from raiden_contracts.tests.fixtures import fake_bytes
@pytest.mark.skip(reason='Delayed to another milestone')
def test_recover_address_from_withdraw_message(
token_network_test_signatures,
create_withdraw_signatures,
create_channel_and_deposit,
get_accounts,
):
(A, B) = get_accounts(2)
token_network = token_network_test_signatures
fake_signature = fake_bytes(64)
deposit_A = 5
deposit_B = 7
withdraw_A = 3
channel_identifier = create_channel_and_deposit(A, B, deposit_A, deposit_B)
(signature_A, signature_B) = create_withdraw_signatures(
[A, B],
channel_identifier,
A,
withdraw_A,
token_network.address,
)
recovered_address_A = token_network.functions.recoverAddressFromWithdrawMessagePublic(
channel_identifier,
A,
withdraw_A,
signature_A,
).call()
assert recovered_address_A == A
recovered_address_B = token_network.functions.recoverAddressFromWithdrawMessagePublic(
channel_identifier,
A,
withdraw_A,
signature_B,
).call()
assert recovered_address_B == B
with pytest.raises(TransactionFailed):
token_network.functions.recoverAddressFromWithdrawMessagePublic(
channel_identifier,
A,
withdraw_A,
fake_signature,
).call()
wrong_participant = token_network.functions.recoverAddressFromWithdrawMessagePublic(
channel_identifier,
B,
withdraw_A,
signature_A,
).call()
assert recovered_address_A != wrong_participant
wrong_withdraw_value = token_network.functions.recoverAddressFromWithdrawMessagePublic(
channel_identifier,
A,
1,
signature_A,
).call()
assert recovered_address_A != wrong_withdraw_value
wrong_signature = token_network.functions.recoverAddressFromWithdrawMessagePublic(
channel_identifier,
A,
withdraw_A,
signature_B,
).call()
assert recovered_address_A != wrong_signature
def test_recover_address_from_balance_proof(
token_network_test_signatures,
create_balance_proof,
get_accounts,
):
(A, B) = get_accounts(2)
channel_identifier = 4
balance_proof = create_balance_proof(
channel_identifier,
A,
other_token_network=token_network_test_signatures,
)
balance_proof_wrong_token_network = create_balance_proof(
channel_identifier,
A,
)
balance_proof_other_signer = create_balance_proof(
channel_identifier,
A,
signer=B,
other_token_network=token_network_test_signatures,
)
assert A == token_network_test_signatures.functions.recoverAddressFromBalanceProofPublic(
channel_identifier, *balance_proof).call()
assert B == token_network_test_signatures.functions.recoverAddressFromBalanceProofPublic(
channel_identifier,
*balance_proof_other_signer,
).call()
assert A != token_network_test_signatures.functions.recoverAddressFromBalanceProofPublic(
channel_identifier, *balance_proof_wrong_token_network).call()
def test_recover_address_from_balance_proof_update(
token_network_test_signatures,
create_balance_proof,
create_balance_proof_update_signature,
get_accounts,
):
(A, B) = get_accounts(2)
other_token_network = token_network_test_signatures
channel_identifier = 4
balance_proof = create_balance_proof(
channel_identifier,
A,
other_token_network=other_token_network,
)
balance_proof_update_signature = create_balance_proof_update_signature(
B,
channel_identifier,
*balance_proof,
other_token_network=other_token_network,
)
balance_proof_update_signature_wrong_token_network = create_balance_proof_update_signature(
B,
channel_identifier,
*balance_proof,
)
balance_proof_signed_B = create_balance_proof(
channel_identifier,
B,
other_token_network=other_token_network,
)
balance_proof_update_signature_wrong_signer = create_balance_proof_update_signature(
B,
channel_identifier,
*balance_proof_signed_B,
)
assert B == other_token_network.functions.recoverAddressFromBalanceProofUpdateMessagePublic(
channel_identifier, *balance_proof, balance_proof_update_signature).call()
assert B != other_token_network.functions.recoverAddressFromBalanceProofUpdateMessagePublic(
channel_identifier,
*balance_proof,
balance_proof_update_signature_wrong_token_network,
).call()
assert B != other_token_network.functions.recoverAddressFromBalanceProofUpdateMessagePublic(
channel_identifier,
*balance_proof,
balance_proof_update_signature_wrong_signer,
).call()
@pytest.mark.skip(reason='Delayed to another milestone')
def test_recover_address_from_cooperative_settle_signature(
token_network_test_signatures,
create_cooperative_settle_signatures,
get_accounts,
):
(A, B) = get_accounts(2)
other_token_network = token_network_test_signatures
channel_identifier = 4
fake_signature = fake_bytes(64)
(signature_A, signature_B) = create_cooperative_settle_signatures(
[A, B],
channel_identifier,
A,
0,
B,
0,
other_token_network=other_token_network,
)
assert A == other_token_network.functions.recoverAddressFromCooperativeSettleSignaturePublic(
channel_identifier,
A,
0,
B,
0,
signature_A,
).call()
assert B == other_token_network.functions.recoverAddressFromCooperativeSettleSignaturePublic(
channel_identifier,
A,
0,
B,
0,
signature_B,
).call()
assert B != other_token_network.functions.recoverAddressFromCooperativeSettleSignaturePublic(
channel_identifier,
A,
0,
B,
0,
signature_A,
).call()
assert A != other_token_network.functions.recoverAddressFromCooperativeSettleSignaturePublic(
channel_identifier,
A,
0,
B,
0,
signature_B,
).call()
with pytest.raises(TransactionFailed):
other_token_network.functions.recoverAddressFromCooperativeSettleSignaturePublic(
channel_identifier,
A,
0,
B,
0,
fake_signature,
).call()