diff --git a/jota/src/main/java/org/iota/jota/IotaAccount.java b/jota/src/main/java/org/iota/jota/IotaAccount.java index 69e1c193..dc2ad2cb 100644 --- a/jota/src/main/java/org/iota/jota/IotaAccount.java +++ b/jota/src/main/java/org/iota/jota/IotaAccount.java @@ -27,6 +27,7 @@ import org.iota.jota.config.types.FileConfig; import org.iota.jota.dto.response.GetAttachToTangleResponse; import org.iota.jota.dto.response.GetTransactionsToApproveResponse; +import org.iota.jota.dto.response.SendTransferResponse; import org.iota.jota.error.ArgumentException; import org.iota.jota.model.Bundle; import org.iota.jota.model.Input; @@ -392,7 +393,7 @@ public Future send(String address, long amount, Optional message Transfer transfer = new Transfer(address, amount, tryteMsg, tryteTag); List inputs = accountManager.getInputAddresses(amount); - + AtomicLong totalValue = new AtomicLong(0); inputs.stream().forEach(input -> totalValue.addAndGet(input.getBalance())); diff --git a/jota/src/test/java/org/iota/jota/IotaAccountIntegrationTest.java b/jota/src/test/java/org/iota/jota/IotaAccountIntegrationTest.java index 3af81646..c93e9f86 100644 --- a/jota/src/test/java/org/iota/jota/IotaAccountIntegrationTest.java +++ b/jota/src/test/java/org/iota/jota/IotaAccountIntegrationTest.java @@ -9,11 +9,9 @@ import org.iota.jota.config.types.FileConfig; import org.iota.jota.error.ArgumentException; import org.iota.jota.model.Bundle; -import org.iota.jota.model.Transaction; import org.iota.jota.pow.pearldiver.PearlDiverLocalPoW; import org.iota.jota.store.JsonFlatFileStore; import org.iota.jota.utils.BundleValidator; -import org.iota.jota.utils.Signing; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,8 +20,6 @@ import java.io.File; import java.io.IOException; import java.util.Date; -import java.util.LinkedList; -import java.util.List; import java.util.concurrent.ExecutionException; import static org.junit.jupiter.api.Assertions.*; @@ -40,8 +36,8 @@ public class IotaAccountIntegrationTest { private static final String TEST_SEED = "IJEEPFTJEFGFRDTSQGLGEAUZPUJFP9LDMDOOYUNOZFJ9JMJFALJATJGHEUPHHFVTFDYSGZNKMRK9EQKWG"; private static final String TEST_SEED_ID = "J9SPZIPMIHEGZEBNDLMBTVVTCGQREQXZFXUYTJTYVQCR9TUZWZDBSJBOZLTTLJYXCGGVAIEQFPWLNUGHD"; - private static final String ADDR_0_SEC_3 = "TAKWNELREDNHLFYCQ9LMGZVYGTPTABFDEPQZILJAYAZSSCPXMEGCVAH9AHTJRDPVDCGIH9APCWG9KBSGA9VKXRLMU9"; - private static final String ADDR_1_SEC_3 = "LJGVBUTNFABXQUGMQROIMVXAPHAPXGZUFDMLALGSNUBAZLONQCKAUIMNUIHEDVRMBUEPUMCLHQZHVHCZBRGGLRBGAC"; + private static final String ADDR_1_SEC_3 = "TAKWNELREDNHLFYCQ9LMGZVYGTPTABFDEPQZILJAYAZSSCPXMEGCVAH9AHTJRDPVDCGIH9APCWG9KBSGA9VKXRLMU9"; + private static final String ADDR_2_SEC_3 = "LJGVBUTNFABXQUGMQROIMVXAPHAPXGZUFDMLALGSNUBAZLONQCKAUIMNUIHEDVRMBUEPUMCLHQZHVHCZBRGGLRBGAC"; private IotaAPI iotaAPI; private File file; @@ -51,7 +47,10 @@ public class IotaAccountIntegrationTest { @BeforeEach public void setUp() throws Exception { file = File.createTempFile("client", "account"); - iotaAPI = new IotaAPI.Builder().config(new FileConfig()).localPoW(new PearlDiverLocalPoW()).build(); + iotaAPI = new IotaAPI.Builder() + .config(new FileConfig()) + .localPoW(new PearlDiverLocalPoW()) + .build(); } @AfterEach @@ -65,7 +64,12 @@ public void tearDown() throws IOException { @Test void load() { store = new AccountFileStore(file); - IotaAccount account = new IotaAccount.Builder(TEST_SEED).mwm(9).store(store).api(iotaAPI).build(); + IotaAccount account = new IotaAccount.Builder(TEST_SEED) + .securityLevel(3) + .mwm(9) + .store(store) + .api(iotaAPI) + .build(); assertTrue(account.loaded, "Account should be loaded after build"); assertEquals(TEST_SEED_ID, account.getId(), "Account ID should be set to the seed id "); @@ -105,7 +109,7 @@ void sendLongZeroMessage() throws ArgumentException, SendException, InterruptedE @Test void sendValueTest() throws AccountError, InterruptedException, ExecutionException { - IotaAPI iotaAPI = fakeBalance(ADDR_0_SEC_3, 5l); + IotaAPI iotaAPI = fakeBalance(ADDR_1_SEC_3, 5l); JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-test.store"), System.out); store = new AccountFileStore(json); @@ -119,24 +123,12 @@ void sendValueTest() throws AccountError, InterruptedException, ExecutionExcepti "Another IOTA Accounts test run at " + new Date().toString(), "IOTA9ACCOUNTS").get(); - List res = iotaAPI.findTransactionObjectsByBundle(sent.getBundleHash()); - Bundle remote = new Bundle(res); - - Signing sig = new Signing(); - boolean valid = sig.validateSignatures(sent, sent.getTransactions().get(1).getAddress()); - - String[] fragments = new String[] { - sent.getTransactions().get(2).getSignatureFragments(), - sent.getTransactions().get(1).getSignatureFragments() - }; - boolean valid2 = sig.validateSignatures(sent.getTransactions().get(1).getAddress(), fragments, sent.getBundleHash()); - assertTrue(BundleValidator.isBundle(sent), "Should be a valid bundle"); } @Test void sendLongValueTest() throws AccountError, InterruptedException, ExecutionException { - IotaAPI iotaAPI = fakeBalance(ADDR_0_SEC_3, 10l); + IotaAPI iotaAPI = fakeBalance(ADDR_1_SEC_3, 10l); JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-test.store"), System.out); store = new AccountFileStore(json); @@ -146,7 +138,7 @@ void sendLongValueTest() throws AccountError, InterruptedException, ExecutionExc Date timeOut = new Date(Long.MAX_VALUE); ConditionalDepositAddress cda = account.newDepositAddress(timeOut, false, 10).get(); - Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 1, + Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 10, lorem, "IOTA9ACCOUNTS").get(); assertTrue(BundleValidator.isBundle(sent), "Should be a valid bundle"); @@ -154,10 +146,29 @@ void sendLongValueTest() throws AccountError, InterruptedException, ExecutionExc @Test void sendLongMultiValueTest() throws AccountError, InterruptedException, ExecutionException { - IotaAPI iotaAPI = fakeBalance(ADDR_0_SEC_3, 5l); - iotaAPI = fakeBalance(ADDR_1_SEC_3, 5l, iotaAPI); + IotaAPI iotaAPI = fakeBalance(ADDR_1_SEC_3, 5l); + iotaAPI = fakeBalance(ADDR_2_SEC_3, 5l, iotaAPI); - JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-test.store"), System.out); + JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-testMulti.store"), System.out); + store = new AccountFileStore(json); + + IotaAccount account = new IotaAccount.Builder(TEST_SEED).mwm(9).store(store).api(iotaAPI).build(); + + Date timeOut = new Date(Long.MAX_VALUE); + ConditionalDepositAddress cda = account.newDepositAddress(timeOut, false, 10).get(); + + Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 10, + lorem, "IOTA9ACCOUNTS").get(); + + assertTrue(BundleValidator.isBundle(sent), "Should be a valid bundle"); + } + + @Test + void sendLongMultiValueRemainderTest() throws AccountError, InterruptedException, ExecutionException { + IotaAPI iotaAPI = fakeBalance(ADDR_1_SEC_3, 6l); + iotaAPI = fakeBalance(ADDR_2_SEC_3, 5l, iotaAPI); + + JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-testMulti.store"), System.out); store = new AccountFileStore(json); IotaAccount account = new IotaAccount.Builder(TEST_SEED).mwm(9).store(store).api(iotaAPI).build(); @@ -165,7 +176,7 @@ void sendLongMultiValueTest() throws AccountError, InterruptedException, Executi Date timeOut = new Date(Long.MAX_VALUE); ConditionalDepositAddress cda = account.newDepositAddress(timeOut, false, 10).get(); - Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 1, + Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 10, lorem, "IOTA9ACCOUNTS").get(); assertTrue(BundleValidator.isBundle(sent), "Should be a valid bundle"); diff --git a/jota/src/test/java/org/iota/jota/utils/InputValidatorTest.java b/jota/src/test/java/org/iota/jota/utils/InputValidatorTest.java index 14e57297..26189d0c 100644 --- a/jota/src/test/java/org/iota/jota/utils/InputValidatorTest.java +++ b/jota/src/test/java/org/iota/jota/utils/InputValidatorTest.java @@ -44,7 +44,13 @@ public void shouldIsArrayOfHashes() { @Test public void shouldIsArrayOfTrytes() { - assertEquals(InputValidator.isArrayOfRawTransactionTrytes(new String[]{TEST_TRYTES, TEST_TRYTES}), true); + assertEquals(InputValidator.isArrayOfTrytes(new String[]{TEST_TRYTES, TEST_TRYTES}), true); + } + + @Test + public void shouldInvalidTxTrytes() { + // We fail on having value above max supply + assertEquals(InputValidator.isArrayOfRawTransactionTrytes(new String[]{TEST_TRYTES, TEST_TRYTES}), false); } @Test diff --git a/jota/src/test/resources/accounts/client-test.store b/jota/src/test/resources/accounts/client-test.store index 59a6c93d..55271092 100644 --- a/jota/src/test/resources/accounts/client-test.store +++ b/jota/src/test/resources/accounts/client-test.store @@ -3,7 +3,7 @@ "keyIndex":4, "depositRequests":{ "1":{ - "securityLevel": 2, + "securityLevel": 3, "request": { "timeOut":0, "multiUse":false,