Skip to content

Commit

Permalink
Fixed mocked data in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Zijderveld committed Nov 13, 2020
1 parent a850826 commit b24673b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/test_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
48 changes: 47 additions & 1 deletion test/test_runtime_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit b24673b

Please sign in to comment.