Beispiel #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()
Beispiel #2
0
    def generate_block(self):
        """임시 블럭 생성하는 메소드

        :return: 임시 블럭
        """
        block = Block(channel_name=conf.LOOPCHAIN_DEFAULT_CHANNEL)
        for x in range(10):
            tx = test_util.create_basic_tx(self.__peer_id, self.__peer_auth)
            block.put_transaction(tx)
        block.generate_block(self.chain.last_block)
        return block
Beispiel #3
0
    def generate_block(self):
        """
        임시 블럭 생성하는 메소드
        :return: 임시 블럭
        """

        block = Block()
        for x in range(10):
            tx = Transaction()
            tx.put_data("{args:[]}")
            block.put_transaction(tx)
        block.generate_block(self.chain.last_block)
        return block
Beispiel #4
0
 def test_put_transaction(self):
     """
     Block 에 여러 개 transaction 들을 넣는 것을 test.
     """
     block = Block(channel_name=conf.LOOPCHAIN_DEFAULT_CHANNEL)
     tx_list = []
     tx_size = 10
     for x in range(0, tx_size):
         tx = test_util.create_basic_tx(self.__peer_id, self.peer_auth)
         tx2 = test_util.create_basic_tx(self.__peer_id, self.peer_auth)
         tx_list.append(tx2)
         self.assertNotEqual(tx.tx_hash, "", "트랜잭션 생성 실패")
         self.assertTrue(block.put_transaction(tx), "Block에 트랜잭션 추가 실패")
     self.assertTrue(block.put_transaction(tx_list), "Block에 여러 트랜잭션 추가 실패")
     self.assertEqual(block.confirmed_tx_len, tx_size * 2, "트랜잭션 사이즈 확인 실패")
Beispiel #5
0
    def __add_single_tx_block_blockchain_return_tx(self):
        last_block = self.chain.last_block
        block = Block(channel_name=conf.LOOPCHAIN_DEFAULT_CHANNEL)
        tx = test_util.create_basic_tx(self.__peer_id, self.peer_auth)
        block.put_transaction(tx)

        logging.debug("tx_hash: " + tx.tx_hash)

        block.generate_block(last_block)
        block.block_status = BlockStatus.confirmed

        # add_block to blockchain
        self.assertTrue(self.chain.add_block(block),
                        "Fail Add Block to BlockChain")
        return tx
Beispiel #6
0
    def __generate_block_data(self) -> Block:
        """ block data generate
        :return: unsigned block
        """
        genesis = Block(channel_name="test_channel")
        genesis.generate_block()
        # Block 생성
        block = Block(channel_name=conf.LOOPCHAIN_DEFAULT_CHANNEL)
        # Transaction(s) 추가
        for x in range(0, 10):
            block.put_transaction(
                test_util.create_basic_tx(self.__peer_id, self.__peer_auth))

        # Hash 생성 이 작업까지 끝내고 나서 Block을 peer에 보낸다
        block.generate_block(genesis)
        return block
Beispiel #7
0
 def test_put_transaction(self):
     """
     Block 에 여러 개 transaction 들을 넣는 것을 test.
     """
     block = Block()
     tx_list = []
     tx_size = 10
     for x in range(0, tx_size):
         tx = Transaction()
         tx2 = Transaction()
         hashed_value = tx.put_data("{args:[]}")
         tx2.put_data("{args:[]}")
         tx_list.append(tx2)
         self.assertNotEqual(hashed_value, "", "트랜잭션 생성 실패")
         self.assertTrue(block.put_transaction(tx), "Block에 트랜잭션 추가 실패")
     self.assertTrue(block.put_transaction(tx_list), "Block에 여러 트랜잭션 추가 실패")
     self.assertEqual(len(block.confirmed_transaction_list), tx_size * 2,
                      "트랜잭션 사이즈 확인 실패")
Beispiel #8
0
    def generate_block(self):
        """
        블럭 생성기
        :return: 임의생성블럭
        """
        genesis = Block()
        genesis.generate_block()
        # Block 생성
        block = Block()
        # Transaction(s) 추가
        for x in range(0, 10):
            tx = Transaction()
            tx.put_data("{args:[]}")
            block.put_transaction(tx)

        # Hash 생성 이 작업까지 끝내고 나서 Block을 peer에 보낸다
        block.generate_block(genesis)
        return block
Beispiel #9
0
    def generate_test_block(self):
        """
        임시 블럭 생성하는 메소드
        :return: 임시 블럭
        """

        block = Block(channel_name=conf.LOOPCHAIN_DEFAULT_CHANNEL)
        for x in range(0, 10):
            tx = test_util.create_basic_tx(self.__peer_id, self.peer_auth)
            self.assertNotEqual(tx.tx_hash, "", "트랜잭션 생성 실패")
            self.assertTrue(block.put_transaction(tx), "Block에 트랜잭션 추가 실패")

        return block
Beispiel #10
0
    def generate_test_block(self):
        """
        임시 블럭 생성하는 메소드
        :return: 임시 블럭
        """

        block = Block()
        for x in range(0, 10):
            tx = Transaction()
            hashed_value = tx.put_data("{args:[]}")
            self.assertNotEqual(hashed_value, "", "트랜잭션 생성 실패")
            self.assertTrue(block.put_transaction(tx), "Block에 트랜잭션 추가 실패")

        return block
Beispiel #11
0
 def test_block_rebuild(self):
     """ GIVEN 1Block with 3tx, and conf remove failed tx when in block
     WHEN Block call verify_through_score_invoke
     THEN all order 3tx must removed in block
     """
     block = Block(conf.LOOPCHAIN_DEFAULT_CHANNEL)
     fail_tx_hash = None
     for i in range(3):
         tx = Transaction()
         tx.put_meta(Transaction.CHANNEL_KEY,
                     conf.LOOPCHAIN_DEFAULT_CHANNEL)
         tx.put_data("aaaaa")
         tx.sign_hash(self.peer_auth)
         block.put_transaction(tx)
         if i == 2:
             fail_tx_hash = tx.tx_hash
     verify, need_rebuild, invoke_results = block.verify_through_score_invoke(
         True)
     self.assertTrue(need_rebuild)
     logging.debug(f"fail tx hash : {fail_tx_hash}")
     self.assertEqual(block.confirmed_tx_len, 2)
     for i, tx in enumerate(block.confirmed_transaction_list):
         self.assertNotEqual(i, 2, "index 2 must be deleted")
         self.assertNotEqual(tx.tx_hash, fail_tx_hash)
Beispiel #12
0
    def __add_single_tx_to_block_return_tx_with_test(self):
        last_block = self.chain.last_block
        block = Block()
        tx = Transaction()
        hashed_value = tx.put_data("1234")
        self.assertNotEqual(hashed_value, "", "트랜잭션 생성 실패")
        self.assertTrue(block.put_transaction(tx), "Block에 트랜잭션 추가 실패")

        logging.debug("tx_hash: " + tx.get_tx_hash())

        block.generate_block(last_block)
        block.block_status = BlockStatus.confirmed
        # add_block include __add_tx_to_block_db what we want to test
        self.assertTrue(self.chain.add_block(block),
                        "Fail Add Block to BlockChain in test_add_tx_to_block_db")
        return tx