Esempio n. 1
0
def create_basic_tx(peer_id: str, peer_auth: PeerAuthorization) -> Transaction:
    """ create basic tx data is "{args:[]}"

    :param peer_id: peer_id
    :param peer_auth:
    :return: transaction
    """
    tx = Transaction()
    tx.put_meta('peer_id', peer_id)
    tx.put_data("{args:[]}")
    tx.sign_hash(peer_auth)
    return tx
Esempio n. 2
0
def create_tx(peer_id: str, data: str, peer_auth: PeerAuthorization) -> Transaction:
    """ create basic tx data is "{args:[]}"

    :param peer_id: peer_id
    :param data: tx_data
    :param peer_auth:
    :return: transaction
    """
    tx = Transaction()
    tx.put_meta('peer_id', peer_id)
    tx.put_meta(Transaction.CHANNEL_KEY, conf.LOOPCHAIN_DEFAULT_CHANNEL)
    tx.put_data(data)
    tx.sign_hash(peer_auth)
    return tx
Esempio n. 3
0
    def test_get_meta_and_put_meta(self):
        # GIVEN
        tx = Transaction()
        tx.put_meta("peer_id", "12345")

        # WHEN
        meta_data = tx.meta
        tx.put_meta("peer_id", "ABCDE")

        # THEN
        logging.debug("tx peer_id(before): " + meta_data["peer_id"])
        logging.debug("tx peer_id(after): " + tx.meta["peer_id"])

        self.assertNotEqual(meta_data["peer_id"], tx.meta["peer_id"])
 def restore(self, tx_json: str, channel):
     tx = Transaction()
     tx.put_meta(Transaction.SEND_TX_TYPE_KEY, conf.SendTxType.icx)
     tx.put_meta(Transaction.CHANNEL_KEY, channel)
     tx.put_meta(Transaction.METHOD_KEY, self.SEND_TX)
     self.__init_icx_tx(tx_json, tx)
     return tx
Esempio n. 5
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)
Esempio n. 6
0
    def test_generate_and_validate_hash(self):
        """트랜잭션 생성시 만들어진 hash 와 검증시 비교하는 hash 가 동일한지 확인하는 테스트

        :return:
        """
        # GIVEN
        tx = Transaction()
        tx.init_meta("AAAAA", "BBBBB", "CCCCC", conf.LOOPCHAIN_DEFAULT_CHANNEL, conf.SendTxType.pickle)
        tx.put_meta("1234", "5678")
        tx.put_meta("1", "5")
        tx.put_meta("2", "5")
        tx.put_meta("3", "5")
        tx.put_meta("4", "5")
        txhash1 = tx.put_data("TEST DATA DATA")
        txtime = tx.get_timestamp()

        tx2 = Transaction()
        tx2.init_meta("AAAAA", "BBBBB", "CCCCC", conf.LOOPCHAIN_DEFAULT_CHANNEL, conf.SendTxType.pickle)
        tx2.put_meta("1234", "5678")
        tx2.put_meta("1", "5")
        tx2.put_meta("2", "5")
        tx2.put_meta("3", "5")
        tx2.put_meta("4", "5")
        txhash2 = tx2.put_data("TEST DATA DATA", txtime)

        # WHEN
        txhash1_1 = Transaction.generate_transaction_hash(tx)

        # THEN
        logging.debug("txhash1: " + str(txhash1))
        logging.debug("txhash1_1: " + str(txhash1_1))
        logging.debug("txhash2: " + str(txhash2))

        self.assertEqual(txhash1, txhash2)
        self.assertEqual(txhash1, txhash1_1)
        self.assertEqual(txhash2, txhash1_1)