@Bean Wallet wallet(DefaultConfig defaultConfig) throws IOException, InvalidCipherTextException { return new Wallet(defaultConfig); } }
@Before public void setUp() throws IOException, InvalidCipherTextException { wallet = new Wallet(); }
@Before public void setUp() throws IOException, InvalidCipherTextException { wallet = new Wallet(); }
@Before public void setUp() throws IOException, InvalidCipherTextException { wallet = new Wallet(); }
@Test public void testWalletAndConfig() throws IOException, InvalidCipherTextException { DefaultConfig config = new DefaultConfig(); Wallet wallet = new Wallet(config); Path path = Paths.get(config.getKeyPath()); String keyPath = path.getParent().toString(); String keyName = path.getFileName().toString(); log.debug("walletKeyPath: " + wallet.getKeyPath()); log.debug("walletKeyName: " + wallet.getKeyName()); log.debug("configKeyPath: " + keyPath); log.debug("configKeyName: " + keyName); assertEquals(wallet.getKeyPath(), keyPath); assertEquals(wallet.getKeyName(), keyName); } }
@Test public void testWalletConstructor() throws IOException, InvalidCipherTextException { DefaultConfig config = new DefaultConfig(); Wallet wallet = new Wallet(config); log.debug(wallet.toString()); assertNotNull(wallet); byte[] data = "sign data".getBytes(); byte[] signature = wallet.sign(data); boolean verifyResult = wallet.verify(data, signature); assertTrue(verifyResult); }
@Test public void testWalletSignAndVerify() throws IOException, InvalidCipherTextException { Wallet wallet = new Wallet(null, "tmp/temp", "temp.key", "Aa1234567890!"); byte[] plain = "test data 1111".getBytes(); log.debug("Plain data: " + new String(plain)); byte[] signature = wallet.sign(plain); log.debug("Signature: " + Hex.toHexString(signature)); boolean verifyResult = wallet.verify(plain, signature); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); verifyResult = wallet.verifyHashedData(HashUtil.sha3(plain), signature); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); verifyResult = Wallet.verify(HashUtil.sha3(plain), signature, true); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); verifyResult = Wallet.verify(plain, signature, false); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); verifyResult = Wallet.verify(plain, signature, false, wallet.getPubicKey()); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); }
@Before public void setUp() throws Exception { JsonObject jsonParam1 = new JsonObject(); jsonParam1.addProperty("address", "5db10750e8caff27f906b41c71b3471057dd2000"); jsonParam1.addProperty("amount", "10000000"); JsonObject jsonObject1 = new JsonObject(); jsonObject1.addProperty("method", "transfer"); jsonObject1.add("params", jsonParam1); JsonObject jsonParam2 = new JsonObject(); jsonParam2.addProperty("address", "5db10750e8caff27f906b41c71b3471057dd2001"); jsonParam2.addProperty("amount", "5000000"); JsonObject jsonObject2 = new JsonObject(); jsonObject2.addProperty("method", "transfer"); jsonObject2.add("params", jsonParam2); JsonArray jsonArray = new JsonArray(); jsonArray.add(jsonObject1); jsonArray.add(jsonObject2); txBody = new TransactionBody(jsonArray); byte[] chain = new byte[20]; byte[] version = new byte[8]; byte[] type = new byte[8]; long timestamp = TimeUtils.time(); txHeader = new TransactionHeader(chain, version, type, timestamp, txBody); wallet = new Wallet(); log.debug("wallet.pubKey=" + Hex.toHexString(wallet.getPubicKey())); txSig = new TransactionSignature(wallet, txHeader.getHashForSigning()); tx1 = new Transaction(txHeader, txSig.getSignature(), txBody); assertTrue(tx1.verify()); }
@Test public void testKeySave() throws IOException, InvalidCipherTextException { // generate key & save a file Wallet wt = new Wallet(null, "/tmp/", "nodePri.key", "Password1234!"); byte[] encData = FileUtil.readFile(wt.getKeyPath(), wt.getKeyName()); log.debug("path:" + wt.getKeyPath() + wt.getKeyName()); log.debug("encData:" + Hex.toHexString(encData)); log.debug("pubKey:" + Hex.toHexString(wt.getPubicKey())); // load key Wallet wt2 = new Wallet("/tmp/", wt.getKeyName(), "Password1234!"); log.debug("pubKey2:" + Hex.toHexString(wt2.getPubicKey())); assertArrayEquals(wt.getPubicKey(), wt2.getPubicKey()); }
@Before public void setUp() throws Exception { JsonObject params = new JsonObject(); params.addProperty("address", "5db10750e8caff27f906b41c71b3471057dd2000"); params.addProperty("amount", "10000000"); JsonArray txArrayBody = ContractTestUtils.txBodyJson(Constants.STEM_CONTRACT_ID, "tansfer", params); txBody = new TransactionBody(txArrayBody); byte[] chain = new byte[20]; byte[] version = new byte[8]; byte[] type = new byte[8]; long timestamp = TimeUtils.time(); txHeader = new TransactionHeader(chain, version, type, timestamp, txBody); wallet = new Wallet(); txSig = new TransactionSignature(wallet, txHeader.getHashForSigning()); tx1 = new Transaction(txHeader, txSig.getSignature(), txBody); assertTrue(tx1.verify()); txBytes1 = tx1.toBinary(); }
@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()); }
Wallet wallet = new Wallet(defaultConfig); Transaction tx = new Transaction(txHeader, wallet, txBody); List<Transaction> txList = new ArrayList<>();
@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); }
@Before public void setUp() throws IOException, InvalidCipherTextException { builder = new BlockConStoreBuilder(new DefaultConfig()); wallet = new Wallet(); genesisBlock = new TestUtils(wallet).sampleBlock(); genesisBlockCon = new BlockCon(genesisBlock.getHeader().getIndex(), genesisBlock.getHeader().getPrevBlockHash(), genesisBlock); branchId = new BranchId(genesisBlock.getHash()); }