Skip to content

Commit f8000db

Browse files
Cylixthibault-martinez
authored andcommitted
Private testnet (#175)
* add some files related to private testnet setup as well as a documentation explaining how to set it up * rename README in test/testnet * add a bundle with 2 trxs in the testing data (update the testnet db) and setup some constants for testing * safe json parsing, update core test with local private testnet * remove unused tests * switch test to local private testnet setup. two tests are still failing for now * avoid sigsegv in test if number of transfers returned is less than expected for getAccountData test * first attempt install & run IRI on travis * skip install of maven on mac
1 parent df84d67 commit f8000db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2874
-14334
lines changed

.travis.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,44 @@ before_install:
8383
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
8484

8585
install:
86-
# ccache on osx
86+
####
87+
# OSX
88+
####
89+
# ccache
8790
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ccache; fi
8891
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi
92+
# java
93+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew cask install java; fi
8994

90-
# lcov & coveralls on linux
95+
####
96+
# Linux
97+
####
98+
# lcov & coveralls
9199
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install lcov; fi
92100
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pip install --user cpp-coveralls; fi
101+
# java
102+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install default-jre; fi
103+
# maven
104+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install maven; fi
93105

94106
before_script:
95107
# setup environment
96108
- eval "${MATRIX_EVAL}"
109+
# set IRI
110+
- git clone https://github.com/iotaledger/iri.git
111+
- cd iri
112+
- cp ../test/testnet/Snapshot.txt src/main/resources
113+
- cp ../test/testnet/Snapshot.java src/main/java/com/iota/iri/Snapshot.java
114+
- mvn clean compile
115+
- mvn package
116+
- cp -r ../test/testnet/testnetdb .
117+
- java -jar target/iri-1.4.1.6.jar --testnet -p 14265 &
118+
- cd ..
97119

98120
script:
99121
- mkdir -p build
100122
- cd build
101-
- cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_TESTS=1 -DTRAVIS_KEEP_ALIVE=1 ..
123+
- cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_TESTS=1 ..
102124
- make -j4
103125
- ./bin/runUnitTests ../test/files
104126

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ add_library(${CMAKE_PROJECT_NAME} STATIC ${PROJECT_SOURCE_FILES})
8181

8282
include(compilation_settings)
8383

84-
if(TRAVIS_KEEP_ALIVE)
85-
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES COMPILE_DEFINITIONS "TRAVIS_KEEP_ALIVE=${TRAVIS_KEEP_ALIVE}")
86-
endif(TRAVIS_KEEP_ALIVE)
87-
8884
########## EXTERNAL LIBRARIES SETTINGS ##########
8985

9086
include(cpr_settings)

include/iota/api/service.hpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,41 @@ class Service {
6666
{ "X-IOTA-API-Version", APIVersion } };
6767
auto res = cpr::Post(url, body, headers, cpr::Timeout{ timeout * 1000 });
6868

69-
if (res.elapsed >= timeout) {
70-
throw Errors::Timeout("IRI timed out after " + std::to_string(timeout) + "s");
69+
json resJson;
70+
std::string error;
71+
try {
72+
resJson = json::parse(res.text);
73+
74+
if (resJson.count("error")) {
75+
error = resJson["error"].get<std::string>();
76+
}
77+
} catch (const std::runtime_error&) {
78+
if (res.elapsed >= timeout) {
79+
throw Errors::Timeout("IRI timed out after " + std::to_string(timeout) + "s");
80+
}
81+
82+
throw Errors::Unrecognized("invalid reply from node (unrecognized format): " + res.text);
7183
}
7284

7385
Response response;
7486
// TODO set duration ?
75-
if (res.status_code == 200)
76-
response.deserialize(json::parse(res.text));
77-
else if (res.status_code == 400)
78-
throw Errors::BadRequest(json::parse(res.text)["error"].get<std::string>());
79-
else if (res.status_code == 401)
80-
throw Errors::Unauthorized(json::parse(res.text)["error"].get<std::string>());
81-
else if (res.status_code == 500)
82-
throw Errors::InternalServerError(json::parse(res.text)["error"].get<std::string>());
83-
else
84-
throw Errors::Unrecognized(json::parse(res.text)["error"].get<std::string>());
87+
switch (res.status_code) {
88+
case 200:
89+
response.deserialize(resJson);
90+
break;
91+
case 400:
92+
throw Errors::BadRequest(error);
93+
case 401:
94+
throw Errors::Unauthorized(error);
95+
case 500:
96+
throw Errors::InternalServerError(error);
97+
default:
98+
if (res.elapsed >= timeout) {
99+
throw Errors::Timeout("IRI timed out after " + std::to_string(timeout) + "s");
100+
}
101+
102+
throw Errors::Unrecognized(error);
103+
}
85104

86105
return response;
87106
}

run_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ info "Building project..." #
3939
############################
4040
mkdir -p build
4141
cd build
42-
cmake -DBUILD_TESTS=1 -DTRAVIS_KEEP_ALIVE=1 ..
42+
cmake -DBUILD_TESTS=1 ..
4343
make -j4
4444
if [ $? -ne 0 ]; then
4545
fail "Error : compilation failed !"

source/api/core.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ Core::findTransactions(const std::vector<Types::Trytes>& addresses,
7979
const std::vector<Types::Trytes>& tags,
8080
const std::vector<Types::Trytes>& approvees,
8181
const std::vector<Types::Trytes>& bundles) const {
82+
//! skip request if no input, simply return empty
83+
if (addresses.empty() && tags.empty() && approvees.empty() && bundles.empty()) {
84+
return Responses::FindTransactions();
85+
}
86+
8287
return service_.request<Requests::FindTransactions, Responses::FindTransactions>(
8388
addresses, tags, approvees, bundles);
8489
}

source/api/extended.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ Extended::getNewAddresses(const Types::Trytes& seed, const uint32_t& index, cons
175175
// of addresses.
176176
else {
177177
for (int32_t i = index; true; i++) {
178-
#ifdef TRAVIS_KEEP_ALIVE
179-
std::cout << "TRAVIS_KEEP_ALIVE: getNewAddresses[" << i << "]" << std::endl;
180-
#endif /* TRAVIS_KEEP_ALIVE */
181-
182178
const auto addr = newAddress(seed, i, security, checksum);
183179
const auto res = findTransactionsByAddresses({ addr });
184180

@@ -337,16 +333,6 @@ Extended::bundlesFromAddresses(const std::vector<Types::Trytes>& addresses,
337333
std::mutex bundlesMtx;
338334

339335
Utils::parallel_for(0, tailTransactions.size(), [&](int i) {
340-
#ifdef TRAVIS_KEEP_ALIVE
341-
//! This part can be very slow, especially if network bandwidth is limited
342-
//! When running tests on Travis, Travis stops and report failure if the program does not output
343-
//! anything for too long
344-
//! So if TRAVIS_KEEP_ALIVE is defined, then we add some intermediate output while running the
345-
//! tests to make sure Travis does not termine the tests while it is actually running
346-
std::cout << "TRAVIS_KEEP_ALIVE: bundlesFromAddresses[" << tailTransactions[i] << "]"
347-
<< std::endl;
348-
#endif /* TRAVIS_KEEP_ALIVE */
349-
350336
try {
351337
const auto& transaction = tailTransactions[i];
352338
const auto bundleResponse = getBundle(transaction);

source/api/responses/add_neighbors.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ AddNeighbors::AddNeighbors(const int64_t& addedNeighbors) : addedNeighbors_(adde
3737
void
3838
AddNeighbors::deserialize(const json& res) {
3939
Base::deserialize(res);
40-
addedNeighbors_ = res.at("addedNeighbors").get<int64_t>();
40+
41+
if (res.count("addedNeighbors")) {
42+
addedNeighbors_ = res.at("addedNeighbors").get<int64_t>();
43+
}
4144
}
4245

4346
const int64_t&

source/api/responses/attach_to_tangle.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ AttachToTangle::AttachToTangle(const std::vector<Types::Trytes>& trytes) : tryte
3737
void
3838
AttachToTangle::deserialize(const json& res) {
3939
Base::deserialize(res);
40-
trytes_ = res.at("trytes").get<std::vector<Types::Trytes>>();
40+
41+
if (res.count("trytes")) {
42+
trytes_ = res.at("trytes").get<std::vector<Types::Trytes>>();
43+
}
4144
}
4245

4346
const std::vector<Types::Trytes>&

source/api/responses/base.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Base::Base(const int64_t& duration) : duration_(duration) {
3636

3737
void
3838
Base::deserialize(const json& res) {
39-
duration_ = res.at("duration").get<long>();
39+
if (res.count("duration")) {
40+
duration_ = res.at("duration").get<long>();
41+
}
4042
}
4143

4244
const int64_t&

source/api/responses/find_transactions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ FindTransactions::FindTransactions(const std::vector<Types::Trytes>& hashes) : h
3737
void
3838
FindTransactions::deserialize(const json& res) {
3939
Base::deserialize(res);
40-
hashes_ = res.at("hashes").get<std::vector<Types::Trytes>>();
40+
41+
if (res.count("hashes")) {
42+
hashes_ = res.at("hashes").get<std::vector<Types::Trytes>>();
43+
}
4144
}
4245

4346
const std::vector<Types::Trytes>&

0 commit comments

Comments
 (0)