From b24673ba7c3bca6a6082b05b76ff4325a7f18293 Mon Sep 17 00:00:00 2001 From: Arjan Zijderveld Date: Fri, 13 Nov 2020 13:45:15 +0100 Subject: [PATCH] Fixed mocked data in unit tests --- test/test_helper_functions.py | 15 +++++++++++ test/test_runtime_state.py | 48 ++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/test/test_helper_functions.py b/test/test_helper_functions.py index 3029d54..5abc32c 100644 --- a/test/test_helper_functions.py +++ b/test/test_helper_functions.py @@ -41,6 +41,21 @@ def mocked_request(method, params): "result": {"specVersion": 2023}, "id": 1 } + elif method == 'chain_getHeader': + return { + "jsonrpc": "2.0", + "result": { + "digest": { + "logs": [ + ] + }, + "extrinsicsRoot": "0xa94148d938c7b7976abf4272dca95724d7a74da2f3649ec0bd53dc3daaedda44", + "number": "0x4abaaa", + "parentHash": "0xe1781813275653a970b4260298b3858b36d38e072256dad674f7c786a0cae236", + "stateRoot": "0xb6aa468385c82d15b343a676b3488d9f141ac100fc548bb8a546f27a7241c44a" + }, + "id": 1 + } cls.substrate.rpc_request = MagicMock(side_effect=mocked_request) diff --git a/test/test_runtime_state.py b/test/test_runtime_state.py index 734427a..76d4694 100644 --- a/test/test_runtime_state.py +++ b/test/test_runtime_state.py @@ -34,18 +34,34 @@ def setUpClass(cls): def test_plaintype_call(self): def mocked_request(method, params): + if method == 'chain_getRuntimeVersion': return { "jsonrpc": "2.0", "result": {"specVersion": 2023}, "id": 1 } - if method == 'state_getStorageAt': + elif method == 'state_getStorageAt': return { "jsonrpc": "2.0", "result": '0x0800000000000000482d7c0900000000020000000100000000000000000000000000020000', "id": 1 } + elif method == 'chain_getHeader': + return { + "jsonrpc": "2.0", + "result": { + "digest": { + "logs": [ + ] + }, + "extrinsicsRoot": "0xa94148d938c7b7976abf4272dca95724d7a74da2f3649ec0bd53dc3daaedda44", + "number": "0x4abaaa", + "parentHash": "0xe1781813275653a970b4260298b3858b36d38e072256dad674f7c786a0cae236", + "stateRoot": "0xb6aa468385c82d15b343a676b3488d9f141ac100fc548bb8a546f27a7241c44a" + }, + "id": 1 + } metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v12_hex)) metadata_decoder.decode() @@ -79,6 +95,21 @@ def mocked_request(method, params): 'result': '0x00000000030000c16ff28623000000000000000000000000000000000000000000000000000000c16ff286230000000000000000000000c16ff28623000000000000000000', 'id': 1 } + elif method == 'chain_getHeader': + return { + "jsonrpc": "2.0", + "result": { + "digest": { + "logs": [ + ] + }, + "extrinsicsRoot": "0xa94148d938c7b7976abf4272dca95724d7a74da2f3649ec0bd53dc3daaedda44", + "number": "0x4abaaa", + "parentHash": "0xe1781813275653a970b4260298b3858b36d38e072256dad674f7c786a0cae236", + "stateRoot": "0xb6aa468385c82d15b343a676b3488d9f141ac100fc548bb8a546f27a7241c44a" + }, + "id": 1 + } self.substrate.rpc_request = MagicMock(side_effect=mocked_request) metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v12_hex)) @@ -121,6 +152,21 @@ def mocked_request(method, params): ], "id": 1 } + elif method == 'chain_getHeader': + return { + "jsonrpc": "2.0", + "result": { + "digest": { + "logs": [ + ] + }, + "extrinsicsRoot": "0xa94148d938c7b7976abf4272dca95724d7a74da2f3649ec0bd53dc3daaedda44", + "number": "0x4abaaa", + "parentHash": "0xe1781813275653a970b4260298b3858b36d38e072256dad674f7c786a0cae236", + "stateRoot": "0xb6aa468385c82d15b343a676b3488d9f141ac100fc548bb8a546f27a7241c44a" + }, + "id": 1 + } self.substrate.rpc_request = MagicMock(side_effect=mocked_request) metadata_decoder = MetadataDecoder(ScaleBytes(metadata_v12_hex))