ts_chainsplit.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.util import die
  24. from .common import get_file_with_ext
  25. from .ts_regtest import TestSuiteRegtest
  26. class TestSuiteChainsplit(TestSuiteRegtest):
  27. 'forking scenario tests for the test.py test suite'
  28. cmd_group = (
  29. ('split_setup', 'regtest forking scenario setup'),
  30. ('walletgen_bob', "generating Bob's wallet"),
  31. ('addrgen_bob', "generating Bob's addresses"),
  32. ('addrimport_bob', "importing Bob's addresses"),
  33. ('fund_bob', "funding Bob's wallet"),
  34. ('split_fork', 'regtest split fork'),
  35. ('split_start_btc', 'start regtest daemon (BTC)'),
  36. ('split_start_b2x', 'start regtest daemon (B2X)'),
  37. ('split_gen_btc', 'mining a block (BTC)'),
  38. ('split_gen_b2x', 'mining 100 blocks (B2X)'),
  39. ('split_do_split', 'creating coin splitting transactions'),
  40. ('split_sign_b2x', 'signing B2X split transaction'),
  41. ('split_sign_btc', 'signing BTC split transaction'),
  42. ('split_send_b2x', 'sending B2X split transaction'),
  43. ('split_send_btc', 'sending BTC split transaction'),
  44. ('split_gen_btc', 'mining a block (BTC)'),
  45. ('split_gen_b2x2', 'mining a block (B2X)'),
  46. ('split_txdo_timelock_bad_btc', 'sending transaction with bad locktime (BTC)'),
  47. ('split_txdo_timelock_good_btc','sending transaction with good locktime (BTC)'),
  48. ('split_txdo_timelock_bad_b2x', 'sending transaction with bad locktime (B2X)'),
  49. ('split_txdo_timelock_good_b2x','sending transaction with good locktime (B2X)'),
  50. )
  51. def split_setup(self):
  52. if self.proto.coin != 'BTC':
  53. die(1,'Test valid only for coin BTC')
  54. self.coin = 'BTC'
  55. return self.setup()
  56. def split_fork(self):
  57. self.coin = 'B2X'
  58. t = self.spawn('mmgen-regtest',['fork','btc'])
  59. t.expect('Creating fork from coin')
  60. t.expect('successfully created')
  61. t.ok()
  62. def split_start(self,coin):
  63. self.coin = coin
  64. t = self.spawn('mmgen-regtest',['bob'])
  65. t.expect('Starting')
  66. t.expect('done')
  67. t.ok()
  68. def split_start_btc(self): self.regtest_start(coin='BTC')
  69. def split_start_b2x(self): self.regtest_start(coin='B2X')
  70. def split_gen_btc(self): self.regtest_generate(coin='BTC')
  71. def split_gen_b2x(self): self.regtest_generate(coin='B2X',num_blocks=100)
  72. def split_gen_b2x2(self): self.regtest_generate(coin='B2X')
  73. def split_do_split(self):
  74. self.coin = 'B2X'
  75. sid = self.regtest_user_sid('bob')
  76. t = self.spawn('mmgen-split',[
  77. '--bob',
  78. '--outdir='+self.tmpdir,
  79. '--tx-fees=0.0001,0.0003',
  80. sid+':S:1',sid+':S:2'])
  81. t.expect(r'\[q\]uit menu, .*?:.','q', regex=True)
  82. t.expect('outputs to spend: ','1\n')
  83. for tx in ('timelocked','split'):
  84. for q in ('fee','change'): t.expect('OK? (Y/n): ','y')
  85. t.do_comment(False)
  86. t.view_tx('t')
  87. t.written_to_file('Long chain (timelocked) transaction')
  88. t.written_to_file('Short chain transaction')
  89. t.ok()
  90. def split_sign(self,coin,ext):
  91. wf = get_file_with_ext(self.regtest_user_dir('bob',coin=coin.lower()),'mmdat')
  92. txfile = self.get_file_with_ext(ext,no_dot=True)
  93. self.coin = coin
  94. self.txsign(txfile,wf,extra_opts=['--bob'])
  95. def split_sign_b2x(self):
  96. return self.regtest_sign(coin='B2X',ext='533].rawtx')
  97. def split_sign_btc(self):
  98. return self.regtest_sign(coin='BTC',ext='9997].rawtx')
  99. def split_send(self,coin,ext):
  100. self.coin = coin
  101. txfile = self.get_file_with_ext(ext,no_dot=True)
  102. self.txsend(txfile,bogus_send=False,extra_opts=['--bob'])
  103. def split_send_b2x(self):
  104. return self.regtest_send(coin='B2X',ext='533].sigtx')
  105. def split_send_btc(self):
  106. return self.regtest_send(coin='BTC',ext='9997].sigtx')
  107. def split_txdo_timelock(self,coin,locktime,bad_locktime):
  108. self.coin = coin
  109. sid = self.regtest_user_sid('bob')
  110. self.regtest_user_txdo( 'bob','0.0001',[sid+':S:5'],'1',pw=rt_pw,
  111. extra_args=['--locktime='+str(locktime)],
  112. bad_locktime=bad_locktime)
  113. def split_txdo_timelock_bad_btc(self):
  114. self.regtest_txdo_timelock('BTC',locktime=8888,bad_locktime=True)
  115. def split_txdo_timelock_good_btc(self):
  116. self.regtest_txdo_timelock('BTC',locktime=1321009871,bad_locktime=False)
  117. def split_txdo_timelock_bad_b2x(self):
  118. self.regtest_txdo_timelock('B2X',locktime=8888,bad_locktime=True)
  119. def split_txdo_timelock_good_b2x(self):
  120. self.regtest_txdo_timelock('B2X',locktime=1321009871,bad_locktime=False)