Пример #1
0
def tree_b(redis_store: Store):
    tree = ActionTree(redis_store)
    tree.add_action(ActionB())

    redis_store.add(b_times_ran, 0)
    yield tree
    redis_store.delete(b_times_ran)
Пример #2
0
    async def test_on_next(self, trade1, trade2):
        store = Store()
        store.add("all_trades", [trade1, trade2])
        tree = ActionTree(store)
        tree.add_action(Arbitrage())
        await tree.run()

        assert len(store.get("filtered_trades")) == 2
Пример #3
0
 def trade_store(self, w3, router, real_weth, dummy_account):
     real_weth.set_account(dummy_account)
     store = Store()
     store.add("weth", real_weth)
     store.add("web3", w3)
     store.add("account", dummy_account)
     store.add("router", router)
     return store
Пример #4
0
    async def test_subscribe_publish(self, redis_store: Store,
                                     tree_a: ActionTree, tree_b: ActionTree):
        tree_b.register_event(redis_channel)

        await asyncio.gather(tree_b.run(), tree_a.run(), wait_and_stop(tree_b))
        assert redis_store.get(b_times_ran) == 1
        assert redis_store.get(a_times_ran) == 1
        assert redis_store.get(a_result) == 1337
        assert redis_store.get(b_result) == 1338
Пример #5
0
    async def test_on_next(self, mocker: MockerFixture):
        mocker.patch.object(
            Coingecko,
            "coins",
            return_value=[
                "0xdac17f958d2ee523a2206206994597c13d831ec7",
                "0x514910771af9ca656af840dff83e8264ecf986ca",
            ],
        )
        store = Store()
        tree = ActionTree(store)
        tree.add_action(Whitelist())
        await tree.run()

        assert len(store.get("whitelist")) == 2
Пример #6
0
 async def test_on_next_no_coins(self, mocker: MockerFixture):
     mocker.patch.object(Coingecko, "coins", return_value=None)
     store = Store()
     tree = ActionTree(store)
     tree.add_action(Whitelist())
     with pytest.raises(ConnectionError):
         await tree.run()
Пример #7
0
 async def test_on_next(self, pools):
     store = Store()
     store.add("web3", MagicMock())
     store.add("all_pools", pools)
     tree = ActionTree(store)
     tree.add_action(PoolUpdater())
     with pytest.raises(ValueError):
         await tree.run()
Пример #8
0
def tree_a(redis_store: Store):
    tree = ActionTree(redis_store)
    tree.add_action(ActionA())

    redis_store.add(a_times_ran, 0)
    yield tree
    redis_store.delete(a_times_ran)
    redis_store.delete(a_result)
Пример #9
0
def store(pools, eth) -> Store:
    store = Store()
    store.add("pools", pools)
    future = asyncio.Future()
    future.set_result(eth)
    weth_mock = MagicMock()
    weth_mock.create_token.return_value = future
    store.add("eth", weth_mock)
    return store
Пример #10
0
def trade_store(w3_with_gas_strategy, router, bad_trade, trade, weth,
                trader_account):
    store = Store()
    store.add("router", router)
    store.add("filtered_trades", [bad_trade, trade])
    store.add("weth", weth)
    store.add("web3", w3_with_gas_strategy)
    store.add("account", trader_account)
    return store
Пример #11
0
 def test_delete(self, local_store: Store):
     with pytest.raises(StateError):
         local_store.delete("random key")
Пример #12
0
def local_store():
    return Store()
Пример #13
0
 async def test_subscribe(self, redis_store: Store, tree_a):
     tree_a.register_event("my_channel")
     redis_store.publish("my_channel", "new pool added")
     await asyncio.gather(tree_a.run(), wait_and_stop(tree_a))
     assert redis_store.get(a_times_ran) == 1
Пример #14
0
    def test_store_get(self, redis_state, mocker: MockerFixture):
        mock_get = mocker.patch.object(RedisState, "__getitem__")
        store = Store(redis_state)

        store[MockAction.redis_item_key]  # noqa: WPS428
        assert mock_get.called
Пример #15
0
    def test_store_add(self, redis_state, mocker: MockerFixture):
        mock_set = mocker.patch.object(RedisState, "__setitem__")
        store = Store(redis_state)

        store.add(MockAction.redis_collection_key, None)
        assert mock_set.called
Пример #16
0
 def test_publish(self, local_store: Store):
     with pytest.raises(StateError):
         local_store.publish("random channel", "random message")
Пример #17
0
 def test_subscribe(self, local_store: Store):
     with pytest.raises(StateError):
         local_store.subscribe("random channel")
Пример #18
0
import yaml

from Arbie.Actions import Action, ActionTree, Store


class DummyAction(Action):
    """
    Dummy description for dummy action.

    [Settings]
    input:
    output:
    """


store = Store()


class TestActionTree(object):
    def test_create(self):
        tree = ActionTree.create({"PathFinder": {}}, store)
        assert len(tree.actions) == 1

    def test_create_bad_arg(self):
        config = """
        PathFinder:
            input:
                non_existing: []
        """
        with pytest.raises(ValueError):
            ActionTree.create(yaml.safe_load(config), store)
Пример #19
0
def redis_store(redis_state):
    return Store(redis_state)
Пример #20
0
def store() -> Store:
    store = Store()
    store.add("pools", None)
    store.add("weth", None)
    return store
Пример #21
0
 def store(self):
     if Keys.store in self.config:
         store_config = self.config[Keys.store]
         redis_state = RedisState(store_config[Keys.address])
         return Store(redis_state)
     return Store()