ot_eth_mainnet.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2024 The MMGen Project <mmgen@tuta.io>
  5. """
  6. test.objtest_d.ot_eth_mainnet: ETH mainnet test vectors for MMGen data objects
  7. """
  8. from decimal import Decimal
  9. from mmgen.obj import ETHNonce
  10. from mmgen.amt import ETHAmt
  11. from mmgen.protocol import init_proto
  12. from mmgen.addr import CoinAddr
  13. from ..include.common import cfg
  14. proto = init_proto(cfg, 'eth', need_amt=True)
  15. tests = {
  16. 'CoinAddr': {
  17. 'arg1': 'addr',
  18. 'good': (
  19. {'addr': 'beadcafe' * 5, 'proto': proto},
  20. ),
  21. 'bad': (
  22. {'addr': 'aaaaxxxx' * 5, 'proto': proto},
  23. {'addr': 'beadcafe' * 2, 'proto': proto},
  24. {'addr': 'beadcafe' * 6, 'proto': proto},
  25. ),
  26. },
  27. 'ETHAmt': {
  28. 'bad': ('-3.2', '0.1234567891234567891', 123, '123L',
  29. {'num': '1', 'from_decimal': True},
  30. {'num': 1, 'from_decimal': True},
  31. ),
  32. 'good': (('123.123456789123456789', Decimal('123.123456789123456789')),
  33. { 'num': Decimal('1.12345678912345678892345'), # rounding
  34. 'from_decimal': True,
  35. 'ret': Decimal('1.123456789123456789')},
  36. {'num': Decimal('1.234'), 'from_decimal': True, 'ret': Decimal('1.234')},
  37. {'num': Decimal('0.0'), 'from_decimal': True, 'ret': Decimal('0')},
  38. {'num': 1234, 'from_unit': 'wei', 'ret': Decimal('0.000000000000001234')},
  39. {'num': 1234, 'from_unit': 'Mwei', 'ret': Decimal('0.000000001234')},
  40. )
  41. },
  42. 'ETHNonce': {
  43. 'bad': ('z', 'я', -1, '-1', 0.0, '0.0'),
  44. 'good': (
  45. ('0', 0), ('1', 1), ('100', 100), 1, 100,
  46. {'n': '0x0', 'base': 16, 'ret': 0},
  47. {'n': '0x1', 'base': 16, 'ret': 1},
  48. {'n': '0xf', 'base': 16, 'ret': 15},
  49. {'n': '0xff', 'base': 16, 'ret': 255},
  50. )
  51. },
  52. }