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)
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
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
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
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
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()
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()
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)
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
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
def test_delete(self, local_store: Store): with pytest.raises(StateError): local_store.delete("random key")
def local_store(): return Store()
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
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
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
def test_publish(self, local_store: Store): with pytest.raises(StateError): local_store.publish("random channel", "random message")
def test_subscribe(self, local_store: Store): with pytest.raises(StateError): local_store.subscribe("random channel")
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)
def redis_store(redis_state): return Store(redis_state)
def store() -> Store: store = Store() store.add("pools", None) store.add("weth", None) return store
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()