forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tmpl_sig.py
213 lines (172 loc) · 7.93 KB
/
test_tmpl_sig.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
from algosdk.encoding import decode_address
import pytest
from algosdk.future import transaction
from algosdk.logic import get_application_address
from algosdk.error import AlgodHTTPError
@pytest.fixture(scope='module')
def correct_app_id(portal_core, client, creator):
return portal_core.createTestApp(client,creator)
@pytest.fixture(scope='module')
def incorrect_app_id(portal_core, client, creator):
return portal_core.createTestApp(client,creator)
@pytest.fixture(scope='module')
def tmpl_lsig(portal_core, client, correct_app_id, creator, suggested_params):
appAddress = get_application_address(correct_app_id)
tsig = portal_core.tsig
lsig = tsig.populate(
{
"TMPL_APP_ID": correct_app_id,
"TMPL_APP_ADDRESS": decode_address(appAddress).hex(),
"TMPL_ADDR_IDX": 0,
"TMPL_EMITTER_ID": b"emitter".hex(),
}
)
txn = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=lsig.address(),
amt=1000000,
sp=suggested_params,
)
signedTxn = txn.sign(creator.getPrivateKey())
client.send_transaction(signedTxn)
portal_core.waitForTransaction(client, signedTxn.get_txid())
return lsig
def tests_rejection_on_payment(client, portal_core, tmpl_lsig, creator, suggested_params):
with pytest.raises(AlgodHTTPError):
feePayment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=suggested_params
)
feePayment.fee = 2 * feePayment.fee
payment = transaction.PaymentTxn(
sender=tmpl_lsig.address(),
receiver=tmpl_lsig.address(),
amt=0,
sp=suggested_params
)
payment.fee = 0
transaction.assign_group_id([feePayment, payment])
signedFeePayment = feePayment.sign(creator.getPrivateKey())
signedPayment = transaction.LogicSigTransaction(lsig=tmpl_lsig, transaction=payment)
client.send_transactions([signedFeePayment, signedPayment])
portal_core.waitForTransaction(client, signedPayment.get_txid())
def tests_rejection_on_asset_transfer(client, portal_core, tmpl_lsig, creator, suggested_params):
with pytest.raises(AlgodHTTPError):
fee_payment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=suggested_params
)
fee_payment.fee = 2 * fee_payment.fee
asset_transfer = transaction.AssetTransferTxn(
index=1,
sender=tmpl_lsig.address(),
receiver=tmpl_lsig.address(),
amt=0,
sp=suggested_params
)
asset_transfer.fee = 0
transaction.assign_group_id([fee_payment, asset_transfer])
signedFeePayment = fee_payment.sign(creator.getPrivateKey())
signedAssetTransfer = transaction.LogicSigTransaction(lsig=tmpl_lsig, transaction=asset_transfer)
client.send_transactions([signedFeePayment, signedAssetTransfer])
portal_core.waitForTransaction(client, signedAssetTransfer.get_txid())
def tests_rejection_on_nop(client, portal_core, tmpl_lsig, correct_app_id, creator, suggested_params):
with pytest.raises(AlgodHTTPError):
fee_payment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=suggested_params
)
fee_payment.fee = 2 * fee_payment.fee
noop = transaction.ApplicationCallTxn(
index=correct_app_id,
sender=tmpl_lsig.address(),
sp=suggested_params,
on_complete=transaction.OnComplete.NoOpOC
)
noop.fee = 0
transaction.assign_group_id([fee_payment, noop])
signedFeePayment = fee_payment.sign(creator.getPrivateKey())
signedNoop = transaction.LogicSigTransaction(lsig=tmpl_lsig, transaction=noop)
client.send_transactions([signedFeePayment, signedNoop])
portal_core.waitForTransaction(client, signedNoop.get_txid())
def tests_rejection_on_opt_in_to_incorrect_app(client, portal_core, tmpl_lsig, incorrect_app_id, creator, suggested_params):
with pytest.raises(AlgodHTTPError):
fee_payment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=suggested_params
)
fee_payment.fee = 2*fee_payment.fee
opt_in = transaction.ApplicationCallTxn(
index=incorrect_app_id,
sender=tmpl_lsig.address(),
sp=suggested_params,
on_complete=transaction.OnComplete.OptInOC
)
opt_in.fee = 0
transaction.assign_group_id([fee_payment, opt_in])
signedFeePayment = fee_payment.sign(creator.getPrivateKey())
signedOptIn = transaction.LogicSigTransaction(lsig=tmpl_lsig, transaction=opt_in)
client.send_transactions([signedFeePayment, signedOptIn])
portal_core.waitForTransaction(client, signedOptIn.get_txid())
def tests_rejection_on_opt_in_to_correct_app_without_rekeying(client, portal_core, tmpl_lsig, correct_app_id, creator, suggested_params):
with pytest.raises(AlgodHTTPError):
fee_payment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=suggested_params
)
fee_payment.fee = 2*fee_payment.fee
opt_in = transaction.ApplicationCallTxn(
index=correct_app_id,
sender=tmpl_lsig.address(),
sp=suggested_params,
on_complete=transaction.OnComplete.OptInOC
)
opt_in.fee = 0
transaction.assign_group_id([fee_payment, opt_in])
signedFeePayment = fee_payment.sign(creator.getPrivateKey())
signedOptIn = transaction.LogicSigTransaction(lsig=tmpl_lsig, transaction=opt_in)
client.send_transactions([signedFeePayment, signedOptIn])
portal_core.waitForTransaction(client, signedOptIn.get_txid())
def tests_rejection_on_opt_in_to_correct_app_with_rekeying_with_non_zero_fee(client, portal_core, tmpl_lsig, correct_app_id, suggested_params):
with pytest.raises(AlgodHTTPError):
txn = transaction.ApplicationCallTxn(
index=correct_app_id,
sender=tmpl_lsig.address(),
sp=suggested_params,
rekey_to=get_application_address(correct_app_id),
on_complete=transaction.OnComplete.NoOpOC
)
signedTxn = transaction.LogicSigTransaction(lsig=tmpl_lsig, transaction=txn)
client.send_transaction(signedTxn)
portal_core.waitForTransaction(client, signedTxn.get_txid())
def tests_success(client, portal_core, creator, tmpl_lsig, correct_app_id, suggested_params):
fee_payment = transaction.PaymentTxn(
sender=creator.getAddress(),
receiver=creator.getAddress(),
amt=0,
sp=suggested_params
)
fee_payment.fee = 2*fee_payment.fee
opt_in = transaction.ApplicationCallTxn(
index=correct_app_id,
sender=tmpl_lsig.address(),
sp=suggested_params,
rekey_to=get_application_address(correct_app_id),
on_complete=transaction.OnComplete.OptInOC
)
opt_in.fee = 0
transaction.assign_group_id([fee_payment, opt_in])
signedFeePayment = fee_payment.sign(creator.getPrivateKey())
signedOptIn = transaction.LogicSigTransaction(lsig=tmpl_lsig, transaction=opt_in)
client.send_transactions([signedFeePayment, signedOptIn])
portal_core.waitForTransaction(client, signedOptIn.get_txid())