def test_send_call(self, _make_id): call_transaction_without_step_limit = CallTransactionBuilder()\ .from_(self.setting["from"])\ .to(self.setting["to"]) \ .nid(self.setting["nid"])\ .step_limit(self.setting["step_limit"])\ .nonce(self.setting["nonce"]) \ .method(self.setting["method"])\ .params(self.setting["params_call"])\ .build() signed_transaction = SignedTransaction( call_transaction_without_step_limit, self.wallet) with requests_mock.Mocker() as m: response_json = { 'jsonrpc': '2.0', 'id': 1234, 'result': '0x4bf74e6aeeb43bde5dc8d5b62537a33ac8eb7605ebbdb51b015c1881b45b3aed' } m.post(self.matcher, json=response_json) result_dict = self.icon_service.send_transaction( signed_transaction, full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_content = result_dict['result'] self.assertTrue(is_T_HASH(result_content)) self.assertEqual(result_success_v3.keys(), result_dict.keys())
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_send_deploy(self, _make_id): deploy_transaction = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_install"]) \ .params(self.setting["params_install"]) \ .build() signed_transaction = SignedTransaction(deploy_transaction, self.wallet) with requests_mock.Mocker() as m: response_json = { "jsonrpc": "2.0", "id": 1234, "result": "0x4bf74e6aeeb43bde5dc8d5b62537a33ac8eb7605ebbdb51b015c1881b45b3aed" } m.post(self.matcher, json=response_json) result_dict = self.icon_service.send_transaction( signed_transaction, full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_content = result_dict['result'] self.assertEqual(result_success_v3.keys(), result_dict.keys()) self.assertTrue(is_T_HASH(result_content))
def test_get_balance_full_response(self, _make_id): # get_balance with full_response with requests_mock.Mocker() as m: expected_request = { 'jsonrpc': '2.0', 'method': 'icx_getBalance', 'id': 1234, 'params': { 'address': self.setting['from'] } } response_json = { 'jsonrpc': '2.0', 'result': hex(self.setting['value']), 'id': 1234 } m.post(self.matcher, json=response_json) result_dict = self.icon_service.get_balance(self.setting['from'], 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.assertEqual(int(result_content, 16), self.setting['value'])
def test_send_transfer(self, _make_id): icx_transaction = TransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to"]) \ .value(self.setting["value"]) \ .step_limit(self.setting["step_limit"]) \ .nid(3) \ .nonce(self.setting["nonce"]) \ .version(3) \ .timestamp(self.setting["timestamp"]) \ .build() signed_transaction = SignedTransaction(icx_transaction, self.wallet) with requests_mock.Mocker() as m: response_json: dict = { "jsonrpc": "2.0", "result": "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238", "id": 1234 } m.post(self.matcher, json=response_json) result_dict = self.icon_service.send_transaction( signed_transaction, full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_content = result_dict['result'] self.assertTrue(is_T_HASH(result_content)) self.assertEqual(result_success_v3.keys(), result_dict.keys())
def test_add_deposit(self, _make_id): # transaction instance for add action action = "add" deposit_transaction = DepositTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to"]) \ .value(self.setting["value"]) \ .timestamp(self.setting["timestamp"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .action(action) \ .build() signed_transaction = SignedTransaction(deposit_transaction, self.wallet) with requests_mock.Mocker() as m: tx_hash = "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238" expected_request = { 'id': 1234, 'jsonrpc': '2.0', 'method': 'icx_sendTransaction', 'params': { 'data': { 'action': action }, 'dataType': 'deposit', 'from': self.setting["from"], 'nid': hex(self.setting["nid"]), 'nonce': hex(self.setting["nonce"]), 'signature': signed_transaction.signed_transaction_dict["signature"], 'stepLimit': hex(self.setting["step_limit"]), 'timestamp': hex(self.setting["timestamp"]), 'to': self.setting["to"], 'value': hex(self.setting["value"]), 'version': hex(3) } } response_json = {"jsonrpc": "2.0", "result": tx_hash, "id": 1234} m.post(self.matcher, json=response_json) result_dict = self.icon_service.send_transaction( signed_transaction, full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_content = result_dict['result'] self.assertEqual(expected_request, actual_request) self.assertEqual(result_success_v3.keys(), result_dict.keys()) self.assertTrue(is_T_HASH(result_content))
def test_get_score_api_full_response(self, _make_id): governance_address = "cx0000000000000000000000000000000000000001" with requests_mock.Mocker() as m: expected_request = { 'id': 1234, 'jsonrpc': '2.0', 'method': 'icx_getScoreApi', 'params': { 'address': governance_address } } m.post(self.matcher, json=response_governance_json) result_dict = self.icon_service.get_score_api(governance_address, full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_content = result_dict['result'] self.assertEqual(expected_request, actual_request) self.assertEqual(result_success_v3.keys(), result_dict.keys()) self.assertTrue(is_score_apis(result_content))
def test_get_total_supply(self, _make_id): with requests_mock.Mocker() as m: supply = 1_000_000_000 expected_request = { 'id': 1234, 'jsonrpc': '2.0', 'method': 'icx_getTotalSupply', } response_json = { 'jsonrpc': '2.0', 'result': hex(supply), 'id': 1234 } m.post(self.matcher, json=response_json) result_dict = self.icon_service.get_total_supply( full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_content = result_dict['result'] self.assertEqual(expected_request, actual_request) self.assertEqual(result_success_v3.keys(), result_dict.keys()) self.assertEqual(int(result_content, 16), supply)
def test_get_transaction_by_hash(self, _make_id): with requests_mock.Mocker() as m: expected_request = { 'id': 1234, 'jsonrpc': '2.0', 'method': 'icx_getTransactionByHash', 'params': { 'txHash': self.transaction_hash } } response_json = { "jsonrpc": "2.0", "result": self.transaction, "id": 1234 } m.post(self.matcher, json=response_json) result_dict = self.icon_service.get_transaction(self.transaction_hash, full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_content = result_dict['result'] self.assertEqual(expected_request, actual_request) self.assertEqual(result_success_v3.keys(), result_dict.keys()) self.assertTrue(is_transaction(result_content))