-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtest_offchain_jws.py
38 lines (32 loc) · 1.21 KB
/
test_offchain_jws.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
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0
from diem import offchain
from diem.testing import LocalAccount
import cryptography, pytest
def test_serialize_deserialize():
account = LocalAccount.generate()
response = offchain.CommandResponseObject(
status=offchain.CommandResponseStatus.success,
cid="3185027f05746f5526683a38fdb5de98",
)
ret = offchain.jws.serialize(response, account.compliance_key.sign)
resp = offchain.jws.deserialize(
ret,
offchain.CommandResponseObject,
account.compliance_key.public_key().verify,
)
assert resp == response
def test_deserialize_error_for_invalid_signature():
account = LocalAccount.generate()
response = offchain.CommandResponseObject(
status=offchain.CommandResponseStatus.success,
cid="3185027f05746f5526683a38fdb5de98",
)
data = offchain.jws.serialize(response, account.compliance_key.sign)
account2 = LocalAccount.generate()
with pytest.raises(cryptography.exceptions.InvalidSignature):
offchain.jws.deserialize(
data,
offchain.CommandResponseObject,
account2.compliance_key.public_key().verify,
)