-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_tx_metadata.py
615 lines (510 loc) · 24.3 KB
/
test_tx_metadata.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
"""Tests for transactions with metadata."""
import json
import logging
import pathlib as pl
import allure
import cbor2
import pytest
from cardano_clusterlib import clusterlib
from cardano_node_tests.cluster_management import cluster_management
from cardano_node_tests.tests import common
from cardano_node_tests.utils import clusterlib_utils
from cardano_node_tests.utils import dbsync_utils
from cardano_node_tests.utils import helpers
from cardano_node_tests.utils import tx_view
LOGGER = logging.getLogger(__name__)
DATA_DIR = pl.Path(__file__).parent / "data"
@pytest.mark.testnets
@pytest.mark.smoke
class TestMetadata:
"""Tests for transactions with metadata."""
JSON_METADATA_FILE = DATA_DIR / "tx_metadata.json"
JSON_METADATA_WRONG_FILE = DATA_DIR / "tx_metadata_wrong.json"
JSON_METADATA_INVALID_FILE = DATA_DIR / "tx_metadata_invalid.json"
JSON_METADATA_LONG_FILE = DATA_DIR / "tx_metadata_long.json"
CBOR_METADATA_FILE = DATA_DIR / "tx_metadata.cbor"
METADATA_DUPLICATES = "tx_metadata_duplicate_keys*.json"
@pytest.fixture
def payment_addr(
self,
cluster_manager: cluster_management.ClusterManager,
cluster: clusterlib.ClusterLib,
) -> clusterlib.AddressRecord:
"""Create new payment address."""
with cluster_manager.cache_fixture() as fixture_cache:
if fixture_cache.value:
return fixture_cache.value # type: ignore
addr = clusterlib_utils.create_payment_addr_records(
f"addr_test_metadata_ci{cluster_manager.cluster_instance_num}_0",
cluster_obj=cluster,
)[0]
fixture_cache.value = addr
# fund source addresses
clusterlib_utils.fund_from_faucet(
addr,
cluster_obj=cluster,
faucet_data=cluster_manager.cache.addrs_data["user1"],
)
return addr
@allure.link(helpers.get_vcs_link())
def test_tx_wrong_json_metadata_format(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Try to build a transaction with wrong format of metadata JSON.
The metadata file is a valid JSON, but not in a format that is expected.
"""
common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_WRONG_FILE],
)
# It should NOT be possible to build a transaction using wrongly formatted metadata JSON
with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.build_raw_tx(
src_address=payment_addr.address,
tx_name="wrong_json_format",
tx_files=tx_files,
)
str_err = str(excinfo.value)
assert "The JSON metadata top level must be a map" in str_err, str_err
@allure.link(helpers.get_vcs_link())
@common.SKIPIF_BUILD_UNUSABLE
def test_build_tx_wrong_json_metadata_format(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Try to build a transaction with wrong format of metadata JSON.
Uses `cardano-cli transaction build` command for building the transactions.
The metadata file is a valid JSON, but not in a format that is expected.
"""
common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_WRONG_FILE],
)
with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.build_tx(
src_address=payment_addr.address,
tx_name="wrong_json_format",
tx_files=tx_files,
fee_buffer=1_000_000,
)
str_err = str(excinfo.value)
assert "The JSON metadata top level must be a map" in str_err, str_err
@allure.link(helpers.get_vcs_link())
def test_tx_invalid_json_metadata(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Try to build a transaction with invalid metadata JSON.
The metadata file is an invalid JSON.
"""
common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_INVALID_FILE],
)
# it should NOT be possible to build a transaction using an invalid metadata JSON
with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.build_raw_tx(
src_address=payment_addr.address,
tx_name="invalid_metadata",
tx_files=tx_files,
)
str_err = str(excinfo.value)
assert (
"Failed reading: satisfy" in str_err # cardano-node < 8.7.0
or "JSON parse error:" in str_err
), str_err
@allure.link(helpers.get_vcs_link())
@common.SKIPIF_BUILD_UNUSABLE
def test_build_tx_invalid_json_metadata(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Try to build a transaction with invalid metadata JSON.
Uses `cardano-cli transaction build` command for building the transactions.
The metadata file is an invalid JSON.
"""
common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_INVALID_FILE],
)
# it should NOT be possible to build a transaction using an invalid metadata JSON
with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.build_tx(
src_address=payment_addr.address,
tx_name="invalid_metadata",
tx_files=tx_files,
fee_buffer=1_000_000,
)
str_err = str(excinfo.value)
assert (
"Failed reading: satisfy" in str_err # cardano-node < 8.7.0
or "JSON parse error:" in str_err
), str_err
@allure.link(helpers.get_vcs_link())
def test_tx_too_long_metadata_json(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Try to build a transaction with metadata JSON longer than 64 bytes."""
common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_LONG_FILE],
)
# It should NOT be possible to build a transaction using too long metadata JSON
with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.build_raw_tx(
src_address=payment_addr.address,
tx_name="too_long_metadata",
tx_files=tx_files,
)
str_err = str(excinfo.value)
assert (
"Text string metadata value must consist of at most 64 UTF8 bytes" in str_err
), str_err
@allure.link(helpers.get_vcs_link())
@common.SKIPIF_BUILD_UNUSABLE
def test_build_tx_too_long_metadata_json(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Try to build a transaction with metadata JSON longer than 64 bytes.
Uses `cardano-cli transaction build` command for building the transactions.
"""
common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_LONG_FILE],
)
# It should NOT be possible to build a transaction using too long metadata JSON
with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_transaction.build_tx(
src_address=payment_addr.address,
tx_name="too_long_metadata",
tx_files=tx_files,
fee_buffer=1_000_000,
)
str_err = str(excinfo.value)
assert (
"Text string metadata value must consist of at most 64 UTF8 bytes" in str_err
), str_err
@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
def test_tx_metadata_json(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Send transaction with metadata JSON.
* check that the metadata in TX body matches the original metadata
* (optional) check transactions in db-sync
"""
temp_template = common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_FILE],
)
tx_raw_output = cluster.g_transaction.send_tx(
src_address=payment_addr.address, tx_name=temp_template, tx_files=tx_files
)
assert tx_raw_output.fee, "Transaction had no fee"
cbor_body_metadata = clusterlib_utils.load_tx_metadata(tx_body_file=tx_raw_output.out_file)
# dump it as JSON, so keys are converted to strings
json_body_metadata = json.loads(json.dumps(cbor_body_metadata.metadata))
with open(self.JSON_METADATA_FILE, encoding="utf-8") as metadata_fp:
json_file_metadata = json.load(metadata_fp)
assert (
json_body_metadata == json_file_metadata
), "Metadata in TX body doesn't match the original metadata"
# check TX and metadata in db-sync if available
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_raw_output)
if tx_db_record:
db_metadata = tx_db_record._convert_metadata()
assert (
db_metadata == cbor_body_metadata.metadata
), "Metadata in db-sync doesn't match the original metadata"
@allure.link(helpers.get_vcs_link())
@common.SKIPIF_BUILD_UNUSABLE
@pytest.mark.dbsync
def test_build_tx_metadata_json(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Send transaction with metadata JSON.
Uses `cardano-cli transaction build` command for building the transactions.
* check that the metadata in TX body matches the original metadata
* (optional) check transactions in db-sync
"""
temp_template = common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_FILE],
)
tx_output = cluster.g_transaction.build_tx(
src_address=payment_addr.address,
tx_name=temp_template,
tx_files=tx_files,
fee_buffer=1_000_000,
)
tx_signed = cluster.g_transaction.sign_tx(
tx_body_file=tx_output.out_file,
signing_key_files=tx_files.signing_key_files,
tx_name=temp_template,
)
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_output.txins)
cbor_body_metadata = clusterlib_utils.load_tx_metadata(tx_body_file=tx_output.out_file)
# dump it as JSON, so keys are converted to strings
json_body_metadata = json.loads(json.dumps(cbor_body_metadata.metadata))
with open(self.JSON_METADATA_FILE, encoding="utf-8") as metadata_fp:
json_file_metadata = json.load(metadata_fp)
assert (
json_body_metadata == json_file_metadata
), "Metadata in TX body doesn't match the original metadata"
# check TX and metadata in db-sync if available
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_output)
if tx_db_record:
db_metadata = tx_db_record._convert_metadata()
assert (
db_metadata == cbor_body_metadata.metadata
), "Metadata in db-sync doesn't match the original metadata"
@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
def test_tx_metadata_cbor(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Send transaction with metadata CBOR.
Check that the metadata in TX body matches the original metadata.
"""
temp_template = common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_cbor_files=[self.CBOR_METADATA_FILE],
)
tx_raw_output = cluster.g_transaction.send_tx(
src_address=payment_addr.address, tx_name=temp_template, tx_files=tx_files
)
assert tx_raw_output.fee, "Transaction had no fee"
cbor_body_metadata = clusterlib_utils.load_tx_metadata(tx_body_file=tx_raw_output.out_file)
with open(self.CBOR_METADATA_FILE, "rb") as metadata_fp:
cbor_file_metadata = cbor2.load(metadata_fp)
assert (
cbor_body_metadata.metadata == cbor_file_metadata
), "Metadata in TX body doesn't match original metadata"
# check TX and metadata in db-sync if available
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_raw_output)
if tx_db_record:
db_metadata = tx_db_record._convert_metadata()
assert (
db_metadata == cbor_file_metadata
), "Metadata in db-sync doesn't match the original metadata"
@allure.link(helpers.get_vcs_link())
@common.SKIPIF_BUILD_UNUSABLE
@pytest.mark.dbsync
def test_build_tx_metadata_cbor(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Send transaction with metadata CBOR.
Uses `cardano-cli transaction build` command for building the transactions.
Check that the metadata in TX body matches the original metadata.
"""
temp_template = common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_cbor_files=[self.CBOR_METADATA_FILE],
)
tx_output = cluster.g_transaction.build_tx(
src_address=payment_addr.address,
tx_name=temp_template,
tx_files=tx_files,
fee_buffer=1_000_000,
)
tx_signed = cluster.g_transaction.sign_tx(
tx_body_file=tx_output.out_file,
signing_key_files=tx_files.signing_key_files,
tx_name=temp_template,
)
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_output.txins)
cbor_body_metadata = clusterlib_utils.load_tx_metadata(tx_body_file=tx_output.out_file)
with open(self.CBOR_METADATA_FILE, "rb") as metadata_fp:
cbor_file_metadata = cbor2.load(metadata_fp)
assert (
cbor_body_metadata.metadata == cbor_file_metadata
), "Metadata in TX body doesn't match original metadata"
# check TX and metadata in db-sync if available
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_output)
if tx_db_record:
db_metadata = tx_db_record._convert_metadata()
assert (
db_metadata == cbor_file_metadata
), "Metadata in db-sync doesn't match the original metadata"
@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
def test_tx_metadata_both(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Send transaction with both metadata JSON and CBOR.
Check that the metadata in TX body matches the original metadata.
"""
temp_template = common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_FILE],
metadata_cbor_files=[self.CBOR_METADATA_FILE],
)
tx_raw_output = cluster.g_transaction.send_tx(
src_address=payment_addr.address, tx_name=temp_template, tx_files=tx_files
)
assert tx_raw_output.fee, "Transaction had no fee"
cbor_body_metadata = clusterlib_utils.load_tx_metadata(tx_body_file=tx_raw_output.out_file)
# dump it as JSON, so keys are converted to strings
json_body_metadata = json.loads(json.dumps(cbor_body_metadata.metadata))
with open(self.JSON_METADATA_FILE, encoding="utf-8") as metadata_fp_json:
json_file_metadata = json.load(metadata_fp_json)
with open(self.CBOR_METADATA_FILE, "rb") as metadata_fp_cbor:
cbor_file_metadata = cbor2.load(metadata_fp_cbor)
cbor_file_metadata = json.loads(json.dumps(cbor_file_metadata))
assert json_body_metadata == {
**json_file_metadata,
**cbor_file_metadata,
}, "Metadata in TX body doesn't match original metadata"
# check `transaction view` command
tx_view_out = tx_view.check_tx_view(cluster_obj=cluster, tx_raw_output=tx_raw_output)
assert json_body_metadata == tx_view_out["metadata"]
# check TX and metadata in db-sync if available
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_raw_output)
if tx_db_record:
db_metadata = tx_db_record._convert_metadata()
assert (
db_metadata == cbor_body_metadata.metadata
), "Metadata in db-sync doesn't match the original metadata"
@allure.link(helpers.get_vcs_link())
@common.SKIPIF_BUILD_UNUSABLE
@pytest.mark.dbsync
def test_build_tx_metadata_both(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Send transaction with both metadata JSON and CBOR.
Uses `cardano-cli transaction build` command for building the transactions.
Check that the metadata in TX body matches the original metadata.
"""
temp_template = common.get_test_id(cluster)
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=[self.JSON_METADATA_FILE],
metadata_cbor_files=[self.CBOR_METADATA_FILE],
)
tx_output = cluster.g_transaction.build_tx(
src_address=payment_addr.address,
tx_name=temp_template,
tx_files=tx_files,
fee_buffer=1_000_000,
)
tx_signed = cluster.g_transaction.sign_tx(
tx_body_file=tx_output.out_file,
signing_key_files=tx_files.signing_key_files,
tx_name=temp_template,
)
cluster.g_transaction.submit_tx(tx_file=tx_signed, txins=tx_output.txins)
cbor_body_metadata = clusterlib_utils.load_tx_metadata(tx_body_file=tx_output.out_file)
# dump it as JSON, so keys are converted to strings
json_body_metadata = json.loads(json.dumps(cbor_body_metadata.metadata))
with open(self.JSON_METADATA_FILE, encoding="utf-8") as metadata_fp_json:
json_file_metadata = json.load(metadata_fp_json)
with open(self.CBOR_METADATA_FILE, "rb") as metadata_fp_cbor:
cbor_file_metadata = cbor2.load(metadata_fp_cbor)
cbor_file_metadata = json.loads(json.dumps(cbor_file_metadata))
assert json_body_metadata == {
**json_file_metadata,
**cbor_file_metadata,
}, "Metadata in TX body doesn't match original metadata"
# check `transaction view` command
tx_view_out = tx_view.check_tx_view(cluster_obj=cluster, tx_raw_output=tx_output)
assert json_body_metadata == tx_view_out["metadata"]
# check TX and metadata in db-sync if available
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_output)
if tx_db_record:
db_metadata = tx_db_record._convert_metadata()
assert (
db_metadata == cbor_body_metadata.metadata
), "Metadata in db-sync doesn't match the original metadata"
@allure.link(helpers.get_vcs_link())
def test_tx_duplicate_metadata_keys(
self, cluster: clusterlib.ClusterLib, payment_addr: clusterlib.AddressRecord
):
"""Send transaction with multiple metadata JSON files and with duplicate keys.
* check that the metadata in TX body matches the original metadata
* check that in case of duplicate keys the first occurrence is used
"""
temp_template = common.get_test_id(cluster)
metadata_json_files = list(DATA_DIR.glob(self.METADATA_DUPLICATES))
tx_files = clusterlib.TxFiles(
signing_key_files=[payment_addr.skey_file],
metadata_json_files=metadata_json_files,
)
tx_raw_output = cluster.g_transaction.send_tx(
src_address=payment_addr.address, tx_name=temp_template, tx_files=tx_files
)
assert tx_raw_output.fee, "Transaction had no fee"
cbor_body_metadata = clusterlib_utils.load_tx_metadata(tx_body_file=tx_raw_output.out_file)
# dump it as JSON, so keys are converted to strings
json_body_metadata = json.loads(json.dumps(cbor_body_metadata.metadata))
# merge the input JSON files and alter the result so it matches the expected metadata
with open(metadata_json_files[0], encoding="utf-8") as metadata_fp:
json_file_metadata1 = json.load(metadata_fp)
with open(metadata_json_files[1], encoding="utf-8") as metadata_fp:
json_file_metadata2 = json.load(metadata_fp)
json_file_metadata = {**json_file_metadata2, **json_file_metadata1}
json_file_metadata["5"] = "baz1"
assert (
json_body_metadata == json_file_metadata
), "Metadata in TX body doesn't match the original metadata"
# check TX and metadata in db-sync if available
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_raw_output)
if tx_db_record:
db_metadata = tx_db_record._convert_metadata()
assert (
db_metadata == cbor_body_metadata.metadata
), "Metadata in db-sync doesn't match the original metadata"
@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
def test_tx_metadata_no_txout(
self,
cluster: clusterlib.ClusterLib,
cluster_manager: cluster_management.ClusterManager,
):
"""Send transaction with just metadata, no UTxO is produced.
* submit a transaction where all funds available on source address is used for fee
* check that no UTxOs are created by the transaction
* check that there are no funds left on source address
* check that the metadata in TX body matches the original metadata
"""
temp_template = common.get_test_id(cluster)
src_record = clusterlib_utils.create_payment_addr_records(
f"{temp_template}_0", cluster_obj=cluster
)[0]
clusterlib_utils.fund_from_faucet(
src_record,
cluster_obj=cluster,
faucet_data=cluster_manager.cache.addrs_data["user1"],
amount=2_000_000,
)
tx_files = clusterlib.TxFiles(
signing_key_files=[src_record.skey_file],
metadata_json_files=[self.JSON_METADATA_FILE],
)
fee = cluster.g_query.get_address_balance(src_record.address)
tx_raw_output = cluster.g_transaction.send_tx(
src_address=src_record.address, tx_name=temp_template, tx_files=tx_files, fee=fee
)
assert not tx_raw_output.txouts, "Transaction has unexpected txouts"
cbor_body_metadata = clusterlib_utils.load_tx_metadata(tx_body_file=tx_raw_output.out_file)
# dump it as JSON, so keys are converted to strings
json_body_metadata = json.loads(json.dumps(cbor_body_metadata.metadata))
with open(self.JSON_METADATA_FILE, encoding="utf-8") as metadata_fp:
json_file_metadata = json.load(metadata_fp)
assert (
json_body_metadata == json_file_metadata
), "Metadata in TX body doesn't match the original metadata"
# check TX and metadata in db-sync if available
tx_db_record = dbsync_utils.check_tx(cluster_obj=cluster, tx_raw_output=tx_raw_output)
if tx_db_record:
db_metadata = tx_db_record._convert_metadata()
assert (
db_metadata == cbor_body_metadata.metadata
), "Metadata in db-sync doesn't match the original metadata"