forked from woodser/monero-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestMoneroWalletFull.java
2216 lines (1887 loc) · 75.2 KB
/
TestMoneroWalletFull.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import common.utils.GenUtils;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import monero.common.MoneroError;
import monero.common.MoneroRpcConnection;
import monero.common.MoneroUtils;
import monero.daemon.model.MoneroKeyImage;
import monero.daemon.model.MoneroNetworkType;
import monero.wallet.MoneroWallet;
import monero.wallet.MoneroWalletFull;
import monero.wallet.MoneroWalletRpc;
import monero.wallet.model.MoneroMultisigInfo;
import monero.wallet.model.MoneroMultisigInitResult;
import monero.wallet.model.MoneroOutputQuery;
import monero.wallet.model.MoneroOutputWallet;
import monero.wallet.model.MoneroSyncResult;
import monero.wallet.model.MoneroTransfer;
import monero.wallet.model.MoneroTransferQuery;
import monero.wallet.model.MoneroTxWallet;
import monero.wallet.model.MoneroWalletConfig;
import monero.wallet.model.MoneroWalletListener;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import utils.StartMining;
import utils.TestUtils;
import utils.WalletEqualityUtils;
import utils.WalletSyncPrinter;
/**
* Tests specific to the fully client-side wallet.
*/
@TestInstance(Lifecycle.PER_CLASS) // so @BeforeAll and @AfterAll can be used on non-static functions
public class TestMoneroWalletFull extends TestMoneroWalletCommon {
public static boolean FULL_TESTS_RUN = false;
public TestMoneroWalletFull() {
super();
}
@Override
@BeforeAll
public void beforeAll() {
super.beforeAll();
}
@Override
@AfterAll
public void afterAll() {
super.afterAll();
FULL_TESTS_RUN = true;
}
@Override
protected MoneroWallet getTestWallet() {
return TestUtils.getWalletFull();
}
@Override
protected MoneroWalletFull openWallet(MoneroWalletConfig config) {
return openWallet(config, true);
}
protected MoneroWalletFull openWallet(MoneroWalletConfig config, boolean startSyncing) {
// assign defaults
if (config == null) config = new MoneroWalletConfig();
if (config.getPassword() == null) config.setPassword(TestUtils.WALLET_PASSWORD);
if (config.getNetworkType() == null) config.setNetworkType(TestUtils.NETWORK_TYPE);
if (config.getServer() == null && config.getConnectionManager() == null) config.setServer(daemon.getRpcConnection());
// open wallet
MoneroWalletFull wallet = MoneroWalletFull.openWallet(config);
if (startSyncing != false && wallet.isConnectedToDaemon()) wallet.startSyncing(TestUtils.SYNC_PERIOD_IN_MS);
return wallet;
}
@Override
protected MoneroWalletFull createWallet(MoneroWalletConfig config) {
return createWallet(config, true);
}
protected MoneroWalletFull createWallet(MoneroWalletConfig config, boolean startSyncing) {
// assign defaults
if (config == null) config = new MoneroWalletConfig();
boolean random = config.getSeed() == null && config.getPrimaryAddress() == null;
if (config.getPath() == null) config.setPath(TestUtils.TEST_WALLETS_DIR + "/" + UUID.randomUUID().toString());
if (config.getPassword() == null) config.setPassword(TestUtils.WALLET_PASSWORD);
if (config.getNetworkType() == null) config.setNetworkType(TestUtils.NETWORK_TYPE);
if (config.getServer() == null && config.getConnectionManager() == null) config.setServer(daemon.getRpcConnection());
if (config.getRestoreHeight() == null && !random) config.setRestoreHeight(0l);
// create wallet
MoneroWalletFull wallet = MoneroWalletFull.createWallet(config);
if (!random) assertEquals(config.getRestoreHeight() == null ? 0l : config.getRestoreHeight(), wallet.getRestoreHeight());
if (startSyncing != false && wallet.isConnectedToDaemon()) wallet.startSyncing(TestUtils.SYNC_PERIOD_IN_MS);
return wallet;
}
@Override
public void closeWallet(MoneroWallet wallet, boolean save) {
wallet.close(save);
}
@Override
protected List<String> getSeedLanguages() {
return MoneroWalletFull.getSeedLanguages();
}
// --------------- DEMONSTRATION OF MONERO PROJECT ISSUES ----------------------
/**
* This test demonstrates that importing key images erases incoming transfers.
*/
//@Disabled // TODO monero-project: fix this https://github.com/monero-project/monero/issues/5812
@Test
public void testImportKeyImagesAndTransfers() {
MoneroWalletFull wallet = null; // create a wallet for this test since it becomes corrupt TODO: use common wallet and move to common tests when fixed
try {
// create and sync a new wallet
String path = getRandomWalletPath();
wallet = createWallet(new MoneroWalletConfig().setPath(path).setSeed(TestUtils.SEED).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT));
wallet.sync();
// repeatedly export and re-import key images and test transfer size
for (int i = 0; i < 3; i++) {
// get incoming transfers before importing
List<MoneroTransfer> inTransfers1 = wallet.getTransfers(new MoneroTransferQuery().setIsIncoming(true));
// export and re-import key images
List<MoneroKeyImage> keyImages = wallet.exportKeyImages();
wallet.importKeyImages(keyImages);
// get incoming transfers after importing
List<MoneroTransfer> inTransfers2 = wallet.getTransfers(new MoneroTransferQuery().setIsIncoming(true));
// incoming transfers should be equal
assertEquals(inTransfers1.size(), inTransfers2.size());
assertEquals(inTransfers1, inTransfers2);
}
} finally {
wallet.close();
}
}
/**
* Test the daemon's ability to not hang from wallets which are continuously
* syncing, have registered listeners, and which are not closed.
*/
@Test
//@Disabled // TODO monero-project: disabled because observing memory leak behavior when all tests run together
public void testCreateWalletsWithoutClose() {
// lets make some wallets and then go away
for (int i = 0; i < 20; i++) {
String path = getRandomWalletPath();
MoneroWalletFull willLeaveYouHanging = createWallet(new MoneroWalletConfig().setPath(path));
willLeaveYouHanging.startSyncing();
willLeaveYouHanging.addListener(new MoneroWalletListener()); // listen for wallet events which could aggrevate hanging
}
// check in on the daemon
daemon.getHeight();
// start mining
try { StartMining.startMining(); }
catch (MoneroError e) { }
// wait for a block
daemon.waitForNextBlockHeader();
// stop mining
try { daemon.stopMining(); }
catch (MoneroError e) { }
// check in on the daemon
daemon.getHeight();
// wallet's intentionally not closed (daemon da man)
}
// ------------------------------- BEGIN TESTS ------------------------------
// Can get the daemon's height
@Test
public void testDaemon() {
assumeTrue(TEST_NON_RELAYS);
assertTrue(wallet.isConnectedToDaemon());
long daemonHeight = wallet.getDaemonHeight();
assertTrue(daemonHeight > 0);
}
// Can get the daemon's max peer height
@Test
public void testGetDaemonMaxPeerHeight() {
assumeTrue(TEST_NON_RELAYS);
long height = ((MoneroWalletFull) wallet).getDaemonMaxPeerHeight();
assertTrue(height > 0);
}
// @Test
// public void getApproximateChainHeight() {
// long height = wallet.getApproximateChainHeight();
// assertTrue(height > 0);
// }
// Can create a random full wallet
@Test
public void testCreateWalletRandomFull() {
assumeTrue(TEST_NON_RELAYS);
// create random wallet with defaults
String path = getRandomWalletPath();
MoneroWalletFull wallet = createWallet(new MoneroWalletConfig().setPath(path).setNetworkType(MoneroNetworkType.MAINNET).setServerUri(TestUtils.OFFLINE_SERVER_URI));
MoneroUtils.validateMnemonic(wallet.getSeed());
MoneroUtils.validateAddress(wallet.getPrimaryAddress(), MoneroNetworkType.MAINNET);
assertEquals(MoneroNetworkType.MAINNET, wallet.getNetworkType());
assertEquals(new MoneroRpcConnection(TestUtils.OFFLINE_SERVER_URI), wallet.getDaemonConnection());
assertFalse(wallet.isConnectedToDaemon());
assertEquals("English", wallet.getSeedLanguage());
assertEquals(path, wallet.getPath());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight()); // TODO monero-project: why does height of new unsynced wallet start at 1?
assertTrue(wallet.getRestoreHeight() >= 0);
// cannot get daemon chain height
try {
wallet.getDaemonHeight();
} catch (MoneroError e) {
assertEquals("Wallet is not connected to daemon", e.getMessage());
}
// set daemon connection and check chain height
wallet.setDaemonConnection(daemon.getRpcConnection());
assertEquals(daemon.getHeight(), wallet.getDaemonHeight());
// close wallet which releases resources
wallet.close();
// create random wallet with non defaults
path = getRandomWalletPath();
wallet = createWallet(new MoneroWalletConfig().setPath(path).setNetworkType(MoneroNetworkType.TESTNET).setLanguage("Spanish"), false);
MoneroUtils.validateMnemonic(wallet.getSeed());
MoneroUtils.validateAddress(wallet.getPrimaryAddress(), MoneroNetworkType.TESTNET);
assertEquals(MoneroNetworkType.TESTNET, wallet.getNetworkType());
assertNotNull(wallet.getDaemonConnection());
assertTrue(daemon.getRpcConnection() != wallet.getDaemonConnection());
assertTrue(daemon.getRpcConnection().equals(wallet.getDaemonConnection()));
assertTrue(wallet.isConnectedToDaemon());
assertEquals("Spanish", wallet.getSeedLanguage());
assertEquals(path, wallet.getPath());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight()); // TODO monero-project: why is height of unsynced wallet 1?
if (daemon.isConnected()) assertEquals(daemon.getHeight(), wallet.getRestoreHeight());
else assertTrue(wallet.getRestoreHeight() >= 0);
wallet.close();
}
// Can create a full wallet from seed
@Test
public void testCreateWalletFromSeedFull() {
assumeTrue(TEST_NON_RELAYS);
// create unconnected wallet with seed
String path = getRandomWalletPath();
MoneroWalletFull wallet = createWallet(new MoneroWalletConfig().setPath(path).setSeed(TestUtils.SEED).setServerUri(TestUtils.OFFLINE_SERVER_URI));
assertEquals(TestUtils.SEED, wallet.getSeed());
assertEquals(TestUtils.ADDRESS, wallet.getPrimaryAddress());
assertEquals(TestUtils.NETWORK_TYPE, wallet.getNetworkType());
assertEquals(new MoneroRpcConnection(TestUtils.OFFLINE_SERVER_URI), wallet.getDaemonConnection());
assertFalse(wallet.isConnectedToDaemon());
assertEquals("English", wallet.getSeedLanguage());
assertEquals(path, wallet.getPath());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight());
assertEquals(0, wallet.getRestoreHeight());
try { wallet.startSyncing(); } catch (MoneroError e) { assertEquals("Wallet is not connected to daemon", e.getMessage()); }
wallet.close();
// create wallet without restore height
path = getRandomWalletPath();
wallet = createWallet(new MoneroWalletConfig().setPath(path).setSeed(TestUtils.SEED), false);
assertEquals(TestUtils.SEED, wallet.getSeed());
assertEquals(TestUtils.ADDRESS, wallet.getPrimaryAddress());
assertEquals(TestUtils.NETWORK_TYPE, wallet.getNetworkType());
assertNotNull(wallet.getDaemonConnection());
assertTrue(daemon.getRpcConnection() != wallet.getDaemonConnection());
assertTrue(daemon.getRpcConnection().equals(wallet.getDaemonConnection()));
assertTrue(wallet.isConnectedToDaemon());
assertEquals("English", wallet.getSeedLanguage());
assertEquals(path, wallet.getPath());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight());
assertEquals(0, wallet.getRestoreHeight()); // TODO: restore height is lost after closing only in JNI
wallet.close();
// create wallet with seed, no connection, and restore height
long restoreHeight = 10000;
path = getRandomWalletPath();
wallet = createWallet(new MoneroWalletConfig().setPath(path).setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight).setServerUri(TestUtils.OFFLINE_SERVER_URI));
assertEquals(TestUtils.SEED, wallet.getSeed());
assertEquals(TestUtils.ADDRESS, wallet.getPrimaryAddress());
assertEquals(TestUtils.NETWORK_TYPE, wallet.getNetworkType());
assertEquals(new MoneroRpcConnection(TestUtils.OFFLINE_SERVER_URI), wallet.getDaemonConnection());
assertFalse(wallet.isConnectedToDaemon());
assertEquals("English", wallet.getSeedLanguage());
assertEquals(1, wallet.getHeight()); // TODO monero-project: why does height of new unsynced wallet start at 1?
assertEquals(restoreHeight, wallet.getRestoreHeight());
assertEquals(path, wallet.getPath());
wallet.close(true);
wallet = openWallet(new MoneroWalletConfig().setPath(path).setServerUri(TestUtils.OFFLINE_SERVER_URI));
assertFalse(wallet.isConnectedToDaemon());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight());
assertEquals(0, wallet.getRestoreHeight()); // restore height is lost after closing
wallet.close();
// create wallet with seed, connection, and restore height
path = getRandomWalletPath();
wallet = createWallet(new MoneroWalletConfig().setPath(path).setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight), false);
assertEquals(TestUtils.SEED, wallet.getSeed());
assertEquals(TestUtils.ADDRESS, wallet.getPrimaryAddress());
assertEquals(TestUtils.NETWORK_TYPE, wallet.getNetworkType());
assertNotNull(wallet.getDaemonConnection());
assertTrue(daemon.getRpcConnection() != wallet.getDaemonConnection());
assertTrue(daemon.getRpcConnection().equals(wallet.getDaemonConnection()));
assertTrue(wallet.isConnectedToDaemon());
assertEquals("English", wallet.getSeedLanguage());
assertEquals(path, wallet.getPath());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight()); // TODO monero-project: why does height of new unsynced wallet start at 1?
assertEquals(restoreHeight, wallet.getRestoreHeight());
wallet.close();
}
// Can create a full wallet from keys
@Test
public void testCreateWalletFromKeysJni() {
assumeTrue(TEST_NON_RELAYS);
// recreate test wallet from keys
String path = getRandomWalletPath();
MoneroWalletFull walletKeys = createWallet(new MoneroWalletConfig().setPath(path).setPrimaryAddress(wallet.getPrimaryAddress()).setPrivateViewKey(wallet.getPrivateViewKey()).setPrivateSpendKey(wallet.getPrivateSpendKey()).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT));
try {
assertEquals(wallet.getSeed(), walletKeys.getSeed());
assertEquals(wallet.getPrimaryAddress(), walletKeys.getPrimaryAddress());
assertEquals(wallet.getPrivateViewKey(), walletKeys.getPrivateViewKey());
assertEquals(wallet.getPublicViewKey(), walletKeys.getPublicViewKey());
assertEquals(wallet.getPrivateSpendKey(), walletKeys.getPrivateSpendKey());
assertEquals(wallet.getPublicSpendKey(), walletKeys.getPublicSpendKey());
assertEquals(TestUtils.FIRST_RECEIVE_HEIGHT, walletKeys.getRestoreHeight());
assertTrue(walletKeys.isConnectedToDaemon());
assertFalse(walletKeys.isSynced());
} finally {
walletKeys.close();
}
}
// Is compatible with monero-wallet-rpc wallet files
@Test
public void testWalletFileCompatibility() {
assumeTrue(TEST_NON_RELAYS);
// create wallet using monero-wallet-rpc
String walletName = GenUtils.getUUID();
MoneroWalletRpc walletRpc = TestUtils.getWalletRpc();
walletRpc.createWallet(new MoneroWalletConfig().setPath(walletName).setPassword(TestUtils.WALLET_PASSWORD).setSeed(TestUtils.SEED).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT));
walletRpc.sync();
BigInteger balance = walletRpc.getBalance();
String outputsHex = walletRpc.exportOutputs();
walletRpc.close(true);
// open as full wallet
MoneroWalletFull walletFull = MoneroWalletFull.openWallet(new MoneroWalletConfig().setPath(TestUtils.WALLET_RPC_LOCAL_WALLET_DIR + "/" + walletName).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
walletFull.sync();
assertEquals(TestUtils.SEED, walletFull.getSeed());
assertEquals(TestUtils.ADDRESS, walletFull.getPrimaryAddress());
assertEquals(balance, walletFull.getBalance());
assertEquals(outputsHex.length(), walletFull.exportOutputs().length());
walletFull.close(true);
// create full wallet
walletName = GenUtils.getUUID();
String path = TestUtils.WALLET_RPC_LOCAL_WALLET_DIR + "/" + walletName;
walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setSeed(TestUtils.SEED).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
walletFull.sync();
balance = walletFull.getBalance();
outputsHex = walletFull.exportOutputs();
walletFull.close(true);
// rebuild wallet cache using full wallet
new File(path).delete();
walletFull = MoneroWalletFull.openWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
walletFull.close(true);
// open wallet using monero-wallet-rpc
walletRpc.openWallet(new MoneroWalletConfig().setPath(walletName).setPassword(TestUtils.WALLET_PASSWORD));
walletRpc.sync();
assertEquals(TestUtils.SEED, walletRpc.getSeed());
assertEquals(TestUtils.ADDRESS, walletRpc.getPrimaryAddress());
assertEquals(balance, walletRpc.getBalance());
assertEquals(outputsHex.length(), walletRpc.exportOutputs().length());
walletRpc.close(true);
}
// Is compatible with monero-wallet-rpc outputs and offline transaction signing
@SuppressWarnings("unused")
@Test
public void testViewOnlyAndOfflineWalletCompatibility() throws InterruptedException, IOException {
assumeTrue(!LITE_MODE && (TEST_NON_RELAYS || TEST_RELAYS));
// create view-only wallet in wallet rpc process
MoneroWalletRpc viewOnlyWallet = TestUtils.startWalletRpcProcess();
viewOnlyWallet.createWallet(new MoneroWalletConfig().setPath(GenUtils.getUUID()).setPassword(TestUtils.WALLET_PASSWORD).setPrimaryAddress(wallet.getPrimaryAddress()).setPrivateViewKey(wallet.getPrivateViewKey()).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT));
viewOnlyWallet.sync();
// create offline full wallet
MoneroWalletFull offlineWallet = createWallet(new MoneroWalletConfig().setPrimaryAddress(wallet.getPrimaryAddress()).setPrivateViewKey(wallet.getPrivateViewKey()).setPrivateSpendKey(wallet.getPrivateSpendKey()).setServerUri(TestUtils.OFFLINE_SERVER_URI).setRestoreHeight(0l));
// test tx signing with wallets
try {
testViewOnlyAndOfflineWallets(viewOnlyWallet, offlineWallet);
} finally {
TestUtils.stopWalletRpcProcess(viewOnlyWallet);
closeWallet(offlineWallet);
}
};
// Is compatible with monero-wallet-rpc multisig wallets
@Test
public void testMultisigCompatibility() throws InterruptedException, IOException {
assumeTrue(!LITE_MODE);
// create participants with full wallet and monero-wallet-rpc
List<MoneroWallet> participants = new ArrayList<MoneroWallet>();
participants.add(TestUtils.startWalletRpcProcess().createWallet(new MoneroWalletConfig().setPath(GenUtils.getUUID()).setPassword(TestUtils.WALLET_PASSWORD)));
participants.add(TestUtils.startWalletRpcProcess().createWallet(new MoneroWalletConfig().setPath(GenUtils.getUUID()).setPassword(TestUtils.WALLET_PASSWORD)));
participants.add(createWallet(new MoneroWalletConfig()));
// test multisig
try {
testMultisig(participants, 3, 3, true);
} finally {
// stop mining at end of test
try { daemon.stopMining(); }
catch (MoneroError e) { }
// save and close participants
if (participants.get(0) instanceof MoneroWalletRpc) TestUtils.stopWalletRpcProcess((MoneroWalletRpc) participants.get(0));
else participants.get(0).close(true); // multisig tests might restore wallet from seed
TestUtils.stopWalletRpcProcess((MoneroWalletRpc) participants.get(1));
closeWallet(participants.get(2), true);
}
};
// Can re-sync an existing wallet from scratch
@Test
@Disabled // TODO monero-project: cannot re-sync from lower block height after wallet saved
public void testResyncExisting() {
assertTrue(MoneroWalletFull.walletExists(TestUtils.WALLET_FULL_PATH));
MoneroWalletFull wallet = openWallet(new MoneroWalletConfig().setPath(TestUtils.WALLET_FULL_PATH).setServerUri(TestUtils.OFFLINE_SERVER_URI), false);
wallet.setDaemonConnection(TestUtils.getDaemonRpc().getRpcConnection());
//long startHeight = TestUtils.TEST_RESTORE_HEIGHT;
long startHeight = 0;
SyncProgressTester progressTester = new SyncProgressTester(wallet, startHeight, wallet.getDaemonHeight());
wallet.setRestoreHeight(1);
MoneroSyncResult result = wallet.sync(1l, progressTester);
progressTester.onDone(wallet.getDaemonHeight());
// test result after syncing
assertTrue(wallet.isConnectedToDaemon());
assertTrue(wallet.isSynced());
assertEquals(wallet.getDaemonHeight() - startHeight, (long) result.getNumBlocksFetched());
assertTrue(result.getReceivedMoney());
assertEquals(daemon.getHeight(), wallet.getHeight());
wallet.close(true);
}
// Can sync a wallet with a randomly generated seed
@Test
public void testSyncRandom() {
assumeTrue(TEST_NON_RELAYS);
assertTrue(daemon.isConnected(), "Not connected to daemon");
// create test wallet
MoneroWalletFull wallet = createWallet(new MoneroWalletConfig(), false);
long restoreHeight = daemon.getHeight();
// test wallet's height before syncing
assertEquals(TestUtils.getDaemonRpc().getRpcConnection(), wallet.getDaemonConnection());
assertEquals(restoreHeight, wallet.getDaemonHeight());
assertTrue(wallet.isConnectedToDaemon());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight());
assertEquals(restoreHeight, wallet.getRestoreHeight());
assertEquals(daemon.getHeight(), wallet.getDaemonHeight());
// sync the wallet
SyncProgressTester progressTester = new SyncProgressTester(wallet, wallet.getRestoreHeight(), wallet.getDaemonHeight());
MoneroSyncResult result = wallet.sync(null, progressTester);
progressTester.onDone(wallet.getDaemonHeight());
// test result after syncing
MoneroWalletFull walletGt = TestUtils.createWalletGroundTruth(TestUtils.NETWORK_TYPE, wallet.getSeed(), null, restoreHeight);
walletGt.sync();
try {
assertTrue(wallet.isConnectedToDaemon());
assertTrue(wallet.isSynced());
assertEquals(0, (long) result.getNumBlocksFetched());
assertFalse(result.getReceivedMoney());
assertEquals(daemon.getHeight(), wallet.getHeight());
// sync the wallet with default params
wallet.sync();
assertTrue(wallet.isSynced());
assertEquals(daemon.getHeight(), wallet.getHeight());
// compare wallet to ground truth
testWalletEqualityOnChain(walletGt, wallet);
} finally {
if (walletGt != null) walletGt.close(true);
wallet.close();
}
// attempt to sync unconnected wallet
wallet = createWallet(new MoneroWalletConfig().setServerUri(TestUtils.OFFLINE_SERVER_URI));
try {
wallet.sync();
fail("Should have thrown exception");
} catch (MoneroError e) {
assertEquals("Wallet is not connected to daemon", e.getMessage());
} finally {
wallet.close();
}
}
// Can sync a wallet created from seed from the genesis
@Test
public void testSyncSeedFromGenesis() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
testSyncSeed(null, null, true, false);
}
// Can sync a wallet created from seed from a restore height
@Test
public void testSyncSeedFromRestoreHeight() {
assumeTrue(TEST_NON_RELAYS);
testSyncSeed(null, TestUtils.FIRST_RECEIVE_HEIGHT);
}
// Can sync a wallet created from seed from a start height.
@Test
public void testSyncSeedFromStartHeight() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
testSyncSeed(TestUtils.FIRST_RECEIVE_HEIGHT, null, false, true);
}
// Can sync a wallet created from seed from a start height less than the restore height
@Test
public void testSyncSeedStartHeightLTRestoreHeight() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
testSyncSeed(TestUtils.FIRST_RECEIVE_HEIGHT, TestUtils.FIRST_RECEIVE_HEIGHT + 3l);
}
// Can sync a wallet created from seed from a start height greater than the restore height
@Test
public void testSyncSeedStartHeightGTRestoreHeight() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
testSyncSeed(TestUtils.FIRST_RECEIVE_HEIGHT + 3l, TestUtils.FIRST_RECEIVE_HEIGHT);
}
private void testSyncSeed(Long startHeight, Long restoreHeight) { testSyncSeed(startHeight, restoreHeight, false, false); }
private void testSyncSeed(Long startHeight, Long restoreHeight, boolean skipGtComparison, boolean testPostSyncNotifications) {
assertTrue(daemon.isConnected(), "Not connected to daemon");
if (startHeight != null && restoreHeight != null) assertTrue(startHeight <= TestUtils.FIRST_RECEIVE_HEIGHT || restoreHeight <= TestUtils.FIRST_RECEIVE_HEIGHT);
// create wallet from seed
MoneroWalletFull wallet = createWallet(new MoneroWalletConfig().setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight), false);
// sanitize expected sync bounds
if (restoreHeight == null) restoreHeight = 0l;
long startHeightExpected = startHeight == null ? restoreHeight : startHeight;
if (startHeightExpected == 0) startHeightExpected = 1;
long endHeightExpected = wallet.getDaemonMaxPeerHeight();
// test wallet and close as final step
MoneroWalletFull walletGt = null;
try {
// test wallet's height before syncing
assertTrue(wallet.isConnectedToDaemon());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight());
assertEquals((long) restoreHeight, wallet.getRestoreHeight());
// register a wallet listener which tests notifications throughout the sync
WalletSyncTester walletSyncTester = new WalletSyncTester(wallet, startHeightExpected, endHeightExpected);
wallet.addListener(walletSyncTester);
// sync the wallet with a listener which tests sync notifications
SyncProgressTester progressTester = new SyncProgressTester(wallet, startHeightExpected, endHeightExpected);
MoneroSyncResult result = wallet.sync(startHeight, progressTester);
// test completion of the wallet and sync listeners
progressTester.onDone(wallet.getDaemonHeight());
walletSyncTester.onDone(wallet.getDaemonHeight());
// test result after syncing
assertTrue(wallet.isSynced());
assertEquals(wallet.getDaemonHeight() - startHeightExpected, (long) result.getNumBlocksFetched());
assertTrue(result.getReceivedMoney());
if (wallet.getHeight() != daemon.getHeight()) System.out.println("WARNING: wallet height " + wallet.getHeight() + " is not synced with daemon height " + daemon.getHeight()); // TODO: height may not be same after long sync
assertEquals(daemon.getHeight(), wallet.getDaemonHeight(), "Daemon heights are not equal: " + wallet.getDaemonHeight() + " vs " + daemon.getHeight());
if (startHeightExpected > TestUtils.FIRST_RECEIVE_HEIGHT) assertTrue(wallet.getTxs().get(0).getHeight() > TestUtils.FIRST_RECEIVE_HEIGHT); // wallet is partially synced so first tx happens after true restore height
else assertEquals(TestUtils.FIRST_RECEIVE_HEIGHT, (long) wallet.getTxs().get(0).getHeight()); // wallet should be fully synced so first tx happens on true restore height
// sync the wallet with default params
result = wallet.sync();
assertTrue(wallet.isSynced());
assertEquals(daemon.getHeight(), wallet.getHeight());
assertTrue(result.getNumBlocksFetched() == 0 || result.getNumBlocksFetched() == 1); // block might be added to chain
assertFalse(result.getReceivedMoney());
// compare with ground truth
if (!skipGtComparison) {
walletGt = TestUtils.createWalletGroundTruth(TestUtils.NETWORK_TYPE, wallet.getSeed(), startHeight, restoreHeight);
testWalletEqualityOnChain(walletGt, wallet);
}
// if testing post-sync notifications, wait for a block to be added to the chain
// then test that sync arg listener was not invoked and registered wallet listener was invoked
if (testPostSyncNotifications) {
// start automatic syncing
wallet.startSyncing(TestUtils.SYNC_PERIOD_IN_MS);
// attempt to start mining to push the network along // TODO: TestUtils.tryStartMining() : reqId, TestUtils.tryStopMining(reqId)
boolean startedMining = false;
try {
StartMining.startMining();
startedMining = true;
} catch (Exception e) {
// no problem
}
try {
// wait for block
System.out.println("Waiting for next block to test post sync notifications");
daemon.waitForNextBlockHeader();
// ensure wallet has time to detect new block
try {
TimeUnit.MILLISECONDS.sleep(TestUtils.SYNC_PERIOD_IN_MS + 3000); // sleep for wallet interval + time to sync
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
// test that wallet listener's onSyncProgress() and onNewBlock() were invoked after previous completion
assertTrue(walletSyncTester.getOnSyncProgressAfterDone());
assertTrue(walletSyncTester.getOnNewBlockAfterDone());
} finally {
if (startedMining) wallet.stopMining();
}
}
} finally {
if (walletGt != null) walletGt.close(true);
wallet.close();
}
}
// Can sync a wallet created from keys
@Test
public void testSyncWalletFromKeys() {
assumeTrue(TEST_NON_RELAYS);
// recreate test wallet from keys
String path = getRandomWalletPath();
MoneroWalletFull walletKeys = createWallet(new MoneroWalletConfig().setPath(path).setPrimaryAddress(wallet.getPrimaryAddress()).setPrivateViewKey(wallet.getPrivateViewKey()).setPrivateSpendKey(wallet.getPrivateSpendKey()).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT), false);
// create ground truth wallet for comparison
MoneroWalletFull walletGt = TestUtils.createWalletGroundTruth(TestUtils.NETWORK_TYPE, TestUtils.SEED, null, TestUtils.FIRST_RECEIVE_HEIGHT);
// test wallet and close as final step
try {
assertEquals(walletKeys.getSeed(), walletGt.getSeed());
assertEquals(walletKeys.getPrimaryAddress(), walletGt.getPrimaryAddress());
assertEquals(walletKeys.getPrivateViewKey(), walletGt.getPrivateViewKey());
assertEquals(walletKeys.getPublicViewKey(), walletGt.getPublicViewKey());
assertEquals(walletKeys.getPrivateSpendKey(), walletGt.getPrivateSpendKey());
assertEquals(walletKeys.getPublicSpendKey(), walletGt.getPublicSpendKey());
assertEquals(TestUtils.FIRST_RECEIVE_HEIGHT, walletGt.getRestoreHeight());
assertTrue(walletKeys.isConnectedToDaemon());
assertFalse(walletKeys.isSynced());
// sync the wallet
SyncProgressTester progressTester = new SyncProgressTester(walletKeys, TestUtils.FIRST_RECEIVE_HEIGHT, walletKeys.getDaemonMaxPeerHeight());
MoneroSyncResult result = walletKeys.sync(progressTester);
progressTester.onDone(walletKeys.getDaemonHeight());
// test result after syncing
assertTrue(walletKeys.isSynced());
assertEquals(walletKeys.getDaemonHeight() - TestUtils.FIRST_RECEIVE_HEIGHT, (long) result.getNumBlocksFetched());
assertTrue(result.getReceivedMoney());
assertEquals(daemon.getHeight(), walletKeys.getHeight());
assertEquals(daemon.getHeight(), walletKeys.getDaemonHeight());
assertEquals(TestUtils.FIRST_RECEIVE_HEIGHT, (long) walletKeys.getTxs().get(0).getHeight()); // wallet should be fully synced so first tx happens on true restore height
// compare with ground truth
testWalletEqualityOnChain(walletGt, walletKeys);
} finally {
walletGt.close(true);
walletKeys.close();
}
// TODO monero-project: importing key images can cause erasure of incoming transfers per wallet2.cpp:11957 which causes this test to fail
// // sync the wallets until same height
// while (wallet.getHeight() != walletKeys.getHeight()) {
// wallet.sync();
// walletKeys.sync(new WalletSyncPrinter());
// }
//
// List<MoneroKeyImage> keyImages = walletKeys.exportKeyImages();
// walletKeys.importKeyImages(keyImages);
}
// TODO: test start syncing, notification of syncs happening, stop syncing, no notifications, etc
// Can start and stop syncing
@Test
public void testStartStopSyncing() {
assumeTrue(TEST_NON_RELAYS);
// test unconnected wallet
String path = getRandomWalletPath();
MoneroWalletFull wallet = createWallet(new MoneroWalletConfig().setServerUri(TestUtils.OFFLINE_SERVER_URI));
try {
assertNotNull(wallet.getSeed());
assertEquals(1, wallet.getHeight());
assertEquals(BigInteger.valueOf(0), wallet.getBalance());
wallet.startSyncing();
} catch (MoneroError e) {
assertEquals("Wallet is not connected to daemon", e.getMessage());
} finally {
wallet.close();
}
// test connecting wallet
path = getRandomWalletPath();
wallet = createWallet(new MoneroWalletConfig().setPath(path).setServerUri(TestUtils.OFFLINE_SERVER_URI));
try {
assertNotNull(wallet.getSeed());
wallet.setDaemonConnection(daemon.getRpcConnection());
assertEquals(1, wallet.getHeight());
assertFalse(wallet.isSynced());
assertEquals(BigInteger.valueOf(0), wallet.getBalance());
long chainHeight = wallet.getDaemonHeight();
wallet.setRestoreHeight(chainHeight - 3);
wallet.startSyncing();
assertEquals(chainHeight - 3, wallet.getRestoreHeight());
assertEquals(daemon.getRpcConnection(), wallet.getDaemonConnection());
wallet.stopSyncing();
wallet.sync();
wallet.stopSyncing();
wallet.stopSyncing();
} finally {
wallet.close();
}
// test that sync starts automatically
long restoreHeight = daemon.getHeight() - 100;
path = getRandomWalletPath();
wallet = createWallet(new MoneroWalletConfig().setPath(path).setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight), false);
try {
// start syncing
assertEquals(1, wallet.getHeight());
assertEquals(restoreHeight, wallet.getRestoreHeight());
assertFalse(wallet.isSynced());
assertEquals(BigInteger.valueOf(0), wallet.getBalance());
wallet.startSyncing(TestUtils.SYNC_PERIOD_IN_MS);
// pause for sync to start
try {
System.out.println("Sleeping to test that sync starts automatically...");
TimeUnit.MILLISECONDS.sleep(TestUtils.SYNC_PERIOD_IN_MS + 1000);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
// test that wallet has started syncing
assertTrue(wallet.getHeight() > 1);
// stop syncing
wallet.stopSyncing();
// TODO monero-project: wallet.cpp m_synchronized only ever set to true, never false
// // wait for block to be added to chain
// daemon.getNextBlockHeader();
//
// // wallet is no longer synced
// assertFalse(wallet.isSynced());
} finally {
wallet.close();
}
}
// Does not interfere with other wallet notifications
@Test
public void testWalletsDoNotInterfere() {
// create 2 wallets with a recent restore height
long height = daemon.getHeight();
long restoreHeight = height - 5;
MoneroWalletFull wallet1 = createWallet(new MoneroWalletConfig().setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight), false);
MoneroWalletFull wallet2 = createWallet(new MoneroWalletConfig().setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight), false);
// track notifications of each wallet
SyncProgressTester tester1 = new SyncProgressTester(wallet1, restoreHeight, height);
SyncProgressTester tester2 = new SyncProgressTester(wallet1, restoreHeight, height);
wallet1.addListener(tester1);
wallet2.addListener(tester2);
// sync first wallet and test that 2nd is not notified
wallet1.sync();
assertTrue(tester1.isNotified());
assertFalse(tester2.isNotified());
// sync 2nd wallet and test that 1st is not notified
SyncProgressTester tester3 = new SyncProgressTester(wallet1, restoreHeight, height);
wallet1.addListener(tester3);
wallet2.sync();
assertTrue(tester2.isNotified());
assertFalse(tester3.isNotified());
}
// Is equal to the RPC wallet.
@Test
public void testWalletEqualityRpc() {
WalletEqualityUtils.testWalletEqualityOnChain(TestUtils.getWalletRpc(), wallet);
}
// Is equal to the RPC wallet with a seed offset
@Test
public void testWalletEqualityRpcWithOffset() {
// use common offset to compare wallet implementations
String seedOffset = "my super secret offset!";
// create rpc wallet with offset
MoneroWalletRpc walletRpc = TestUtils.getWalletRpc();
walletRpc.createWallet(new MoneroWalletConfig().setPath(UUID.randomUUID().toString()).setPassword(TestUtils.WALLET_PASSWORD).setSeed(walletRpc.getSeed()).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT).setSeedOffset(seedOffset));
// create full wallet with offset
MoneroWalletFull walletFull = createWallet(new MoneroWalletConfig()
.setPath(getRandomWalletPath())
.setPassword(TestUtils.WALLET_PASSWORD)
.setNetworkType(TestUtils.NETWORK_TYPE)
.setSeed(TestUtils.SEED)
.setServer(TestUtils.getDaemonRpc().getRpcConnection())
.setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT)
.setSeedOffset(seedOffset));
// deep compare
try {
WalletEqualityUtils.testWalletEqualityOnChain(walletRpc, walletFull);
} finally {
walletFull.close();
}
}
// Can be saved
@Test
public void testSave() {
assumeTrue(TEST_NON_RELAYS);
// create unique path for new test wallet
String path = getRandomWalletPath();
// wallet does not exist
assertFalse(MoneroWalletFull.walletExists(path));
// cannot open non-existent wallet
try {
openWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE));
fail("Cannot open non-existent wallet");
} catch (MoneroError e) {
assertEquals("Wallet does not exist at path: " + path, e.getMessage());
}
// create wallet at the path
long restoreHeight = daemon.getHeight() - 200;
MoneroWalletFull wallet = createWallet(new MoneroWalletConfig().setPath(path).setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight).setServerUri(TestUtils.OFFLINE_SERVER_URI));
// test wallet at newly created state
try {
assertTrue(MoneroWalletFull.walletExists(path));
assertEquals(TestUtils.SEED, wallet.getSeed());
assertEquals(TestUtils.NETWORK_TYPE, wallet.getNetworkType());
assertEquals(new MoneroRpcConnection(TestUtils.OFFLINE_SERVER_URI), wallet.getDaemonConnection());
assertEquals(restoreHeight, wallet.getRestoreHeight());
assertEquals("English", wallet.getSeedLanguage());
assertEquals(1, wallet.getHeight());
assertEquals(restoreHeight, wallet.getRestoreHeight());
// set the wallet's connection and sync
wallet.setDaemonConnection(TestUtils.getDaemonRpc().getRpcConnection());
wallet.sync();
assertEquals(wallet.getDaemonHeight(), wallet.getHeight());
// close the wallet without saving
wallet.close();
// re-open the wallet
wallet = openWallet(new MoneroWalletConfig().setPath(path).setServerUri(TestUtils.OFFLINE_SERVER_URI));
// test wallet is at newly created state
assertTrue(MoneroWalletFull.walletExists(path));
assertEquals(TestUtils.SEED, wallet.getSeed());
assertEquals(TestUtils.NETWORK_TYPE, wallet.getNetworkType());
assertEquals(new MoneroRpcConnection(TestUtils.OFFLINE_SERVER_URI), wallet.getDaemonConnection());
assertFalse(wallet.isConnectedToDaemon());
assertEquals("English", wallet.getSeedLanguage());
assertFalse(wallet.isSynced());
assertEquals(1, wallet.getHeight());
assertEquals(0, wallet.getRestoreHeight()); // TODO monero-project: restoreHeight is reset to 0 after closing
// set the wallet's connection and sync
wallet.setDaemonConnection(TestUtils.getDaemonRpc().getRpcConnection());
assertTrue(wallet.isConnectedToDaemon());
wallet.setRestoreHeight(restoreHeight);
wallet.sync();
assertTrue(wallet.isSynced());
assertEquals(wallet.getDaemonHeight(), wallet.getHeight());
long prevHeight = wallet.getHeight();
// save and close the wallet
wallet.save();
wallet.close();
// re-open the wallet
wallet = openWallet(new MoneroWalletConfig().setPath(path).setServerUri(TestUtils.OFFLINE_SERVER_URI));
// test wallet state is saved
assertFalse(wallet.isConnectedToDaemon());
wallet.setDaemonConnection(TestUtils.getDaemonRpc().getRpcConnection()); // TODO monero-project: daemon connection not stored in wallet files so must be explicitly set each time
assertEquals(TestUtils.getDaemonRpc().getRpcConnection(), wallet.getDaemonConnection());
assertTrue(wallet.isConnectedToDaemon());
assertEquals(prevHeight, wallet.getHeight());
assertEquals(0, wallet.getRestoreHeight()); // TODO monero-project: restoreHeight is reset to 0 after closing
assertTrue(MoneroWalletFull.walletExists(path));
assertEquals(TestUtils.SEED, wallet.getSeed());
assertEquals(TestUtils.NETWORK_TYPE, wallet.getNetworkType());
assertEquals("English", wallet.getSeedLanguage());
// sync
wallet.sync();
} finally {
wallet.close();
}
}
// Can export and import wallet files
@Test
public void testGetData() {
assumeTrue(TEST_NON_RELAYS);
MoneroWalletFull wallet = null;
MoneroWalletFull wallet2 = null;
try {
// create random wallet
wallet = MoneroWalletFull.createWallet(new MoneroWalletConfig()
.setNetworkType(MoneroNetworkType.MAINNET)
.setPassword("password123"));