Skip to content

Commit efecd1a

Browse files
author
Brord van Wierst
committed
Fixed error in test forwrong sec level, made ticket iotaledger-archive#172
1 parent 8fe55aa commit efecd1a

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

jota/src/main/java/org/iota/jota/IotaAccount.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.iota.jota.config.types.FileConfig;
2828
import org.iota.jota.dto.response.GetAttachToTangleResponse;
2929
import org.iota.jota.dto.response.GetTransactionsToApproveResponse;
30+
import org.iota.jota.dto.response.SendTransferResponse;
3031
import org.iota.jota.error.ArgumentException;
3132
import org.iota.jota.model.Bundle;
3233
import org.iota.jota.model.Input;
@@ -392,7 +393,7 @@ public Future<Bundle> send(String address, long amount, Optional<String> message
392393
Transfer transfer = new Transfer(address, amount, tryteMsg, tryteTag);
393394

394395
List<Input> inputs = accountManager.getInputAddresses(amount);
395-
396+
396397
AtomicLong totalValue = new AtomicLong(0);
397398
inputs.stream().forEach(input -> totalValue.addAndGet(input.getBalance()));
398399

jota/src/test/java/org/iota/jota/IotaAccountIntegrationTest.java

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
import org.iota.jota.config.types.FileConfig;
1010
import org.iota.jota.error.ArgumentException;
1111
import org.iota.jota.model.Bundle;
12-
import org.iota.jota.model.Transaction;
1312
import org.iota.jota.pow.pearldiver.PearlDiverLocalPoW;
1413
import org.iota.jota.store.JsonFlatFileStore;
1514
import org.iota.jota.utils.BundleValidator;
16-
import org.iota.jota.utils.Signing;
1715
import org.junit.jupiter.api.AfterEach;
1816
import org.junit.jupiter.api.BeforeEach;
1917
import org.junit.jupiter.api.Test;
@@ -22,8 +20,6 @@
2220
import java.io.File;
2321
import java.io.IOException;
2422
import java.util.Date;
25-
import java.util.LinkedList;
26-
import java.util.List;
2723
import java.util.concurrent.ExecutionException;
2824

2925
import static org.junit.jupiter.api.Assertions.*;
@@ -40,8 +36,8 @@ public class IotaAccountIntegrationTest {
4036

4137
private static final String TEST_SEED = "IJEEPFTJEFGFRDTSQGLGEAUZPUJFP9LDMDOOYUNOZFJ9JMJFALJATJGHEUPHHFVTFDYSGZNKMRK9EQKWG";
4238
private static final String TEST_SEED_ID = "J9SPZIPMIHEGZEBNDLMBTVVTCGQREQXZFXUYTJTYVQCR9TUZWZDBSJBOZLTTLJYXCGGVAIEQFPWLNUGHD";
43-
private static final String ADDR_0_SEC_3 = "TAKWNELREDNHLFYCQ9LMGZVYGTPTABFDEPQZILJAYAZSSCPXMEGCVAH9AHTJRDPVDCGIH9APCWG9KBSGA9VKXRLMU9";
44-
private static final String ADDR_1_SEC_3 = "LJGVBUTNFABXQUGMQROIMVXAPHAPXGZUFDMLALGSNUBAZLONQCKAUIMNUIHEDVRMBUEPUMCLHQZHVHCZBRGGLRBGAC";
39+
private static final String ADDR_1_SEC_3 = "TAKWNELREDNHLFYCQ9LMGZVYGTPTABFDEPQZILJAYAZSSCPXMEGCVAH9AHTJRDPVDCGIH9APCWG9KBSGA9VKXRLMU9";
40+
private static final String ADDR_2_SEC_3 = "LJGVBUTNFABXQUGMQROIMVXAPHAPXGZUFDMLALGSNUBAZLONQCKAUIMNUIHEDVRMBUEPUMCLHQZHVHCZBRGGLRBGAC";
4541
private IotaAPI iotaAPI;
4642

4743
private File file;
@@ -51,7 +47,10 @@ public class IotaAccountIntegrationTest {
5147
@BeforeEach
5248
public void setUp() throws Exception {
5349
file = File.createTempFile("client", "account");
54-
iotaAPI = new IotaAPI.Builder().config(new FileConfig()).localPoW(new PearlDiverLocalPoW()).build();
50+
iotaAPI = new IotaAPI.Builder()
51+
.config(new FileConfig())
52+
.localPoW(new PearlDiverLocalPoW())
53+
.build();
5554
}
5655

5756
@AfterEach
@@ -65,7 +64,12 @@ public void tearDown() throws IOException {
6564
@Test
6665
void load() {
6766
store = new AccountFileStore(file);
68-
IotaAccount account = new IotaAccount.Builder(TEST_SEED).mwm(9).store(store).api(iotaAPI).build();
67+
IotaAccount account = new IotaAccount.Builder(TEST_SEED)
68+
.securityLevel(3)
69+
.mwm(9)
70+
.store(store)
71+
.api(iotaAPI)
72+
.build();
6973

7074
assertTrue(account.loaded, "Account should be loaded after build");
7175
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
105109

106110
@Test
107111
void sendValueTest() throws AccountError, InterruptedException, ExecutionException {
108-
IotaAPI iotaAPI = fakeBalance(ADDR_0_SEC_3, 5l);
112+
IotaAPI iotaAPI = fakeBalance(ADDR_1_SEC_3, 5l);
109113

110114
JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-test.store"), System.out);
111115
store = new AccountFileStore(json);
@@ -119,24 +123,12 @@ void sendValueTest() throws AccountError, InterruptedException, ExecutionExcepti
119123
"Another IOTA Accounts test run at " + new Date().toString(),
120124
"IOTA9ACCOUNTS").get();
121125

122-
List<Transaction> res = iotaAPI.findTransactionObjectsByBundle(sent.getBundleHash());
123-
Bundle remote = new Bundle(res);
124-
125-
Signing sig = new Signing();
126-
boolean valid = sig.validateSignatures(sent, sent.getTransactions().get(1).getAddress());
127-
128-
String[] fragments = new String[] {
129-
sent.getTransactions().get(2).getSignatureFragments(),
130-
sent.getTransactions().get(1).getSignatureFragments()
131-
};
132-
boolean valid2 = sig.validateSignatures(sent.getTransactions().get(1).getAddress(), fragments, sent.getBundleHash());
133-
134126
assertTrue(BundleValidator.isBundle(sent), "Should be a valid bundle");
135127
}
136128

137129
@Test
138130
void sendLongValueTest() throws AccountError, InterruptedException, ExecutionException {
139-
IotaAPI iotaAPI = fakeBalance(ADDR_0_SEC_3, 10l);
131+
IotaAPI iotaAPI = fakeBalance(ADDR_1_SEC_3, 10l);
140132

141133
JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-test.store"), System.out);
142134
store = new AccountFileStore(json);
@@ -146,26 +138,45 @@ void sendLongValueTest() throws AccountError, InterruptedException, ExecutionExc
146138
Date timeOut = new Date(Long.MAX_VALUE);
147139
ConditionalDepositAddress cda = account.newDepositAddress(timeOut, false, 10).get();
148140

149-
Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 1,
141+
Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 10,
150142
lorem, "IOTA9ACCOUNTS").get();
151143

152144
assertTrue(BundleValidator.isBundle(sent), "Should be a valid bundle");
153145
}
154146

155147
@Test
156148
void sendLongMultiValueTest() throws AccountError, InterruptedException, ExecutionException {
157-
IotaAPI iotaAPI = fakeBalance(ADDR_0_SEC_3, 5l);
158-
iotaAPI = fakeBalance(ADDR_1_SEC_3, 5l, iotaAPI);
149+
IotaAPI iotaAPI = fakeBalance(ADDR_1_SEC_3, 5l);
150+
iotaAPI = fakeBalance(ADDR_2_SEC_3, 5l, iotaAPI);
159151

160-
JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-test.store"), System.out);
152+
JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-testMulti.store"), System.out);
153+
store = new AccountFileStore(json);
154+
155+
IotaAccount account = new IotaAccount.Builder(TEST_SEED).mwm(9).store(store).api(iotaAPI).build();
156+
157+
Date timeOut = new Date(Long.MAX_VALUE);
158+
ConditionalDepositAddress cda = account.newDepositAddress(timeOut, false, 10).get();
159+
160+
Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 10,
161+
lorem, "IOTA9ACCOUNTS").get();
162+
163+
assertTrue(BundleValidator.isBundle(sent), "Should be a valid bundle");
164+
}
165+
166+
@Test
167+
void sendLongMultiValueRemainderTest() throws AccountError, InterruptedException, ExecutionException {
168+
IotaAPI iotaAPI = fakeBalance(ADDR_1_SEC_3, 6l);
169+
iotaAPI = fakeBalance(ADDR_2_SEC_3, 5l, iotaAPI);
170+
171+
JsonFlatFileStore json = new JsonFlatFileStore(this.getClass().getResourceAsStream("/accounts/client-testMulti.store"), System.out);
161172
store = new AccountFileStore(json);
162173

163174
IotaAccount account = new IotaAccount.Builder(TEST_SEED).mwm(9).store(store).api(iotaAPI).build();
164175

165176
Date timeOut = new Date(Long.MAX_VALUE);
166177
ConditionalDepositAddress cda = account.newDepositAddress(timeOut, false, 10).get();
167178

168-
Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 1,
179+
Bundle sent = account.send(cda.getDepositAddress().getHashCheckSum(), 10,
169180
lorem, "IOTA9ACCOUNTS").get();
170181

171182
assertTrue(BundleValidator.isBundle(sent), "Should be a valid bundle");

jota/src/test/java/org/iota/jota/utils/InputValidatorTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ public void shouldIsArrayOfHashes() {
4444

4545
@Test
4646
public void shouldIsArrayOfTrytes() {
47-
assertEquals(InputValidator.isArrayOfRawTransactionTrytes(new String[]{TEST_TRYTES, TEST_TRYTES}), true);
47+
assertEquals(InputValidator.isArrayOfTrytes(new String[]{TEST_TRYTES, TEST_TRYTES}), true);
48+
}
49+
50+
@Test
51+
public void shouldInvalidTxTrytes() {
52+
// We fail on having value above max supply
53+
assertEquals(InputValidator.isArrayOfRawTransactionTrytes(new String[]{TEST_TRYTES, TEST_TRYTES}), false);
4854
}
4955

5056
@Test

jota/src/test/resources/accounts/client-test.store

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"keyIndex":4,
44
"depositRequests":{
55
"1":{
6-
"securityLevel": 2,
6+
"securityLevel": 3,
77
"request": {
88
"timeOut":0,
99
"multiUse":false,

0 commit comments

Comments
 (0)