1
1
import base64
2
2
import json
3
- from enum import IntEnum
4
3
5
4
import pytest
6
5
from eth_utils import keccak
7
6
from pystarport import cluster
8
7
from web3 .datastructures import AttributeDict
9
8
10
9
from .ibc_utils import (
10
+ Status ,
11
11
funds_ica ,
12
12
gen_send_msg ,
13
13
get_next_channel ,
14
14
prepare_network ,
15
15
wait_for_check_channel_ready ,
16
16
wait_for_check_tx ,
17
+ wait_for_status_change ,
17
18
)
18
19
from .utils import (
19
20
ADDRS ,
35
36
amt = 1000
36
37
37
38
38
- class Status (IntEnum ):
39
- NONE , SUCCESS , FAIL = range (3 )
40
-
41
-
42
39
@pytest .fixture (scope = "module" )
43
40
def ibc (request , tmp_path_factory ):
44
41
"prepare-network"
@@ -76,11 +73,12 @@ def submit_msgs(
76
73
add_delegate ,
77
74
expected_seq ,
78
75
event ,
76
+ channel_id ,
79
77
timeout = no_timeout ,
80
78
amount = amt ,
81
79
need_wait = True ,
82
80
msg_num = 2 ,
83
- channel_id = "" ,
81
+ with_channel_id = True ,
84
82
):
85
83
cli_host = ibc .chainmain .cosmos_cli ()
86
84
cli_controller = ibc .cronos .cosmos_cli ()
@@ -110,7 +108,10 @@ def submit_msgs(
110
108
num_txs = len (cli_host .query_all_txs (ica_address )["txs" ])
111
109
str = base64 .b64decode (generated_packet ["data" ])
112
110
# submit transaction on host chain on behalf of interchain account
113
- tx = func (connid , str , timeout ).build_transaction (data )
111
+ if with_channel_id :
112
+ tx = func (connid , channel_id , str , timeout ).build_transaction (data )
113
+ else :
114
+ tx = func (connid , str , timeout ).build_transaction (data )
114
115
receipt = send_transaction (w3 , tx , keys )
115
116
assert receipt .status == 1
116
117
if timeout < no_timeout :
@@ -160,7 +161,8 @@ def test_call(ibc):
160
161
False ,
161
162
expected_seq ,
162
163
contract .events .SubmitMsgsResult ,
163
- channel_id = channel_id ,
164
+ channel_id ,
165
+ with_channel_id = False ,
164
166
)
165
167
balance -= diff
166
168
assert cli_host .balance (ica_address , denom = denom ) == balance
@@ -173,22 +175,13 @@ def test_call(ibc):
173
175
True ,
174
176
expected_seq ,
175
177
contract .events .SubmitMsgsResult ,
176
- channel_id = channel_id ,
178
+ channel_id ,
179
+ with_channel_id = False ,
177
180
)
178
181
balance -= diff
179
182
assert cli_host .balance (ica_address , denom = denom ) == balance
180
183
181
184
182
- def wait_for_status_change (tcontract , channel_id , seq ):
183
- print (f"wait for status change for { seq } " )
184
-
185
- def check_status ():
186
- status = tcontract .caller .getStatus (channel_id , seq )
187
- return status
188
-
189
- wait_for_fn ("current status" , check_status )
190
-
191
-
192
185
def wait_for_packet_log (start , event , channel_id , seq , status ):
193
186
print ("wait for log arrive" , seq , status )
194
187
expected = AttributeDict (
@@ -218,7 +211,7 @@ def test_sc_call(ibc):
218
211
name = "signer2"
219
212
signer = ADDRS [name ]
220
213
keys = KEYS [name ]
221
- default_gas = 400000
214
+ default_gas = 500000
222
215
data = {"from" : signer , "gas" : default_gas }
223
216
channel_id = get_next_channel (cli_controller , connid )
224
217
ica_address = register_acc (
@@ -270,7 +263,7 @@ def submit_msgs_ro(func, str):
270
263
False ,
271
264
expected_seq ,
272
265
contract .events .SubmitMsgsResult ,
273
- channel_id = channel_id ,
266
+ channel_id ,
274
267
)
275
268
submit_msgs_ro (tcontract .functions .delegateSubmitMsgs , str )
276
269
submit_msgs_ro (tcontract .functions .staticSubmitMsgs , str )
@@ -293,7 +286,7 @@ def submit_msgs_ro(func, str):
293
286
True ,
294
287
expected_seq ,
295
288
contract .events .SubmitMsgsResult ,
296
- channel_id = channel_id ,
289
+ channel_id ,
297
290
)
298
291
submit_msgs_ro (tcontract .functions .delegateSubmitMsgs , str )
299
292
submit_msgs_ro (tcontract .functions .staticSubmitMsgs , str )
@@ -317,9 +310,9 @@ def submit_msgs_ro(func, str):
317
310
False ,
318
311
expected_seq ,
319
312
contract .events .SubmitMsgsResult ,
313
+ channel_id ,
320
314
amount = 100000001 ,
321
315
need_wait = False ,
322
- channel_id = channel_id ,
323
316
)
324
317
last_seq = tcontract .caller .getLastSeq ()
325
318
wait_for_status_change (tcontract , channel_id , last_seq )
@@ -342,9 +335,9 @@ def submit_msgs_ro(func, str):
342
335
False ,
343
336
expected_seq ,
344
337
contract .events .SubmitMsgsResult ,
338
+ channel_id ,
345
339
timeout ,
346
340
msg_num = 100 ,
347
- channel_id = channel_id ,
348
341
)
349
342
last_seq = tcontract .caller .getLastSeq ()
350
343
wait_for_status_change (tcontract , channel_id , last_seq )
@@ -377,7 +370,7 @@ def submit_msgs_ro(func, str):
377
370
False ,
378
371
expected_seq ,
379
372
contract .events .SubmitMsgsResult ,
380
- channel_id = channel_id2 ,
373
+ channel_id2 ,
381
374
)
382
375
last_seq = tcontract .caller .getLastSeq ()
383
376
wait_for_status_change (tcontract , channel_id2 , last_seq )
0 commit comments