Exemplo n.º 1
0
    def test_block_prevent_tx_duplication(self):
        origin_send_tx_type = conf.CHANNEL_OPTION[
            conf.LOOPCHAIN_DEFAULT_CHANNEL]["send_tx_type"]
        conf.CHANNEL_OPTION[conf.LOOPCHAIN_DEFAULT_CHANNEL][
            "send_tx_type"] = conf.SendTxType.icx
        tx_validator.refresh_tx_validators()

        try:
            block = Block(channel_name=conf.LOOPCHAIN_DEFAULT_CHANNEL)

            client = IcxWallet()
            client.to_address = 'hxebf3a409845cd09dcb5af31ed5be5e34e2af9433'
            client.value = 1

            hash_generator = get_tx_hash_generator(
                conf.LOOPCHAIN_DEFAULT_CHANNEL)
            validator = IconValidateStrategy(hash_generator)
            icx_origin = client.create_icx_origin()
            for i in range(10):
                tx = validator.restore(json.dumps(icx_origin), 'icx/score')
                block.put_transaction(tx)

            block.generate_block()
            self.assertEqual(block.confirmed_tx_len, 1)
        finally:
            conf.CHANNEL_OPTION[conf.LOOPCHAIN_DEFAULT_CHANNEL][
                "send_tx_type"] = origin_send_tx_type
            tx_validator.refresh_tx_validators()
Exemplo n.º 2
0
    def test_transaction_invalid_hash_foramt(self):
        wallet = IcxWallet()
        wallet.value = 1

        params = wallet.create_icx_origin()
        params['tx_hash'] = "12312"
        self.__test_wallet_exception(params, TransactionInvalidHashForamtError)
Exemplo n.º 3
0
    def test_transaction_invalid_wrong_nid(self):
        wallet = IcxWallet()
        wallet.value = 1
        wallet.nid = '0x5'

        ChannelProperty().nid = '0x3'

        param3 = wallet.create_icx_origin_v3()

        exception: TransactionInvalidNoNidError = self.__test_wallet_exception(param3, TransactionInvalidNoNidError)
        self.assertEqual(exception.expected_nid, ChannelProperty().nid)
        self.assertEqual(exception.nid, wallet.nid)
Exemplo n.º 4
0
    def test_transaction_invalid_hash_not_match(self):
        wallet = IcxWallet()
        wallet.value = 1

        # V3 params does not have `txHash`.
        # So it cannot raise `HashNotMatch` Exception but `AddressNotMatch`
        paramsv2 = wallet.create_icx_origin()

        time.sleep(0.1)
        paramsv2["timestamp"] = str(utils.get_now_time_stamp())

        self.__test_wallet_exception(paramsv2, TransactionInvalidHashNotMatchError)
Exemplo n.º 5
0
    def test_transacion_invalid_signature(self):
        wallet = IcxWallet()
        wallet.value = 1

        paramsv2 = wallet.create_icx_origin()

        try:
            icon_validator = IconValidateStrategy(self.hash_generator)
            icon_validator._IconValidateStrategy__validate_icx_signature(
                paramsv2['tx_hash'], "weds", paramsv2['from'])
        except TransactionInvalidSignatureError as e:
            logging.info(TransactionInvalidSignatureError.__name__)
            logging.info(e)
        else:
            raise RuntimeError(f"{TransactionInvalidSignatureError.__name__} did not raise.")
Exemplo n.º 6
0
    def test_transaction_invalid_hash_generation(self):
        wallet = IcxWallet()
        wallet.value = 1

        paramsv2 = wallet.create_icx_origin()

        # make recursion for raising an exception.
        paramsv2['recursion'] = paramsv2

        try:
            icon_validator = IconValidateStrategy(self.hash_generator)
            icon_validator._IconValidateStrategy__validate_icx_params(paramsv2, paramsv2['tx_hash'])
        except TransactionInvalidHashGenerationError as e:
            logging.info(TransactionInvalidHashGenerationError.__name__)
            logging.info(e)
        else:
            raise RuntimeError(f"{TransactionInvalidHashGenerationError.__name__} did not raise.")
Exemplo n.º 7
0
    def test_transcation_invalid_address_not_match(self):
        wallet = IcxWallet()
        wallet.value = 1

        paramsv2 = wallet.create_icx_origin()
        paramsv3 = wallet.create_icx_origin_v3()

        another_wallet = IcxWallet()

        # sign hash with another wallet's private key
        paramsv2['signature'] = another_wallet.create_signature(
            self.hash_generator.generate_hash(paramsv2))
        paramsv3['signature'] = another_wallet.create_signature(
            self.hash_generator.generate_hash(paramsv3))

        logging.info("address: " + wallet.address)
        logging.info("another addres: " + another_wallet.address)

        ChannelProperty().nid = '0x3'

        exception: TransactionInvalidAddressNotMatchError = self.__test_wallet_exception(
            paramsv2, TransactionInvalidAddressNotMatchError)
        self.assertEquals(exception.address, wallet.address)
        self.assertEquals(exception.expected_address, another_wallet.address)

        exception: TransactionInvalidAddressNotMatchError = self.__test_wallet_exception(
            paramsv3, TransactionInvalidAddressNotMatchError)
        self.assertEquals(exception.address, wallet.address)
        self.assertEquals(exception.expected_address, another_wallet.address)

        # These codes below affects hash generation.
        # V3 params does not have `txHash`.
        # So it cannot raise `HashNotMatch` Exception but `AddressNotMatch`
        paramsv3 = wallet.create_icx_origin_v3()
        paramsv3["timestamp"] = hex(utils.get_now_time_stamp())

        exception: TransactionInvalidAddressNotMatchError = self.__test_wallet_exception(
            paramsv3, TransactionInvalidAddressNotMatchError)
        self.assertEquals(exception.address, wallet.address)
Exemplo n.º 8
0
    def test_transaction_invalid_address(self):
        wallet = IcxWallet()
        wallet.value = 1
        wallet._IcxWallet__address = "hx2983"

        params = wallet.create_icx_origin()
        self.__test_wallet_exception(params, TransactionInvalidAddressError)

        params = wallet.create_icx_origin_v3()
        self.__test_wallet_exception(params, TransactionInvalidAddressError)