You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.0 KiB

  1. package address
  2. import "fmt"
  3. import "bytes"
  4. import "testing"
  5. import "encoding/hex"
  6. import "github.com/deroproject/derosuite/config"
  7. func TestAddressError(t *testing.T) {
  8. _, err := NewAddress("")
  9. /*want := "Address is the wrong length"
  10. if err != want {
  11. t.Errorf("want: %s, got: %s", want, err)
  12. }
  13. */
  14. _, err = NewAddress("46w3n5EGhBeYmKvQRsd8UK9GhvcbYWQDobJape3NLMMFEjFZnJ3CnRmeKspubQGiP8iMTwFEX2QiBsjUkjKT4SSPd3fK1")
  15. want := fmt.Errorf("Checksum does not validate")
  16. if err.Error() != want.Error() {
  17. t.Errorf("want: %s, got: %s", want, err)
  18. }
  19. }
  20. func TestAddress(t *testing.T) {
  21. const Monero_MainNetwork = 18
  22. const Monero_TestNetwork = 53
  23. tests := []struct {
  24. name string
  25. Network uint64
  26. SpendingKeyHex string
  27. ViewingKeyHex string
  28. Address string
  29. }{
  30. {
  31. name: "generic",
  32. Network: Monero_MainNetwork,
  33. SpendingKeyHex: "8c1a9d5ff5aaf1c3cdeb2a1be62f07a34ae6b15fe47a254c8bc240f348271679",
  34. ViewingKeyHex: "0a29b163e392eb9416a52907fd7d3b84530f8d02ff70b1f63e72fdcb54cf7fe1",
  35. Address: "46w3n5EGhBeZkYmKvQRsd8UK9GhvcbYWQDobJape3NLMMFEjFZnJ3CnRmeKspubQGiP8iMTwFEX2QiBsjUkjKT4SSPd3fKp",
  36. },
  37. {
  38. name: "generic 2",
  39. Network: Monero_MainNetwork,
  40. SpendingKeyHex: "5007b84275af9a173c2080683afce90b2157ab640c18ddd5ce3e060a18a9ce99",
  41. ViewingKeyHex: "27024b45150037b677418fcf11ba9675494ffdf994f329b9f7a8f8402b7934a0",
  42. Address: "44f1Y84r9Lu4tQdLWRxV122rygfhUeVBrcmBaqcYCwUHScmf1ht8DFLXX9YN4T7nPPLcpqYLUdrFiY77nQYeH9RuK9gg4p6",
  43. },
  44. {
  45. name: "require 1 padding in middle",
  46. Network: Monero_MainNetwork,
  47. SpendingKeyHex: "6add197bd82866e8bfbf1dc2fdf49873ec5f679059652da549cd806f2b166756",
  48. ViewingKeyHex: "f5cf2897088fda0f7ac1c42491ed7d558a46ee41d0c81d038fd53ff4360afda0",
  49. Address: "45fzHekTd5FfvxWBPYX2TqLPbtWjaofxYUeWCi6BRQXYFYd85sY2qw73bAuKhqY7deFJr6pN3STY81bZ9x2Zf4nGKASksqe",
  50. },
  51. {
  52. name: "require 1 padding in last chunk",
  53. Network: Monero_MainNetwork,
  54. SpendingKeyHex: "50defe92d88b19aaf6bf66f061dd4380b79866a4122b25a03bceb571767dbe7b",
  55. ViewingKeyHex: "f8f6f28283921bf5a17f0bcf4306233fc25ce9b6276154ad0de22aebc5c67702",
  56. Address: "44grjkXtDHJVbZgtU1UKnrNXidcHfZ3HWToU5WjR3KgHMjgwrYLjXC6i5vm3HCp4vnBfYaNEyNiuZVwqtHD2SenS1JBRyco",
  57. },
  58. {
  59. name: "testnet",
  60. Network: Monero_TestNetwork,
  61. SpendingKeyHex: "8de9cce254e60cd940abf6c77ef344c3a21fad74320e45734fbfcd5870e5c875",
  62. ViewingKeyHex: "27024b45150037b677418fcf11ba9675494ffdf994f329b9f7a8f8402b7934a0",
  63. Address: "9xYZvCDf6aFdLd7Qawg5XHZitWLKoeFvcLHfe5GxsGCFLbXSWeQNKciXX9YN4T7nPPLcpqYLUdrFiY77nQYeH9RuK9bogZJ",
  64. },
  65. {
  66. name: "DERO testnet",
  67. Network: config.Testnet.Public_Address_Prefix,
  68. SpendingKeyHex: "ffb4baf32792d38d36c5f1792201d1cff142a10bad6aa088090156a35858739d",
  69. ViewingKeyHex: "0ea428a9608fc9dc06acceea608ac97cc9119647b943941a381306548ee43455",
  70. Address: "dETosYceeTxRZQBk5hQzN51JepzZn5H24JqR96q7mY7ZFo6JhJKPNSKR3vs9ES1ibyQDQgeRheDP6CJbb7AKJY2H9eacz2RtPy",
  71. },
  72. }
  73. var base58 string
  74. var spendingKey, viewingKey []byte
  75. for _, test := range tests {
  76. spendingKey, _ = hex.DecodeString(test.SpendingKeyHex)
  77. viewingKey, _ = hex.DecodeString(test.ViewingKeyHex)
  78. _ = spendingKey
  79. _ = viewingKey
  80. address, err := NewAddress(test.Address)
  81. if err != nil {
  82. t.Errorf("%s: Failed while parsing address %s", test.name, err)
  83. continue
  84. }
  85. _ = address
  86. if address.Network != test.Network {
  87. t.Errorf("%s: want: %d, got: %d", test.name, test.Network, address.Network)
  88. continue
  89. }
  90. if bytes.Compare(address.SpendingKey, spendingKey) != 0 {
  91. t.Errorf("%s: want: %x, got: %x", test.name, spendingKey, address.SpendingKey)
  92. continue
  93. }
  94. if bytes.Compare(address.ViewingKey, viewingKey) != 0 {
  95. t.Errorf("%s: want: %x, got: %x", test.name, viewingKey, address.ViewingKey)
  96. continue
  97. }
  98. base58 = address.Base58()
  99. if base58 != test.Address {
  100. t.Errorf("%s: want: %s, got: %s", test.name, test.Address, base58)
  101. continue
  102. }
  103. }
  104. }