Debian Codegraph @

tests/functional_tests/speed.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 # Copyright (c) 2018-2022, The Monero Project
4
5 #
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without modification, are
9 # permitted provided that the following conditions are met:
10 #
11 # 1. Redistributions of source code must retain the above copyright notice, this list of
12 # conditions and the following disclaimer.
13 #
14 # 2. Redistributions in binary form must reproduce the above copyright notice, this list
15 # of conditions and the following disclaimer in the documentation and/or other
16 # materials provided with the distribution.
17 #
18 # 3. Neither the name of the copyright holder nor the names of its contributors may be
19 # used to endorse or promote products derived from this software without specific
20 # prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25 # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 """Test speed of various procedures
33
34 Test the following RPCs:
35 - generateblocks
36 - transfer
37 - [TODO: many tests still need to be written]
38
39 """
40
41
42 import time
43 from time import sleep
44 from __future__ import print_function
45
46 from framework.daemon import Daemon
47 from framework.wallet import Wallet
48
49
50 class SpeedTest():
51 def reset(self):
52 print('Resetting blockchain')
53 daemon = Daemon()
54 res = daemon.get_height()
55 daemon.pop_blocks(res.height - 1)
56 daemon.flush_txpool()
57
58 def run_test(self):
59 self.reset()
60
61 daemon = Daemon()
62 wallet = Wallet()
63
64 # close the wallet if any, will throw if none is loaded
65 try: wallet.close_wallet()
66 except: pass
67 wallet.restore_deterministic_wallet('velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted')
68
69 destinations = []
70 for i in range(3):
71 destinations.append({"amount":1,"address":'888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H'})
72
73 self._test_speed_generateblocks(daemon=daemon, blocks=70)
74 for i in range(1, 10):
75 while wallet.get_balance().unlocked_balance == 0:
76 print('Waiting for wallet to refresh...')
77 sleep(1)
78 self._test_speed_transfer_split(wallet=wallet)
79 self._test_speed_generateblocks(daemon=daemon, blocks=10)
80
81 def _test_speed_generateblocks(self, daemon, blocks):
82 print('Test speed of block generation')
83 start = time.time()
84
85 res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', blocks)
86
87 print('generating ', blocks, 'blocks took: ', time.time() - start, 'seconds')
88
89 def _test_speed_transfer_split(self, wallet):
90 print('Test speed of transfer')
91 start = time.time()
92
93 destinations = [{"amount":1,"address":'888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H'}]
94 res = wallet.transfer_split(destinations)
95
96 print('generating tx took: ', time.time() - start, 'seconds')
97
98
99 if __name__ == '__main__':
100 SpeedTest().run_test()