Skip to content

Commit

Permalink
Add test for config validation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsereda committed Dec 18, 2024
1 parent 08acf28 commit 362854b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/dipdup/config/starknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from abc import ABC
from typing import Annotated
from typing import Literal
from typing import TypeAlias

from pydantic import AfterValidator
from pydantic import ConfigDict
Expand All @@ -17,7 +18,7 @@
from dipdup.config.starknet_subsquid import StarknetSubsquidDatasourceConfig
from dipdup.exceptions import ConfigurationError

StarknetDatasourceConfigU = StarknetSubsquidDatasourceConfig | StarknetNodeDatasourceConfig
StarknetDatasourceConfigU: TypeAlias = StarknetSubsquidDatasourceConfig | StarknetNodeDatasourceConfig

_HEX_ADDRESS_REGEXP = re.compile(r'(0x)?[0-9a-f]{1,64}', re.IGNORECASE | re.ASCII)

Expand Down
27 changes: 27 additions & 0 deletions tests/configs/demo_starknet_events.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
spec_version: 3.0
package: demo_starknet_events

datasources:
subsquid:
kind: starknet.subsquid
url: https://v2.archive.subsquid.io/network/starknet-mainnet
node:
kind: starknet.node
url: https://starknet-mainnet.g.alchemy.com/v2

contracts:
stark_usdt:
kind: starknet
address: '0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8'
typename: stark_usdt

indexes:
starknet_usdt_events:
kind: starknet.events
datasources:
- subsquid
- node
handlers:
- callback: on_transfer
contract: stark_usdt
name: Transfer
19 changes: 12 additions & 7 deletions tests/test_config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@
from dipdup.models.tezos_tzkt import TransactionSubscription
from dipdup.yaml import DipDupYAMLConfig

TEST_CONFIGS = Path(__file__).parent.parent / 'configs'


@pytest.fixture(params=list(Path.glob(TEST_CONFIGS, 'demo_*.yml')))
def demo_dipdup_config(request):
yield request.param


def create_config(merge_subs: bool = False, origs: bool = False) -> DipDupConfig:
path = Path(__file__).parent.parent / 'configs' / 'dipdup.yaml'
path = TEST_CONFIGS / 'dipdup.yaml'
config = DipDupConfig.load([path])
if origs:
config.indexes['hen_mainnet'].types += (TezosOperationType.origination,) # type: ignore
Expand Down Expand Up @@ -88,12 +95,10 @@ async def test_reserved_keywords() -> None:
)

# FIXME: Can't use `from_` field alias in dataclasses
raw_config, _ = DipDupYAMLConfig.load(
paths=[Path(__file__).parent.parent / 'configs' / 'demo_tezos_token_transfers_4.yml']
)
raw_config, _ = DipDupYAMLConfig.load(paths=[TEST_CONFIGS / 'demo_tezos_token_transfers_4.yml'])
assert raw_config['indexes']['tzbtc_holders_mainnet']['handlers'][1]['from_'] == 'tzbtc_mainnet'

config = DipDupConfig.load([Path(__file__).parent.parent / 'configs' / 'demo_tezos_token_transfers_4.yml'])
config = DipDupConfig.load([TEST_CONFIGS / 'demo_tezos_token_transfers_4.yml'])
assert config.indexes['tzbtc_holders_mainnet'].handlers[1].from_ == 'tzbtc_mainnet' # type: ignore[misc,union-attr]


Expand Down Expand Up @@ -148,5 +153,5 @@ async def test_http_config() -> None:
)


# async def test_evm() -> None:
# DipDupConfig.load([Path(__file__).parent.parent / 'configs' / 'evm_subsquid.yml'])
async def test_load_demo_config(demo_dipdup_config) -> None:
DipDupConfig.load([demo_dipdup_config])

0 comments on commit 362854b

Please sign in to comment.