ts_chainsplit.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.test_py_d.ts_chainsplit: Forking scenario tests for the test.py test suite
  20. This module is unmaintained and currently non-functional
  21. """
  22. import os
  23. from mmgen.globalvars import g
  24. from mmgen.opts import opt
  25. from mmgen.util import die
  26. from ..include.common import *
  27. from .common import *
  28. from .ts_base import *
  29. from .ts_shared import *
  30. from .ts_regtest import *
  31. class TestSuiteChainsplit(TestSuiteRegtest):
  32. 'forking scenario tests for the test.py test suite'
  33. cmd_group = (
  34. ('split_setup', 'regtest forking scenario setup'),
  35. ('walletgen_bob', "generating Bob's wallet"),
  36. ('addrgen_bob', "generating Bob's addresses"),
  37. ('addrimport_bob', "importing Bob's addresses"),
  38. ('fund_bob', "funding Bob's wallet"),
  39. ('split_fork', 'regtest split fork'),
  40. ('split_start_btc', 'start regtest daemon (BTC)'),
  41. ('split_start_b2x', 'start regtest daemon (B2X)'),
  42. ('split_gen_btc', 'mining a block (BTC)'),
  43. ('split_gen_b2x', 'mining 100 blocks (B2X)'),
  44. ('split_do_split', 'creating coin splitting transactions'),
  45. ('split_sign_b2x', 'signing B2X split transaction'),
  46. ('split_sign_btc', 'signing BTC split transaction'),
  47. ('split_send_b2x', 'sending B2X split transaction'),
  48. ('split_send_btc', 'sending BTC split transaction'),
  49. ('split_gen_btc', 'mining a block (BTC)'),
  50. ('split_gen_b2x2', 'mining a block (B2X)'),
  51. ('split_txdo_timelock_bad_btc', 'sending transaction with bad locktime (BTC)'),
  52. ('split_txdo_timelock_good_btc','sending transaction with good locktime (BTC)'),
  53. ('split_txdo_timelock_bad_b2x', 'sending transaction with bad locktime (B2X)'),
  54. ('split_txdo_timelock_good_b2x','sending transaction with good locktime (B2X)'),
  55. )
  56. def split_setup(self):
  57. if self.proto.coin != 'BTC':
  58. die(1,'Test valid only for coin BTC')
  59. self.coin = 'BTC'
  60. return self.setup()
  61. def split_fork(self):
  62. self.coin = 'B2X'
  63. t = self.spawn('mmgen-regtest',['fork','btc'])
  64. t.expect('Creating fork from coin')
  65. t.expect('successfully created')
  66. t.ok()
  67. def split_start(self,coin):
  68. self.coin = coin
  69. t = self.spawn('mmgen-regtest',['bob'])
  70. t.expect('Starting')
  71. t.expect('done')
  72. t.ok()
  73. def split_start_btc(self): self.regtest_start(coin='BTC')
  74. def split_start_b2x(self): self.regtest_start(coin='B2X')
  75. def split_gen_btc(self): self.regtest_generate(coin='BTC')
  76. def split_gen_b2x(self): self.regtest_generate(coin='B2X',num_blocks=100)
  77. def split_gen_b2x2(self): self.regtest_generate(coin='B2X')
  78. def split_do_split(self):
  79. self.coin = 'B2X'
  80. sid = self.regtest_user_sid('bob')
  81. t = self.spawn('mmgen-split',[
  82. '--bob',
  83. '--outdir='+self.tmpdir,
  84. '--tx-fees=0.0001,0.0003',
  85. sid+':S:1',sid+':S:2'])
  86. t.expect(r'\[q\]uit menu, .*?:.','q', regex=True)
  87. t.expect('outputs to spend: ','1\n')
  88. for tx in ('timelocked','split'):
  89. for q in ('fee','change'): 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( 'bob','0.0001',[sid+':S:5'],'1',pw=rt_pw,
  116. extra_args=['--locktime='+str(locktime)],
  117. bad_locktime=bad_locktime)
  118. def split_txdo_timelock_bad_btc(self):
  119. self.regtest_txdo_timelock('BTC',locktime=8888,bad_locktime=True)
  120. def split_txdo_timelock_good_btc(self):
  121. self.regtest_txdo_timelock('BTC',locktime=1321009871,bad_locktime=False)
  122. def split_txdo_timelock_bad_b2x(self):
  123. self.regtest_txdo_timelock('B2X',locktime=8888,bad_locktime=True)
  124. def split_txdo_timelock_good_b2x(self):
  125. self.regtest_txdo_timelock('B2X',locktime=1321009871,bad_locktime=False)