forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_vaa_verify.py
179 lines (144 loc) · 6.34 KB
/
test_vaa_verify.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
import pytest
import coincurve
from algosdk.future import transaction
from algosdk.error import AlgodHTTPError
from algosdk.logic import get_application_address
from Cryptodome.Hash import keccak
@pytest.fixture(scope='module')
def app_id(portal_core, client, creator):
return portal_core.createTestApp(client,creator)
@pytest.fixture(scope='module')
def signers(gen_test):
return bytes.fromhex("".join(gen_test.guardianKeys))
@pytest.fixture(scope='module')
def signers_private_keys(gen_test):
return gen_test.guardianPrivKeys
@pytest.fixture(scope='module')
def hash():
return keccak.new(digest_bits=256).update(b"42").digest()
@pytest.fixture(scope='module')
def incorrect_hash():
return keccak.new(digest_bits=256).update(b"error").digest()
@pytest.fixture
def signatures(gen_test,signers_private_keys, hash):
signatures = ""
for i in range(len(signers_private_keys)):
signatures += gen_test.encoder("uint8", i)
key = coincurve.PrivateKey(bytes.fromhex(signers_private_keys[i]))
signature = key.sign_recoverable(hash, hasher=None)
signatures += signature.hex()
return bytes.fromhex(signatures)
def tests_rejection_on_rekey(client, portal_core, creator, vaa_verify_lsig, app_id):
with pytest.raises(AlgodHTTPError):
doubleFee = client.suggested_params()
doubleFee.flat_fee = True
doubleFee.fee = 2000
feePayment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=doubleFee
)
zeroFee = client.suggested_params()
zeroFee.flat_fee = True
zeroFee.fee = 0
noop = transaction.ApplicationCallTxn(
index=app_id,
sender=vaa_verify_lsig.address(),
sp=zeroFee,
rekey_to=get_application_address(app_id),
on_complete=transaction.OnComplete.NoOpOC
)
transaction.assign_group_id([feePayment, noop])
signedFeePayment = feePayment.sign(creator.getPrivateKey())
signedNoop = transaction.LogicSigTransaction(lsig=vaa_verify_lsig, transaction=noop)
client.send_transactions([signedFeePayment, signedNoop])
portal_core.waitForTransaction(client, signedNoop.get_txid())
def tests_rejection_on_non_app_call(client, portal_core, creator, vaa_verify_lsig):
with pytest.raises(AlgodHTTPError):
doubleFee = client.suggested_params()
doubleFee.flat_fee = True
doubleFee.fee = 2000
feePayment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=doubleFee
)
zeroFee = client.suggested_params()
zeroFee.flat_fee = True
zeroFee.fee = 0
payment = transaction.PaymentTxn(
sender=vaa_verify_lsig.address(),
receiver=vaa_verify_lsig.address(),
amt=0,
sp=zeroFee,
)
transaction.assign_group_id([feePayment, payment])
signedFeePayment = feePayment.sign(creator.getPrivateKey())
signedPayment = transaction.LogicSigTransaction(lsig=vaa_verify_lsig, transaction=payment)
client.send_transactions([signedFeePayment, signedPayment])
portal_core.waitForTransaction(client, signedPayment.get_txid())
def tests_rejection_on_zero_fee(client, portal_core, vaa_verify_lsig, app_id, signatures, hash, signers, suggested_params):
with pytest.raises(AlgodHTTPError):
noop = transaction.ApplicationCallTxn(
index=app_id,
sender=vaa_verify_lsig.address(),
sp=suggested_params,
on_complete=transaction.OnComplete.NoOpOC,
app_args=[b"nop", signatures, signers, hash]
)
signedNoop = transaction.LogicSigTransaction(lsig=vaa_verify_lsig, transaction=noop)
client.send_transaction(signedNoop)
portal_core.waitForTransaction(client, signedNoop.get_txid())
def tests_rejection_on_hash_not_signed(client, portal_core, creator, vaa_verify_lsig, app_id, signatures, incorrect_hash, signers):
with pytest.raises(AlgodHTTPError):
doubleFee = client.suggested_params()
doubleFee.flat_fee = True
doubleFee.fee = 2000
feePayment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=doubleFee
)
zeroFee = client.suggested_params()
zeroFee.flat_fee = True
zeroFee.fee = 0
noop = transaction.ApplicationCallTxn(
index=app_id,
sender=vaa_verify_lsig.address(),
sp=zeroFee,
on_complete=transaction.OnComplete.NoOpOC,
app_args=[b"nop", signatures, signers, incorrect_hash]
)
transaction.assign_group_id([feePayment, noop])
signedFeePayment = feePayment.sign(creator.getPrivateKey())
signedNoop = transaction.LogicSigTransaction(lsig=vaa_verify_lsig, transaction=noop)
client.send_transactions([signedFeePayment, signedNoop])
portal_core.waitForTransaction(client, signedNoop.get_txid())
def tests_success(client, portal_core, creator, vaa_verify_lsig, app_id, signatures, hash, signers):
doubleFee = client.suggested_params()
doubleFee.flat_fee = True
doubleFee.fee = 2000
feePayment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=doubleFee
)
zeroFee = client.suggested_params()
zeroFee.flat_fee = True
zeroFee.fee = 0
noop = transaction.ApplicationCallTxn(
index=app_id,
sender=vaa_verify_lsig.address(),
sp=zeroFee,
on_complete=transaction.OnComplete.NoOpOC,
app_args=[b"nop", signatures, signers, hash]
)
transaction.assign_group_id([feePayment, noop])
signedFeePayment = feePayment.sign(creator.getPrivateKey())
signedNoop = transaction.LogicSigTransaction(lsig=vaa_verify_lsig, transaction=noop)
client.send_transactions([signedFeePayment, signedNoop])
portal_core.waitForTransaction(client, signedNoop.get_txid())