forked from Consensys/ethjsonrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
84 lines (68 loc) · 2.44 KB
/
test.py
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
from ethjsonrpc import EthJsonRpc
methods = [
'web3_clientVersion',
'net_version',
'net_peerCount',
'net_listening',
'eth_protocolVersion',
'eth_coinbase',
'eth_mining',
'eth_hashrate',
'eth_gasPrice',
'eth_accounts',
'eth_blockNumber',
'eth_getCompilers',
'eth_newPendingTransactionFilter',
'eth_getWork',
# 'shh_version',
# 'shh_newIdentity',
# 'shh_newGroup',
]
c = EthJsonRpc()
print len(methods)
for m in methods:
meth = getattr(c, m)
result = meth()
print '%s: %s (%s)' % (m, result, type(result))
################################################################################
print '*' * 80
addr = '0x1dcb8d1f0fcc8cbc8c2d76528e877f915e299fbe'
for x in ['earliest', 'latest', 'pending', 150000]:
result = c.eth_getTransactionCount(addr, x)
print 'eth_getTransactionCount: %s (%s)' % (result, type(result))
b = (231301, '0x9476018748ba1dae5bdf5e3725f8966df1fa127d49f58e66f621bf6868a23c85')
result = c.eth_getBlockTransactionCountByHash(b[1])
print 'eth_getBlockTransactionCountByHash: %s (%s)' % (result, type(result))
for x in ['earliest', 'latest', 'pending', b[0]]:
result = c.eth_getBlockTransactionCountByNumber(x)
print 'eth_getBlockTransactionCountByNumber: %s (%s)' % (result, type(result))
b = (199583, '0x19d761c6f944eefe91ad70b9aff3d2d76c972e5bb68c443eea7c0eaa144cef9f')
result = c.eth_getUncleCountByBlockHash(b[1])
print 'eth_getUncleCountByBlockHash: %s (%s)' % (result, type(result))
for x in ['earliest', 'latest', 'pending', b[0]]:
result = c.eth_getUncleCountByBlockNumber(x)
print 'eth_getUncleCountByBlockNumber: %s (%s)' % (result, type(result))
################################################################################
print '*' * 80
db_name = 'db_name'
k = 'my_key'
v = 'my_value'
print c.db_putString(db_name, k, v)
x = c.db_getString(db_name, k)
print x
assert v == x
db_name = 'db_name'
k = 'my_key'
v = '0xabcdef'
print c.db_putHex(db_name, k, v)
x = c.db_getHex(db_name, k)
print x
assert v == x
################################################################################
print '*' * 80
b = (199583, '0x19d761c6f944eefe91ad70b9aff3d2d76c972e5bb68c443eea7c0eaa144cef9f')
print c.eth_getBlockByHash(b[1], tx_objects=False)
for x in ['earliest', 'latest', 'pending', b[0]]:
print c.eth_getBlockByNumber(x, tx_objects=False)
tx = '0x12cd5d9a82049154c8990214a551479853d1bfe45852688833bc4ef86a29b1a3'
print c.eth_getTransactionByHash(tx)