ct_chainsplit.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. test.cmdtest_py_d.ct_chainsplit: Forking scenario tests for the cmdtest.py test suite
  20. This module is unmaintained and currently non-functional
  21. """
  22. from mmgen.util import die
  23. from .common import get_file_with_ext,rt_pw
  24. from .ct_regtest import CmdTestRegtest
  25. class CmdTestChainsplit(CmdTestRegtest):
  26. 'forking scenario tests for the cmdtest.py test suite'
  27. cmd_group = (
  28. ('split_setup', 'regtest forking scenario setup'),
  29. ('walletgen_bob', "generating Bob's wallet"),
  30. ('addrgen_bob', "generating Bob's addresses"),
  31. ('addrimport_bob', "importing Bob's addresses"),
  32. ('fund_bob', "funding Bob's wallet"),
  33. ('split_fork', 'regtest split fork'),
  34. ('split_start_btc', 'start regtest daemon (BTC)'),
  35. ('split_start_b2x', 'start regtest daemon (B2X)'),
  36. ('split_gen_btc', 'mining a block (BTC)'),
  37. ('split_gen_b2x', 'mining 100 blocks (B2X)'),
  38. ('split_do_split', 'creating coin splitting transactions'),
  39. ('split_sign_b2x', 'signing B2X split transaction'),
  40. ('split_sign_btc', 'signing BTC split transaction'),
  41. ('split_send_b2x', 'sending B2X split transaction'),
  42. ('split_send_btc', 'sending BTC split transaction'),
  43. ('split_gen_btc', 'mining a block (BTC)'),
  44. ('split_gen_b2x2', 'mining a block (B2X)'),
  45. ('split_txdo_timelock_bad_btc', 'sending transaction with bad locktime (BTC)'),
  46. ('split_txdo_timelock_good_btc','sending transaction with good locktime (BTC)'),
  47. ('split_txdo_timelock_bad_b2x', 'sending transaction with bad locktime (B2X)'),
  48. ('split_txdo_timelock_good_b2x','sending transaction with good locktime (B2X)'),
  49. )
  50. def split_setup(self):
  51. if self.proto.coin != 'BTC':
  52. die(1,'Test valid only for coin BTC')
  53. self.coin = 'BTC'
  54. return self.setup()
  55. def split_fork(self):
  56. self.coin = 'B2X'
  57. t = self.spawn('mmgen-regtest',['fork','btc'])
  58. t.expect('Creating fork from coin')
  59. t.expect('successfully created')
  60. t.ok()
  61. def split_start(self,coin):
  62. self.coin = coin
  63. t = self.spawn('mmgen-regtest',['bob'])
  64. t.expect('Starting')
  65. t.expect('done')
  66. t.ok()
  67. def split_start_btc(self):
  68. self.regtest_start(coin='BTC')
  69. def split_start_b2x(self):
  70. self.regtest_start(coin='B2X')
  71. def split_gen_btc(self):
  72. self.regtest_generate(coin='BTC')
  73. def split_gen_b2x(self):
  74. self.regtest_generate(coin='B2X',num_blocks=100)
  75. def split_gen_b2x2(self):
  76. self.regtest_generate(coin='B2X')
  77. def split_do_split(self):
  78. self.coin = 'B2X'
  79. sid = self.regtest_user_sid('bob')
  80. t = self.spawn('mmgen-split',[
  81. '--bob',
  82. '--outdir='+self.tmpdir,
  83. '--tx-fees=0.0001,0.0003',
  84. sid+':S:1',sid+':S:2'])
  85. t.expect(r'\[q\]uit menu, .*?:.','q', regex=True)
  86. t.expect('outputs to spend: ','1\n')
  87. for tx in ('timelocked','split'):
  88. for q in ('fee','change'):
  89. t.expect('OK? (Y/n): ','y')
  90. t.do_comment(False)
  91. t.view_tx('t')
  92. t.written_to_file('Long chain (timelocked) transaction')
  93. t.written_to_file('Short chain transaction')
  94. t.ok()
  95. def split_sign(self,coin,ext):
  96. wf = get_file_with_ext(self.regtest_user_dir('bob',coin=coin.lower()),'mmdat')
  97. txfile = self.get_file_with_ext(ext,no_dot=True)
  98. self.coin = coin
  99. self.txsign(txfile,wf,extra_opts=['--bob'])
  100. def split_sign_b2x(self):
  101. return self.regtest_sign(coin='B2X',ext='533].rawtx')
  102. def split_sign_btc(self):
  103. return self.regtest_sign(coin='BTC',ext='9997].rawtx')
  104. def split_send(self,coin,ext):
  105. self.coin = coin
  106. txfile = self.get_file_with_ext(ext,no_dot=True)
  107. self.txsend(txfile,bogus_send=False,extra_opts=['--bob'])
  108. def split_send_b2x(self):
  109. return self.regtest_send(coin='B2X',ext='533].sigtx')
  110. def split_send_btc(self):
  111. return self.regtest_send(coin='BTC',ext='9997].sigtx')
  112. def split_txdo_timelock(self,coin,locktime,bad_locktime):
  113. self.coin = coin
  114. sid = self.regtest_user_sid('bob')
  115. self.regtest_user_txdo(
  116. 'bob',
  117. '0.0001',
  118. [sid+':S:5'],
  119. '1',
  120. pw = rt_pw,
  121. extra_args = ['--locktime='+str(locktime)],
  122. bad_locktime = bad_locktime)
  123. def split_txdo_timelock_bad_btc(self):
  124. self.regtest_txdo_timelock('BTC',locktime=8888,bad_locktime=True)
  125. def split_txdo_timelock_good_btc(self):
  126. self.regtest_txdo_timelock('BTC',locktime=1321009871,bad_locktime=False)
  127. def split_txdo_timelock_bad_b2x(self):
  128. self.regtest_txdo_timelock('B2X',locktime=8888,bad_locktime=True)
  129. def split_txdo_timelock_good_b2x(self):
  130. self.regtest_txdo_timelock('B2X',locktime=1321009871,bad_locktime=False)