@Test public void serializeEncryptedEmpty() throws Exception { pocket.maybeInitializeAllKeys(); pocket.encrypt(crypter, aesKey); Protos.WalletPocket walletPocketProto = pocket.toProtobuf(); WalletPocketHD newPocket = new WalletPocketProtobufSerializer().readWallet(walletPocketProto, crypter); assertEquals(walletPocketProto.toString(), newPocket.toProtobuf().toString()); pocket.decrypt(aesKey); // One is encrypted, so they should not match assertNotEquals(pocket.toProtobuf().toString(), newPocket.toProtobuf().toString()); newPocket.decrypt(aesKey); assertEquals(pocket.toProtobuf().toString(), newPocket.toProtobuf().toString()); }
private WalletPocketHD testWalletSerializationForCoin(WalletPocketHD account) throws UnreadableWalletException { Protos.WalletPocket proto = account.toProtobuf(); WalletPocketHD newAccount = new WalletPocketProtobufSerializer().readWallet(proto, null); assertEquals(account.getBalance().value, newAccount.getBalance().value); Map<Sha256Hash, BitTransaction> transactions = account.getTransactions(); Map<Sha256Hash, BitTransaction> newTransactions = newAccount.getTransactions(); for (Sha256Hash txId : transactions.keySet()) { assertTrue(newTransactions.containsKey(txId)); assertEquals(transactions.get(txId), newTransactions.get(txId)); } return newAccount; }
@Test public void serializeUnencryptedEmpty() throws Exception { pocket.maybeInitializeAllKeys(); Protos.WalletPocket walletPocketProto = pocket.toProtobuf(); WalletPocketHD newPocket = new WalletPocketProtobufSerializer().readWallet(walletPocketProto, null); assertEquals(walletPocketProto.toString(), newPocket.toProtobuf().toString()); // Issued keys assertEquals(0, newPocket.keys.getNumIssuedExternalKeys()); assertEquals(0, newPocket.keys.getNumIssuedInternalKeys()); // 20 lookahead + 20 lookahead assertEquals(40, newPocket.keys.getActiveKeys().size()); }
@Test public void xpubWalletSerialized() throws Exception { WalletPocketHD account = new WalletPocketHD(rootKey, BTC, null, null); Protos.WalletPocket proto = account.toProtobuf(); WalletPocketHD newAccount = new WalletPocketProtobufSerializer().readWallet(proto, null); assertEquals(account.getPublicKeySerialized(), newAccount.getPublicKeySerialized()); }
pocket.onConnection(getBlockchainConnection(DOGE)); Protos.WalletPocket walletPocketProto = pocket.toProtobuf(); System.out.println(walletPocketProto.toString());
@Test public void serializeEncryptedNormal() throws Exception { pocket.maybeInitializeAllKeys(); pocket.encrypt(crypter, aesKey); pocket.onConnection(getBlockchainConnection(DOGE)); assertEquals(DOGE.value(11000000000l), pocket.getBalance()); assertAllKeysEncrypted(pocket); WalletPocketHD newPocket = new WalletPocketProtobufSerializer().readWallet(pocket.toProtobuf(), crypter); assertEquals(DOGE.value(11000000000l), newPocket.getBalance()); Map<TrimmedOutPoint, OutPointOutput> expectedUtxoSet = getDummyUtxoSet(); checkUnspentOutputs(expectedUtxoSet, pocket); checkUnspentOutputs(expectedUtxoSet, newPocket); assertAllKeysEncrypted(newPocket); pocket.decrypt(aesKey); newPocket.decrypt(aesKey); assertAllKeysDecrypted(pocket); assertAllKeysDecrypted(newPocket); }