fix: Misc fixes around byte encoding.
Also initialize TychoDB for each test case individually.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
import subprocess
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import argparse
|
||||
from .runner import TestRunner
|
||||
from runner import TestRunner
|
||||
|
||||
|
||||
def main() -> None:
|
||||
|
||||
@@ -10,6 +10,7 @@ from pathlib import Path
|
||||
|
||||
import yaml
|
||||
from protosim_py.evm.decoders import ThirdPartyPoolTychoDecoder
|
||||
from protosim_py.evm.storage import TychoDBSingleton
|
||||
from protosim_py.models import EVMBlock
|
||||
from pydantic import BaseModel
|
||||
from tycho_client.dto import (
|
||||
@@ -24,12 +25,11 @@ from tycho_client.dto import (
|
||||
Snapshot,
|
||||
)
|
||||
from tycho_client.rpc_client import TychoRPCClient
|
||||
from tycho_client.stream import TychoStream
|
||||
|
||||
from .adapter_handler import AdapterContractHandler
|
||||
from .evm import get_token_balance, get_block_header
|
||||
from .tycho import TychoRunner
|
||||
from .utils import build_snapshot_message, token_factory
|
||||
from adapter_handler import AdapterContractHandler
|
||||
from evm import get_token_balance, get_block_header
|
||||
from tycho import TychoRunner
|
||||
from utils import build_snapshot_message, token_factory
|
||||
|
||||
|
||||
class TestResult:
|
||||
@@ -109,14 +109,10 @@ class TestRunner:
|
||||
|
||||
def validate_state(self, expected_state: dict, stop_block: int) -> TestResult:
|
||||
"""Validate the current protocol state against the expected state."""
|
||||
protocol_components: list[
|
||||
ProtocolComponent
|
||||
] = self.tycho_rpc_client.get_protocol_components(
|
||||
protocol_components = self.tycho_rpc_client.get_protocol_components(
|
||||
ProtocolComponentsParams(protocol_system="test_protocol")
|
||||
)
|
||||
protocol_states: list[
|
||||
ResponseProtocolState
|
||||
] = self.tycho_rpc_client.get_protocol_state(
|
||||
protocol_states = self.tycho_rpc_client.get_protocol_state(
|
||||
ProtocolStateParams(protocol_system="test_protocol")
|
||||
)
|
||||
components_by_id = {
|
||||
@@ -175,9 +171,9 @@ class TestRunner:
|
||||
None,
|
||||
)
|
||||
if state:
|
||||
balance_hex = state.balances.get(token, "0x0")
|
||||
balance_hex = state.balances.get(token, HexBytes("0x00"))
|
||||
else:
|
||||
balance_hex = "0x0"
|
||||
balance_hex = HexBytes("0x00")
|
||||
tycho_balance = int(balance_hex)
|
||||
token_balances[comp_id][token] = tycho_balance
|
||||
|
||||
@@ -188,9 +184,9 @@ class TestRunner:
|
||||
f"Balance mismatch for {comp_id}:{token} at block {stop_block}: got {node_balance} "
|
||||
f"from rpc call and {tycho_balance} from Substreams"
|
||||
)
|
||||
contract_states: list[
|
||||
ResponseAccount
|
||||
] = self.tycho_rpc_client.get_contract_state(ContractStateParams())
|
||||
contract_states = self.tycho_rpc_client.get_contract_state(
|
||||
ContractStateParams()
|
||||
)
|
||||
filtered_components = [
|
||||
pc
|
||||
for pc in protocol_components
|
||||
@@ -227,6 +223,7 @@ class TestRunner:
|
||||
protocol_components: list[ProtocolComponent],
|
||||
contract_states: list[ResponseAccount],
|
||||
) -> dict[str, list[SimulationFailure]]:
|
||||
TychoDBSingleton.initialize()
|
||||
protocol_type_names = self.config["protocol_type_names"]
|
||||
|
||||
block_header = get_block_header(block_number)
|
||||
|
||||
@@ -4,7 +4,6 @@ import threading
|
||||
import time
|
||||
|
||||
import psycopg2
|
||||
import requests
|
||||
from psycopg2 import sql
|
||||
|
||||
import os
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from logging import getLogger
|
||||
from typing import Union
|
||||
|
||||
from protosim_py.evm.pool_state import ThirdPartyPool
|
||||
from eth_utils import to_checksum_address
|
||||
from protosim_py.models import EthereumToken
|
||||
from tycho_client.dto import (
|
||||
ResponseProtocolState,
|
||||
@@ -12,7 +12,6 @@ from tycho_client.dto import (
|
||||
HexBytes,
|
||||
TokensParams,
|
||||
PaginationParams,
|
||||
ResponseToken,
|
||||
)
|
||||
from tycho_client.rpc_client import TychoRPCClient
|
||||
|
||||
@@ -43,16 +42,18 @@ def build_snapshot_message(
|
||||
|
||||
def token_factory(rpc_client: TychoRPCClient) -> callable(HexBytes):
|
||||
_client = rpc_client
|
||||
_token_cache: dict[HexBytes, EthereumToken] = {}
|
||||
_token_cache: dict[str, EthereumToken] = {}
|
||||
|
||||
def factory(addresses: Union[HexBytes, list[HexBytes]]) -> list[EthereumToken]:
|
||||
if not isinstance(addresses, list):
|
||||
addresses = [addresses]
|
||||
def factory(requested_addresses: Union[str, list[str]]) -> list[EthereumToken]:
|
||||
if not isinstance(requested_addresses, list):
|
||||
requested_addresses = [to_checksum_address(requested_addresses)]
|
||||
else:
|
||||
requested_addresses = [to_checksum_address(a) for a in requested_addresses]
|
||||
|
||||
response = dict()
|
||||
to_fetch = []
|
||||
|
||||
for address in addresses:
|
||||
for address in requested_addresses:
|
||||
if address in _token_cache:
|
||||
response[address] = _token_cache[address]
|
||||
else:
|
||||
@@ -63,11 +64,17 @@ def token_factory(rpc_client: TychoRPCClient) -> callable(HexBytes):
|
||||
params = TokensParams(token_addresses=to_fetch, pagination=pagination)
|
||||
tokens = _client.get_tokens(params)
|
||||
for token in tokens:
|
||||
eth_token = EthereumToken(**token.dict())
|
||||
address = to_checksum_address(token.address)
|
||||
eth_token = EthereumToken(
|
||||
symbol=token.symbol,
|
||||
address=address,
|
||||
decimals=token.decimals,
|
||||
gas=token.gas,
|
||||
)
|
||||
|
||||
response[token.address] = eth_token
|
||||
_token_cache[token.address] = eth_token
|
||||
response[address] = eth_token
|
||||
_token_cache[address] = eth_token
|
||||
|
||||
return [response[address] for address in addresses]
|
||||
return [response[address] for address in requested_addresses]
|
||||
|
||||
return factory
|
||||
|
||||
Reference in New Issue
Block a user