def test_recover_key_step_with_tx_v3(self):
        step_cost: int = self._calc_step_cost(ScoreApiStepRatio.RECOVER_KEY)

        signature: bytes = base64.b64decode(self.tx_v3['signature'])
        self.assertIsInstance(signature, bytes)
        self.assertTrue(len(signature) > 0)

        msg_hash: bytes = create_msg_hash(self.tx_v3, ('txHash', 'signature'))
        self.assertEqual(msg_hash, bytes.fromhex(self.tx_v3['txHash']))

        uncompressed_public_key: bytes = recover_key(msg_hash, signature, compressed=False)
        self.assertIsInstance(uncompressed_public_key, bytes)
        self.assertEqual(65, len(uncompressed_public_key))
        self.assertEqual(0x04, uncompressed_public_key[0])

        step_used: int = self.context.step_counter.step_used
        self.assertEqual(step_cost, step_used)

        self.context.step_counter.reset(self.step_limit)

        compressed_public_key: bytes = recover_key(msg_hash, signature, compressed=True)
        self.assertIsInstance(compressed_public_key, bytes)
        self.assertEqual(33, len(compressed_public_key))
        self.assertIn(compressed_public_key[0], (0x02, 0x03))

        step_used: int = self.context.step_counter.step_used
        self.assertEqual(step_cost, step_used)
    def test_create_address_with_key_step_with_tx_v3(self):
        uncompressed_step_cost: int = self._calc_step_cost(ScoreApiStepRatio.CREATE_ADDRESS_WITH_UNCOMPRESSED_KEY)
        compressed_step_cost: int = self._calc_step_cost(ScoreApiStepRatio.CREATE_ADDRESS_WITH_COMPRESSED_KEY)
        self.assertTrue(uncompressed_step_cost != compressed_step_cost)

        signature: bytes = base64.b64decode(self.tx_v3['signature'])
        self.assertIsInstance(signature, bytes)
        self.assertTrue(len(signature) > 0)

        msg_hash: bytes = create_msg_hash(self.tx_v3, ('txHash', 'signature'))
        self.assertEqual(msg_hash, bytes.fromhex(self.tx_v3['txHash']))

        uncompressed_public_key: bytes = recover_key(msg_hash, signature, compressed=False)
        self.assertIsInstance(uncompressed_public_key, bytes)
        self.assertEqual(65, len(uncompressed_public_key))
        self.assertEqual(0x04, uncompressed_public_key[0])

        self.context.step_counter.reset(self.step_limit)

        address: Address = create_address_with_key(uncompressed_public_key)
        self.assertEqual(self.tx_v3['from'], str(address))

        step_used: int = self.context.step_counter.step_used
        self.assertEqual(uncompressed_step_cost, step_used)

        compressed_public_key: bytes = recover_key(msg_hash, signature, compressed=True)
        self.assertIsInstance(compressed_public_key, bytes)
        self.assertEqual(33, len(compressed_public_key))
        self.assertIn(compressed_public_key[0], (0x02, 0x03))

        self.context.step_counter.reset(self.step_limit)

        address: Address = create_address_with_key(compressed_public_key)
        self.assertEqual(self.tx_v3['from'], str(address))

        step_used: int = self.context.step_counter.step_used
        self.assertEqual(compressed_step_cost, step_used)
示例#3
0
    def xtest_create_address_with_key_step_with_tx_v3(self, context,
                                                      compressed,
                                                      expected_step_costs):
        tx_v3 = TX_V3.copy()
        signature: bytes = _base64_decode_signature(tx_v3['signature'])
        msg_hash: bytes = create_msg_hash(tx_v3, ('txHash', 'signature'))
        public_key: bytes = recover_key(msg_hash,
                                        signature,
                                        compressed=compressed)
        context.step_counter.reset(STEP_LIMIT)

        create_address_with_key(public_key)

        step_used: int = context.step_counter.step_used
        assert step_used == expected_step_costs