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 createTransactionAndBroadcast() throws Exception { pocket.onConnection(getBlockchainConnection(DOGE)); BitAddress toAddr = BitAddress.from(DOGE, "nZB8PHkfgJvuCJqchSexmfY3ABXa2aE1vp"); Value orgBalance = pocket.getBalance(); BitSendRequest sendRequest = pocket.sendCoinsOffline(toAddr, DOGE.value(AMOUNT_TO_SEND)); sendRequest.shuffleOutputs = false; sendRequest.feePerTxSize = DOGE.value(0); pocket.completeTransaction(sendRequest); // FIXME, mock does not work here // pocket.broadcastTx(tx); pocket.addNewTransactionIfNeeded(sendRequest.tx); assertEquals(orgBalance.subtract(AMOUNT_TO_SEND), pocket.getBalance()); }
assertEquals(BTC.value("1"), account1.getBalance()); assertEquals(BTC.value("0"), account2.getBalance()); assertEquals(BTC.value("0"), account3.getBalance()); assertEquals(BTC.value("0.94"), account1.getBalance()); assertEquals(BTC.value("0"), account2.getBalance()); assertEquals(BTC.value("0"), account3.getBalance()); assertEquals(BTC.value("0.94"), account1.getBalance()); assertEquals(BTC.value("0.05"), account2.getBalance()); setTrustedTransaction(account3, txId); assertEquals(BTC.value("0.86"), account1.getBalance()); assertEquals(BTC.value("0.05"), account2.getBalance()); assertEquals(BTC.value("0.07"), account3.getBalance()); setTrustedTransaction(account3, txId); assertEquals(BTC.value("0.86"), account1.getBalance()); assertEquals(BTC.value("0.01"), account2.getBalance()); assertEquals(BTC.value("0.1"), account3.getBalance());
@Test public void fillTransactions() throws Exception { pocket.onConnection(getBlockchainConnection(DOGE)); checkUnspentOutputs(getDummyUtxoSet(), pocket); assertEquals(11000000000L, pocket.getBalance().value); // Issued keys assertEquals(18, pocket.keys.getNumIssuedExternalKeys()); assertEquals(9, pocket.keys.getNumIssuedInternalKeys()); // No addresses left to subscribe List<AbstractAddress> addressesToWatch = pocket.getAddressesToWatch(); assertEquals(0, addressesToWatch.size()); // 18 external issued + 20 lookahead + 9 external issued + 20 lookahead assertEquals(67, pocket.addressesStatus.size()); assertEquals(67, pocket.addressesSubscribed.size()); BitAddress receiveAddr = pocket.getReceiveAddress(); // This key is not issued assertEquals(18, pocket.keys.getNumIssuedExternalKeys()); assertEquals(67, pocket.addressesStatus.size()); assertEquals(67, pocket.addressesSubscribed.size()); DeterministicKey key = pocket.keys.findKeyFromPubHash(receiveAddr.getHash160()); assertNotNull(key); // 18 here is the key index, not issued keys count assertEquals(18, key.getChildNumber().num()); assertEquals(11000000000L, pocket.getBalance().value); }
@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); }
assertEquals(pocket.getBalance().value, newPocket.getBalance().value); assertEquals(DOGE.value(11000000000l), newPocket.getBalance());