oat_btc_mainnet.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. test.objattrtest_py_d.oat_btc_mainnet: BTC mainnet test vectors for MMGen data objects
  7. """
  8. from .oat_common import sample_objs,seed_bin,atd
  9. from ..include.common import cfg
  10. from mmgen.protocol import init_proto
  11. proto = init_proto( cfg, 'btc', need_amt=True )
  12. from mmgen.key import PrivKey,WifKey
  13. from mmgen.addr import CoinAddr,MMGenID,AddrIdx,MMGenAddrType,MMGenPasswordType
  14. from mmgen.amt import BTCAmt
  15. from mmgen.tw.shared import TwMMGenID
  16. sample_objs.update({
  17. 'PrivKey': PrivKey(proto,seed_bin,compressed=True,pubkey_type='std'),
  18. 'WifKey': WifKey(proto,'5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX'),
  19. 'CoinAddr': CoinAddr(proto,'1111111111111111111114oLvT2'),
  20. 'BTCAmt': BTCAmt('0.01'),
  21. 'MMGenID': MMGenID(proto,'F00F00BB:B:1'),
  22. 'TwMMGenID': TwMMGenID(proto,'F00F00BB:S:23'),
  23. })
  24. from mmgen.addrlist import AddrListEntry
  25. from mmgen.passwdlist import PasswordListEntry
  26. from mmgen.obj import TwComment,CoinTxID,HexStr
  27. from mmgen.seed import SeedID,SeedBase
  28. from mmgen.subseed import SubSeed,SubSeedIdx
  29. from mmgen.seedsplit import (
  30. SeedShareCount,
  31. SeedSplitIDString,
  32. SeedShareIdx,
  33. MasterShareIdx,
  34. SeedShareList,
  35. SeedShareLast,
  36. SeedShareMaster,
  37. SeedShareMasterJoining
  38. )
  39. from mmgen.proto.btc.tw.unspent import BitcoinTwUnspentOutputs
  40. from mmgen.tx.base import Base
  41. tests = {
  42. # addr.py
  43. 'AddrListEntry': atd({
  44. 'addr': (0b01001, CoinAddr),
  45. 'idx': (0b01001, AddrIdx),
  46. 'comment': (0b01101, TwComment),
  47. 'sec': (0b01001, PrivKey),
  48. # 'viewkey': (0b01001, ViewKey), # TODO
  49. # 'wallet_passwd': (0b01001, WalletPassword), # TODO
  50. },
  51. (proto,),
  52. {}
  53. ),
  54. 'PasswordListEntry': atd({
  55. 'passwd': (0b00001, str),
  56. 'idx': (0b01001, AddrIdx),
  57. 'comment':(0b01101, TwComment),
  58. 'sec': (0b01001, PrivKey),
  59. },
  60. (proto,),
  61. {'passwd':'ΑlphaΩmega', 'idx':1 },
  62. ),
  63. # obj.py
  64. 'PrivKey': atd({
  65. 'compressed': (0b00001, bool),
  66. 'wif': (0b00001, WifKey),
  67. },
  68. (proto,seed_bin),
  69. {'compressed':True, 'pubkey_type':'std'},
  70. ),
  71. 'MMGenAddrType': atd({
  72. 'name': (0b01001, str),
  73. 'pubkey_type': (0b01001, str),
  74. 'compressed': (0b11001, bool),
  75. 'gen_method': (0b11001, str),
  76. 'addr_fmt': (0b11001, str),
  77. 'wif_label': (0b11001, str),
  78. 'extra_attrs': (0b11001, tuple),
  79. 'desc': (0b01001, str),
  80. },
  81. (proto,'S'),
  82. {},
  83. ),
  84. # seed.py
  85. 'SeedBase': atd({
  86. 'data': (0b00001, bytes),
  87. 'sid': (0b00001, SeedID),
  88. },
  89. [cfg,seed_bin],
  90. {},
  91. ),
  92. 'SubSeed': atd({
  93. 'idx': (0b00001, int),
  94. 'nonce': (0b00001, int),
  95. 'ss_idx': (0b01001, SubSeedIdx),
  96. },
  97. [sample_objs['SubSeedList'],1,1,'short'],
  98. {},
  99. ),
  100. 'SeedShareList': atd({
  101. 'count': (0b01001, SeedShareCount),
  102. 'id_str': (0b01001, SeedSplitIDString),
  103. },
  104. [sample_objs['Seed'],sample_objs['SeedShareCount']],
  105. {},
  106. ),
  107. 'SeedShareLast': atd({
  108. 'idx': (0b01001, SeedShareIdx),
  109. },
  110. [sample_objs['SeedShareList']],
  111. {},
  112. ),
  113. 'SeedShareMaster': atd({
  114. 'idx': (0b01001, MasterShareIdx),
  115. 'nonce': (0b00001, int),
  116. },
  117. [sample_objs['SeedShareList'],7,0],
  118. {},
  119. ),
  120. 'SeedShareMasterJoining': atd({
  121. 'id_str': (0b01001, SeedSplitIDString),
  122. 'count': (0b01001, SeedShareCount),
  123. },
  124. [cfg,sample_objs['MasterShareIdx'], sample_objs['Seed'], 'foo', 2],
  125. {},
  126. ),
  127. # twuo.py
  128. 'BitcoinTwUnspentOutputs.MMGenTwUnspentOutput': atd({
  129. 'txid': (0b01001, CoinTxID),
  130. 'vout': (0b01001, int),
  131. 'amt': (0b01001, BTCAmt),
  132. 'amt2': (0b01001, BTCAmt),
  133. 'comment': (0b01101, TwComment),
  134. 'twmmid': (0b01001, TwMMGenID),
  135. 'addr': (0b01001, CoinAddr),
  136. 'confs': (0b00001, int),
  137. 'scriptPubKey': (0b01001, HexStr),
  138. 'skip': (0b00101, str),
  139. },
  140. (proto,),
  141. {
  142. 'amt':BTCAmt('0.01'),
  143. 'twmmid':'F00F00BB:B:17',
  144. 'addr':'1111111111111111111114oLvT2',
  145. 'confs': 100000,
  146. 'scriptPubKey':'ff',
  147. },
  148. ),
  149. # tx.py
  150. 'Base.Input': atd({
  151. 'vout': (0b01001, int),
  152. 'amt': (0b01001, BTCAmt),
  153. 'comment': (0b01101, TwComment),
  154. 'mmid': (0b01001, MMGenID),
  155. 'addr': (0b01001, CoinAddr),
  156. 'confs': (0b01001, int),
  157. 'txid': (0b01001, CoinTxID),
  158. 'have_wif': (0b00011, bool),
  159. 'scriptPubKey': (0b01001, HexStr),
  160. 'sequence': (0b00001, int),
  161. },
  162. (proto,),
  163. { 'amt':BTCAmt('0.01'), 'addr':sample_objs['CoinAddr'] },
  164. ),
  165. 'Base.Output': atd({
  166. 'vout': (0b01001, int),
  167. 'amt': (0b01001, BTCAmt),
  168. 'comment': (0b01101, TwComment),
  169. 'mmid': (0b01001, MMGenID),
  170. 'addr': (0b01001, CoinAddr),
  171. 'confs': (0b01001, int),
  172. 'txid': (0b01001, CoinTxID),
  173. 'have_wif': (0b00011, bool),
  174. 'is_chg': (0b00001, bool),
  175. },
  176. (proto,),
  177. { 'amt':BTCAmt('0.01'), 'addr':sample_objs['CoinAddr'] },
  178. ),
  179. }
  180. tests['MMGenPasswordType'] = atd(tests['MMGenAddrType'].attrs, [proto,'P'], {})