Skip to content

Commit

Permalink
feat: add event topic test
Browse files Browse the repository at this point in the history
  • Loading branch information
platonfloria committed May 13, 2024
1 parent fc94895 commit 341c528
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fastlane_bot/events/exchanges/solidly_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..base import Exchange
from .base import SolidlyV2 as SolidlyV2Base
from .velocimeter_v2 import VelocimeterV2
from .equalizer_v2 import EqualizerV2
from .velodrome_v2 import VelodromeV2
Expand All @@ -9,7 +9,7 @@
from .xfai_v0 import XFaiV2


class SolidlyV2(Exchange):
class SolidlyV2(SolidlyV2Base):
def __new__(cls, **kwargs):
return {
"velocimeter_v2": VelocimeterV2,
Expand Down
36 changes: 36 additions & 0 deletions fastlane_bot/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

import pandas as pd

from fastlane_bot import Config
from fastlane_bot.events.managers.manager import Manager


@pytest.fixture
def config():
return Config.new(config=Config.CONFIG_MAINNET)


@pytest.fixture
def manager(config):
static_pool_data_filename = "static_pool_data"
static_pool_data = pd.read_csv(f"fastlane_bot/data/{static_pool_data_filename}.csv", low_memory=False)
uniswap_v2_event_mappings = pd.read_csv("fastlane_bot/data/uniswap_v2_event_mappings.csv", low_memory=False)

exchanges = "carbon_v1,bancor_v3,uniswap_v3,uniswap_v2,sushiswap_v2,bancor_pol,bancor_v2,balancer"
exchanges = exchanges.split(",")

alchemy_max_block_fetch = 20

tokens = pd.read_csv("fastlane_bot/data/tokens.csv", low_memory=False)

return Manager(
web3=config.w3,
w3_async=config.w3_async,
cfg=config,
pool_data=static_pool_data.to_dict(orient="records"),
SUPPORTED_EXCHANGES=exchanges,
alchemy_max_block_fetch=alchemy_max_block_fetch,
uniswap_v2_event_mappings=uniswap_v2_event_mappings,
tokens=tokens.to_dict(orient="records"),
)
50 changes: 50 additions & 0 deletions fastlane_bot/tests/test_event_topics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from fastlane_bot.events.exchanges.carbon_v1 import CarbonV1
from fastlane_bot.events.exchanges.bancor_pol import BancorPol
from fastlane_bot.events.exchanges.bancor_v2 import BancorV2
from fastlane_bot.events.exchanges.bancor_v3 import BancorV3
from fastlane_bot.events.exchanges.uniswap_v2 import UniswapV2
from fastlane_bot.events.exchanges.uniswap_v3 import UniswapV3
from fastlane_bot.events.exchanges.solidly_v2 import SolidlyV2


def test_event_topics(manager):
for exchange_name, exchange in manager.exchanges.items():
contract = manager.event_contracts[exchange_name]
for subscription in exchange.get_subscriptions(contract):
if isinstance(exchange, CarbonV1):
if subscription._event == contract.events.StrategyCreated:
assert subscription.topic == "0xff24554f8ccfe540435cfc8854831f8dcf1cf2068708cfaf46e8b52a4ccc4c8d"
elif subscription._event == contract.events.StrategyUpdated:
assert subscription.topic == "0x720da23a5c920b1d8827ec83c4d3c4d90d9419eadb0036b88cb4c2ffa91aef7d"
elif subscription._event == contract.events.StrategyDeleted:
assert subscription.topic == "0x4d5b6e0627ea711d8e9312b6ba56f50e0b51d41816fd6fd38643495ac81d38b6"
elif subscription._event == contract.events.PairTradingFeePPMUpdated:
assert subscription.topic == "0x831434d05f3ad5f63be733ea463b2933c70d2162697fd200a22b5d56f5c454b6"
elif subscription._event == contract.events.TradingFeePPMUpdated:
assert subscription.topic == "0x66db0986e1156e2e747795714bf0301c7e1c695c149a738cb01bcf5cfead8465"
elif subscription._event == contract.events.PairCreated:
assert subscription.topic == "0x6365c594f5448f79c1cc1e6f661bdbf1d16f2e8f85747e13f8e80f1fd168b7c3"
elif isinstance(exchange, BancorPol):
if subscription._event == contract.events.TokenTraded:
assert subscription.topic == "0x16ddee9b3f1b2e6f797172fe2cd10a214e749294074e075e451f95aecd0b958c"
if subscription._event == contract.events.TradingEnabled:
assert subscription.topic == "0xe695080c3c54317994bff9c7069120ba78f950937caeb98bf02d395abf2a2867"
elif isinstance(exchange, BancorV2):
if subscription._event == contract.events.TokenRateUpdate:
assert subscription.topic == "0x77f29993cf2c084e726f7e802da0719d6a0ade3e204badc7a3ffd57ecb768c24"
elif isinstance(exchange, BancorV3):
if subscription._event == contract.events.TradingLiquidityUpdated:
assert subscription.topic == "0x6e96dc5343d067ec486a9920e0304c3610ed05c65e45cc029d9b9fe7ecfa7620"
elif isinstance(exchange, UniswapV2):
if subscription._event == contract.events.Sync:
assert subscription.topic == "0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1"
elif isinstance(exchange, UniswapV3):
if subscription._event == contract.events.Swap:
assert subscription.topic == "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67"
elif isinstance(exchange, SolidlyV2):
if subscription._event == contract.events.Sync:
assert subscription.topic == "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67"
else:
print(exchange_name)
print(subscription)
assert False

0 comments on commit 341c528

Please sign in to comment.