Skip to content

Commit

Permalink
Fixed error in test forwrong sec level, made ticket iotaledger#172
Browse files Browse the repository at this point in the history
  • Loading branch information
Brord van Wierst committed May 30, 2019
1 parent 8fe55aa commit efecd1a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
3 changes: 2 additions & 1 deletion jota/src/main/java/org/iota/jota/IotaAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -392,7 +393,7 @@ public Future<Bundle> send(String address, long amount, Optional<String> message
Transfer transfer = new Transfer(address, amount, tryteMsg, tryteTag);

List<Input> inputs = accountManager.getInputAddresses(amount);

AtomicLong totalValue = new AtomicLong(0);
inputs.stream().forEach(input -> totalValue.addAndGet(input.getBalance()));

Expand Down
65 changes: 38 additions & 27 deletions jota/src/test/java/org/iota/jota/IotaAccountIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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 ");
Expand Down Expand Up @@ -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);
Expand All @@ -119,24 +123,12 @@ void sendValueTest() throws AccountError, InterruptedException, ExecutionExcepti
"Another IOTA Accounts test run at " + new Date().toString(),
"IOTA9ACCOUNTS").get();

List<Transaction> 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);
Expand All @@ -146,26 +138,45 @@ 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");
}

@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();

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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jota/src/test/resources/accounts/client-test.store
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"keyIndex":4,
"depositRequests":{
"1":{
"securityLevel": 2,
"securityLevel": 3,
"request": {
"timeOut":0,
"multiUse":false,
Expand Down

0 comments on commit efecd1a

Please sign in to comment.