Ejemplo n.º 1
0
    async def test_append(self):
        tp = TxPool()
        txes = [build_tx(i) for i in range(3)]
        for tx in txes:
            await tp.add_tx(tx)

        check_tx_pool(tp, txes)
Ejemplo n.º 2
0
    async def test_max_size(self):
        tp = TxPool(max_size=2)
        await tp.add_tx(build_tx(1))
        await tp.add_tx(build_tx(2))

        # NOTE: should this be a ValueError?
        with pytest.raises(ValueError):
            await tp.add_tx(build_tx(3))
Ejemplo n.º 3
0
    async def test_no_transition_fn(self):
        tp = TxPool()
        txes = [build_tx(i) for i in range(3)]
        for tx in txes:
            await tp.add_tx(tx)

        returned_txes = await tp.retrieve_batch()
        assert returned_txes == txes
        check_tx_pool(tp, [])
Ejemplo n.º 4
0
    async def test_omit_failing_txes(self):
        def omit_evens_transition_fn(state, tx):
            if tx.nonce % 2 is 1:
                return state
            else:
                return None

        tp = TxPool()
        for i in range(6):
            await tp.add_tx(build_tx(i))

        txes = await tp.retrieve_batch({}, omit_evens_transition_fn)
        assert txes == [build_tx(i) for i in range(6) if i % 2 is 1]
        check_tx_pool(tp, [])
Ejemplo n.º 5
0
import asyncio

from fastapi import FastAPI

# TODO: specify env variable configuration in binary or distribution
from web3.auto import w3

from acala.chain_state import ChainState, sync_chain_state
from acala.collector import Collector
from acala.tx_pool import TxPool

# NOTE: can change server based on what works for us
app = FastAPI()

chain_state = ChainState()
tx_pool = TxPool()

collector = Collector(chain_state, tx_pool)


# TODO: Remove!
@app.get('/')
async def test():
    return {'hello': 'world'}


# TODO: route for submitting a tx
# Make sure to check nonce with chain state!

# Run sync tasks
asyncio.gather(sync_chain_state(chain_state, w3), collector.start())
Ejemplo n.º 6
0
    async def test_early_nonce(self):
        tp = TxPool()
        await tp.add_tx(build_tx(2))

        with pytest.raises(ValueError):
            await tp.add_tx(build_tx(1))
Ejemplo n.º 7
0
    async def test_skipped_nonce(self):
        tp = TxPool()
        await tp.add_tx(build_tx(1))

        with pytest.raises(ValueError):
            await tp.add_tx(build_tx(3))
Ejemplo n.º 8
0
    async def test_multiple_from(self):
        tp = TxPool()
        await tp.add_tx(build_tx(1))
        await tp.add_tx(build_tx(1, from_address='0x1'))

        check_tx_pool(tp, [build_tx(1), build_tx(1, from_address='0x1')])
Ejemplo n.º 9
0
    async def test_replace(self):
        tp = TxPool()
        await tp.add_tx(build_tx(3))
        await tp.add_tx(build_tx(3, data='bar'))

        check_tx_pool(tp, [build_tx(3, data='bar')])
Ejemplo n.º 10
0
    async def test_fresh_append(self):
        tp = TxPool()
        await tp.add_tx(build_tx(3))

        check_tx_pool(tp, [build_tx(3)])
Ejemplo n.º 11
0
def test_init_tx_pool():
    tp = TxPool()

    assert dict(tp.from_address_to_last_nonce) == {}
    assert tp.txes == []