diff --git a/CHANGELOG.md b/CHANGELOG.md index 818731fc..244ab76b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Added + +- added Blockchain API endpoint ([#104]) + ### Changed - improved class members and test coverage ([#93]) diff --git a/README.md b/README.md index 7afdd012..b2ac7930 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ ## Documentation -You can find installation instructions and detailed instructions on how to use this package at the [dedicated documentation site](https://docs.ark.io/sdk/clients/cpp.html). +You can find installation instructions and detailed instructions on how to use this package at the [dedicated documentation site](https://docs.ark.io/sdk/clients/usage.html). ## Security diff --git a/docs/INSTALL_ARDUINO.md b/docs/INSTALL_ARDUINO.md index 9a9d7172..dd0f181e 100644 --- a/docs/INSTALL_ARDUINO.md +++ b/docs/INSTALL_ARDUINO.md @@ -48,6 +48,8 @@ void setup() { Ark::Client::Connection<Ark::Client::Api> connection(CustomNetwork); + Serial.println(arkClient.blockchain.get().c_str()); + Serial.println(arkClient.blocks.all().c_str()); Serial.println(); diff --git a/docs/cpp.md b/docs/cpp.md index ab7a71d8..c839c39d 100644 --- a/docs/cpp.md +++ b/docs/cpp.md @@ -11,21 +11,22 @@ This package is still under development. This page will get more content as it e [[toc]] ## Platforms -* [Arduino](#Arduino) -* [Linux >= 16.04](#OS) -* [macOS >= 10.10](#OS) -* [Windows >= 7](#OS) + +- [Arduino](#Arduino) +- [Linux >= 16.04](#OS) +- [macOS >= 10.10](#OS) +- [Windows >= 7](#OS) ## Usage -The Cpp Client is meant to be used for creating request to an API endpoint. -For cryptography related functionality, such as generating addresses or creating transactions, +The Cpp Client is meant to be used for creating request to an API endpoint. +For cryptography related functionality, such as generating addresses or creating transactions, please see the [Cpp Crypto](https://github.com/ArkEcosystem/cpp-crypto) repository. ### Connection -Before making a request, you should create a `Connection`. -A `Connection` expects a `host`, which is an url on which the API can be reached. +Before making a request, you should create a `Connection`. +A `Connection` expects a `host`, which is an url on which the API can be reached. An example `Connection`, that interfaces with the API of an Ark Node, would be created as follows: ```cpp @@ -38,10 +39,9 @@ Ark::Client::Connection<Ark::Client::Api> connection("167.114.29.54", 4003); The below example shows how you can perform a request. ```cpp -// Check the API Version -auto apiVersion = connection.api.version(); - // Perform an API call using the connection to access endpoint +const auto blockchainResponse = connection.api.blockchain.get(); + const auto blockResponse = connection.api.blocks.get("13114381566690093367") const auto delegateResponse = connection.api.delegates.get("boldninja"); @@ -56,19 +56,23 @@ const auto vote = connection.api.votes.get("d202acbfa947acac53ada2ac8a0eb662c9f7 const auto walletsSearch = connection.api.wallets.search({"username", "baldninja"}); ``` -> *note: All API response are of the type `std::string` -# +> \*note: All API response are of the type `std::string` + +# ### Getting an API Path -There are instances when a client may use a gateway or bridge to do http get/post; -for this we have provided an interface for obtaining a properly formatted API Path for a given API Endpoint. +There are instances when a client may use a gateway or bridge to do http get/post; +for this we have provided an interface for obtaining a properly formatted API Path for a given API Endpoint. Below are examples of how to access the Path interface: ```cpp Ark::Client::Host dummyHost("0.0.0.0:4003"); +std::string blockchainGetPath = Ark::Client::API::Paths::Blockschain::get(dummyHost); +// blockchainGetPath will be the string "0.0.0.0:4003/api/blockchain" + std::string blocksAllPath = Ark::Client::API::Paths::Blocks::all(dummyHost, 5 /* limit */, 1 /* page */); // blocksAllPath will be the string "0.0.0.0:4003/api/v2/blocks?limit=5&page=1" @@ -100,14 +104,15 @@ std::pair<std::string, std::string> walletsSearchPath = Ark::Client::API::Paths: ``` # Arduino -**Arduino IDE:** -Download and install the Arduino IDE (>=1.8.5) from the following link: -```https://www.arduino.cc/en/Main/Software``` -Using the Arduino IDE's built in Library Manager, -install the following Libraries: -```ArduinoJson v6.10.1``` -```AUnit``` +**Arduino IDE:** +Download and install the Arduino IDE (>=1.8.5) from the following link: +`https://www.arduino.cc/en/Main/Software` + +Using the Arduino IDE's built in Library Manager, +install the following Libraries: +`ArduinoJson v6.10.1` +`AUnit` #### Arduino Example using the Adafruit Feather ESP8266 @@ -129,15 +134,17 @@ void setup() { Ark::Client::Connection<Ark::Client::Api> connection("167.114.29.54", 4003); + Serial.println(arkClient.blockchain.get().c_str()); + auto allBlocks = arkClient.blocks.all(); Serial.println(allBlocks.c_str()); auto allDelegates = arkClient.delegates.all(); Serial.println(allDelegates.c_str()); - + auto delegatesCount = arkClient.delegates.count(); Serial.println(delegatesCount.c_str()); - + auto allPeers = arkClient.peers.all(); Serial.println(allPeers.c_str()); @@ -148,15 +155,17 @@ void setup() { void loop() {} ``` -**PlatformIO IDE:** +**PlatformIO IDE:** + +#### Python: -#### Python: -Use an installer package from the following link or use your preferred method to install Python: -```https://www.python.org/downloads/``` +Use an installer package from the following link or use your preferred method to install Python: +`https://www.python.org/downloads/` Install PlatformIO: pip install -U platformio + or python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py)" @@ -165,12 +174,14 @@ Install ArduinoJson@6.10.1 AUnit (2778) platformio lib -g install 64@6.10.1 2778 -#### Provide your WiFi info for your board to access the internet +#### Provide your WiFi info for your board to access the internet + +Open the following file in your preferred code editor: -Open the following file in your preferred code editor: -> "*.../cpp-client/test/IoT/test_main.cpp*" +> "_.../cpp-client/test/IoT/test_main.cpp_" + +lines 19 & 20: -lines 19 & 20: ``` char ssid[] = "your_ssid"; // your network SSID (name) const char password[] = "your_password"; // your network password @@ -178,36 +189,39 @@ const char password[] = "your_password"; // your network password #### running the tests on an Arduino board - cd Cpp-Client + cd Cpp-Client cd test -#### execute the following command to upload test to your board +#### execute the following command to upload test to your board ->| board | command | ->|:-- |:-- | ->| ESP8266 | ```pio run -e esp8266 -t upload``` | ->| ESP32 | ```pio run -e esp32 -t upload``` | +> | board | command | +> | :------ | :----------------------------- | +> | ESP8266 | `pio run -e esp8266 -t upload` | +> | ESP32 | `pio run -e esp32 -t upload` | # # OS + ## Linux, macOS and Windows -**CMake:** +**CMake:** -Use an installer package from the following link, Homebrew, or use your preferred method: -```https://www.cmake.org/download/``` +Use an installer package from the following link, Homebrew, or use your preferred method: +`https://www.cmake.org/download/` using -**Homebrew:** +**Homebrew:** brew install cmake > note: all other dependencies will be automatically installed via git submodule and CMake. ### make and build - cd cpp-client/ + + cd cpp-client/ cmake . && cmake --build . ### run tests + ./bin/Ark-Cpp-Client-tests diff --git a/examples/arduino/ESP32/ESP32.ino b/examples/arduino/ESP32/ESP32.ino index 61f5b12a..fd1bcc8d 100644 --- a/examples/arduino/ESP32/ESP32.ino +++ b/examples/arduino/ESP32/ESP32.ino @@ -6,7 +6,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. **/ - + /** * ESP32 Cpp-Client Usage Example Sketch * @@ -46,11 +46,11 @@ const char* password = "yourWiFiPassword"; /****************************************/ -/** +/** * This is the IP address of an Ark Node * Specifically, this is a Devnet V2 Node IP * You can find more peers here: https://github.com/ArkEcosystem/peers - * + * * The Public API port for the V2 Ark network is '4003' */ const char* peer = "167.114.29.55"; @@ -69,26 +69,33 @@ Ark::Client::Connection<Ark::Client::Api> connection(peer, port); /****************************************/ void checkAPI() { - /** - * This is how you can check the Version of the API - * In this example, it should return '2' as an 'int' for V2 of Arks' API. - */ - auto apiVersion = connection.api.version(); - Serial.print("\nAPI Version: "); - Serial.println(apiVersion); - /**/ + // With this API endpoint, you can find ARK Blockchain info. + // This is equivalent to calling 'https://dexplorer.ark.io/api//blockchain' + // + // { + // "data": { + // "block": { + // "height": 2922163, + // "id": "84125ec94ba3f3a2d6fd6643d50c98ed2f3c8fa62d8c939355974f404e9b3906" + // }, + // "supply": "13082272800000000" + // } + // } + const auto blockchainResponse = connection.api.blockchain.get(); + Serial.print("\nBlockchain Response: "); + Serial.println(blockchainResponse.c_str()); /********************/ /** * Here you can call a list of 'All' 'Blocks' on the network. * The '2' and '1' refer to the pagination (e.g. response limit and how many pages) - * + * * This is equivalent to calling '167.114.29.49:4003/api/v2/blocks?limit=2&page=1' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this - * + * * { * "meta": { * "count": 2, @@ -159,7 +166,7 @@ void checkAPI() { * } * ] * } - * + * */ const auto blocksResponse = connection.api.blocks.all(2, 1); Serial.print("\nBlocks Response: "); @@ -171,12 +178,12 @@ void checkAPI() { /** * The following method can be used to search for a speficit Delegate. * In this case, 'boldninja'. - * + * * This is equivalent to calling '167.114.29.49:4003/api/v2/delegates/boldninja' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: - * + * * { * "data": { * "username": "boldninja", @@ -218,12 +225,12 @@ void checkAPI() { /** * The following method can be used to get the Status of a Node. - * + * * This is equivalent to calling '167.114.29.49:4003/api/v2/node/status' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: - * + * * { * "data": { * "synced": true, @@ -241,11 +248,11 @@ void checkAPI() { /** * The following method can be used to get a list of 'All' 'Peers' on the network. - * + * * The '2' and '1' refer to the pagination (e.g. response limit and how many pages) - * + * * This is equivalent to calling 'http://167.114.29.49:4003/api/v2/peers?limit=2&page=1' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: * @@ -293,9 +300,9 @@ void checkAPI() { /** * The following method can be used to get a list of 'Transaction' 'Types'. - * + * * This is equivalent to calling 'http://167.114.29.49:4003/api/v2/transactions/types' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: * @@ -323,9 +330,9 @@ void checkAPI() { /** * This method can be used to get a list of 'Vote' Transactions. * The '2' and '1' refer to the pagination (e.g. response limit and how many pages) - * + * * This is equivalent to calling 'http://167.114.29.49:4003/api/v2/votes?limit=2&page=1' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: * @@ -398,9 +405,9 @@ void checkAPI() { /** * This method can be used to get a list of 'Top' 'Wallets' (Wallets with the most ARK). * The '2' and '1' refer to the pagination (e.g. response limit and how many pages) - * + * * This is equivalent to calling '167.114.29.49:4003/api/v2/wallets/top?limit=2&page=1' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: * @@ -463,4 +470,4 @@ void setup() /****************************************/ -void loop() {}; // We can leave this empty, as we don't want to repeat anything in this example. \ No newline at end of file +void loop() {}; // We can leave this empty, as we don't want to repeat anything in this example. diff --git a/examples/arduino/ESP8266/ESP8266.ino b/examples/arduino/ESP8266/ESP8266.ino index 60a80ab2..7db6f8b9 100644 --- a/examples/arduino/ESP8266/ESP8266.ino +++ b/examples/arduino/ESP8266/ESP8266.ino @@ -6,7 +6,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. **/ - + /** * ESP8266 Cpp-Client Usage Example Sketch * @@ -46,11 +46,11 @@ const char* password = "yourWiFiPassword"; /****************************************/ -/** +/** * This is the IP address of an Ark Node * Specifically, this is a Devnet V2 Node IP * You can find more peers here: https://github.com/ArkEcosystem/peers - * + * * The Public API port for the V2 Ark network is '4003' */ const char* peer = "167.114.29.55"; @@ -69,26 +69,33 @@ Ark::Client::Connection<Ark::Client::Api> connection(peer, port); /****************************************/ void checkAPI() { - /** - * This is how you can check the Version of the API - * In this example, it should return '2' as an 'int' for V2 of Arks' API. - */ - auto apiVersion = connection.api.version(); - Serial.print("\nAPI Version: "); - Serial.println(apiVersion); - /**/ + // With this API endpoint, you can find ARK Blockchain info. + // This is equivalent to calling 'https://dexplorer.ark.io/api//blockchain' + // + // { + // "data": { + // "block": { + // "height": 2922163, + // "id": "84125ec94ba3f3a2d6fd6643d50c98ed2f3c8fa62d8c939355974f404e9b3906" + // }, + // "supply": "13082272800000000" + // } + // } + const auto blockchainResponse = connection.api.blockchain.get(); + Serial.print("\nBlockchain Response: "); + Serial.println(blockchainResponse.c_str()); /********************/ /** * Here you can call a list of 'All' 'Blocks' on the network. * The '2' and '1' refer to the pagination (e.g. response limit and how many pages) - * + * * This is equivalent to calling '167.114.29.49:4003/api/v2/blocks?limit=2&page=1' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this - * + * * { * "meta": { * "count": 2, @@ -159,7 +166,7 @@ void checkAPI() { * } * ] * } - * + * */ const auto blocksResponse = connection.api.blocks.all(2, 1); Serial.print("\nBlocks Response: "); @@ -171,12 +178,12 @@ void checkAPI() { /** * The following method can be used to search for a speficit Delegate. * In this case, 'boldninja'. - * + * * This is equivalent to calling '167.114.29.49:4003/api/v2/delegates/boldninja' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: - * + * * { * "data": { * "username": "boldninja", @@ -218,12 +225,12 @@ void checkAPI() { /** * The following method can be used to get the Status of a Node. - * + * * This is equivalent to calling '167.114.29.49:4003/api/v2/node/status' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: - * + * * { * "data": { * "synced": true, @@ -241,11 +248,11 @@ void checkAPI() { /** * The following method can be used to get a list of 'All' 'Peers' on the network. - * + * * The '2' and '1' refer to the pagination (e.g. response limit and how many pages) - * + * * This is equivalent to calling 'http://167.114.29.49:4003/api/v2/peers?limit=2&page=1' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: * @@ -293,9 +300,9 @@ void checkAPI() { /** * The following method can be used to get a list of 'Transaction' 'Types'. - * + * * This is equivalent to calling 'http://167.114.29.49:4003/api/v2/transactions/types' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: * @@ -323,9 +330,9 @@ void checkAPI() { /** * This method can be used to get a list of 'Vote' Transactions. * The '2' and '1' refer to the pagination (e.g. response limit and how many pages) - * + * * This is equivalent to calling 'http://167.114.29.49:4003/api/v2/votes?limit=2&page=1' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: * @@ -398,9 +405,9 @@ void checkAPI() { /** * This method can be used to get a list of 'Top' 'Wallets' (Wallets with the most ARK). * The '2' and '1' refer to the pagination (e.g. response limit and how many pages) - * + * * This is equivalent to calling '167.114.29.49:4003/api/v2/wallets/top?limit=2&page=1' - * + * * The response should be a json-formatted object * The "pretty print" version would look something like this: * @@ -464,4 +471,4 @@ void setup() /****************************************/ -void loop() {}; // We can leave this empty, as we don't want to repeat anything in this example. \ No newline at end of file +void loop() {}; // We can leave this empty, as we don't want to repeat anything in this example. diff --git a/examples/cmake_example/main.cpp b/examples/cmake_example/main.cpp index a800ebc7..5dbace5c 100644 --- a/examples/cmake_example/main.cpp +++ b/examples/cmake_example/main.cpp @@ -6,11 +6,11 @@ int main(int argc, char* argv[]) { // Create a connection Ark::Client::Connection<Ark::Client::Api> connection("167.114.29.54", 4003); - // Check the API Version - const auto apiVersion = connection.api.version(); - std::cout << "API Version: " << apiVersion << "\n\n"; - // Perform an API call using the connection to access endpoint + const auto blockchainResponse = connection.api.blockchain.get(); + std::cout << "Response for blockchain:\n"; + std::cout << blockchainResponse << "\n\n"; + const auto blockResponse = connection.api.blocks.get("13114381566690093367"); std::cout << "Response for block '13114381566690093367':\n"; std::cout << blockResponse << "\n\n"; diff --git a/examples/platformio_example/src/main.ino b/examples/platformio_example/src/main.ino index 462b058b..26c891fb 100644 --- a/examples/platformio_example/src/main.ino +++ b/examples/platformio_example/src/main.ino @@ -12,13 +12,12 @@ void setup() { void loop() { // Create a connection Ark::Client::Connection<Ark::Client::Api> connection("167.114.29.54", 4003); - - // Check the API Version - const auto apiVersion = connection.api.version(); - Serial.print("API Version: "); Serial.println(apiVersion); - Serial.println(); // Perform an API call using the connection to access endpoint + const auto blockchainResponse = connection.api.blockchain.get(); + Serial.print("\nResponse for blockchain:"); + Serial.println(blockchainResponse.c_str()); + const auto blockResponse = connection.api.blocks.get("13114381566690093367"); Serial.println("Response for block '13114381566690093367':"); Serial.println(blockResponse.c_str()); diff --git a/extras/ARDUINO_IDE.sh b/extras/ARDUINO_IDE.sh index e051b9b4..5e564f75 100644 --- a/extras/ARDUINO_IDE.sh +++ b/extras/ARDUINO_IDE.sh @@ -35,6 +35,7 @@ SRC_DIR=${EXTRAS_DIR}/../src INCLUDE_API_DIR=${INCLUDE_DIR}/api SRC_API_DIR=${SRC_DIR}/api +INCLUDE_BLOCKCHAIN_DIR=${INCLUDE_DIR}/api/blockchain INCLUDE_BLOCKS_DIR=${INCLUDE_DIR}/api/blocks INCLUDE_DELEGATES_DIR=${INCLUDE_DIR}/api/delegates INCLUDE_NODE_DIR=${INCLUDE_DIR}/api/node @@ -43,6 +44,7 @@ INCLUDE_TRANSACTIONS_DIR=${INCLUDE_DIR}/api/transactions INCLUDE_VOTES_DIR=${INCLUDE_DIR}/api/votes INCLUDE_WALLETS_DIR=${INCLUDE_DIR}/api/wallets +SRC_BLOCKCHAIN_DIR=${SRC_DIR}/api/blockchain SRC_BLOCKS_DIR=${SRC_DIR}/api/blocks SRC_DELEGATES_DIR=${SRC_DIR}/api/delegates SRC_NODE_DIR=${SRC_DIR}/api/node @@ -105,6 +107,7 @@ if [[ -d ${INCLUDE_DIR} ]]; then mv ${INCLUDE_API_DIR}/base.h ${SRC_API_DIR} mv ${INCLUDE_API_DIR}/paths.h ${SRC_API_DIR} + mv ${INCLUDE_BLOCKCHAIN_DIR}/blockchain.hpp ${SRC_BLOCKCHAIN_DIR} mv ${INCLUDE_BLOCKS_DIR}/blocks.h ${SRC_BLOCKS_DIR} mv ${INCLUDE_DELEGATES_DIR}/delegates.h ${SRC_DELEGATES_DIR} mv ${INCLUDE_NODE_DIR}/node.h ${SRC_NODE_DIR} @@ -147,6 +150,7 @@ else echo -e "Recreating API directories 🗂\n" mkdir ${INCLUDE_API_DIR} + mkdir ${INCLUDE_BLOCKCHAIN_DIR} mkdir ${INCLUDE_BLOCKS_DIR} mkdir ${INCLUDE_DELEGATES_DIR} mkdir ${INCLUDE_NODE_DIR} @@ -161,6 +165,7 @@ else mv ${SRC_API_DIR}/base.h ${INCLUDE_API_DIR} mv ${SRC_API_DIR}/paths.h ${INCLUDE_API_DIR} + mv ${SRC_BLOCKCHAIN_DIR}/blockchain.hpp ${INCLUDE_BLOCKCHAIN_DIR} mv ${SRC_BLOCKS_DIR}/blocks.h ${INCLUDE_BLOCKS_DIR} mv ${SRC_DELEGATES_DIR}/delegates.h ${INCLUDE_DELEGATES_DIR} mv ${SRC_NODE_DIR}/node.h ${INCLUDE_NODE_DIR} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aca3b95e..6a5c5c53 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ set(API_PATHS_SRC ) set(API_SRC + api/blockchain/blockchain.cpp api/blocks/blocks.cpp api/delegates/delegates.cpp api/node/node.cpp diff --git a/src/api/blockchain/blockchain.cpp b/src/api/blockchain/blockchain.cpp new file mode 100644 index 00000000..f46379fc --- /dev/null +++ b/src/api/blockchain/blockchain.cpp @@ -0,0 +1,22 @@ +/** + * This file is part of Ark Cpp Client. + * + * (c) Ark Ecosystem <info@ark.io> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + **/ + +#include "api/blockchain/blockchain.hpp" + +namespace Ark { +namespace Client { +namespace API { + +std::string API::Blockchain::get() { + return http_->get(Paths::Blockchain::get(this->host_).c_str()); +} + +} // namespace API +} // namespaceClient +} // namespaceArk diff --git a/src/api/paths.cpp b/src/api/paths.cpp index 85d7ed1b..7a2db614 100644 --- a/src/api/paths.cpp +++ b/src/api/paths.cpp @@ -1,6 +1,26 @@ #include "api/paths.h" +/** + * Blockchain + **/ +const char* Ark::Client::API::Paths::Blockchain::base() { + return "/api/blockchain"; +} + +/**/ +std::string Ark::Client::API::Paths::Blockchain::get( + Host& newHost) { + char url[56] = {}; + snprintf(url, sizeof(url), + "%s%s", + newHost.toString().c_str(), + Ark::Client::API::Paths::Blockchain::base()); + return url; +} + +/****/ + /** * Blocks **/ diff --git a/src/http/iot/http.cpp b/src/http/iot/http.cpp index a62e722f..a5d26a60 100644 --- a/src/http/iot/http.cpp +++ b/src/http/iot/http.cpp @@ -41,7 +41,6 @@ class PlatformHTTP : public AbstractHTTP { /* Bad HTTP GET.\nRetrying connection.. */ delay(1000); httpClient.addHeader("Content-Type", "application/json"); - httpClient.addHeader("API-Version", "2"); httpClient.begin(request); code = httpClient.GET(); count++; diff --git a/src/http/os/http.cpp b/src/http/os/http.cpp index 3a57ea16..1e2141a0 100644 --- a/src/http/os/http.cpp +++ b/src/http/os/http.cpp @@ -40,7 +40,6 @@ class PlatformHTTP : public AbstractHTTP { curl_slist *header_list = nullptr; header_list = curl_slist_append(header_list, "Content-Type: application/json"); - header_list = curl_slist_append(header_list, "API-Version: 2"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list); /* skip https verification */ @@ -56,7 +55,7 @@ class PlatformHTTP : public AbstractHTTP { return readBuffer; } /**/ - + std::string post(const char *const request, const char *body) override { // https://curl.haxx.se/libcurl/c/http-post.html CURL *curl; @@ -75,7 +74,7 @@ class PlatformHTTP : public AbstractHTTP { ? curl_slist_append(header_list, "Content-Type: application/json") : curl_slist_append(header_list, "Content-Type: application/x-www-form-urlencoded"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list); - + /* skip https verification */ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); // Do NOT verify peer curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); // Do NOT verify host diff --git a/src/include/cpp-client/api/abstract.h b/src/include/cpp-client/api/abstract.h index 50cb67f1..d415cd42 100644 --- a/src/include/cpp-client/api/abstract.h +++ b/src/include/cpp-client/api/abstract.h @@ -23,14 +23,11 @@ class Abstract { protected: Host host_; std::unique_ptr<IHTTP> http_; - int version_; - Abstract(IHTTP* http, int version) : http_(http), version_(version) {} - explicit Abstract(int version) : http_(makeHTTP()), version_(version) {} + Abstract() : http_(makeHTTP()) {} + explicit Abstract(IHTTP* http) : http_(http) {} public: - int version() const noexcept { return this->version_; }; - void setHost(const char* const newHost, int newPort) { this->host_.set(newHost, newPort); }; }; /**/ diff --git a/src/include/cpp-client/api/api.h b/src/include/cpp-client/api/api.h index b993b395..f450a746 100644 --- a/src/include/cpp-client/api/api.h +++ b/src/include/cpp-client/api/api.h @@ -12,6 +12,7 @@ #include "api/abstract.h" #include "api/api.h" +#include "api/blockchain/blockchain.hpp" #include "api/blocks/blocks.h" #include "api/delegates/delegates.h" #include "api/node/node.h" @@ -25,6 +26,7 @@ namespace Client { /**/ class Api : public API::Abstract { public: + API::Blockchain blockchain; API::Blocks blocks; API::Delegates delegates; API::Node node; @@ -34,7 +36,8 @@ class Api : public API::Abstract { API::Wallets wallets; Api() - : API::Abstract(2), + : API::Abstract(), + blockchain(host_, *http_), blocks(host_, *http_), delegates(host_, *http_), node(host_, *http_), diff --git a/src/include/cpp-client/api/blockchain/blockchain.hpp b/src/include/cpp-client/api/blockchain/blockchain.hpp new file mode 100644 index 00000000..0139e5a8 --- /dev/null +++ b/src/include/cpp-client/api/blockchain/blockchain.hpp @@ -0,0 +1,42 @@ +/** + * This file is part of Ark Cpp Client. + * + * (c) Ark Ecosystem <info@ark.io> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + **/ + +#ifndef BLOCKCHAIN_HPP +#define BLOCKCHAIN_HPP + +#include "api/base.h" +#include "api/paths.h" + +#include <string> + +namespace Ark { +namespace Client { +namespace API { +/**/ +class IBlockchain : public API::Base { +protected: + IBlockchain(Host& host, IHTTP& http) : API::Base(host, http) {} + +public: + virtual ~IBlockchain() {} + virtual std::string get() = 0; +}; +/**/ +class Blockchain : public IBlockchain { +public: + Blockchain(Host& host, IHTTP& http) : IBlockchain(host, http) {} + + std::string get() override; +}; +/**/ +}; // namespace API +}; // namespace Client +}; // namespace Ark + +#endif diff --git a/src/include/cpp-client/api/paths.h b/src/include/cpp-client/api/paths.h index fe9ecabe..933d6b95 100644 --- a/src/include/cpp-client/api/paths.h +++ b/src/include/cpp-client/api/paths.h @@ -21,6 +21,13 @@ namespace Client { namespace API { namespace Paths { +namespace Blockchain { +extern const char* base(); +extern std::string get(Host& newHost); +}; // namespace Blockchain + +/***/ + namespace Blocks { extern const char* base(); /***/ diff --git a/src/include/cpp-client/http/http.h b/src/include/cpp-client/http/http.h index bd14cc59..8a2a4aad 100644 --- a/src/include/cpp-client/http/http.h +++ b/src/include/cpp-client/http/http.h @@ -24,8 +24,6 @@ class IHTTP { public: virtual ~IHTTP() {} - virtual int api_version() const /*noexcept*/ = 0; - virtual std::string get(const char* const request) = 0; virtual std::string post(const char* const request, const char* body) = 0; }; @@ -39,26 +37,13 @@ class IHTTP { **/ class AbstractHTTP : public IHTTP { protected: - int api_version_; - - AbstractHTTP() : api_version_(0){}; - + AbstractHTTP() = default; AbstractHTTP(AbstractHTTP&&) = delete; AbstractHTTP& operator=(AbstractHTTP&&) = delete; - - AbstractHTTP(const AbstractHTTP& other) : api_version_(other.api_version_){}; - - AbstractHTTP& operator=(const AbstractHTTP& other) noexcept { - if (this != &other) { - this->api_version_ = other.api_version_; - } - return *this; - }; + AbstractHTTP& operator=(const AbstractHTTP& other) = default; public: virtual ~AbstractHTTP(){}; - - int api_version() const /*noexcept*/ override { return this->api_version_; } }; /**/ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 73671d44..d87691f1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,6 +32,7 @@ set(TEST_API_PATHS_SRC ) set(TEST_API_SRC + ${PROJECT_SOURCE_DIR}/api/blockchain.cpp ${PROJECT_SOURCE_DIR}/api/blocks.cpp ${PROJECT_SOURCE_DIR}/api/delegates.cpp ${PROJECT_SOURCE_DIR}/api/node.cpp diff --git a/test/api/blockchain.cpp b/test/api/blockchain.cpp new file mode 100644 index 00000000..e2862b66 --- /dev/null +++ b/test/api/blockchain.cpp @@ -0,0 +1,34 @@ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include <arkClient.h> + +#include "mocks/mock_api.h" + +using testing::_; +using testing::Return; + +TEST(api, test_blockchain) { // NOLINT + Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); + + const std::string expected_response = R"({ + "data": { + "block": { + "height": 2922163, + "id": "84125ec94ba3f3a2d6fd6643d50c98ed2f3c8fa62d8c939355974f404e9b3906" + }, + "supply": "13082272800000000" + } + })"; + + EXPECT_CALL(connection.api.blockchain, get()) + .Times(1) + .WillOnce(Return(expected_response)); + + const auto blockchain = connection.api.blockchain.get(); + + auto responseMatches = strcmp(expected_response.c_str(), + blockchain.c_str()) == 0; + ASSERT_TRUE(responseMatches); +} diff --git a/test/api/blocks.cpp b/test/api/blocks.cpp index 5beab7d4..4968e4fd 100644 --- a/test/api/blocks.cpp +++ b/test/api/blocks.cpp @@ -11,9 +11,6 @@ using testing::Return; TEST(api, test_block) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string expected_response = R"({ "data": { "id": "58328125061111756", @@ -122,9 +119,6 @@ TEST(api, test_block) { // NOLINT TEST(api, test_block_transactions) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string expected_response = R"({ "meta": { "count": 1, @@ -160,7 +154,7 @@ TEST(api, test_block_transactions) { // NOLINT EXPECT_CALL(connection.api.blocks, transactions(_)).Times(1).WillOnce(Return(expected_response)); const auto blockTransactionsResponse = connection.api.blocks.transactions("14126007750611341900"); - + DynamicJsonDocument doc(1452); DeserializationError error = deserializeJson(doc, blockTransactionsResponse); if (error) { exit(0); } @@ -223,9 +217,6 @@ TEST(api, test_block_transactions) { // NOLINT TEST(api, test_blocks) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string expected_response = R"({ "meta": { "count": 2, @@ -298,9 +289,6 @@ TEST(api, test_blocks) { // NOLINT TEST(api, test_blocks_search) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string expected_response = R"({ "meta": { "count": 1, diff --git a/test/api/delegates.cpp b/test/api/delegates.cpp index c7bdf6ad..b05b2e8a 100644 --- a/test/api/delegates.cpp +++ b/test/api/delegates.cpp @@ -11,9 +11,6 @@ using testing::Return; TEST(api, test_delegate) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string expected_response = R"({ "data": { "username": "boldninja", @@ -199,9 +196,6 @@ TEST(api, test_delegate_blocks) { // NOLINT TEST(api, test_delegate_voters) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string expected_response = R"({ "meta": { "count": 2, @@ -261,9 +255,6 @@ TEST(api, test_delegate_voters) { // NOLINT TEST(api, test_delegates) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string expected_response = R"({ "meta": { "count": 2, diff --git a/test/api/node.cpp b/test/api/node.cpp index 700445f8..810a3586 100644 --- a/test/api/node.cpp +++ b/test/api/node.cpp @@ -14,9 +14,6 @@ using testing::Return; TEST(api, test_node_configuration) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.54", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "nethash": "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23", @@ -103,9 +100,6 @@ TEST(api, test_node_configuration) { // NOLINT TEST(api, test_node_status) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.54", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "synced": false, @@ -139,9 +133,6 @@ TEST(api, test_node_status) { // NOLINT TEST(api, test_node_syncing) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.54", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "syncing": true, diff --git a/test/api/peers.cpp b/test/api/peers.cpp index d0611882..da88ab1f 100644 --- a/test/api/peers.cpp +++ b/test/api/peers.cpp @@ -13,9 +13,6 @@ using testing::Return; TEST(api, test_peer) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.54", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "ip": "167.114.29.55", @@ -61,9 +58,6 @@ TEST(api, test_peer) { // NOLINT TEST(api, test_peers) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, diff --git a/test/api/transactions.cpp b/test/api/transactions.cpp index 8c42b04f..38c47c44 100644 --- a/test/api/transactions.cpp +++ b/test/api/transactions.cpp @@ -12,9 +12,6 @@ using testing::Return; TEST(api, test_transaction) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "id": "5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa", @@ -91,9 +88,6 @@ TEST(api, test_transaction) { // NOLINT TEST(api, test_transaction_types) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "Transfer": 0, @@ -151,9 +145,6 @@ TEST(api, test_transaction_types) { // NOLINT TEST(api, test_transaction_unconfirmed) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "id": "dummy", @@ -231,9 +222,6 @@ TEST(api, test_transaction_unconfirmed) { // NOLINT TEST(api, test_transactions) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, @@ -298,9 +286,6 @@ TEST(api, test_transactions) { // NOLINT TEST(api, test_transactions_unconfirmed) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 1, @@ -358,9 +343,6 @@ TEST(api, test_transactions_unconfirmed) { // NOLINT TEST(api, test_transactions_search) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 1, @@ -441,9 +423,6 @@ TEST(api, test_transactions_search) { // NOLINT TEST(api, test_transactions_send) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "accept": [ @@ -475,7 +454,7 @@ TEST(api, test_transactions_send) { // NOLINT "}" "]" "}"; - + const auto transaction = connection.api.transactions.send(jsonTransaction); DynamicJsonDocument doc(324); diff --git a/test/api/votes.cpp b/test/api/votes.cpp index 9b17ad6d..b3ab8477 100644 --- a/test/api/votes.cpp +++ b/test/api/votes.cpp @@ -12,9 +12,6 @@ using testing::Return; TEST(api, test_vote) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "id": "beb8dd43c640f562704090159154b2742afba7eacada9e8edee447e34e7675c6", @@ -95,9 +92,6 @@ TEST(api, test_vote) { // NOLINT TEST(api, test_votes) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, diff --git a/test/api/wallets.cpp b/test/api/wallets.cpp index 46449b9d..1c15a5f4 100644 --- a/test/api/wallets.cpp +++ b/test/api/wallets.cpp @@ -12,9 +12,6 @@ using testing::Return; TEST(api, test_wallet) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "data": { "address": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", @@ -54,9 +51,6 @@ TEST(api, test_wallet) { // NOLINT TEST(api, test_wallets) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, @@ -119,9 +113,6 @@ TEST(api, test_wallets) { // NOLINT TEST(api, test_wallets_search) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, @@ -231,9 +222,6 @@ TEST(api, test_wallets_search) { // NOLINT TEST(api, test_wallets_top) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, @@ -324,9 +312,6 @@ TEST(api, test_wallets_top) { // NOLINT TEST(api, test_wallets_transactions) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, @@ -379,9 +364,6 @@ TEST(api, test_wallets_transactions) { // NOLINT TEST(api, test_wallets_transactions_received) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, @@ -441,9 +423,6 @@ TEST(api, test_wallets_transactions_received) { // NOLINT TEST(api, test_wallets_transactions_sent) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, @@ -528,9 +507,6 @@ TEST(api, test_wallets_transactions_sent) { // NOLINT TEST(api, test_wallets_votes) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - const std::string response = R"({ "meta": { "count": 2, diff --git a/test/connection/connection.cpp b/test/connection/connection.cpp index c6ac613d..4aaf990c 100644 --- a/test/connection/connection.cpp +++ b/test/connection/connection.cpp @@ -6,8 +6,6 @@ TEST(api, test_connection) { // NOLINT Ark::Client::Connection<MockApi> connection("167.114.29.55", 4003); - int version = connection.api.version(); - ASSERT_EQ(2, version); const auto ip = connection.host.ip().c_str(); ASSERT_STREQ("167.114.29.55", ip); diff --git a/test/http/http.cpp b/test/http/http.cpp index 2f96fd79..57da9308 100644 --- a/test/http/http.cpp +++ b/test/http/http.cpp @@ -4,6 +4,8 @@ // Note: These test HTTP against a live node +#include <iostream> + TEST(api, test_http_get) { // NOLINT // Create the HTTP object const auto http = Ark::Client::makeHTTP(); @@ -12,10 +14,10 @@ TEST(api, test_http_get) { // NOLINT const auto response = http->get("167.114.29.55:4003/api/node/status"); // Create a JSON object of the result - DynamicJsonDocument doc(156); + const size_t capacity = JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(4) + 50; + DynamicJsonDocument doc(capacity); DeserializationError error = deserializeJson(doc, response); - if (error) { exit(0); } - + ASSERT_FALSE(error); // Test JSON object for the "data" key. // The correct response will include this key. ASSERT_TRUE(doc.containsKey("data")); @@ -30,15 +32,17 @@ TEST(api, test_http_post_body) { // NOLINT // Create a Request URL and 'Post' body. const auto request = "167.114.29.55:4003/api/v2/wallets/search?limit=1&page=1"; - const auto body = "username=baldninja"; + const auto body = "{\"username\":\"baldninja\"}"; // Post the 'request' and 'body' for a response using HTTP const auto response = http->post(request, body); // Create a JSON object of the result - DynamicJsonDocument doc(956); + const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(2) + + JSON_OBJECT_SIZE(6) + JSON_OBJECT_SIZE(8) + 470; + DynamicJsonDocument doc(capacity); DeserializationError error = deserializeJson(doc, response); - if (error) { exit(0); } + ASSERT_FALSE(error); // Test JSON object for the "meta" key. // The correct response will include this key @@ -54,16 +58,16 @@ TEST(api, test_http_invalid_post_body) { // NOLINT // Create a malformed Request URL and 'Post' body. const auto request = "/167.114.29.55:4003/api/v2/wallets/search"; - const auto body = "username=baldninja"; + const auto body = "{\"username\":\"baldninja\"}"; // Post the 'request' and 'body' for a response using HTTP const auto response = http->post(request, body); - // Create a JSON object of the result - DynamicJsonDocument doc(100); - DeserializationError error = deserializeJson(doc, response); - // the empty response should cause deserialization to fail - ASSERT_TRUE(error); + // The malformed request will result in the following error being logged: + // 'curl_easy_perform() failed: URL using bad/illegal format or missing URL' + + // the response will be empty + ASSERT_TRUE(response.empty()); } /**/ @@ -81,9 +85,10 @@ TEST(api, test_http_post_json) { // NOLINT const auto response = http->post(request, txJson); // Create a JSON object of the result - DynamicJsonDocument doc(180); + const size_t capacity = JSON_OBJECT_SIZE(3) + 90; + DynamicJsonDocument doc(capacity); DeserializationError error = deserializeJson(doc, response); - if (error) { exit(0); } + ASSERT_FALSE(error); // Test JSON object for the "message" key. // The correct response will include the following @@ -95,9 +100,9 @@ TEST(api, test_http_post_json) { // NOLINT // This tests the use of "http://" in single-line HTTP requests. TEST(api, test_http_request_strings) { // NOLINT char requests[3][43] = { - "167.114.29.55:4003/api/node/status", // No HTTP - "http://167.114.29.55:4003/api/node/status", // HTTP - "https://167.114.29.55:4003/api/node/status" // HTTPS + "167.114.29.55:4003/api/node/status", // No HTTP + "http://167.114.29.55:4003/api/node/status", // HTTP + "https://dexplorer.ark.io/api/node/status" // HTTPS }; // Create the HTTP object @@ -108,26 +113,23 @@ TEST(api, test_http_request_strings) { // NOLINT const auto response = http->get(i); // Create a JSON object of the result - DynamicJsonDocument doc(156); + const size_t capacity = JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(4) + 50; + DynamicJsonDocument doc(capacity); DeserializationError error = deserializeJson(doc, response); // Test JSON object for the "data" key. - // HTTPS is NOT supported and should fail to parse. +#ifdef USE_IOT + // HTTPS is NOT supported on IoT and should fail to parse. if (std::string(i).find("https://") != 0) { - if (error) { exit(0); } + ASSERT_FALSE(error); ASSERT_TRUE(doc.containsKey("data")); } else { + ASSERT_TRUE(error); ASSERT_FALSE(doc.containsKey("data")); }; +#else // OS Builds + ASSERT_FALSE(error); + ASSERT_TRUE(doc.containsKey("data")); +#endif }; } - -/**/ - -TEST(api, test_http_version) { // NOLINT - // Create the HTTP object - const auto http = Ark::Client::makeHTTP(); - - // The default 'api_version' of an unconfigured 'HTTP' object is '0'. - ASSERT_EQ(0, http->api_version()); -} diff --git a/test/mocks/mock_api.h b/test/mocks/mock_api.h index 51975acb..b9492ef0 100644 --- a/test/mocks/mock_api.h +++ b/test/mocks/mock_api.h @@ -17,6 +17,15 @@ #include "http/http.h" #include "mocks/mock_http.h" +class MockBlockchain : public Ark::Client::API::IBlockchain { +public: + MockBlockchain(Ark::Client::Host& host, Ark::Client::IHTTP& http) : IBlockchain(host, http) {} + + MOCK_METHOD0(get, std::string()); +}; + +/**/ + class MockBlocks : public Ark::Client::API::IBlocks { public: MockBlocks(Ark::Client::Host& host, Ark::Client::IHTTP& http) : IBlocks(host, http) {} @@ -103,6 +112,7 @@ class MockWallets : public Ark::Client::API::IWallets { class MockApi : public Ark::Client::API::Abstract { public: + MockBlockchain blockchain; MockBlocks blocks; MockDelegates delegates; MockNode node; @@ -112,7 +122,8 @@ class MockApi : public Ark::Client::API::Abstract { MockWallets wallets; MockApi() - : Abstract(new MockHTTP(), 2), + : Abstract(new MockHTTP()), + blockchain(host_, *http_), blocks(host_, *http_), delegates(host_, *http_), node(host_, *http_), diff --git a/test/mocks/mock_http.h b/test/mocks/mock_http.h index cc970fb8..1e9240a9 100644 --- a/test/mocks/mock_http.h +++ b/test/mocks/mock_http.h @@ -7,9 +7,6 @@ class MockHTTP : public Ark::Client::IHTTP { public: - MockHTTP() = default; - - MOCK_CONST_METHOD0(api_version, int()); MOCK_METHOD1(get, std::string(const char* const)); MOCK_METHOD2(post, std::string(const char* const, const char* const)); };