From 24bdc100fb479843132f8f6e577f69cf62341323 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 10 Nov 2022 15:49:19 -0600 Subject: [PATCH] add address validation tests --- crypto_plugins/flutter_libmonero | 2 +- .../coins/monero/monero_wallet_test.dart | 22 ++++++++++++++++++- .../coins/wownero/wownero_wallet_test.dart | 12 ++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/crypto_plugins/flutter_libmonero b/crypto_plugins/flutter_libmonero index 8a8c88cda..2da774385 160000 --- a/crypto_plugins/flutter_libmonero +++ b/crypto_plugins/flutter_libmonero @@ -1 +1 @@ -Subproject commit 8a8c88cdade6fe18529deea410f862b125167a3b +Subproject commit 2da77438527732dfaa5398aa391eab5253dabe19 diff --git a/test/services/coins/monero/monero_wallet_test.dart b/test/services/coins/monero/monero_wallet_test.dart index d54959ab2..4c4daa9ac 100644 --- a/test/services/coins/monero/monero_wallet_test.dart +++ b/test/services/coins/monero/monero_wallet_test.dart @@ -92,7 +92,7 @@ void main() async { _walletInfoSource = await Hive.openBox(WalletInfo.boxName); walletService = monero.createMoneroWalletService(_walletInfoSource); - group("Mainnet tests", () { + group("Mnemonic recovery", () { setUp(() async { try { // if (name?.isEmpty ?? true) { @@ -133,6 +133,26 @@ void main() async { } }); + test("Test address validation", () async { // TODO I'd like to refactor/separate this out so I can test addresses alone, without having to first create a wallet. + final wallet = await _walletCreationService.restoreFromSeed(credentials); + walletBase = wallet as MoneroWalletBase; + + expect( + await walletBase!.validateAddress(''), false); + expect( + await walletBase!.validateAddress('4AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn'), true); + expect( + await walletBase!.validateAddress('4asdfkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gpjkl'), false); + expect( + await walletBase!.validateAddress('8AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn'), false); + expect( + await walletBase!.validateAddress('84kYPuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenvHy'), true); + expect( + await walletBase!.validateAddress('8asdfuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenjkl'), false); + expect( + await walletBase!.validateAddress('44kYPuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenvHy'), false); + }); + test("Test mainnet address generation from seed", () async { final wallet = await // _walletCreationService.create(credentials); diff --git a/test/services/coins/wownero/wownero_wallet_test.dart b/test/services/coins/wownero/wownero_wallet_test.dart index 660bc1438..8daa91755 100644 --- a/test/services/coins/wownero/wownero_wallet_test.dart +++ b/test/services/coins/wownero/wownero_wallet_test.dart @@ -122,6 +122,18 @@ void main() async { expect(hasThrown, false); }); + test("Test address validation", () async { // TODO I'd like to refactor/separate this out so I can test addresses alone, without having to first create a wallet. + final wallet = await _walletCreationService.restoreFromSeed(credentials); + walletBase = wallet as WowneroWalletBase; + + expect( + await walletBase!.validateAddress(''), false); + expect( + await walletBase!.validateAddress('Wo3jmHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmsEi'), true); + expect( + await walletBase!.validateAddress('WasdfHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmjkl'), false); + }); + test("Wownero 14 word seed address generation", () async { final wallet = await _walletCreationService.create(credentials); // TODO validate mnemonic