Exemplo n.º 1
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()
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def test_create_bad_arg(self):
     config = """
     PathFinder:
         input:
             non_existing: []
     """
     with pytest.raises(ValueError):
         ActionTree.create(yaml.safe_load(config), store)
Exemplo n.º 4
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()
Exemplo n.º 5
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
Exemplo n.º 6
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)
Exemplo n.º 7
0
    async def test_dry_run(self, trade_store, trade, router, conf_dict):
        trade = ArbitrageFinder(trade).find_arbitrage_and_update_trade()

        trade_store.add(min_profit, -1)
        tree = ActionTree(trade_store)
        tree.add_action(Trader(conf_dict))
        await tree.run()
        assert trade_store.get("profit") == 0
Exemplo n.º 8
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
Exemplo n.º 9
0
    async def test_on_next(self, trade_store, trade, router: UniswapV2Router,
                           trade_conf):
        trade = ArbitrageFinder(trade).find_arbitrage_and_update_trade()
        _, gas_cost = router.swap(trade, dry_run=True)

        # min profit is set to -1 because we want to execute a bad trade
        # and see that it is reverted without costing us gas
        trade_store.add(min_profit, -1)
        tree = ActionTree(trade_store)
        tree.add_action(Trader(trade_conf))
        await tree.run()
        assert trade_store.get("profit") == pytest.approx(trade.profit -
                                                          gas_cost,
                                                          rel=1e-4)
Exemplo n.º 10
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
Exemplo n.º 11
0
    def test_create_dummy_action(self):
        config = """
        PathFinder:
        DummyAction:
        """

        tree = ActionTree.create(yaml.safe_load(config), store,
                                 [("DummyAction", DummyAction)])
        assert len(tree.actions) == 2
Exemplo n.º 12
0
    def _setup_action_tree(self, store, config):
        tree = ActionTree.create(config[Keys.actions], store)
        if Keys.event not in config:
            return tree

        events = config[Keys.event]
        if not isinstance(events, list):
            events = [events]
        for event in events:
            tree.register_event(event)
        return tree
Exemplo n.º 13
0
 def test_create_bad_action(self):
     with pytest.raises(ValueError):
         ActionTree.create({"NonExistingAction": {}}, store)
Exemplo n.º 14
0
 def test_create(self):
     tree = ActionTree.create({"PathFinder": {}}, store)
     assert len(tree.actions) == 1
Exemplo n.º 15
0
 async def test_no_profit(self, trade_store, trade_conf):
     trade_store.add(min_profit, 4)
     tree = ActionTree(trade_store)
     tree.add_action(Trader(trade_conf))
     await tree.run()
     assert trade_store.get("profit") == 0
Exemplo n.º 16
0
 async def test_setup_trader(self, trade_store, real_weth: Weth):
     tree = ActionTree(trade_store)
     tree.add_action(SetUpTrader())
     await tree.run()
     assert trade_store.get("balance_weth") == 10
     real_weth.withdraw(10)