forked from Consensys/ethjsonrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
140 lines (108 loc) · 4.18 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from ethjsonrpc import EthJsonRpc
methods = [
'web3_clientVersion',
'net_version',
'net_peerCount',
'net_listening',
'eth_protocolVersion',
'eth_syncing',
'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)
################################################################################
print '*' * 80
code = 'contract Test {}'
print c.eth_compileSolidity(code)
#code = ''
#print c.eth_compileSerpent(code)
#code = ''
#print c.eth_compileLLL(code)
################################################################################
print '*' * 80
b = (246236, '0xcd43703a1ead33ffa1f317636c7b67453c5cc03a3350cd71dbbdd70fcbe0987a')
index = 2
print c.eth_getTransactionByBlockHashAndIndex(b[1], index)
for x in ['earliest', 'latest', 'pending', b[0]]:
print c.eth_getTransactionByBlockNumberAndIndex(b[0], index)
tx = '0x27191ea9e8228c98bc4418fa60843540937b0c615b2db5e828756800f533f8cd'
print c.eth_getTransactionReceipt(tx)
b = (246294, '0x3d596ca3c7b344419567957b41b2132bb339d365b6b6b3b6a7645e5444914a16')
index = 0
print c.eth_getUncleByBlockHashAndIndex(b[1], index)
for x in ['earliest', 'latest', 'pending', b[0]]:
print c.eth_getUncleByBlockNumberAndIndex(b[0], index)
################################################################################
print '*' * 80
addr = '0x1dcb8d1f0fcc8cbc8c2d76528e877f915e299fbe'
for x in ['earliest', 'latest', 'pending', 150000]:
print c.eth_getBalance(addr, x)
addr = '0x407d73d8a49eeb85d32cf465507dd71d507100c1'
for x in ['earliest', 'latest', 'pending', 2]:
print c.eth_getStorageAt(addr, 0, x)
################################################################################
print '*' * 80
hash_rate = 1000000
client_id = '0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c'
print c.eth_submitHashrate(hash_rate, client_id)
digest = c.web3_sha3('')
print digest
# keccak-256, not sha3-256
assert digest == '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'