@Test public void xpubWallet() { String xpub = "xpub67tVq9TLPPoaHVSiYu8mqahm3eztTPUts6JUftNq3pZF1PJwjknrTqQhjc2qRGd6vS8wANu7mLnqkiUzFZ1xZsAZoUMi8o6icMhzGCAhcSW"; DeterministicKey key = DeterministicKey.deserializeB58(null, xpub); WalletPocketHD account = new WalletPocketHD(key, BTC, null, null); assertEquals("1KUDsEDqSBAgxubSEWszoA9xscNRRCmujM", account.getReceiveAddress().toString()); account = new WalletPocketHD(key, NBT, null, null); assertEquals("BNvJUwg3BgkbQk5br1CxvHxdcDp1EC3saE", account.getReceiveAddress().toString()); }
@Test public void signMessageEncryptedFailed() throws AddressMalformedException, MissingPrivateKeyException, KeyIsEncryptedException { WalletPocketHD pocketHD = new WalletPocketHD(rootKey, BTC, null, null); pocketHD.getReceiveAddress(); // Generate the first key pocketHD.encrypt(crypter, aesKey); SignedMessage signedMessage = new SignedMessage("1KUDsEDqSBAgxubSEWszoA9xscNRRCmujM", MESSAGE); pocketHD.signMessage(signedMessage, null); assertEquals(SignedMessage.Status.KeyIsEncrypted, signedMessage.status); }
@Test public void serializeTransactionsBtc() throws Exception, Bip44KeyLookAheadExceededException { WalletPocketHD account = new WalletPocketHD(rootKey, BTC, null, null); Transaction tx = new Transaction(BTC); tx.addOutput(BTC.oneCoin().toCoin(), account.getReceiveAddress()); account.addNewTransactionIfNeeded(tx); testWalletSerializationForCoin(account); }
@Test public void serializeTransactionsNbt() throws Exception, Bip44KeyLookAheadExceededException { WalletPocketHD account = new WalletPocketHD(rootKey, NBT, null, null); Transaction tx = new Transaction(NBT); tx.addOutput(NBT.oneCoin().toCoin(), account.getReceiveAddress()); account.addNewTransactionIfNeeded(tx); testWalletSerializationForCoin(account); }
@Test public void signMessageEncrypted() throws AddressMalformedException, MissingPrivateKeyException, KeyIsEncryptedException { WalletPocketHD pocketHD = new WalletPocketHD(rootKey, BTC, null, null); pocketHD.getReceiveAddress(); // Generate the first key pocketHD.encrypt(crypter, aesKey); SignedMessage signedMessage = new SignedMessage("1KUDsEDqSBAgxubSEWszoA9xscNRRCmujM", MESSAGE); pocketHD.signMessage(signedMessage, aesKey); assertEquals(EXPECTED_BITCOIN_SIG, signedMessage.getSignature()); signedMessage = new SignedMessage("1KUDsEDqSBAgxubSEWszoA9xscNRRCmujM", MESSAGE_UNICODE); pocketHD.signMessage(signedMessage, aesKey); assertEquals(EXPECTED_BITCOIN_SIG_UNICODE, signedMessage.getSignature()); }
@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 signMessage() throws AddressMalformedException, MissingPrivateKeyException, KeyIsEncryptedException { WalletPocketHD pocketHD = new WalletPocketHD(rootKey, BTC, null, null); pocketHD.getReceiveAddress(); // Generate the first key SignedMessage signedMessage = new SignedMessage("1KUDsEDqSBAgxubSEWszoA9xscNRRCmujM", MESSAGE); pocketHD.signMessage(signedMessage, null); assertEquals(EXPECTED_BITCOIN_SIG, signedMessage.getSignature()); signedMessage = new SignedMessage("1KUDsEDqSBAgxubSEWszoA9xscNRRCmujM", MESSAGE_UNICODE); pocketHD.signMessage(signedMessage, null); assertEquals(EXPECTED_BITCOIN_SIG_UNICODE, signedMessage.getSignature()); pocketHD = new WalletPocketHD(rootKey, NBT, null, null); pocketHD.getReceiveAddress(); // Generate the first key signedMessage = new SignedMessage("BNvJUwg3BgkbQk5br1CxvHxdcDp1EC3saE", MESSAGE); pocketHD.signMessage(signedMessage, null); assertEquals(EXPECTED_NUBITS_SIG, signedMessage.getSignature()); signedMessage = new SignedMessage("BNvJUwg3BgkbQk5br1CxvHxdcDp1EC3saE", MESSAGE_UNICODE); pocketHD.signMessage(signedMessage, null); assertEquals(EXPECTED_NUBITS_SIG_UNICODE, signedMessage.getSignature()); }
private Sha256Hash send(Value value, WalletPocketHD w1, WalletPocketHD w2) throws Exception { assertEquals(w1.getCoinType(), w2.getCoinType()); CoinType type = w1.getCoinType(); BitSendRequest req = w1.sendCoinsOffline(w2.getReceiveAddress(), value); req.feePerTxSize = type.value("0.01"); w1.completeAndSignTx(req); byte[] txBytes = req.tx.bitcoinSerialize(); w1.addNewTransactionIfNeeded(new BitTransaction(type, txBytes)); w2.addNewTransactionIfNeeded(new BitTransaction(type, txBytes)); return req.tx.getHash(); }
tx.addOutput(BTC.oneCoin().toCoin(), account1.getReceiveAddress()); tx.getConfidence().setSource(Source.SELF); account1.addNewTransactionIfNeeded(tx);