forked from informalsystems/hermes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
executable file
·277 lines (196 loc) · 10.9 KB
/
run.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env python3
import argparse
import logging as l
from typing import Tuple
from pathlib import Path
import toml
import e2e.channel as channel
import e2e.client as client
import e2e.connection as connection
import e2e.packet as packet
import e2e.relayer as relayer
from e2e.cmd import Config
from e2e.common import *
def passive_packets(
c: Config,
ibc0: ChainId, ibc1: ChainId, port_id: PortId,
ibc0_channel_id: ChannelId, ibc1_channel_id: ChannelId):
# 1. create some unreceived acks
# hermes tx ft-transfer --receiver-chain ibc-1 --sender-chain ibc-0 --sender-port transfer --sender-channel channel-0 --amount 10000 --timeout-height-offset 1000 --number-msgs 2
packet.packet_send(c, src=ibc0, dst=ibc1, src_port=port_id,
src_channel=ibc0_channel_id, amount=10000, height_offset=1000, number_msgs=2)
# hermes tx ft-transfer --receiver-chain ibc-0 --sender-chain ibc-1 --sender-port transfer --sender-channel channel-1 --amount 10000 --timeout-height-offset 1000 --number-msgs 2
packet.packet_send(c, src=ibc1, dst=ibc0, src_port=port_id,
src_channel=ibc1_channel_id, amount=10000, height_offset=1000, number_msgs=2)
sleep(5.0)
# hermes tx packet-recv --receiver-chain ibc-1 --sender-chain ibc-0 --sender-port transfer --sender-channel channel-0
packet.packet_recv(c, src=ibc0, dst=ibc1,
src_port=port_id, src_channel=ibc0_channel_id)
# hermes tx packet-recv --receiver-chain ibc-0 --sender-chain ibc-1 --sender-port transfer --sender-channel channel-1
packet.packet_recv(c, src=ibc1, dst=ibc0,
src_port=port_id, src_channel=ibc1_channel_id)
# 2. create some unreceived packets
# hermes tx ft-transfer --receiver-chain ibc-0 --sender-chain ibc-1 --sender-port transfer --sender-channel channel-1 --amount 10000 --timeout-height-offset 1000 --number-msgs 3
packet.packet_send(c, src=ibc1, dst=ibc0, src_port=port_id,
src_channel=ibc1_channel_id, amount=10000, height_offset=1000, number_msgs=3)
# hermes tx ft-transfer --receiver-chain ibc-1 --sender-chain ibc-0 --sender-port transfer --sender-channel channel-0 --amount 10000 --timeout-height-offset 1000 --number-msgs 4
packet.packet_send(c, src=ibc0, dst=ibc1, src_port=port_id,
src_channel=ibc0_channel_id, amount=10000, height_offset=1000, number_msgs=4)
sleep(10.0)
# 3. verify the expected number of unreceived packets and acks on each channel end
# hermes query packet pending-sends --chain ibc-0 --port transfer --channel channel-0
unreceived = packet.query_unreceived_packets(
c, chain=ibc0, port=port_id, channel=ibc0_channel_id)
assert (len(unreceived) == 3), (unreceived, "unreceived packet mismatch")
# hermes query packet pending-acks --chain ibc-1 --port transfer --channel channel-1
unreceived = packet.query_unreceived_acks(
c, chain=ibc1, port=port_id, channel=ibc1_channel_id)
assert (len(unreceived) == 2), (unreceived, "unreceived packet mismatch")
# hermes query packet pending-sends --chain ibc-1 --port transfer --channel channel-1
unreceived = packet.query_unreceived_packets(
c, chain=ibc1, port=port_id, channel=ibc1_channel_id)
assert (len(unreceived) == 4), (unreceived, "unreceived packet mismatch")
# hermes query packet pending-acks --chain ibc-0 --port transfer --channel channel-0
unreceived = packet.query_unreceived_acks(
c, chain=ibc0, port=port_id, channel=ibc0_channel_id)
assert (len(unreceived) == 2), (unreceived, "unreceived packet mismatch")
# 4. start relaying - it should clear the unreceived packets
proc = relayer.start(c)
# 5. wait for the relayer to initialize and pick up pending packets
sleep(20.0)
# 6. verify that there are no pending packets
# hermes query packet pending-sends --chain ibc-1 --port transfer --channel channel-1
unreceived = packet.query_unreceived_packets(
c, chain=ibc1, port=port_id, channel=ibc1_channel_id)
assert (len(unreceived) == 0), (unreceived,
"unreceived packets mismatch (expected 0)")
# hermes query packet pending-acks --chain ibc-1 --port transfer --channel channel-1
unreceived = packet.query_unreceived_acks(
c, chain=ibc1, port=port_id, channel=ibc1_channel_id)
assert (len(unreceived) == 0), (unreceived,
"unreceived acks mismatch (expected 0)")
# hermes query packet pending-sends --chain ibc-0 --port transfer --channel channel-0
unreceived = packet.query_unreceived_packets(
c, chain=ibc0, port=port_id, channel=ibc0_channel_id)
assert (len(unreceived) == 0), (unreceived,
"unreceived packets mismatch (expected 0)")
# hermes query packet pending-acks --chain ibc-0 --port transfer --channel channel-0
unreceived = packet.query_unreceived_acks(
c, chain=ibc0, port=port_id, channel=ibc0_channel_id)
assert (len(unreceived) == 0), (unreceived,
"unreceived acks mismatch (expected 0)")
# 7. send some packets
# hermes tx ft-transfer --receiver-chain ibc-0 --sender-chain ibc-1 --sender-port transfer --sender-channel channel-1 --amount 10000 --timeout-height-offset 1000 --number-msgs 3
packet.packet_send(c, src=ibc1, dst=ibc0, src_port=port_id,
src_channel=ibc1_channel_id, amount=10000, height_offset=1000, number_msgs=3)
# hermes tx ft-transfer --receiver-chain ibc-1 --sender-chain ibc-0 --sender-port transfer --sender-channel channel-0 --amount 10000 --timeout-height-offset 1000 --number-msgs 4
packet.packet_send(c, src=ibc0, dst=ibc1, src_port=port_id,
src_channel=ibc0_channel_id, amount=10000, height_offset=1000, number_msgs=4)
sleep(20.0)
# 8. verify that there are no pending packets
# hermes query packet pending-sends --chain ibc-1 --port transfer --channel channel-1
unreceived = packet.query_unreceived_packets(
c, chain=ibc1, port=port_id, channel=ibc1_channel_id)
assert (len(unreceived) == 0), (unreceived,
"unreceived packets mismatch (expected 0)")
# hermes query packet pending-acks --chain ibc-1 --port transfer --channel channel-1
unreceived = packet.query_unreceived_acks(
c, chain=ibc1, port=port_id, channel=ibc1_channel_id)
assert (len(unreceived) == 0), (unreceived,
"unreceived acks mismatch (expected 0)")
# hermes query packet pending-sends --chain ibc-0 --port transfer --channel channel-0
unreceived = packet.query_unreceived_packets(
c, chain=ibc0, port=port_id, channel=ibc0_channel_id)
assert (len(unreceived) == 0), (unreceived,
"unreceived packets mismatch (expected 0)")
# hermes query packet pending-acks --chain ibc-0 --port transfer --channel channel-0
unreceived = packet.query_unreceived_acks(
c, chain=ibc0, port=port_id, channel=ibc0_channel_id)
assert (len(unreceived) == 0), (unreceived,
"unreceived acks mismatch (expected 0)")
# 9.Stop the relayer
proc.kill()
def raw(c: Config, ibc0: ChainId, ibc1: ChainId, port_id: PortId) -> Tuple[ClientId, ConnectionId, ChannelId, ClientId, ConnectionId, ChannelId]:
ibc0_client_id = client.create_update_query_client(c, ibc0, ibc1)
# Allocate first IDs on ibc-1
ibc1_client_id = client.create_update_query_client(c, ibc1, ibc0)
ibc1_conn_id = connection.conn_init(
c, ibc1, ibc0, ibc1_client_id, ibc0_client_id)
ibc1_chan_id = channel.chan_open_init(
c, dst=ibc1, src=ibc0, dst_conn=ibc1_conn_id)
ibc1_client_id = client.create_update_query_client(c, ibc1, ibc0)
split()
ibc0_conn_id, ibc1_conn_id = connection.handshake(
c, ibc0, ibc1, ibc0_client_id, ibc1_client_id)
split()
ibc0_chan_id, ibc1_chan_id = channel.handshake(
c, ibc0, ibc1, ibc0_conn_id, ibc1_conn_id, port_id)
split()
packet.ping_pong(c, ibc0, ibc1, ibc0_chan_id, ibc1_chan_id)
split()
sleep(5)
packet.timeout(c, ibc0, ibc1, ibc0_chan_id, ibc1_chan_id)
split()
# The ChannelCloseInit message is currently denied by Gaia,
# and requires a patch to be accepted.
# channel.close(c, ibc0, ibc1, ibc0_conn_id,
# ibc1_conn_id, ibc0_chan_id, ibc1_chan_id)
return ibc0_client_id, ibc0_conn_id, ibc0_chan_id, ibc1_client_id, ibc1_conn_id, ibc1_chan_id
def main():
parser = argparse.ArgumentParser(
description='Test all relayer commands, end-to-end')
parser.add_argument('-c', '--config',
help='configuration file for the relayer',
metavar='CONFIG_FILE',
required=True,
type=Path)
parser.add_argument('--cmd',
help='command to run the relayer (default: cargo run --bin hermes --)',
metavar='CMD',
default='cargo run --bin hermes --')
parser.add_argument('--log-level',
help='minimum log level (default: debug)',
metavar='LOG',
choices=['notset', 'debug', 'info',
'warning', 'error', 'critical'],
default='debug')
args = parser.parse_args()
if not args.config.exists():
print(
f'error: supplied configuration file does not exist: {args.config}')
exit(1)
config = Config(config_file=args.config, relayer_cmd=args.cmd,
log_level=args.log_level.upper())
l.basicConfig(
level=config.log_level,
format='%(asctime)s [%(levelname)8s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
chains = toml.load(config.config_file)['chains']
ibc0 = chains[0]['id']
ibc1 = chains[1]['id']
port_id = PortId('transfer')
ibc0_client_id, ibc0_conn_id, ibc0_chan_id, ibc1_client_id, ibc1_conn_id, ibc1_chan_id = raw(
config, ibc0, ibc1, port_id)
sleep(2.0)
passive_packets(config, ibc0, ibc1, port_id, ibc0_chan_id, ibc1_chan_id)
sleep(2.0)
connection.passive_connection_init_then_start(
config, ibc1, ibc0, ibc1_client_id, ibc0_client_id)
sleep(2.0)
connection.passive_connection_start_then_init(
config, ibc1, ibc0, ibc1_client_id, ibc0_client_id)
sleep(2.0)
connection.passive_connection_try_then_start(
config, ibc1, ibc0, ibc1_client_id, ibc0_client_id)
sleep(2.0)
channel.passive_channel_start_then_init(
config, ibc1, ibc0, ibc1_conn_id, port_id)
sleep(2.0)
channel.passive_channel_init_then_start(
config, ibc1, ibc0, ibc1_conn_id, port_id)
sleep(2.0)
channel.passive_channel_try_then_start(
config, ibc1, ibc0, ibc1_conn_id, ibc0_conn_id, port_id)
sleep(2.0)
if __name__ == "__main__":
main()