Skip to content

Commit 405d959

Browse files
test: added unit and integration testing for contract_client_v2
- updated .gitignore to ignore test related outputs - added conftest.py to load variables for integration tests - added .env.example to help with running tests
1 parent 958f236 commit 405d959

5 files changed

Lines changed: 395 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ __pycache__/
2121

2222
# Intellij IDEA files
2323
.idea/
24+
tests/.env
25+
htmlcov/
26+
.coverage

tests/.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# General Variables
2+
WHITELISTED_WALLET_ADDRESS=<YOUR_WHITELISTED_WALLET_ADDRESS>
3+
WHITELISTED_WALLET_PRIVATE_KEY=<YOUR_WHITELISTED_PRIVATE_KEY>
4+
5+
# Seller Agent Variables
6+
SELLER_ENTITY_ID=<YOUR_SELLER_ENTITY_ID>
7+
SELLER_AGENT_WALLET_ADDRESS=<YOUR_SELLER_AGENT_WALLET_ADDRESS>
8+
9+
# Buyer Agent Variables
10+
BUYER_ENTITY_ID=<YOUR_BUYER_ENTITY_ID>
11+
BUYER_AGENT_WALLET_ADDRESS=<YOUR_BUYER_AGENT_WALLET_ADDRESS>

tests/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
from pathlib import Path
3+
import pytest
4+
5+
6+
# Load .env file from tests directory if it exists
7+
def pytest_configure(config):
8+
"""Load environment variables from tests/.env before running tests"""
9+
env_file = Path(__file__).parent / ".env"
10+
if env_file.exists():
11+
print(f"\n✅ Loading environment variables from {env_file}")
12+
with open(env_file) as f:
13+
for line in f:
14+
line = line.strip()
15+
# Skip comments and empty lines
16+
if line and not line.startswith('#'):
17+
if '=' in line:
18+
key, value = line.split('=', 1)
19+
os.environ[key.strip()] = value.strip()
20+
else:
21+
print(f"\n⚠️ No .env file found at {env_file}")
22+
print("Integration tests will be skipped. Create tests/.env from tests/.env.example")
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pytest
2+
import os
3+
from virtuals_acp.contract_clients.contract_client_v2 import ACPContractClientV2
4+
5+
6+
# Skip all integration tests if environment variables are not set
7+
pytestmark = pytest.mark.integration
8+
9+
# Check if we have required environment variables for integration tests
10+
SKIP_INTEGRATION = not all([
11+
os.getenv("WHITELISTED_WALLET_PRIVATE_KEY"),
12+
os.getenv("SELLER_AGENT_WALLET_ADDRESS"),
13+
os.getenv("SELLER_ENTITY_ID"),
14+
])
15+
16+
17+
@pytest.mark.skipif(SKIP_INTEGRATION, reason="Integration test environment variables not set")
18+
class TestIntegrationACPContractClientV2:
19+
@pytest.fixture(scope="class")
20+
def integration_client(self):
21+
wallet_private_key = os.getenv("WHITELISTED_WALLET_PRIVATE_KEY")
22+
agent_wallet_address = os.getenv("SELLER_AGENT_WALLET_ADDRESS")
23+
entity_id = int(os.getenv("SELLER_ENTITY_ID", "0"))
24+
25+
try:
26+
client = ACPContractClientV2(
27+
agent_wallet_address=agent_wallet_address,
28+
wallet_private_key=wallet_private_key,
29+
entity_id=entity_id,
30+
)
31+
yield client
32+
except Exception as e:
33+
pytest.fail(f"Failed to initialize integration client: {e}")
34+
35+
class TestInitialization:
36+
def test_should_connect_to_mainnet(self, integration_client):
37+
assert integration_client is not None
38+
assert integration_client.agent_wallet_address is not None
39+
40+
def test_should_have_valid_web3_connection(self, integration_client):
41+
assert integration_client.w3 is not None
42+
assert integration_client.w3.is_connected()
43+
44+
def test_should_fetch_manager_addresses(self, integration_client):
45+
assert integration_client.job_manager_address is not None
46+
assert integration_client.job_manager_address.startswith("0x")
47+
48+
def test_should_validate_session_key(self, integration_client):
49+
# If client initialized, session key validation already passed
50+
assert integration_client.account is not None
51+
assert integration_client.entity_id is not None
52+
53+
def test_should_have_x402_instance(self, integration_client):
54+
assert integration_client.x402 is not None
55+
56+
def test_should_have_alchemy_kit_instance(self, integration_client):
57+
assert integration_client.alchemy_kit is not None

0 commit comments

Comments
 (0)