@Test public void usedAddresses() throws Exception { assertEquals(0, pocket.getUsedAddresses().size()); pocket.onConnection(getBlockchainConnection(DOGE)); // Receive and change addresses assertEquals(13, pocket.getUsedAddresses().size()); }
@Test public void testLoading() throws Exception { assertFalse(pocket.isLoading()); pocket.onConnection(getBlockchainConnection(DOGE)); // TODO add fine grained control to the blockchain connection in order to test the loading status assertFalse(pocket.isLoading()); }
@Test public void testSingleAddressWallet() throws Exception { ECKey key = pocket.keys.getCurrentUnusedKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); BitWalletSingleKey bitWalletSingleKey = new BitWalletSingleKey(DOGE, key); bitWalletSingleKey.onConnection(getBlockchainConnection(DOGE)); assertEquals(DOGE.value("10"), bitWalletSingleKey.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 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()); }
@Test public void createDustTransactionFee() throws Exception { pocket.onConnection(getBlockchainConnection(DOGE)); BitAddress toAddr = BitAddress.from(DOGE, "nZB8PHkfgJvuCJqchSexmfY3ABXa2aE1vp"); Value softDust = DOGE.getSoftDustLimit(); assertNotNull(softDust); // Send a soft dust BitSendRequest sendRequest = pocket.sendCoinsOffline(toAddr, softDust.subtract(DOGE.value(1))); pocket.completeTransaction(sendRequest); assertEquals(DOGE.getFeeValue().multiply(2), sendRequest.tx.getFee()); }
pocket.onConnection(getBlockchainConnection(DOGE));
@Test public void serializeUnencryptedNormal() throws Exception { pocket.onConnection(getBlockchainConnection(DOGE)); assertEquals(9, newPocket.keys.getNumIssuedInternalKeys()); newPocket.onConnection(getBlockchainConnection(DOGE));
@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); }