Conditions | 1 |
Total Lines | 64 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | from tradehub.decentralized_client import NetworkCrawlerClient |
||
43 | def test_parse_validator_status(self): |
||
44 | expect: dict = { |
||
45 | 'moniker': str, |
||
46 | 'id': str, |
||
47 | 'ip': str, |
||
48 | 'version': str, |
||
49 | 'network': str, |
||
50 | 'latest_block_hash': str, |
||
51 | 'latest_block_height': str, |
||
52 | 'latest_block_time': str, |
||
53 | 'earliest_block_height': str, |
||
54 | 'earliest_block_time': str, |
||
55 | 'catching_up': bool, |
||
56 | 'validator_address': str, |
||
57 | 'validator_pub_key_type': str, |
||
58 | 'validator_pub_key': str, |
||
59 | 'validator_voting_power': str, |
||
60 | } |
||
61 | |||
62 | validator_status_json: dict = { |
||
63 | 'jsonrpc': '2.0', |
||
64 | 'id': -1, |
||
65 | 'result': { |
||
66 | 'node_info': { |
||
67 | 'protocol_version': { |
||
68 | 'p2p': '7', |
||
69 | 'block': '10', |
||
70 | 'app': '0' |
||
71 | }, |
||
72 | 'id': '756dece3e0a00705c61a7de701f78f51f5e9a91b', |
||
73 | 'listen_addr': 'tcp://0.0.0.0:26656', |
||
74 | 'network': 'switcheo-tradehub-1', |
||
75 | 'version': '0.33.7', |
||
76 | 'channels': '4020212223303800', |
||
77 | 'moniker': 'pike', |
||
78 | 'other': { |
||
79 | 'tx_index': 'on', |
||
80 | 'rpc_address': 'tcp://0.0.0.0:26659' |
||
81 | } |
||
82 | }, |
||
83 | 'sync_info': { |
||
84 | 'latest_block_hash': '3E385BDDF88024B1767BC5E19D4C4F92122FDF16BF93702CCACBD5D1E2299252', |
||
85 | 'latest_app_hash': '0470CC9EA15482ECB5D497A6D70EF9C1181B649244AB589D8858941FB65EC7FB', |
||
86 | 'latest_block_height': '7559634', |
||
87 | 'latest_block_time': '2021-02-16T07:25:24.602077456Z', |
||
88 | 'earliest_block_hash': 'B4AF1F3D3D3FD5795BDDB7A6A2E6CA4E34D06338505D6EC46DD8F99E72ADCDAB', |
||
89 | 'earliest_app_hash': '', |
||
90 | 'earliest_block_height': '1', |
||
91 | 'earliest_block_time': '2020-08-14T07:32:27.856700491Z', |
||
92 | 'catching_up': False |
||
93 | }, |
||
94 | 'validator_info': { |
||
95 | 'address': 'A84B0CB22673DCBCEC8C9EB0A2E83AAC8DE297A2', |
||
96 | 'pub_key': { |
||
97 | 'type': 'tendermint/PubKeyEd25519', |
||
98 | 'value': 'qjqeC/G3OABg7RVbtGDOAS0nWAy3AheJaI7s7OPb5o0=' |
||
99 | }, |
||
100 | 'voting_power': '0' |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | |||
105 | result = self.tradehub_client.parse_validator_status(request_json=validator_status_json, validator_ip=self.tradehub_client.active_sentry_api_ip) |
||
106 | self.assertDictStructure(expect, result) |
||
107 | |||
164 |