def test_get_last_block_full_response(self, _make_id): # used valid hash and got and valid block with requests_mock.Mocker() as m: expected_request = { 'jsonrpc': '2.0', 'method': 'icx_getLastBlock', 'id': 1234, } response_json = { 'jsonrpc': '2.0', 'result': self.block, 'id': 1234 } m.post(self.matcher, json=response_json) result_dict = self.icon_service.get_block("latest", full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_keys = result_dict.keys() result_content = result_dict['result'] self.assertEqual(expected_request, actual_request) self.assertEqual(result_success_v3.keys(), result_keys) self.assertTrue(is_block(result_content))
def test_get_block(self, _make_id): with requests_mock.Mocker() as m: response_json = { "jsonrpc": "2.0", "result": { "version": "0.5", "height": int('0x13f', 16), "signature": "yO4YWy0+pM6IFad3exORZWhFD+4RLNSmhCwzIc5aJ3wfazGJH2e2sBWtGRDjiVK+xnw7SDWVUzik/aq3DmJLeQE=", "prev_block_hash": "6399543b290eef968b68f88459190a4d6aedba1a3fafcc5169dc20184d01932a", "merkle_tree_root_hash": "72bd9b1572a608e9108c285fbe7b34e3e814a1b263dd76065bd90e5b43d390f3", "time_stamp": 1612856659125677, "confirmed_transaction_list": [{ "version": "0x3", "timestamp": "0x5bae2743da5ad", "dataType": "base", "data": { "prep": { "irep": "0x21e19e0c9bab2400000", "rrep": "0x1b0", "totalDelegation": "0x105e700bc013de49eb56d3e", "value": "0x2b2609c5e9b67ee3" }, "result": { "coveredByFee": "0x228c61981e4800", "coveredByOverIssuedICX": "0x0", "issue": "0x2b037d64519836e3" } }, "txHash": "0xd92cce2a115d74544f2561db73a7b525cbb11b2cc95c0691acedfa2cd637fe44" }, { "version": "0x3", "from": self.setting['from'], "to": self.setting['to'], "value": self.setting['value'], "stepLimit": self.setting['step_limit'], "nid": self.setting['nid'], "timestamp": self.setting['nid'], "nonce": self.setting['nonce'], "signature": "gc5mS40dRlqs7qndNDhOZFDU/V6KpGAWc10zcXM4ukp1p7sCFKkMzJY0dVmzxIyE67cW8ybbcgjUa/Bp+yf0JwE=", "txHash": "0x33db06f38424207daa69c9df153649fd3913c21e162f16f4839c9c3318e44388", 'data': self.setting['data'] }], "block_hash": "1ad6d9651bc6038ff330cda87ddefecfa7674d441a4aa7de164237ad43006e22", "peer_id": "hx49ce06eab947cb5ba2475781044d305af9d8d9d5", "next_leader": "hx49ce06eab947cb5ba2475781044d305af9d8d9d5" }, "id": 1234 } m.post(self.matcher, json=response_json) result = self.icon_service.get_block(int('0x13f', 16)) self.assertTrue(is_block(result)) self.assertEqual(result["confirmed_transaction_list"][1]["data"], self.setting["data"])
def test_validate_block(self): result = self.icon_service.get_block(0) self.assertTrue(is_block(result))