@Test public void testGetAddressWithWallet() { TransactionHusk tx1 = createTransferTx(); TransactionHusk tx2 = createTransferTx(); assertThat(tx1.getAddress()).isEqualTo(tx2.getAddress()); Wallet wallet = TestConstants.wallet(); assertThat(wallet.getAddress()).isEqualTo(tx1.getAddress().getBytes()); }
@Test public void testGetAddressWithWalletAccount() throws IOException, InvalidCipherTextException { Account account = new Account(); log.debug("Account: " + account.toString()); log.debug("Account.address: " + Hex.toHexString(account.getAddress())); Wallet wallet = new Wallet(account.getKey(), "tmp/path", "nodePri.key", "Aa1234567890!"); log.debug("Wallet: " + wallet.toString()); log.debug("Wallet.address: " + Hex.toHexString(wallet.getAddress())); TransactionHusk tx1 = createTx(wallet); TransactionHusk tx2 = createTx(wallet); log.debug("Test Transaction1: " + tx1.toString()); log.debug("Test Transaction1 Address: " + tx1.getAddress()); log.debug("Test Transaction2: " + tx2.toString()); log.debug("Test Transaction2 Address: " + tx2.getAddress()); assertThat(wallet.getAddress()).isEqualTo(account.getAddress()); assertThat(tx1.getAddress()).isEqualTo(tx2.getAddress()); assertThat(account.getAddress()).isEqualTo(tx1.getAddress().getBytes()); }
@Test public void testGetAddressWithSig() throws IOException, InvalidCipherTextException, SignatureException { Account account = new Account(); log.debug("Account: " + account.toString()); log.debug("Account.address: " + Hex.toHexString(account.getAddress())); log.debug("Account.pubKey: " + Hex.toHexString(account.getKey().getPubKey())); Wallet wallet = new Wallet(account.getKey(), "tmp/path", "nodePri.key", "Aa1234567890!"); log.debug("Wallet: " + wallet.toString()); log.debug("Wallet.address: " + Hex.toHexString(wallet.getAddress())); log.debug("Wallet.pubKey: " + Hex.toHexString(wallet.getPubicKey())); TransactionHusk txHusk1 = createTx(wallet); log.debug("Test Transaction1: " + txHusk1.toString()); log.debug("Test Transaction1 Address: " + txHusk1.getAddress()); assertThat(txHusk1.verify()).isTrue(); assertThat(wallet.getAddress()).isEqualTo(account.getAddress()); assertThat(wallet.getAddress()).isEqualTo(txHusk1.getAddress().getBytes()); byte[] hashedRawData = txHusk1.getHashForSigning().getBytes(); log.debug("hashedRawData: " + Hex.toHexString(hashedRawData)); byte[] signatureBin = txHusk1.getInstance().getSignature().toByteArray(); log.debug("signatureBin: " + Hex.toHexString(signatureBin)); ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(signatureBin); ECKey key = ECKey.signatureToKey(hashedRawData, ecdsaSignature); byte[] address = key.getAddress(); byte[] pubKey = key.getPubKey(); log.debug("address: " + Hex.toHexString(address)); log.debug("pubKey: " + Hex.toHexString(pubKey)); assertThat(account.getAddress()).isEqualTo(address); assertThat(account.getKey().getPubKey()).isEqualTo(pubKey); }
@Test public void testTransactionKey() throws Exception { Transaction tx2 = tx1.clone(); log.debug("tx2 pubKey=" + tx2.getPubKeyHexString()); log.debug("tx2 headerHash=" + Hex.toHexString(tx2.getHeader().getHashForSigning())); log.debug("tx2 pubKey=" + Hex.toHexString(tx2.getPubKey())); assertEquals(tx1.getPubKeyHexString(), tx2.getPubKeyHexString()); assertArrayEquals(tx1.getPubKey(), tx2.getPubKey()); assertArrayEquals(tx1.getPubKey(), wallet.getPubicKey()); log.debug("tx1 address=" + tx1.getAddressToString()); log.debug("tx2 address=" + tx2.getAddressToString()); log.debug("wallet address=" + wallet.getHexAddress()); log.debug("wallet signature=" + Hex.toHexString( wallet.signHashedData(tx1.getHeader().getHashForSigning()))); log.debug("wallet pubKey=" + Hex.toHexString( wallet.getPubicKey())); assertArrayEquals(tx1.getAddress(), tx2.getAddress()); assertArrayEquals(tx1.getAddress(), wallet.getAddress()); }
@Test public void testTransactionToProto() throws Exception { Transaction tx2 = tx1.clone(); log.debug("tx2 pubKey=" + tx2.getPubKeyHexString()); assertEquals(tx1.getPubKeyHexString(), tx2.getPubKeyHexString()); assertArrayEquals(tx1.getPubKey(), tx2.getPubKey()); assertArrayEquals(tx1.getPubKey(), wallet.getPubicKey()); log.debug("tx1 address=" + tx1.getAddressToString()); log.debug("tx2 address=" + tx2.getAddressToString()); log.debug("wallet address=" + wallet.getHexAddress()); assertArrayEquals(tx1.getAddress(), tx2.getAddress()); assertArrayEquals(tx1.getAddress(), wallet.getAddress()); Proto.Transaction protoTx1 = Transaction.toProtoTransaction(tx1); Proto.Transaction protoTx2 = Transaction.toProtoTransaction(tx2); log.debug("tx1 proto=" + Hex.toHexString(protoTx1.toByteArray())); log.debug("tx2 proto=" + Hex.toHexString(protoTx2.toByteArray())); assertArrayEquals(protoTx1.toByteArray(), protoTx2.toByteArray()); Transaction tx3 = Transaction.toTransaction(protoTx1); log.debug("tx1=" + tx1.toString()); log.debug("tx3=" + tx3.toString()); assertEquals(tx1.toString(), tx3.toString()); Proto.Transaction protoTx3 = Transaction.toProtoTransaction(tx1); assertArrayEquals(protoTx1.toByteArray(), protoTx3.toByteArray()); }