-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.py
More file actions
95 lines (85 loc) · 2.6 KB
/
Copy pathtest_basic.py
File metadata and controls
95 lines (85 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
"""
Quick test script to verify OpenLens core functionality
"""
import sys
sys.path.insert(0, 'src')
from openlens.utils import (
keccak256,
parse_event_signature,
encode_event_signature,
encode_address,
encode_uint256,
bytes_to_hex,
)
def test_keccak():
"""Test keccak256 hashing"""
result = keccak256(b"hello")
print(f"✅ keccak256('hello') = {bytes_to_hex(result)}")
assert len(result) == 32
def test_event_signature_parsing():
"""Test event signature parsing"""
sig = "Transfer(address,address,uint256)"
name, params = parse_event_signature(sig)
print(f"✅ Parsed '{sig}':")
print(f" Name: {name}")
print(f" Params: {params}")
assert name == "Transfer"
assert params == ["address", "address", "uint256"]
def test_event_signature_encoding():
"""Test event signature encoding (topic[0])"""
sig = "Transfer(address,address,uint256)"
topic0 = encode_event_signature(sig)
topic0_hex = bytes_to_hex(topic0)
print(f"✅ Event signature hash for '{sig}':")
print(f" {topic0_hex}")
# This is the well-known Transfer event signature hash
expected = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
assert topic0_hex == expected
def test_address_encoding():
"""Test address encoding"""
addr = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0"
encoded = encode_address(addr)
print(f"✅ Encoded address {addr}:")
print(f" {bytes_to_hex(encoded)}")
assert len(encoded) == 32
# Should be left-padded
assert encoded[:12] == b'\x00' * 12
def test_uint256_encoding():
"""Test uint256 encoding"""
value = 1000000000000000000 # 1 ETH in wei
encoded = encode_uint256(value)
print(f"✅ Encoded uint256 {value}:")
print(f" {bytes_to_hex(encoded)}")
assert len(encoded) == 32
assert int.from_bytes(encoded, byteorder='big') == value
def main():
print("=" * 70)
print("OpenLens Core Functionality Tests")
print("=" * 70)
print()
try:
test_keccak()
print()
test_event_signature_parsing()
print()
test_event_signature_encoding()
print()
test_address_encoding()
print()
test_uint256_encoding()
print()
print("=" * 70)
print("✅ All tests passed!")
print("=" * 70)
return 0
except Exception as e:
print()
print("=" * 70)
print(f"❌ Test failed: {e}")
print("=" * 70)
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(main())