Add Balancer test, move requests to RPC Client class

This commit is contained in:
Thales Lima
2024-07-22 03:47:58 +02:00
committed by tvinagre
parent 3ccf0a8a1f
commit 19bf222e8e
3 changed files with 61 additions and 34 deletions

View File

@@ -0,0 +1,24 @@
substreams_yaml_path: ./substreams.yaml
protocol_type_names:
- "pool"
adapter_contract: "BalancerSwapAdapter.evm.runtime"
skip_balance_check: true
tests:
# WeightedPoolFactory
- name: test_weighted_pool_creation
start_block: 16878326
stop_block: 16971020
expected_state:
protocol_components:
- id: "0x8055b8C947De30130BC1Ec750C8F345a50006B23"
tokens:
- "0xba100000625a3754423978a60c9317c58a424e3D"
- "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
static_attributes:
creation_tx: "0x3ae08d6ff86737a64827855af810f7ee9ee208ff8e6d8c916495d09a83282c8a"
- id: "0xDac7eF49161bdBf0e8f0B4c8e2D38DF19D972874"
tokens:
- "0x9A62fB1CAFEa99f8f0441f80af7F7ccf0d46847D"
- "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
static_attributes:
creation_tx: "0xbed0c745c3761cd54a7489181a5f1165c628c35ef69ecb0bfeec08f09f0ec407"

View File

@@ -14,7 +14,7 @@ from tycho_client.models import Blockchain, EVMBlock
from tycho_client.tycho_adapter import TychoPoolStateStreamAdapter
from evm import get_token_balance, get_block_header
from tycho import TychoRunner
from tycho import TychoRunner, TychoRPCClient
class TestResult:
@@ -49,6 +49,7 @@ class TestRunner:
self.config = load_config(config_path)
self.base_dir = os.path.dirname(config_path)
self.tycho_runner = TychoRunner(with_binary_logs)
self.tycho_rpc_client = TychoRPCClient()
self.db_url = db_url
self._chain = Blockchain.ethereum
@@ -82,8 +83,8 @@ class TestRunner:
def validate_state(self, expected_state: dict, stop_block: int) -> TestResult:
"""Validate the current protocol state against the expected state."""
protocol_components = self.tycho_runner.get_protocol_components()
protocol_states = self.tycho_runner.get_protocol_state()
protocol_components = self.tycho_rpc_client.get_protocol_components()
protocol_states = self.tycho_rpc_client.get_protocol_state()
components = {
component["id"]: component
for component in protocol_components["protocol_components"]
@@ -142,7 +143,7 @@ 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 = self.tycho_runner.get_contract_state()
contract_states = self.tycho_rpc_client.get_contract_state()
simulation_failures = self.simulate_get_amount_out(
token_balances,
stop_block,

View File

@@ -26,6 +26,38 @@ def get_binary_path():
binary_path = get_binary_path()
class TychoRPCClient:
def __init__(self, rpc_url: str = "http://0.0.0.0:4242"):
self.rpc_url = rpc_url
def get_protocol_components(self) -> dict:
"""Retrieve protocol components from the RPC server."""
url = self.rpc_url + "/v1/ethereum/protocol_components"
headers = {"accept": "application/json", "Content-Type": "application/json"}
data = {"protocol_system": "test_protocol"}
response = requests.post(url, headers=headers, json=data)
return response.json()
def get_protocol_state(self) -> dict:
"""Retrieve protocol state from the RPC server."""
url = self.rpc_url + "/v1/ethereum/protocol_state"
headers = {"accept": "application/json", "Content-Type": "application/json"}
data = {}
response = requests.post(url, headers=headers, json=data)
return response.json()
def get_contract_state(self) -> dict:
"""Retrieve contract state from the RPC server."""
url = self.rpc_url + "/v1/ethereum/contract_state"
headers = {"accept": "application/json", "Content-Type": "application/json"}
data = {}
response = requests.post(url, headers=headers, json=data)
return response.json()
class TychoRunner:
def __init__(self, with_binary_logs: bool = False):
self.with_binary_logs = with_binary_logs
@@ -142,36 +174,6 @@ class TychoRunner:
if rpc_thread.is_alive():
rpc_thread.join()
@staticmethod
def get_protocol_components() -> dict:
"""Retrieve protocol components from the RPC server."""
url = "http://0.0.0.0:4242/v1/ethereum/protocol_components"
headers = {"accept": "application/json", "Content-Type": "application/json"}
data = {"protocol_system": "test_protocol"}
response = requests.post(url, headers=headers, json=data)
return response.json()
@staticmethod
def get_protocol_state() -> dict:
"""Retrieve protocol state from the RPC server."""
url = "http://0.0.0.0:4242/v1/ethereum/protocol_state"
headers = {"accept": "application/json", "Content-Type": "application/json"}
data = {}
response = requests.post(url, headers=headers, json=data)
return response.json()
@staticmethod
def get_contract_state() -> dict:
"""Retrieve contract state from the RPC server."""
url = "http://0.0.0.0:4242/v1/ethereum/contract_state"
headers = {"accept": "application/json", "Content-Type": "application/json"}
data = {}
response = requests.post(url, headers=headers, json=data)
return response.json()
@staticmethod
def empty_database(db_url: str) -> None:
"""Drop and recreate the Tycho indexer database."""