def _status(self, tx_digest): url = '{}://{}:{}/api/status/tx/{}'.format(self.protocol, self.host, self.port, tx_digest) response = self._session.get(url).json() return TxStatus(digest=decode_hex_or_b64(response['tx']), status=str(response['status']), exit_code=int(response['exit_code']), charge=int(response['charge']), charge_rate=int(response['charge_rate']), fee=int(response['fee']))
def test_empty(self): self.assertEqual(decode_hex_or_b64(''), b'') self.assertEqual(decode_hex_or_b64(b''), b'')
def test_0x(self): self.assertEqual(decode_hex_or_b64('0x'), b'\xd3') self.assertEqual(decode_hex_or_b64(b'0x'), b'\xd3')
def test_unpadded_base64(self): self.assertEqual(decode_hex_or_b64('YWJjZDEyMzQ'), b'abcd1234') self.assertEqual(decode_hex_or_b64(b'YWJjZDEyMzQ'), b'abcd1234')
def test_prefixed_hex(self): self.assertEqual(decode_hex_or_b64('0xdeadbeef'), b'\xde\xad\xbe\xef') self.assertEqual(decode_hex_or_b64(b'0xdeadbeef'), b'\xde\xad\xbe\xef')
def test_invalid_decode_type(self): with self.assertRaises(TypeError): decode_hex_or_b64(4)