substrate-interface 1.7.9__tar.gz → 1.7.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {substrate-interface-1.7.9/substrate_interface.egg-info → substrate-interface-1.7.11}/PKG-INFO +1 -1
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/setup.py +1 -1
- {substrate-interface-1.7.9 → substrate-interface-1.7.11/substrate_interface.egg-info}/PKG-INFO +1 -1
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrate_interface.egg-info/requires.txt +1 -1
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/contracts.py +27 -2
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_contracts.py +54 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_helper_functions.py +3 -4
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/LICENSE +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/README.md +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/setup.cfg +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrate_interface.egg-info/SOURCES.txt +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrate_interface.egg-info/dependency_links.txt +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrate_interface.egg-info/top_level.txt +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/__init__.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/base.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/constants.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/exceptions.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/extensions.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/interfaces.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/key.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/keypair.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/storage.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/__init__.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/caching.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/ecdsa_helpers.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/encrypted_json.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/hasher.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/ss58.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_block.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_create_extrinsics.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_extension_interface.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_init.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_keypair.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_query.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_query_map.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_rpc_compatibility.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_runtime_call.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_ss58.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_subscriptions.py +0 -0
- {substrate-interface-1.7.9 → substrate-interface-1.7.11}/test/test_type_registry.py +0 -0
|
@@ -90,7 +90,7 @@ class ContractMetadata:
|
|
|
90
90
|
elif 'version' in self.metadata_dict:
|
|
91
91
|
self.metadata_version = int(self.metadata_dict['version'])
|
|
92
92
|
|
|
93
|
-
if self.metadata_version is None or self.metadata_version >
|
|
93
|
+
if self.metadata_version is None or self.metadata_version > 5:
|
|
94
94
|
raise ContractMetadataParseException("Unsupported metadata version")
|
|
95
95
|
|
|
96
96
|
if 1 <= self.metadata_version <= 3:
|
|
@@ -126,6 +126,13 @@ class ContractMetadata:
|
|
|
126
126
|
for idx, c in enumerate(self.metadata_dict['spec']['constructors']):
|
|
127
127
|
c["payable"] = True
|
|
128
128
|
|
|
129
|
+
# V4 -> V5: new event fields: module_path and signature_topic
|
|
130
|
+
if self.metadata_version <= 4:
|
|
131
|
+
for idx, c in enumerate(self.metadata_dict['spec']['events']):
|
|
132
|
+
c["module_path"] = None
|
|
133
|
+
c["signature_topic"] = None
|
|
134
|
+
|
|
135
|
+
|
|
129
136
|
def __parse_metadata(self):
|
|
130
137
|
|
|
131
138
|
self.__convert_to_latest_metadata()
|
|
@@ -392,6 +399,13 @@ class ContractMetadata:
|
|
|
392
399
|
|
|
393
400
|
return self.metadata_dict['spec']['events'][event_id]
|
|
394
401
|
|
|
402
|
+
def get_event_id_by_topic(self, topic: str) -> Optional[int]:
|
|
403
|
+
for event_id, event in enumerate(self.metadata_dict['spec']['events']):
|
|
404
|
+
if topic == event['signature_topic']:
|
|
405
|
+
return event_id
|
|
406
|
+
|
|
407
|
+
# raise ValueError(f'Contract event for topic "{topic}" not found')
|
|
408
|
+
|
|
395
409
|
|
|
396
410
|
class ContractEvent(ScaleType):
|
|
397
411
|
|
|
@@ -485,9 +499,20 @@ class ContractExecutionReceipt(ExtrinsicReceipt):
|
|
|
485
499
|
|
|
486
500
|
if self.substrate.implements_scaleinfo():
|
|
487
501
|
if event.value['module_id'] == 'Contracts' and event.value['event_id'] == 'ContractEmitted' and event.value['attributes']['contract'] == self.contract_address:
|
|
502
|
+
|
|
503
|
+
contract_data = event['event'][1][1]['data'].value_object
|
|
504
|
+
|
|
505
|
+
if self.contract_metadata.metadata_version >= 5:
|
|
506
|
+
# Find corresponding contract event by event topic
|
|
507
|
+
for topic in event.value['topics']:
|
|
508
|
+
event_id = self.contract_metadata.get_event_id_by_topic(topic)
|
|
509
|
+
if event_id is not None:
|
|
510
|
+
event_bytes = self.substrate.create_scale_object("U8").encode(event_id).data
|
|
511
|
+
contract_data = event_bytes + contract_data
|
|
512
|
+
|
|
488
513
|
# Create contract event
|
|
489
514
|
contract_event_obj = ContractEvent(
|
|
490
|
-
data=ScaleBytes(
|
|
515
|
+
data=ScaleBytes(contract_data),
|
|
491
516
|
runtime_config=self.substrate.runtime_config,
|
|
492
517
|
contract_metadata=self.contract_metadata
|
|
493
518
|
)
|
|
@@ -409,5 +409,59 @@ class FlipperInstanceV4TestCase(FlipperInstanceTestCase):
|
|
|
409
409
|
)
|
|
410
410
|
|
|
411
411
|
|
|
412
|
+
class FlipperInstanceV5TestCase(FlipperInstanceTestCase):
|
|
413
|
+
|
|
414
|
+
@classmethod
|
|
415
|
+
def setUpClass(cls):
|
|
416
|
+
|
|
417
|
+
class MockedSubstrateInterface(SubstrateInterface):
|
|
418
|
+
|
|
419
|
+
def rpc_request(self, method, params, result_handler=None):
|
|
420
|
+
if method == 'state_call':
|
|
421
|
+
return {
|
|
422
|
+
'jsonrpc': '2.0',
|
|
423
|
+
'result': '0x1a987a663dbd8e5cf16786bc0100010000000000000000000000000000000000000000000008000000',
|
|
424
|
+
'id': 16
|
|
425
|
+
}
|
|
426
|
+
if method == 'contracts_call':
|
|
427
|
+
return {
|
|
428
|
+
'jsonrpc': '2.0',
|
|
429
|
+
'result': {
|
|
430
|
+
'gasConsumed': 7419127834,
|
|
431
|
+
'gasRequired': 74999922688,
|
|
432
|
+
'storageDeposit': {'charge': '0x0'},
|
|
433
|
+
'debugMessage': '',
|
|
434
|
+
'result': {'Ok': {'flags': 0, 'data': '0x0000'}}
|
|
435
|
+
},
|
|
436
|
+
'id': self.request_id}
|
|
437
|
+
|
|
438
|
+
return super().rpc_request(method, params, result_handler)
|
|
439
|
+
|
|
440
|
+
cls.substrate = MockedSubstrateInterface(
|
|
441
|
+
url=settings.KUSAMA_NODE_URL, type_registry_preset='canvas', type_registry={'types': {"ContractExecResult": "ContractExecResultTo269"}}
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
cls.keypair = Keypair.create_from_uri('//Alice')
|
|
445
|
+
|
|
446
|
+
def setUp(self) -> None:
|
|
447
|
+
self.contract = ContractInstance.create_from_address(
|
|
448
|
+
contract_address="5DaohteAvvR9PZEhynqWvbFT8HEaHNuiiPTZV61VEUHnqsfU",
|
|
449
|
+
metadata_file=os.path.join(os.path.dirname(__file__), 'fixtures', 'flipper-v5.json'),
|
|
450
|
+
substrate=self.substrate
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
def test_instance_read(self):
|
|
454
|
+
|
|
455
|
+
result = self.contract.read(self.keypair, 'get')
|
|
456
|
+
|
|
457
|
+
self.assertEqual({'Ok': False}, result.contract_result_data.value)
|
|
458
|
+
|
|
459
|
+
def test_instance_read_at_not_best_block(self):
|
|
460
|
+
parent_hash = self.substrate.get_block_header()['header']['parentHash']
|
|
461
|
+
result = self.contract.read(self.keypair, 'get', block_hash=parent_hash)
|
|
462
|
+
|
|
463
|
+
self.assertEqual({'Ok': False}, result.contract_result_data.value)
|
|
464
|
+
|
|
465
|
+
|
|
412
466
|
if __name__ == '__main__':
|
|
413
467
|
unittest.main()
|
|
@@ -292,8 +292,8 @@ class TestRPCHelperFunctions(unittest.TestCase):
|
|
|
292
292
|
if method == 'author_pendingExtrinsics':
|
|
293
293
|
return {
|
|
294
294
|
'jsonrpc': '2.0', 'result': [
|
|
295
|
-
'
|
|
296
|
-
|
|
295
|
+
'0x69028400b4c04959acdf1a7d56a3150875d489e9750a28d6bd26a113d14bfff5fecfd76601262318a56de69ac67ffaab965aad882cdbe8b71e4dae5fe0d474e6137575f0780a3f263c778af4c0e9651ff6a0a176f8f4b6cd67883028e607d43297d571a4837502240000630801000100511f0100010300a6db78f2897bc27a8d85b99cc38beefe9eaed00e010400000000076aa8bfdc190000000000',
|
|
296
|
+
],
|
|
297
297
|
'id': 17
|
|
298
298
|
}
|
|
299
299
|
|
|
@@ -304,9 +304,8 @@ class TestRPCHelperFunctions(unittest.TestCase):
|
|
|
304
304
|
def test_pending_extrinsics(self):
|
|
305
305
|
pending_extrinsics = self.substrate.retrieve_pending_extrinsics()
|
|
306
306
|
|
|
307
|
-
self.assertEqual(len(pending_extrinsics),
|
|
307
|
+
self.assertEqual(len(pending_extrinsics), 1)
|
|
308
308
|
self.assertIsInstance(pending_extrinsics[0], GenericExtrinsic)
|
|
309
|
-
self.assertIsInstance(pending_extrinsics[1], GenericExtrinsic)
|
|
310
309
|
|
|
311
310
|
|
|
312
311
|
class SS58HelperTestCase(unittest.TestCase):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrate_interface.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrate_interface.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/__init__.py
RENAMED
|
File without changes
|
{substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/caching.py
RENAMED
|
File without changes
|
{substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/ecdsa_helpers.py
RENAMED
|
File without changes
|
{substrate-interface-1.7.9 → substrate-interface-1.7.11}/substrateinterface/utils/encrypted_json.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|