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-2019 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. ts_chainsplit.py: Forking scenario tests for the test.py test suite
  20. This module is 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 test.common import *
  27. from test.test_py_d.common import *
  28. from test.test_py_d.ts_base import *
  29. from test.test_py_d.ts_shared import *
  30. from test.test_py_d.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 g.coin != 'BTC': die(1,'Test valid only for coin BTC')
  58. opt.coin = 'BTC'
  59. return self.setup()
  60. def split_fork(self):
  61. opt.coin = 'B2X'
  62. t = self.spawn('mmgen-regtest',['fork','btc'])
  63. t.expect('Creating fork from coin')
  64. t.expect('successfully created')
  65. t.ok()
  66. def split_start(self,coin):
  67. opt.coin = coin
  68. t = self.spawn('mmgen-regtest',['bob'])
  69. t.expect('Starting')
  70. t.expect('done')
  71. t.ok()
  72. def split_start_btc(self): self.regtest_start(coin='BTC')
  73. def split_start_b2x(self): self.regtest_start(coin='B2X')
  74. def split_gen_btc(self): self.regtest_generate(coin='BTC')
  75. def split_gen_b2x(self): self.regtest_generate(coin='B2X',num_blocks=100)
  76. def split_gen_b2x2(self): self.regtest_generate(coin='B2X')
  77. def split_do_split(self):
  78. opt.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 view, .*?:.','q', regex=True)
  86. t.expect('outputs to spend: ','1\n')
  87. for tx in ('timelocked','split'):
  88. for q in ('fee','change'): t.expect('OK? (Y/n): ','y')
  89. t.do_comment(False)
  90. t.view_tx('t')
  91. t.written_to_file('Long chain (timelocked) transaction')
  92. t.written_to_file('Short chain transaction')
  93. t.ok()
  94. def split_sign(self,coin,ext):
  95. wf = get_file_with_ext(self.regtest_user_dir('bob',coin=coin.lower()),'mmdat')
  96. txfile = self.get_file_with_ext(ext,no_dot=True)
  97. opt.coin = coin
  98. self.txsign(txfile,wf,extra_opts=['--bob'])
  99. def split_sign_b2x(self):
  100. return self.regtest_sign(coin='B2X',ext='533].rawtx')
  101. def split_sign_btc(self):
  102. return self.regtest_sign(coin='BTC',ext='9997].rawtx')
  103. def split_send(self,coin,ext):
  104. opt.coin = coin
  105. txfile = self.get_file_with_ext(ext,no_dot=True)
  106. self.txsend(txfile,bogus_send=False,extra_opts=['--bob'])
  107. def split_send_b2x(self):
  108. return self.regtest_send(coin='B2X',ext='533].sigtx')
  109. def split_send_btc(self):
  110. return self.regtest_send(coin='BTC',ext='9997].sigtx')
  111. def split_txdo_timelock(self,coin,locktime,bad_locktime):
  112. opt.coin = coin
  113. sid = self.regtest_user_sid('bob')
  114. self.regtest_user_txdo( 'bob','0.0001',[sid+':S:5'],'1',pw=rt_pw,
  115. extra_args=['--locktime='+str(locktime)],
  116. bad_locktime=bad_locktime)
  117. def split_txdo_timelock_bad_btc(self):
  118. self.regtest_txdo_timelock('BTC',locktime=8888,bad_locktime=True)
  119. def split_txdo_timelock_good_btc(self):
  120. self.regtest_txdo_timelock('BTC',locktime=1321009871,bad_locktime=False)
  121. def split_txdo_timelock_bad_b2x(self):
  122. self.regtest_txdo_timelock('B2X',locktime=8888,bad_locktime=True)
  123. def split_txdo_timelock_good_b2x(self):
  124. self.regtest_txdo_timelock('B2X',locktime=1321009871,bad_locktime=False)