Example #1
0
 def __init__(self,
              from_epoch=None,
              to_epoch=None,
              from_block=None,
              to_block=None,
              block_hashes=None,
              address=None,
              topics=[],
              offset=None,
              limit=None,
              encode_address=True):
     if encode_address and address is not None:
         if isinstance(address, list):
             base32_address = []
             for a in address:
                 base32_address.append(hex_to_b32_address(a))
         else:
             base32_address = hex_to_b32_address(address)
         address = base32_address
     self.fromEpoch = from_epoch
     self.toEpoch = to_epoch
     self.fromBlock = from_block
     self.toBlock = to_block
     self.blockHashes = block_hashes
     self.address = address
     self.topics = topics
     self.offset = offset
     self.limit = limit
Example #2
0
    def test_tx_pending_in_pool(self):
        cur_nonce = self.get_nonce(self.GENESIS_ADDR)
        addr = hex_to_b32_address(self.GENESIS_ADDR)

        self.clear_tx_pool()

        # enter ready queue since tx.nonce = account.nonce
        tx0 = self.new_tx(nonce=cur_nonce)
        assert_equal(self.send_tx(tx0), tx0.hash_hex())

        # enter ready queue since tx0 in ready queue
        tx1 = self.new_tx(nonce=cur_nonce + 1)
        assert_equal(self.send_tx(tx1), tx1.hash_hex())

        # enter pending queue since tx2 not in ready queue
        tx3 = self.new_tx(nonce=cur_nonce + 3)
        assert_equal(self.send_tx(tx3), tx3.hash_hex())

        pending_info = self.node.cfx_getAccountPendingInfo(addr)
        assert_equal(pending_info["localNonce"], hex(cur_nonce))
        assert_equal(pending_info["pendingCount"], hex(3))
        assert_equal(pending_info["pendingNonce"], hex(cur_nonce))
        assert_equal(pending_info["nextPendingTx"], tx0.hash_hex())

        # generate a block to pack above txs.
        self.generate_blocks_to_state(num_txs=4)

        pending_info = self.node.cfx_getAccountPendingInfo(addr)
        assert_equal(pending_info["localNonce"], hex(cur_nonce + 2))
        assert_equal(pending_info["pendingCount"], hex(1))
        assert_equal(pending_info["pendingNonce"], hex(cur_nonce + 3))
        assert_equal(pending_info["nextPendingTx"], tx3.hash_hex())

        # enter the ready queue since tx1 in ready queue,
        # and also promote the tx3 into ready queue.
        tx2 = self.new_tx(nonce=cur_nonce + 2)
        assert_equal(self.send_tx(tx2), tx2.hash_hex())

        pending_info = self.node.cfx_getAccountPendingInfo(addr)
        assert_equal(pending_info["localNonce"], hex(cur_nonce + 2))
        assert_equal(pending_info["pendingCount"], hex(2))
        assert_equal(pending_info["pendingNonce"], hex(cur_nonce + 2))
        assert_equal(pending_info["nextPendingTx"], tx2.hash_hex())

        # generate a block to pack above txs.
        self.generate_blocks_to_state(num_txs=4)

        pending_info = self.node.cfx_getAccountPendingInfo(addr)
        assert_equal(pending_info["localNonce"], hex(cur_nonce + 4))
        assert_equal(pending_info["pendingCount"], hex(0))
        assert_equal(pending_info["pendingNonce"], hex(0))
        assert_equal(
            pending_info["nextPendingTx"],
            "0x0000000000000000000000000000000000000000000000000000000000000000"
        )

        self.generate_blocks_to_state(num_txs=4)
        for tx in [tx0, tx1, tx2, tx3]:
            assert_equal(
                self.get_transaction_receipt(tx.hash_hex()) is None, False)
Example #3
0
 def __init__(self, from_epoch="earliest", to_epoch="latest_state", block_hashes = None, address = None, topics = [],
              limit = None, encode_address=True):
     if encode_address and address is not None:
         if isinstance(address, list):
             base32_address = []
             for a in address:
                 base32_address.append(hex_to_b32_address(a))
         else:
             base32_address = hex_to_b32_address(address)
         address = base32_address
     self.fromEpoch = from_epoch
     self.toEpoch = to_epoch
     self.blockHashes = block_hashes
     self.address = address
     self.topics = topics
     self.limit = limit
Example #4
0
    def test_tx_pending_in_pool(self):
        cur_nonce = self.get_nonce(self.GENESIS_ADDR)
        addr = hex_to_b32_address(self.GENESIS_ADDR)

        self.clear_tx_pool()

        # enter ready queue since tx.nonce = account.nonce
        tx0 = self.new_tx(nonce=cur_nonce)
        assert_equal(self.send_tx(tx0), tx0.hash_hex())

        # enter ready queue since tx0 in ready queue
        tx1 = self.new_tx(nonce=cur_nonce + 1)
        assert_equal(self.send_tx(tx1), tx1.hash_hex())

        # enter pending queue since tx2 not in ready queue
        tx3 = self.new_tx(nonce=cur_nonce + 3)
        assert_equal(self.send_tx(tx3), tx3.hash_hex())

        pending_info = self.node.cfx_getAccountPendingInfo(addr)
        assert_equal(pending_info["localNonce"], hex(cur_nonce))
        assert_equal(pending_info["pendingCount"], hex(3))
        assert_equal(pending_info["pendingNonce"], hex(cur_nonce))
        assert_equal(pending_info["nextPendingTx"], tx0.hash_hex())

        r = self.node.cfx_getAccountPendingTransactions(addr)
        pending_txs = r["pendingTransactions"]
        tx_status = r["firstTxStatus"]
        assert_equal(len(pending_txs), 3)
        assert_equal(tx_status, "ready")

        # generate a block to pack above txs.
        self.generate_blocks_to_state(num_txs=4)

        pending_info = self.node.cfx_getAccountPendingInfo(addr)
        assert_equal(pending_info["localNonce"], hex(cur_nonce + 2))
        assert_equal(pending_info["pendingCount"], hex(1))
        assert_equal(pending_info["pendingNonce"], hex(cur_nonce + 3))
        assert_equal(pending_info["nextPendingTx"], tx3.hash_hex())

        r = self.node.cfx_getAccountPendingTransactions(addr)
        pending_txs = r["pendingTransactions"]
        tx_status = r["firstTxStatus"]
        assert_equal(len(pending_txs), 1)
        assert_equal(tx_status, {'pending': 'futureNonce'})

        # enter the ready queue since tx1 in ready queue,
        # and also promote the tx3 into ready queue.
        tx2 = self.new_tx(nonce=cur_nonce + 2)
        assert_equal(self.send_tx(tx2), tx2.hash_hex())

        pending_info = self.node.cfx_getAccountPendingInfo(addr)
        assert_equal(pending_info["localNonce"], hex(cur_nonce + 2))
        assert_equal(pending_info["pendingCount"], hex(2))
        assert_equal(pending_info["pendingNonce"], hex(cur_nonce + 2))
        assert_equal(pending_info["nextPendingTx"], tx2.hash_hex())

        # generate a block to pack above txs.
        self.generate_blocks_to_state(num_txs=4)

        pending_info = self.node.cfx_getAccountPendingInfo(addr)
        assert_equal(pending_info["localNonce"], hex(cur_nonce + 4))
        assert_equal(pending_info["pendingCount"], hex(0))
        assert_equal(pending_info["pendingNonce"], hex(0))
        assert_equal(
            pending_info["nextPendingTx"],
            "0x0000000000000000000000000000000000000000000000000000000000000000"
        )

        self.generate_blocks_to_state(num_txs=4)
        for tx in [tx0, tx1, tx2, tx3]:
            assert_equal(
                self.get_transaction_receipt(tx.hash_hex()) is None, False)

        tx4 = self.new_tx(nonce=cur_nonce + 4,
                          value=default_config["TOTAL_COIN"])
        assert_equal(self.send_tx(tx4), tx4.hash_hex())
        r = self.node.cfx_getAccountPendingTransactions(addr)
        r2 = self.node.cfx_getAccountPendingTransactions(addr, "0x0")
        assert_equal(r, r2)
        pending_txs = r["pendingTransactions"]
        tx_status = r["firstTxStatus"]
        assert_equal(len(pending_txs), 1)
        assert_equal(tx_status, {'pending': 'notEnoughCash'})
Example #5
0
from conflux.address import hex_to_b32_address, b32_address_to_hex

print(hex_to_b32_address("F5BF48B397DAE70BE82B3CCA4793F8EB2B6CDAC9") == "cfx:ad458wfxw9rssc9jfp8pyv6x9dzw05g43eaexucerd")
print(b32_address_to_hex("cfx:ad458wfxw9rssc9jfp8pyv6x9dzw05g43eaexucerd") == "F5BF48B397DAE70BE82B3CCA4793F8EB2B6CDAC9".lower())