예제 #1
0
def test_tx_in_chainstate(monkeypatch):
    """
    test do not add transaction if it is accounted for in the 
    Chainstate
    """
    hmining.mempool.clear()
    monkeypatch.setattr(hchaindb, "get_transaction", lambda x: {"mock": "fragment"})
    syn_tx = make_synthetic_transaction()
    assert hmining.receive_transaction(syn_tx) == True
    hmining.mempool.clear()
예제 #2
0
def test_invalid_transaction(monkeypatch):
   """
   tests that an invalid transaction is not added to the mempool
   """
   monkeypatch.setattr(hchaindb, "get_transaction", lambda x: False)
   monkeypatch.setattr(tx, "validate_transaction", lambda x: False)
   hmining.mempool.clear()
   syn_tx = make_synthetic_transaction()
   assert hmining.receive_transaction(syn_tx) == False
   assert len(hmining.mempool) == 0
async def receive_transaction(trx):
    """
     receives a transaction that is propagating on the Helium network 
     """
    try:
        with hmining.semaphore:
            ret = hmining.receive_transaction(trx)
            if ret == False: return "error: invalid transaction"
        return "ok"
    except Exception as err:
        return "error: " + err
예제 #4
0
def test_tx_in_mempool(monkeypatch):
    """
    test do not add transaction to mempool if it is
    already in the mempool
    """
    hmining.mempool.clear()
    monkeypatch.setattr(tx, "validate_transaction", lambda x: True)
    monkeypatch.setattr(hchaindb, "get_transaction", lambda x: True)

    syn_tx = make_synthetic_transaction()
    hmining.mempool.append(syn_tx)
    assert hmining.receive_transaction(syn_tx) == False
    assert len(hmining.mempool) == 1
    hmining.mempool.clear()