forked from Conflux-Chain/conflux-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue2159_test.py
executable file
·72 lines (55 loc) · 2.44 KB
/
issue2159_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
#!/usr/bin/env python3
import asyncio
import websockets
from conflux.rpc import RpcClient
from jsonrpcclient.clients.websockets_client import WebSocketsClient
from jsonrpcclient.exceptions import ReceivedErrorResponseError
from jsonrpcclient.requests import Request
from test_framework.test_framework import ConfluxTestFramework
from test_framework.util import pubsub_url
FULLNODE = 0
def block_on(op):
return asyncio.get_event_loop().run_until_complete(op)
class Issue2159Test(ConfluxTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.conf_parameters = {
# make `cfx_getEpochReceipts` available through ws
"public_rpc_apis": "\"cfx,debug\"",
# limit max response payload size
"jsonrpc_ws_max_payload_bytes": 1024,
}
def setup_network(self):
self.add_nodes(self.num_nodes)
self.start_node(FULLNODE, ["--archive"])
# set up RPC over HTTP
node = self.nodes[FULLNODE]
self.rpc = RpcClient(node)
# set up RPC over WS
url = pubsub_url(node.index, False, node.rpchost, node.pubsubport)
self.ws = WebSocketsClient(block_on(websockets.connect(url)))
# wait for phase changes to complete
self.nodes[FULLNODE].wait_for_phase(["NormalSyncPhase"])
def run_test(self):
# generate block with many transactions
parent_hash = self.rpc.block_by_epoch("latest_mined")['hash']
start_nonce = self.rpc.get_nonce(self.rpc.GENESIS_ADDR)
txs = [self.rpc.new_tx(nonce = start_nonce + ii) for ii in range(0, 100)]
hash = self.rpc.generate_custom_block(parent_hash = parent_hash, referee = [], txs = txs)
epoch = self.rpc.block_by_hash(hash)["epochNumber"]
# make sure block is executed
self.rpc.generate_empty_blocks(5)
# getting epoch receipts should result in error
try:
resp = block_on(self.ws.send(Request("cfx_getEpochReceipts", epoch)))
assert False, "cfx_getEpochReceipts request should have failed"
except ReceivedErrorResponseError as e:
self.log.info(e.response)
assert e.response.data.startswith("\"Oversized payload")
except Exception as e:
assert False, f"unexpected error: {e}"
# this should succeed
# resp = self.rpc.node.cfx_getEpochReceipts(epoch)
self.log.info("Pass")
if __name__ == "__main__":
Issue2159Test().main()