diff --git a/.circleci/clang_format.sh b/.circleci/clang_format.sh deleted file mode 100644 index 19c7f38c..00000000 --- a/.circleci/clang_format.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -ex - -grep -nr '\s$' src test examples .gitignore .gitmodules 2>&1 > /dev/null -if $?; then - echo Trailing whitespace found, aborting - exit 1 -fi - -# Default clang-format points to default 5.0 version one -CLANG_FORMAT=clang-format-5.0 -$CLANG_FORMAT --version - -#TODO: Create equivlient for CircleCI -#if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then -# # Get list of every file modified in this pull request -# files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' || true)" -#else - # Check everything for branch pushes - files_to_lint="$(find . -not \( -path ./_3rdParty -prune \) -not \( -path ./CMakeFiles -prune \) -not \( -path ./src/lib -prune \) -not \( -path ./test/lib -prune \) -not \( -path ./examples/cmake_example/lib -prune \) -not \( -path ./examples/cmake_example/CMakeFiles -prune \) -not \( -path ./examples/platformio_example -prune \) -name \*.h -o -name \*.cpp)" -#fi - -# Turn off tracing for this because it's too verbose -set +x - -for f in $files_to_lint; do - d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true) - if ! [ -z "$d" ]; then - echo "!!! $f not compliant to coding style, here is the fix:" - echo "$d" - fail=1 - fi -done - -set -x - -if [ "$fail" = 1 ]; then - # Don't fail the build yet - #exit 1 - exit 0 -fi diff --git a/.circleci/clang_tidy.sh b/.circleci/clang_tidy.sh deleted file mode 100644 index b97b592d..00000000 --- a/.circleci/clang_tidy.sh +++ /dev/null @@ -1,16 +0,0 @@ -# run clang tidy -cmake -DENABLE_CLANG_TIDY=ON . -make tidy > output.txt -#if [[ -n $(grep "warning: " output.txt) ]] || [[ -n $(grep "error: " output.txt) ]]; then -# for now only fail the test on errors. Change this as project matures -if [[ -n $(grep "error: " output.txt) ]]; then - echo "You must pass the clang tidy checks before submitting a pull request" - echo "" - grep --color -E '^|warning: |error: ' output.txt - exit -1; -else - # still output the file to show warnings - echo "" - grep --color -E '^|warning: |error: ' output.txt - echo -e "\033[1;32m\xE2\x9C\x93 passed:\033[0m $1"; -fi diff --git a/.circleci/config.yml b/.circleci/config.yml index b2d27e7a..8f75049b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,108 +13,9 @@ jobs: - run: name: Build command: ./.circleci/script_arduino.sh - build-linux-default: - machine: true - steps: - - checkout - - run: - name: Make scripts executable - command: sudo chmod -R +x ./.circleci/*.sh - - run: - name: Install - command: ./.circleci/install_platform_io.sh - - run: - name: Build - command: ./.circleci/script_platform_io.sh - build-linux-gcc7: - machine: true - steps: - - checkout - - run: - name: Install dependencies - command: | - sudo apt-get remove cmake cmake-data - sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-add-repository -y ppa:george-edison55/cmake-3.x - sudo apt-get update - sudo apt-get -y install g++-7 lcov cmake - - run: - name: Make scripts executable - command: sudo chmod -R +x ./.circleci/*.sh - - run: - name: Environment variables - command: CC=gcc-7 && CXX=g++-7 - - run: - name: Build - command: ./.circleci/script_desktop.sh - - run: - name: Codecov upload - command: bash <(curl -s https://codecov.io/bash) - build-linux-clang-5: - machine: true - steps: - - checkout - - run: - name: Install dependencies - command: | - sudo apt-get remove cmake cmake-data - sudo apt-add-repository -y "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main" - sudo apt-add-repository -y ppa:george-edison55/cmake-3.x - sudo apt-get update - sudo apt-get -y install clang-5.0 clang-format-5.0 clang-tidy-5.0 lcov cmake - - run: - name: Make scripts executable - command: sudo chmod -R +x ./.circleci/*.sh - - run: - name: Environment variables - command: CC=clang-5.0 && CXX=clang++-5.0 - - run: - name: Build - command: ./.circleci/script_desktop.sh - - run: - name: Clang Tidy - command: ./.circleci/clang_tidy.sh - - run: - name: Clang Format - command: ./.circleci/clang_format.sh - - build-macos-9-2: - macos: - xcode: "9.2.0" - steps: - - checkout - - run: COMPILER=clang++ - - run: - name: Install dependencies - command: brew install cmake lcov - - run: - name: Make scripts executable - command: sudo chmod -R +x ./.circleci/*.sh - - run: - name: Build - command: ./.circleci/script_desktop.sh - build-macos-9-3: - macos: - xcode: "9.3.0" - steps: - - checkout - - run: - name: Install dependencies - command: brew install cmake lcov - - run: - name: Make scripts executable - command: sudo chmod -R +x ./.circleci/*.sh - - run: - name: Build - command: ./.circleci/script_desktop.sh workflows: version: 2 build: jobs: - build-arduino-default - - build-linux-default - - build-linux-gcc7 - - build-linux-clang-5 - - build-macos-9-2 - - build-macos-9-3 diff --git a/.circleci/install_platform_io.sh b/.circleci/install_platform_io.sh deleted file mode 100644 index 4d7860a5..00000000 --- a/.circleci/install_platform_io.sh +++ /dev/null @@ -1,5 +0,0 @@ -# install PlatformIO -sudo pip install -U platformio - -# update PlatformIO -platformio update diff --git a/.circleci/script_arduino.sh b/.circleci/script_arduino.sh index 06a8c8de..dc802825 100644 --- a/.circleci/script_arduino.sh +++ b/.circleci/script_arduino.sh @@ -5,4 +5,4 @@ bash ./extras/ARDUINO_IDE.sh --auto mkdir -p ~/Arduino/libraries/cpp-client/ mv ~/project/* ~/Arduino/libraries/cpp-client -arduino-cli compile --output temp.bin -b esp32:esp32:esp32 ~/Arduino/libraries/cpp-client/examples/arduino/ESP32/ESP32.ino --debug +arduino-cli compile --output temp.bin -b esp32:esp32:esp32 ~/Arduino/libraries/cpp-client/examples/ESP32/ESP32.ino --debug diff --git a/.circleci/script_desktop.sh b/.circleci/script_desktop.sh deleted file mode 100644 index f76a2b5e..00000000 --- a/.circleci/script_desktop.sh +++ /dev/null @@ -1,13 +0,0 @@ -# run desktop builds -cmake . -DCMAKE_BUILD_TYPE=Coverage -cmake --build . - -# disable build examples until breaking changes are committed so the example can pull them in -# build examples -#cd ./examples/cmake_example -#cmake . -#cmake --build . - -# run Gtest -# cd ../../ -./test/Ark-Cpp-Client-tests diff --git a/.circleci/script_platform_io.sh b/.circleci/script_platform_io.sh deleted file mode 100644 index 7b558de4..00000000 --- a/.circleci/script_platform_io.sh +++ /dev/null @@ -1,5 +0,0 @@ -# run PlatformIO builds -platformio run - -# run PlatformIO unit tests -platformio run -d ./test diff --git a/.clang-format b/.clang-format deleted file mode 100644 index d3f8d0c6..00000000 --- a/.clang-format +++ /dev/null @@ -1,117 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: Google -AccessModifierOffset: -1 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlines: Left -AlignOperands: true -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Inline -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: true -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Attach -BreakBeforeInheritanceComma: false -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: true -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^' - Priority: 2 - - Regex: '^<.*\.h>' - Priority: 1 - - Regex: '^<.*' - Priority: 2 - - Regex: '.*' - Priority: 3 -IncludeIsMainRegex: '([-_](test|unittest))?$' -IndentCaseLabels: true -IndentPPDirectives: None -IndentWidth: 2 -IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: false -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBlockIndentWidth: 2 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: false -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 1 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Left -RawStringFormats: - - Delimiter: pb - Language: TextProto - BasedOnStyle: google -ReflowComments: true -SortIncludes: true -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Auto -TabWidth: 8 -UseTab: Never -... - diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index fd94d85b..00000000 --- a/.codecov.yml +++ /dev/null @@ -1,3 +0,0 @@ -ignore: - - "test" - - "extras" diff --git a/.gitattributes b/.gitattributes index 73a76bc4..a084fcab 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,4 +5,3 @@ /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/README.md export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7c7eb12d..e9589af5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,84 +1,4 @@ -/.history -/.vs +/.circleci /.vscode -/bin -/lib -/_Base -/CMakeFiles - -/bin/CMakeFiles -/libraries -/lib -/bin -/src/.pioenvs -/src/.vscode -/tests/.vscode -/tests/.pioenvs -.pioenvs -.piolibdeps -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -/test/.vscode -/test/lib/readme.txt .DS_Store -/src/Ark-Cpp-Client-lib.dir -/src/CMakeFiles -/src/cmake_install.cmake -/src/Ark-Cpp-Client-lib.vcxproj.filters -/src/Ark-Cpp-Client-lib.vcxproj -/src/Ark-Cpp-Client-lib.sln -/src/ALL_BUILD.vcxproj.filters -/src/ALL_BUILD.vcxproj -/test/Ark-Cpp-Client-tests.dir -/Win32 -/test/NightlyMemoryCheck.vcxproj.filters -/test/NightlyMemoryCheck.vcxproj -/test/Nightly.vcxproj.filters -/test/Nightly.vcxproj -/test/Experimental.vcxproj.filters -/test/Experimental.vcxproj -/test/DartConfiguration.tcl -/test/CTestTestfile.cmake -/test/Continuous.vcxproj.filters -/test/Continuous.vcxproj -/test/cmake_install.cmake -/test/CMakeFiles/generate.stamp.depend -/test/CMakeFiles/generate.stamp -/test/CMakeFiles -/test/Ark-Cpp-Client-tests.vcxproj.filters -/test/Ark-Cpp-Client-tests.vcxproj -/test/Ark-Cpp-Client-tests.sln -/test/ALL_BUILD.vcxproj.filters -/test/ALL_BUILD.vcxproj -/_3rdParty -/ZERO_CHECK.vcxproj.filters -/ZERO_CHECK.vcxproj -/cmake_install.cmake -/CMakeCache.txt -/Ark-Cpp-Client.sln -/ALL_BUILD.vcxproj.filters -/ALL_BUILD.vcxproj -/src/Win32 -/test/Debug -/src/Debug -/test/Release -/src/Release -/examples/cmake_example/CMakeFiles -/examples/cmake_example/CMakeCache.txt -/examples/cmake_example/Win32/ -/examples/cmake_example/_3rdParty -/examples/cmake_example/lib/Debug -/examples/cmake_example/bin -/examples/cmake_example/Cpp-Client-Example.dir -/examples/cmake_example/ZERO_CHECK.vcxproj.filters -/examples/cmake_example/ZERO_CHECK.vcxproj -/examples/cmake_example/Cpp-Client-Example.vcxproj.filters -/examples/cmake_example/Cpp-Client-Example.vcxproj -/examples/cmake_example/Cpp-Client-Example.sln -/examples/cmake_example/cmake_install.cmake -/examples/cmake_example/ALL_BUILD.vcxproj.filters -/examples/cmake_example/ALL_BUILD.vcxproj -/examples/cmake_example/Win32 -/examples/cmake_example/Debug diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 80f01793..00000000 --- a/.gitmodules +++ /dev/null @@ -1,7 +0,0 @@ -[submodule "test/lib/ArduinoJson"] - path = test/lib/ArduinoJson - url = https://github.com/bblanchon/ArduinoJson -[submodule "test/lib/googletest"] - path = test/lib/googletest - url = https://github.com/google/googletest.git - diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 672a5380..00000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -cmake_minimum_required(VERSION 3.2.2) - -set(HUNTER_STATUS_DEBUG ON) -set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake") - -include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/HunterGate.cmake") - -HunterGate( - URL "https://github.com/ruslo/hunter/archive/v0.23.29.tar.gz" - SHA1 "797be99a8a4f4666766257563fad8aa3aa032da2" -) -project(Ark-Cpp-Client) - -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 11) - -set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) - -if (MSVC) - add_definitions( - -D_CRT_SECURE_NO_WARNINGS - -D_SCL_SECURE_NO_WARNINGS - -DNOMINMAX - ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") -endif() - -# clone submodules -execute_process( - COMMAND git submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) - -# ------------------------------------------------------------------------------ -# Clang Tidy -# ------------------------------------------------------------------------------ - -if(ENABLE_CLANG_TIDY) - - find_program(CLANG_TIDY_BIN clang-tidy-5.0) - find_program(RUN_CLANG_TIDY_BIN run-clang-tidy-5.0.py) - - if(CLANG_TIDY_BIN STREQUAL "CLANG_TIDY_BIN-NOTFOUND") - message(FATAL_ERROR "unable to locate clang-tidy-5.0") - endif() - - if(RUN_CLANG_TIDY_BIN STREQUAL "RUN_CLANG_TIDY_BIN-NOTFOUND") - message(FATAL_ERROR "unable to locate run-clang-tidy-5.0.py") - endif() - - list(APPEND RUN_CLANG_TIDY_BIN_ARGS - -clang-tidy-binary ${CLANG_TIDY_BIN} - "\"-header-filter=.*\\b(src|test|examples)\\b\\/(?!lib).*\"" #Only run clang tidy on src, test, examples and skip 3rd party libraries - -checks=clan*,cert*,misc*,perf*,cppc*,read*,mode*,-cert-err58-cpp,-misc-noexcept-move-constructor,-cppcoreguidelines-* - ) - - add_custom_target( - tidy - COMMAND ${RUN_CLANG_TIDY_BIN} ${RUN_CLANG_TIDY_BIN_ARGS} - COMMENT "running clang tidy" - ) - -endif() - -add_subdirectory(src) -add_subdirectory(test) - diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake deleted file mode 100644 index 71fd6b27..00000000 --- a/cmake/CodeCoverage.cmake +++ /dev/null @@ -1,204 +0,0 @@ -# Copyright (c) 2012 - 2015, Lars Bilke -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# -# -# 2012-01-31, Lars Bilke -# - Enable Code Coverage -# -# 2013-09-17, Joakim SΓΆderberg -# - Added support for Clang. -# - Some additional usage instructions. -# -# USAGE: - -# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here: -# http://stackoverflow.com/a/22404544/80480 -# -# 1. Copy this file into your cmake modules path. -# -# 2. Add the following line to your CMakeLists.txt: -# INCLUDE(CodeCoverage) -# -# 3. Set compiler flags to turn off optimization and enable coverage: -# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") -# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") -# -# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target -# which runs your test executable and produces a lcov code coverage report: -# Example: -# SETUP_TARGET_FOR_COVERAGE( -# my_coverage_target # Name for custom target. -# test_driver # Name of the test driver executable that runs the tests. -# # NOTE! This should always have a ZERO as exit code -# # otherwise the coverage generation will not complete. -# coverage # Name of output directory. -# ) -# -# 4. Build a Debug build: -# cmake -DCMAKE_BUILD_TYPE=Debug .. -# make -# make my_coverage_target -# -# - -# Check prereqs -FIND_PROGRAM( GCOV_PATH gcov ) -FIND_PROGRAM( LCOV_PATH lcov ) -FIND_PROGRAM( GENHTML_PATH genhtml ) -FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests) - -IF(NOT GCOV_PATH) - MESSAGE(FATAL_ERROR "gcov not found! Aborting...") -ENDIF() # NOT GCOV_PATH - -IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") - IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) - MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") - ENDIF() -ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX) - MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") -ENDIF() # CHECK VALID COMPILER - -SET(CMAKE_CXX_FLAGS_COVERAGE - "-g -O0 --coverage -fprofile-arcs -ftest-coverage" - CACHE STRING "Flags used by the C++ compiler during coverage builds." - FORCE ) -SET(CMAKE_C_FLAGS_COVERAGE - "-g -O0 --coverage -fprofile-arcs -ftest-coverage" - CACHE STRING "Flags used by the C compiler during coverage builds." - FORCE ) -SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE - "" - CACHE STRING "Flags used for linking binaries during coverage builds." - FORCE ) -SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE - "" - CACHE STRING "Flags used by the shared libraries linker during coverage builds." - FORCE ) -MARK_AS_ADVANCED( - CMAKE_CXX_FLAGS_COVERAGE - CMAKE_C_FLAGS_COVERAGE - CMAKE_EXE_LINKER_FLAGS_COVERAGE - CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) - -IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage")) - MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" ) -ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" - - -# Param _targetname The name of new the custom make target -# Param _testrunner The name of the target which runs the tests. -# MUST return ZERO always, even on errors. -# If not, no coverage report will be created! -# Param _outputname lcov output is generated as _outputname.info -# HTML report is generated in _outputname/index.html -# Optional fourth parameter is passed as arguments to _testrunner -# Pass them in list form, e.g.: "-j;2" for -j 2 -FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) - - IF(NOT LCOV_PATH) - MESSAGE(FATAL_ERROR "lcov not found! Aborting...") - ENDIF() # NOT LCOV_PATH - - IF(NOT GENHTML_PATH) - MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") - ENDIF() # NOT GENHTML_PATH - - SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info") - SET(coverage_cleaned "${coverage_info}.cleaned") - - SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}") - - # Setup target - ADD_CUSTOM_TARGET(${_targetname} - - # Cleanup lcov - ${LCOV_PATH} --directory . --zerocounters - - # Run tests - COMMAND ${test_command} ${ARGV3} - - COMMAND lcov --version - COMMAND gcov --version - COMMAND g++ --version - - # Capturing lcov counters and generating report - COMMAND ${LCOV_PATH} --directory . --base-directory . --capture --output-file coverage.info - COMMAND ${LCOV_PATH} --remove coverage.info '/usr*' '*/test/*' '*/ext/*' -o coverage.info - - #COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info} - #COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned} - #COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned} - #COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned} - - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." - ) - - # Show info where to find the report - #ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD - # COMMAND ; - # COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report." - #) - -ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE - -# Param _targetname The name of new the custom make target -# Param _testrunner The name of the target which runs the tests -# Param _outputname cobertura output is generated as _outputname.xml -# Optional fourth parameter is passed as arguments to _testrunner -# Pass them in list form, e.g.: "-j;2" for -j 2 -FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname) - - IF(NOT PYTHON_EXECUTABLE) - MESSAGE(FATAL_ERROR "Python not found! Aborting...") - ENDIF() # NOT PYTHON_EXECUTABLE - - IF(NOT GCOVR_PATH) - MESSAGE(FATAL_ERROR "gcovr not found! Aborting...") - ENDIF() # NOT GCOVR_PATH - - ADD_CUSTOM_TARGET(${_targetname} - - # Run tests - ${_testrunner} ${ARGV3} - - # Running gcovr - COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Running gcovr to produce Cobertura code coverage report." - ) - - # Show info where to find the report - ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD - COMMAND ; - COMMENT "Cobertura code coverage report saved in ${_outputname}.xml." - ) - -ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake deleted file mode 100644 index 00a3fbef..00000000 --- a/cmake/Hunter/config.cmake +++ /dev/null @@ -1 +0,0 @@ -hunter_config(CURL VERSION 7.61.1) \ No newline at end of file diff --git a/cmake/HunterGate.cmake b/cmake/HunterGate.cmake deleted file mode 100644 index 7a62bbfc..00000000 --- a/cmake/HunterGate.cmake +++ /dev/null @@ -1,543 +0,0 @@ -# Copyright (c) 2013-2017, Ruslan Baratov -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# This is a gate file to Hunter package manager. -# Include this file using `include` command and add package you need, example: -# -# cmake_minimum_required(VERSION 3.0) -# -# include("cmake/HunterGate.cmake") -# HunterGate( -# URL "https://github.com/path/to/hunter/archive.tar.gz" -# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d" -# ) -# -# project(MyProject) -# -# hunter_add_package(Foo) -# hunter_add_package(Boo COMPONENTS Bar Baz) -# -# Projects: -# * https://github.com/hunter-packages/gate/ -# * https://github.com/ruslo/hunter - -option(HUNTER_ENABLED "Enable Hunter package manager support" ON) -if(HUNTER_ENABLED) - if(CMAKE_VERSION VERSION_LESS "3.0") - message(FATAL_ERROR "At least CMake version 3.0 required for hunter dependency management." - " Update CMake or set HUNTER_ENABLED to OFF.") - endif() -endif() - -include(CMakeParseArguments) # cmake_parse_arguments - -option(HUNTER_STATUS_PRINT "Print working status" ON) -option(HUNTER_STATUS_DEBUG "Print a lot info" OFF) -option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON) - -set(HUNTER_WIKI "https://github.com/ruslo/hunter/wiki") - -function(hunter_gate_status_print) - foreach(print_message ${ARGV}) - if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG) - message(STATUS "[hunter] ${print_message}") - endif() - endforeach() -endfunction() - -function(hunter_gate_status_debug) - foreach(print_message ${ARGV}) - if(HUNTER_STATUS_DEBUG) - string(TIMESTAMP timestamp) - message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}") - endif() - endforeach() -endfunction() - -function(hunter_gate_wiki wiki_page) - message("------------------------------ WIKI -------------------------------") - message(" ${HUNTER_WIKI}/${wiki_page}") - message("-------------------------------------------------------------------") - message("") - message(FATAL_ERROR "") -endfunction() - -function(hunter_gate_internal_error) - message("") - foreach(print_message ${ARGV}) - message("[hunter ** INTERNAL **] ${print_message}") - endforeach() - message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") - message("") - hunter_gate_wiki("error.internal") -endfunction() - -function(hunter_gate_fatal_error) - cmake_parse_arguments(hunter "" "WIKI" "" "${ARGV}") - string(COMPARE EQUAL "${hunter_WIKI}" "" have_no_wiki) - if(have_no_wiki) - hunter_gate_internal_error("Expected wiki") - endif() - message("") - foreach(x ${hunter_UNPARSED_ARGUMENTS}) - message("[hunter ** FATAL ERROR **] ${x}") - endforeach() - message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") - message("") - hunter_gate_wiki("${hunter_WIKI}") -endfunction() - -function(hunter_gate_user_error) - hunter_gate_fatal_error(${ARGV} WIKI "error.incorrect.input.data") -endfunction() - -function(hunter_gate_self root version sha1 result) - string(COMPARE EQUAL "${root}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("root is empty") - endif() - - string(COMPARE EQUAL "${version}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("version is empty") - endif() - - string(COMPARE EQUAL "${sha1}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("sha1 is empty") - endif() - - string(SUBSTRING "${sha1}" 0 7 archive_id) - - if(EXISTS "${root}/cmake/Hunter") - set(hunter_self "${root}") - else() - set( - hunter_self - "${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked" - ) - endif() - - set("${result}" "${hunter_self}" PARENT_SCOPE) -endfunction() - -# Set HUNTER_GATE_ROOT cmake variable to suitable value. -function(hunter_gate_detect_root) - # Check CMake variable - string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty) - if(not_empty) - set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE) - hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable") - return() - endif() - - # Check environment variable - string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty) - if(not_empty) - set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE) - hunter_gate_status_debug("HUNTER_ROOT detected by environment variable") - return() - endif() - - # Check HOME environment variable - string(COMPARE NOTEQUAL "$ENV{HOME}" "" result) - if(result) - set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE) - hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable") - return() - endif() - - # Check SYSTEMDRIVE and USERPROFILE environment variable (windows only) - if(WIN32) - string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result) - if(result) - set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE) - hunter_gate_status_debug( - "HUNTER_ROOT set using SYSTEMDRIVE environment variable" - ) - return() - endif() - - string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result) - if(result) - set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE) - hunter_gate_status_debug( - "HUNTER_ROOT set using USERPROFILE environment variable" - ) - return() - endif() - endif() - - hunter_gate_fatal_error( - "Can't detect HUNTER_ROOT" - WIKI "error.detect.hunter.root" - ) -endfunction() - -macro(hunter_gate_lock dir) - if(NOT HUNTER_SKIP_LOCK) - if("${CMAKE_VERSION}" VERSION_LESS "3.2") - hunter_gate_fatal_error( - "Can't lock, upgrade to CMake 3.2 or use HUNTER_SKIP_LOCK" - WIKI "error.can.not.lock" - ) - endif() - hunter_gate_status_debug("Locking directory: ${dir}") - file(LOCK "${dir}" DIRECTORY GUARD FUNCTION) - hunter_gate_status_debug("Lock done") - endif() -endmacro() - -function(hunter_gate_download dir) - string( - COMPARE - NOTEQUAL - "$ENV{HUNTER_DISABLE_AUTOINSTALL}" - "" - disable_autoinstall - ) - if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL) - hunter_gate_fatal_error( - "Hunter not found in '${dir}'" - "Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'" - "Settings:" - " HUNTER_ROOT: ${HUNTER_GATE_ROOT}" - " HUNTER_SHA1: ${HUNTER_GATE_SHA1}" - WIKI "error.run.install" - ) - endif() - string(COMPARE EQUAL "${dir}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("Empty 'dir' argument") - endif() - - string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("HUNTER_GATE_SHA1 empty") - endif() - - string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("HUNTER_GATE_URL empty") - endif() - - set(done_location "${dir}/DONE") - set(sha1_location "${dir}/SHA1") - - set(build_dir "${dir}/Build") - set(cmakelists "${dir}/CMakeLists.txt") - - hunter_gate_lock("${dir}") - if(EXISTS "${done_location}") - # while waiting for lock other instance can do all the job - hunter_gate_status_debug("File '${done_location}' found, skip install") - return() - endif() - - file(REMOVE_RECURSE "${build_dir}") - file(REMOVE_RECURSE "${cmakelists}") - - file(MAKE_DIRECTORY "${build_dir}") # check directory permissions - - # Disabling languages speeds up a little bit, reduces noise in the output - # and avoids path too long windows error - file( - WRITE - "${cmakelists}" - "cmake_minimum_required(VERSION 3.0)\n" - "project(HunterDownload LANGUAGES NONE)\n" - "include(ExternalProject)\n" - "ExternalProject_Add(\n" - " Hunter\n" - " URL\n" - " \"${HUNTER_GATE_URL}\"\n" - " URL_HASH\n" - " SHA1=${HUNTER_GATE_SHA1}\n" - " DOWNLOAD_DIR\n" - " \"${dir}\"\n" - " TLS_VERIFY\n" - " ${HUNTER_TLS_VERIFY}\n" - " SOURCE_DIR\n" - " \"${dir}/Unpacked\"\n" - " CONFIGURE_COMMAND\n" - " \"\"\n" - " BUILD_COMMAND\n" - " \"\"\n" - " INSTALL_COMMAND\n" - " \"\"\n" - ")\n" - ) - - if(HUNTER_STATUS_DEBUG) - set(logging_params "") - else() - set(logging_params OUTPUT_QUIET) - endif() - - hunter_gate_status_debug("Run generate") - - # Need to add toolchain file too. - # Otherwise on Visual Studio + MDD this will fail with error: - # "Could not find an appropriate version of the Windows 10 SDK installed on this machine" - if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") - get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE) - set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}") - else() - # 'toolchain_arg' can't be empty - set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=") - endif() - - string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make) - if(no_make) - set(make_arg "") - else() - # Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM - set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") - endif() - - execute_process( - COMMAND - "${CMAKE_COMMAND}" - "-H${dir}" - "-B${build_dir}" - "-G${CMAKE_GENERATOR}" - "${toolchain_arg}" - ${make_arg} - WORKING_DIRECTORY "${dir}" - RESULT_VARIABLE download_result - ${logging_params} - ) - - if(NOT download_result EQUAL 0) - hunter_gate_internal_error("Configure project failed") - endif() - - hunter_gate_status_print( - "Initializing Hunter workspace (${HUNTER_GATE_SHA1})" - " ${HUNTER_GATE_URL}" - " -> ${dir}" - ) - execute_process( - COMMAND "${CMAKE_COMMAND}" --build "${build_dir}" - WORKING_DIRECTORY "${dir}" - RESULT_VARIABLE download_result - ${logging_params} - ) - - if(NOT download_result EQUAL 0) - hunter_gate_internal_error("Build project failed") - endif() - - file(REMOVE_RECURSE "${build_dir}") - file(REMOVE_RECURSE "${cmakelists}") - - file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}") - file(WRITE "${done_location}" "DONE") - - hunter_gate_status_debug("Finished") -endfunction() - -# Must be a macro so master file 'cmake/Hunter' can -# apply all variables easily just by 'include' command -# (otherwise PARENT_SCOPE magic needed) -macro(HunterGate) - if(HUNTER_GATE_DONE) - # variable HUNTER_GATE_DONE set explicitly for external project - # (see `hunter_download`) - set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) - endif() - - # First HunterGate command will init Hunter, others will be ignored - get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET) - - if(NOT HUNTER_ENABLED) - # Empty function to avoid error "unknown function" - function(hunter_add_package) - endfunction() - - set( - _hunter_gate_disabled_mode_dir - "${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode" - ) - if(EXISTS "${_hunter_gate_disabled_mode_dir}") - hunter_gate_status_debug( - "Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}" - ) - list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}") - endif() - elseif(_hunter_gate_done) - hunter_gate_status_debug("Secondary HunterGate (use old settings)") - hunter_gate_self( - "${HUNTER_CACHED_ROOT}" - "${HUNTER_VERSION}" - "${HUNTER_SHA1}" - _hunter_self - ) - include("${_hunter_self}/cmake/Hunter") - else() - set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_LIST_DIR}") - - string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name) - if(_have_project_name) - hunter_gate_fatal_error( - "Please set HunterGate *before* 'project' command. " - "Detected project: ${PROJECT_NAME}" - WIKI "error.huntergate.before.project" - ) - endif() - - cmake_parse_arguments( - HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV} - ) - - string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1) - string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url) - string( - COMPARE - NOTEQUAL - "${HUNTER_GATE_UNPARSED_ARGUMENTS}" - "" - _have_unparsed - ) - string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global) - string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath) - - if(_have_unparsed) - hunter_gate_user_error( - "HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}" - ) - endif() - if(_empty_sha1) - hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory") - endif() - if(_empty_url) - hunter_gate_user_error("URL suboption of HunterGate is mandatory") - endif() - if(_have_global) - if(HUNTER_GATE_LOCAL) - hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)") - endif() - if(_have_filepath) - hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)") - endif() - endif() - if(HUNTER_GATE_LOCAL) - if(_have_global) - hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)") - endif() - if(_have_filepath) - hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)") - endif() - endif() - if(_have_filepath) - if(_have_global) - hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)") - endif() - if(HUNTER_GATE_LOCAL) - hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)") - endif() - endif() - - hunter_gate_detect_root() # set HUNTER_GATE_ROOT - - # Beautify path, fix probable problems with windows path slashes - get_filename_component( - HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE - ) - hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}") - if(NOT HUNTER_ALLOW_SPACES_IN_PATH) - string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces) - if(NOT _contain_spaces EQUAL -1) - hunter_gate_fatal_error( - "HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces." - "Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error" - "(Use at your own risk!)" - WIKI "error.spaces.in.hunter.root" - ) - endif() - endif() - - string( - REGEX - MATCH - "[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*" - HUNTER_GATE_VERSION - "${HUNTER_GATE_URL}" - ) - string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty) - if(_is_empty) - set(HUNTER_GATE_VERSION "unknown") - endif() - - hunter_gate_self( - "${HUNTER_GATE_ROOT}" - "${HUNTER_GATE_VERSION}" - "${HUNTER_GATE_SHA1}" - _hunter_self - ) - - set(_master_location "${_hunter_self}/cmake/Hunter") - if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter") - # Hunter downloaded manually (e.g. by 'git clone') - set(_unused "xxxxxxxxxx") - set(HUNTER_GATE_SHA1 "${_unused}") - set(HUNTER_GATE_VERSION "${_unused}") - else() - get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE) - set(_done_location "${_archive_id_location}/DONE") - set(_sha1_location "${_archive_id_location}/SHA1") - - # Check Hunter already downloaded by HunterGate - if(NOT EXISTS "${_done_location}") - hunter_gate_download("${_archive_id_location}") - endif() - - if(NOT EXISTS "${_done_location}") - hunter_gate_internal_error("hunter_gate_download failed") - endif() - - if(NOT EXISTS "${_sha1_location}") - hunter_gate_internal_error("${_sha1_location} not found") - endif() - file(READ "${_sha1_location}" _sha1_value) - string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal) - if(NOT _is_equal) - hunter_gate_internal_error( - "Short SHA1 collision:" - " ${_sha1_value} (from ${_sha1_location})" - " ${HUNTER_GATE_SHA1} (HunterGate)" - ) - endif() - if(NOT EXISTS "${_master_location}") - hunter_gate_user_error( - "Master file not found:" - " ${_master_location}" - "try to update Hunter/HunterGate" - ) - endif() - endif() - include("${_master_location}") - set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) - endif() -endmacro() \ No newline at end of file diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake deleted file mode 100644 index f14d277f..00000000 --- a/cmake/toolchain.cmake +++ /dev/null @@ -1 +0,0 @@ -set(CMAKE_CXX_STANDARD 11) diff --git a/docs/INSTALL_OS.md b/docs/INSTALL_OS.md deleted file mode 100644 index 73ba248c..00000000 --- a/docs/INSTALL_OS.md +++ /dev/null @@ -1,25 +0,0 @@ - - -# OS Builds - -### dependencies - -**CMake:** -Use an installer package from the following link: -```https://www.cmake.org/download/``` - -or using -**Homebrew:** -`brew install cmake` - -> note: all other dependencies will be automatically installed via CMake and Hunter Package Manager. - -# - -### make and build -**`cd` into `.../cpp-client/`** -then run the following command combo: -`cmake . && cmake --build .` - -### run tests -`./bin/Ark-Cpp-Client-tests` diff --git a/docs/INSTALL_PLATFORMIO.md b/docs/INSTALL_PLATFORMIO.md deleted file mode 100644 index fced1874..00000000 --- a/docs/INSTALL_PLATFORMIO.md +++ /dev/null @@ -1,51 +0,0 @@ - - -# PlatformIO - -### dependencies - -**Python:** -Use an installer package from the following link: -```https://www.python.org/downloads/``` - -# - -**PlatformIO:** -install PlatformIO if not already installed -```pip install -U platformio``` -or -```python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py)"``` - - -also install platformio dependencies: -> install ArduinoJson@5.13.2 AUnit (2778) -```platformio lib -g install 64@5.13.2 2778``` - -# - -### provide your WiFi info for your board to access the internet - -**open the following file in your preferred code editor:** - -> "*.../cpp-client/test/IoT/test_main.cpp*" - - -lines 19 & 20: -``` -char ssid[] = "your_ssid"; // your network SSID (name) -const char password[] = "your_password"; // your network password -``` - -# - -### running the tests on an Arduino board - -**`cd` into this directory "*.../Cpp-Client/test*"** -> ```cd test``` - -**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``` | diff --git a/examples/arduino/ESP32/ESP32.ino b/examples/ESP32/ESP32.ino similarity index 100% rename from examples/arduino/ESP32/ESP32.ino rename to examples/ESP32/ESP32.ino diff --git a/examples/arduino/ESP8266/ESP8266.ino b/examples/ESP8266/ESP8266.ino similarity index 100% rename from examples/arduino/ESP8266/ESP8266.ino rename to examples/ESP8266/ESP8266.ino diff --git a/examples/cmake_example/.gitmodules b/examples/cmake_example/.gitmodules deleted file mode 100644 index 458f10ec..00000000 --- a/examples/cmake_example/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "lib/cpp-client"] - path = lib/cpp-client - url = https://github.com/ArkEcosystem/cpp-client.git diff --git a/examples/cmake_example/CMakeLists.txt b/examples/cmake_example/CMakeLists.txt deleted file mode 100644 index b549ccc2..00000000 --- a/examples/cmake_example/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -cmake_minimum_required(VERSION 3.2) - -# clone submodules -execute_process( - COMMAND git submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) - -add_subdirectory(lib/cpp-client) - -project(Cpp-Client-Example) - -set(CMAKE_CXX_STANDARD 11) - -set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) - -if (MSVC) - add_definitions( - -D_CRT_SECURE_NO_WARNINGS - -D_SCL_SECURE_NO_WARNINGS - -DNOMINMAX - ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") - #set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") - #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") -endif() - -set(SOURCE_FILES main.cpp) - -add_executable(${PROJECT_NAME} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} Ark-Cpp-Client-lib) - diff --git a/examples/cmake_example/CMakeSettings.json b/examples/cmake_example/CMakeSettings.json deleted file mode 100644 index 4ecdae92..00000000 --- a/examples/cmake_example/CMakeSettings.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "configurations": [ - { - "name": "x86-Debug", - "generator": "Visual Studio 15 2017", - "configurationType": "Debug", - "inheritEnvironments": [ "msvc_x86" ], - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "", - "ctestCommandArgs": "" - }, - { - "name": "x86-Release", - "generator": "Visual Studio 15 2017", - "configurationType": "Release", - "inheritEnvironments": [ "msvc_x86" ], - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "", - "ctestCommandArgs": "" - }, - { - "name": "x64-Debug", - "generator": "Visual Studio 15 2017 Win64", - "configurationType": "Debug", - "inheritEnvironments": [ "msvc_x64_x64" ], - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "", - "ctestCommandArgs": "" - }, - { - "name": "x64-Release", - "generator": "Visual Studio 15 2017 Win64", - "configurationType": "Release", - "inheritEnvironments": [ "msvc_x64_x64" ], - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "", - "ctestCommandArgs": "" - }, - { - "name": "Linux-Debug", - "generator": "Unix Makefiles", - "remoteMachineName": "${defaultRemoteMachineName}", - "configurationType": "Debug", - "remoteCMakeListsRoot": "/var/tmp/src/${workspaceHash}/${name}", - "cmakeExecutable": "/usr/local/bin/cmake", - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "remoteBuildRoot": "/var/tmp/build/${workspaceHash}/build/${name}", - "remoteInstallRoot": "/var/tmp/build/${workspaceHash}/install/${name}", - "remoteCopySources": true, - "remoteCopySourcesOutputVerbosity": "Normal", - "remoteCopySourcesConcurrentCopies": "10", - "remoteCopySourcesMethod": "sftp", - "cmakeCommandArgs": "", - "buildCommandArgs": "", - "ctestCommandArgs": "", - "inheritEnvironments": [ "linux-x64" ] - }, - { - "name": "Linux-Release", - "generator": "Unix Makefiles", - "remoteMachineName": "${defaultRemoteMachineName}", - "configurationType": "Release", - "remoteCMakeListsRoot": "/var/tmp/src/${workspaceHash}/${name}", - "cmakeExecutable": "/usr/local/bin/cmake", - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "remoteBuildRoot": "/var/tmp/build/${workspaceHash}/build/${name}", - "remoteInstallRoot": "/var/tmp/build/${workspaceHash}/install/${name}", - "remoteCopySources": true, - "remoteCopySourcesOutputVerbosity": "Normal", - "remoteCopySourcesConcurrentCopies": "10", - "remoteCopySourcesMethod": "sftp", - "cmakeCommandArgs": "", - "buildCommandArgs": "", - "ctestCommandArgs": "", - "inheritEnvironments": [ "linux-x64" ] - } - ] -} \ No newline at end of file diff --git a/examples/cmake_example/lib/put-cpp-client-folder-here b/examples/cmake_example/lib/put-cpp-client-folder-here deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/cmake_example/main.cpp b/examples/cmake_example/main.cpp deleted file mode 100644 index a800ebc7..00000000 --- a/examples/cmake_example/main.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "arkClient.h" - -#include - -int main(int argc, char* argv[]) { - // Create a connection - Ark::Client::Connection 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 blockResponse = connection.api.blocks.get("13114381566690093367"); - std::cout << "Response for block '13114381566690093367':\n"; - std::cout << blockResponse << "\n\n"; - - const auto delegateResponse = connection.api.delegates.get("boldninja"); - std::cout << "Response for delegate 'boldninja':\n"; - std::cout << delegateResponse << "\n\n"; - - const auto nodeConfiguration = connection.api.node.configuration(); - std::cout << "Response for configuration of node '167.114.29.54:4003':\n"; - std::cout << nodeConfiguration << "\n\n"; - - const auto peer = connection.api.peers.get("167.114.29.49"); - std::cout << "Response for peer '167.114.29.49':\n"; - std::cout << peer << "\n\n"; - - const auto transaction = - connection.api.transactions.get("b324cea5c5a6c15e6ced3ec9c3135a8022eeadb8169f7ba66c80ebc82b0ac850"); - std::cout << "Response for transaction 'b324cea5c5a6c15e6ced3ec9c3135a8022eeadb8169f7ba66c80ebc82b0ac850':\n"; - std::cout << transaction << "\n\n"; - - const auto vote = connection.api.votes.get("d202acbfa947acac53ada2ac8a0eb662c9f75421ede3b10a42759352968b4ed2"); - std::cout << "Response for votes 'd202acbfa947acac53ada2ac8a0eb662c9f75421ede3b10a42759352968b4ed2':\n"; - std::cout << vote << "\n\n"; - - const auto walletsSearch = connection.api.wallets.search({"username", "baldninja"}); - std::cout << "Response for wallet search 'username=baldninja':\n"; - std::cout << walletsSearch << std::endl; - - return 0; -} diff --git a/examples/platformio_example/platformio.ini b/examples/platformio_example/platformio.ini deleted file mode 100644 index b4c64367..00000000 --- a/examples/platformio_example/platformio.ini +++ /dev/null @@ -1,29 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; http://docs.platformio.org/page/projectconf.html - - -[platformio] - -[env:esp8266] -lib_deps = Ark-Cpp-Client -platform = espressif8266 -board = huzzah -framework = arduino -upload_speed = 921600 - -[env:esp32] -; THis lib_extra_dirs is required to disambiguate the HTTPCLient library being used by Ark-Cpp-Client -; Currently this cannot be hidden from the user due to limitations in PlatformIO. -lib_extra_dirs = $PIOHOME_DIR/packages/framework-arduinoespressif32/libraries -lib_deps = Ark-Cpp-Client -platform = espressif32 -board = esp32dev -framework = arduino -upload_speed = 921600 diff --git a/examples/platformio_example/src/main.ino b/examples/platformio_example/src/main.ino deleted file mode 100644 index 462b058b..00000000 --- a/examples/platformio_example/src/main.ino +++ /dev/null @@ -1,56 +0,0 @@ -#include "arkClient.h" - -#include - -void setup() { - Serial.begin(115200); - - while (!Serial) { delay(100); }; - // ^for the Arduino Leonardo/Micro only -} - -void loop() { - // Create a connection - Ark::Client::Connection 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 blockResponse = connection.api.blocks.get("13114381566690093367"); - Serial.println("Response for block '13114381566690093367':"); - Serial.println(blockResponse.c_str()); - Serial.println(); - - const auto delegateResponse = connection.api.delegates.get("boldninja"); - Serial.println("Response for delegate 'boldninja':"); - Serial.println(delegateResponse.c_str()); - Serial.println(); - - const auto nodeConfiguration = connection.api.node.configuration(); - Serial.println("Response for configuration of node '167.114.29.54:4003':"); - Serial.println(nodeConfiguration.c_str()); - Serial.println(); - - const auto peer = connection.api.peers.get("167.114.29.49"); - Serial.println("Response for peer '167.114.29.49':"); - Serial.println(peer.c_str()); - Serial.println(); - - const auto transaction = connection.api.transactions.get("b324cea5c5a6c15e6ced3ec9c3135a8022eeadb8169f7ba66c80ebc82b0ac850"); - Serial.println("Response for transaction 'b324cea5c5a6c15e6ced3ec9c3135a8022eeadb8169f7ba66c80ebc82b0ac850':"); - Serial.println(transaction.c_str()); - Serial.println(); - - const auto vote = connection.api.votes.get("d202acbfa947acac53ada2ac8a0eb662c9f75421ede3b10a42759352968b4ed2"); - Serial.println("Response for votes 'd202acbfa947acac53ada2ac8a0eb662c9f75421ede3b10a42759352968b4ed2':"); - Serial.println(vote.c_str()); - Serial.println(); - - const auto walletsSearch = connection.api.wallets.search({ "username", "baldninja" }); - Serial.println("Response for wallet search 'username=baldninja':"); - Serial.println(walletsSearch.c_str()); - -} diff --git a/extras/ARDUINO_IDE.sh b/extras/ARDUINO_IDE.sh deleted file mode 100644 index dcd4642d..00000000 --- a/extras/ARDUINO_IDE.sh +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/env bash -# This file is part of Ark Cpp Client. -# -# (c) Ark Ecosystem -# -# For the full copyright and license information, please view the LICENSE -# file that was distributed with this source code. - -# ######### -# This script extends support to the Arduino IDE. -# -# The Arduino IDE doesn't support extending its search path outside of the 'src' folder. -# The Ark Cpp-Client SDK exposes its public interface via the 'include' folder. -# -# This script moves the headers from 'include' into their relative directories in the 'src' folder; -# it then delete the 'include' folder. -# -# Additionally, once this script has been ran, it can be executed again to undo these changes. -# (i.e. recreates the directory tree and moves headers back to 'include'.) -# ######### - -# Flags -# You can skip the interface by passing '--auto'; eg 'bash ARDUINO_IDE.sh -auto' -AUTO='0' -if [ "$1" == "--auto" ]; then - AUTO='1' -fi - -# Directories -EXTRAS_DIR=`dirname "$0"` -PROJECT_ROOT=${EXTRAS_DIR}/../ -INCLUDE_DIR=${EXTRAS_DIR}/../src/include/cpp-client -SRC_DIR=${EXTRAS_DIR}/../src - -INCLUDE_API_DIR=${INCLUDE_DIR}/api -SRC_API_DIR=${SRC_DIR}/api - -INCLUDE_BLOCKS_DIR=${INCLUDE_DIR}/api/blocks -INCLUDE_DELEGATES_DIR=${INCLUDE_DIR}/api/delegates -INCLUDE_NODE_DIR=${INCLUDE_DIR}/api/node -INCLUDE_PEERS_DIR=${INCLUDE_DIR}/api/peers -INCLUDE_TRANSACTIONS_DIR=${INCLUDE_DIR}/api/transactions -INCLUDE_VOTES_DIR=${INCLUDE_DIR}/api/votes -INCLUDE_WALLETS_DIR=${INCLUDE_DIR}/api/wallets - -SRC_BLOCKS_DIR=${SRC_DIR}/api/blocks -SRC_DELEGATES_DIR=${SRC_DIR}/api/delegates -SRC_NODE_DIR=${SRC_DIR}/api/node -SRC_PEERS_DIR=${SRC_DIR}/api/peers -SRC_TRANSACTIONS_DIR=${SRC_DIR}/api/transactions -SRC_VOTES_DIR=${SRC_DIR}/api/votes -SRC_WALLETS_DIR=${SRC_DIR}/api/wallets - -INCLUDE_CONNECTION_DIR=${INCLUDE_DIR}/connection -SRC_CONNECTION_DIR=${SRC_DIR}/connection - -INCLUDE_HTTP_DIR=${INCLUDE_DIR}/http -SRC_HTTP_DIR=${SRC_DIR}/http - -INCLUDE_HOST_DIR=${INCLUDE_DIR}/host -SRC_HOST_DIR=${SRC_DIR}/host - -if [[ $AUTO == '0' ]]; then - -# Interface -echo -e "\n\nπŸ‘‹ Welcome Aboard 🚒\n\n" -sleep 1 - -if [[ -d ${INCLUDE_DIR} ]]; then - echo -e "πŸ€– This script extends compatibility to the Arduino IDE πŸ€–\n" - sleep 1 - echo -e "πŸ’ͺ All header files will be moved to their 'src' folders πŸ’ͺ\n" - sleep 1 -else - echo -e "πŸ€– Looks like this library was already converted to support the Arduino IDE πŸ€–\n" - sleep 1 - echo -e "πŸ’ͺ All header files will be moved back to the 'include' folder πŸ’ͺ\n" - sleep 1 -fi - -echo -e "\nπŸ›‘ These changes are permanent, any unsaved changes will be lost πŸ›‘\n" -sleep 2 - -# Prompts for continuation -read -p "⚠️ Are you sure you want to continue? (Y/n):" -n 1 -r -echo -if [[ ${REPLY} =~ ^[Nn]$ ]]; then - echo -e "\n\nπŸ‘Œ Exiting script...\nNo Changes were made πŸ‘\n\n"; - exit 0; -else - echo -e "\n\nπŸ‘Œ Let's go!\n"; -fi - -fi # /if [[ ${AUTO} ]]; then - -if [[ -d ${INCLUDE_DIR} ]]; then - # This will run if headers are in the 'include' directory tree. - echo -e "****************************************\n" - echo -e "Moving 'arkClient.h' to 'src' directory.\n" - mv ${INCLUDE_DIR}/arkClient.h ${SRC_DIR} - - echo -e "Moving API headers.\n" - mv ${INCLUDE_API_DIR}/abstract.h ${SRC_API_DIR} - mv ${INCLUDE_API_DIR}/api.h ${SRC_API_DIR} - mv ${INCLUDE_API_DIR}/base.h ${SRC_API_DIR} - mv ${INCLUDE_API_DIR}/paths.h ${SRC_API_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} - mv ${INCLUDE_PEERS_DIR}/peers.h ${SRC_PEERS_DIR} - mv ${INCLUDE_TRANSACTIONS_DIR}/transactions.h ${SRC_TRANSACTIONS_DIR} - mv ${INCLUDE_VOTES_DIR}/votes.h ${SRC_VOTES_DIR} - mv ${INCLUDE_WALLETS_DIR}/wallets.h ${SRC_WALLETS_DIR} - - echo "Creating 'connection' folder πŸ—‚" - mkdir ${SRC_CONNECTION_DIR} - - echo -e "Moving 'connection.h' to 'src/connection'.\n" - mv ${INCLUDE_CONNECTION_DIR}/connection.h ${SRC_CONNECTION_DIR} - - echo -e "Moving 'host.h'\n" - mv ${INCLUDE_HOST_DIR}/host.h ${SRC_HOST_DIR} - - echo -e "Moving 'http.h'\n" - mv ${INCLUDE_HTTP_DIR}/http.h ${SRC_HTTP_DIR} - - echo -e "Moving Docs to the './extras' directory.\n" - mv ${PROJECT_ROOT}/docs ${EXTRAS_DIR} - - echo -e "Removing old directories πŸ—‘\n" - rm -rf ${INCLUDE_DIR} - - echo -e "****************************************\n" - echo -e "\nAll Done!\nπŸ‘πŸ‘πŸ‘πŸ‘πŸ‘\n" - echo -e "\nYou can now use Cpp-Client with the Arduino IDE πŸ‘\n\n" - exit 0 - -else - # This will run if headers are already in the 'src' directory tree. - echo -e "****************************************\n" - echo -e "Creating the 'include' folder πŸ—‚\n" - mkdir ${INCLUDE_DIR} - - echo -e "Moving 'arkClient.h' back to the 'include' directory.\n" - mv ${SRC_DIR}/arkClient.h ${INCLUDE_DIR} - - echo -e "Recreating API directories πŸ—‚\n" - mkdir ${INCLUDE_API_DIR} - mkdir ${INCLUDE_BLOCKS_DIR} - mkdir ${INCLUDE_DELEGATES_DIR} - mkdir ${INCLUDE_NODE_DIR} - mkdir ${INCLUDE_PEERS_DIR} - mkdir ${INCLUDE_TRANSACTIONS_DIR} - mkdir ${INCLUDE_VOTES_DIR} - mkdir ${INCLUDE_WALLETS_DIR} - - echo -e "Moving API headers back to the 'include' tree.\n" - mv ${SRC_API_DIR}/abstract.h ${INCLUDE_API_DIR} - mv ${SRC_API_DIR}/api.h ${INCLUDE_API_DIR} - mv ${SRC_API_DIR}/base.h ${INCLUDE_API_DIR} - mv ${SRC_API_DIR}/paths.h ${INCLUDE_API_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} - mv ${SRC_PEERS_DIR}/peers.h ${INCLUDE_PEERS_DIR} - mv ${SRC_TRANSACTIONS_DIR}/transactions.h ${INCLUDE_TRANSACTIONS_DIR} - mv ${SRC_VOTES_DIR}/votes.h ${INCLUDE_VOTES_DIR} - mv ${SRC_WALLETS_DIR}/wallets.h ${INCLUDE_WALLETS_DIR} - - echo -e "Recreating the 'connection' folder πŸ—‚" - mkdir ${INCLUDE_CONNECTION_DIR} - - echo -e "Moving 'connection.h' to 'include/cpp-client/connection'.\n" - mv ${SRC_CONNECTION_DIR}/connection.h ${INCLUDE_CONNECTION_DIR} - - echo -e "Recreating the 'host' folder πŸ—‚" - mkdir ${INCLUDE_HOST_DIR} - - echo -e "Moving 'host.h'\n" - mv ${SRC_HOST_DIR}/host.h ${INCLUDE_HOST_DIR} - - echo -e "Recreating the 'http' folder πŸ—‚" - mkdir ${INCLUDE_HTTP_DIR} - - echo -e "Moving 'http.h'\n" - mv ${SRC_HTTP_DIR}/http.h ${INCLUDE_HTTP_DIR} - - echo -e "Moving Docs back to the project root directory.\n" - mv ${EXTRAS_DIR}/docs ${PROJECT_ROOT} - - echo -e "Removing old directories πŸ—‘\n" - rm -rf ${SRC_CONNECTION_DIR} - - echo -e "****************************************\n" - echo -e "\nAll Done!\nπŸ‘πŸ‘πŸ‘πŸ‘πŸ‘\n" - echo -e "\nArduino IDE compatibility has been reverted πŸ‘\n\n" - exit 0 - -fi diff --git a/docs/INSTALL_ARDUINO.md b/extras/docs/INSTALL_ARDUINO.md similarity index 100% rename from docs/INSTALL_ARDUINO.md rename to extras/docs/INSTALL_ARDUINO.md diff --git a/docs/cpp.md b/extras/docs/cpp.md similarity index 95% rename from docs/cpp.md rename to extras/docs/cpp.md index c6f5a581..a4a2e07a 100644 --- a/docs/cpp.md +++ b/extras/docs/cpp.md @@ -4,17 +4,10 @@ title: "Cpp" # Cpp -::: warning -This package is still under development. This page will get more content as it evolves more. In the meantime you can view its source on [Github](https://github.com/ArkEcosystem/cpp-client/). -::: - [[toc]] ## Platforms * [Arduino](#Arduino) -* [Linux >= 16.04](#OS) -* [macOS >= 10.10](#OS) -* [Windows >= 7](#OS) ## Usage diff --git a/library.json b/library.json index 27f9fddc..27708914 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/ArkEcosystem/Cpp-Client.git" }, - "version": "1.2.0", + "version": "1.2.0-arduino", "authors": [ { "name": "Ark Ecosystem", @@ -29,14 +29,6 @@ "LICENSE", "*.ini", "keywords.txt" - ], - "exclude": [ - "*/*.txt" - ] - }, - "build": { - "flags": [ - "-I src/include/cpp-client" ] } } diff --git a/library.properties b/library.properties index 1c342a6c..2c425f60 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Ark-Cpp-Client -version=1.2.0 +version=1.2.0-arduino author=Ark Ecosystem maintainer=Ark Ecosystem sentence=A simple API client implementation in C++ for the ARK Blockchain. diff --git a/platformio.ini b/platformio.ini deleted file mode 100644 index 6a02319b..00000000 --- a/platformio.ini +++ /dev/null @@ -1,33 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; http://docs.platformio.org/page/projectconf.html - -[platformio] -description = "A simple API client implementation in C++ for the ARK Blockchain." - -[common] -build_flags = -I./src/ -I./src/include/cpp-client -src_filter = +<*> -<.git/> - - -<_3rdParty> - -upload_speed = 921600 - -[env:esp8266] -platform = espressif8266 -board = huzzah -framework = arduino -build_flags = ${common.build_flags} -src_filter = ${common.src_filter} -upload_speed = ${common.upload_speed} - -[env:esp32] -platform = espressif32 -board = esp32dev -framework = arduino -build_flags = ${common.build_flags} -src_filter = ${common.src_filter} -upload_speed = ${common.upload_speed} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 717dc4e6..00000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ - -cmake_minimum_required(VERSION 3.2.2) - -project(Ark-Cpp-Client-lib) - -hunter_add_package(CURL) -find_package(CURL CONFIG REQUIRED) - -set(PLATFORM_SRC - http/os/http.cpp -) - -set(HOST_SRC - host/host.cpp -) - -set(API_PATHS_SRC - api/paths.cpp -) - -set(API_SRC - api/blocks/blocks.cpp - api/delegates/delegates.cpp - api/node/node.cpp - api/peers/peers.cpp - api/transactions/transactions.cpp - api/votes/votes.cpp - api/wallets/wallets.cpp -) - -add_library(Ark-Cpp-Client-lib STATIC - ${PLATFORM_SRC} - ${HOST_SRC} - ${API_PATHS_SRC} - ${API_SRC} -) - -set(cpp_client_build_include_dirs - ${PROJECT_SOURCE_DIR} - ${PROJECT_SOURCE_DIR}/include/cpp-client -) - -include_directories(${cpp_client_build_include_dirs}) - -target_include_directories( ${PROJECT_NAME} - PUBLIC ${cpp_client_build_include_dirs} -) - -target_link_libraries(${PROJECT_NAME} PUBLIC CURL::libcurl) - -if (MSVC) - target_link_libraries(${PROJECT_NAME} PUBLIC crypt32) -endif() diff --git a/src/include/cpp-client/api/abstract.h b/src/api/abstract.h similarity index 100% rename from src/include/cpp-client/api/abstract.h rename to src/api/abstract.h diff --git a/src/include/cpp-client/api/api.h b/src/api/api.h similarity index 100% rename from src/include/cpp-client/api/api.h rename to src/api/api.h diff --git a/src/include/cpp-client/api/base.h b/src/api/base.h similarity index 100% rename from src/include/cpp-client/api/base.h rename to src/api/base.h diff --git a/src/include/cpp-client/api/blocks/blocks.h b/src/api/blocks/blocks.h similarity index 100% rename from src/include/cpp-client/api/blocks/blocks.h rename to src/api/blocks/blocks.h diff --git a/src/include/cpp-client/api/delegates/delegates.h b/src/api/delegates/delegates.h similarity index 100% rename from src/include/cpp-client/api/delegates/delegates.h rename to src/api/delegates/delegates.h diff --git a/src/include/cpp-client/api/node/node.h b/src/api/node/node.h similarity index 100% rename from src/include/cpp-client/api/node/node.h rename to src/api/node/node.h diff --git a/src/include/cpp-client/api/paths.h b/src/api/paths.h similarity index 100% rename from src/include/cpp-client/api/paths.h rename to src/api/paths.h diff --git a/src/include/cpp-client/api/peers/peers.h b/src/api/peers/peers.h similarity index 100% rename from src/include/cpp-client/api/peers/peers.h rename to src/api/peers/peers.h diff --git a/src/include/cpp-client/api/transactions/transactions.h b/src/api/transactions/transactions.h similarity index 100% rename from src/include/cpp-client/api/transactions/transactions.h rename to src/api/transactions/transactions.h diff --git a/src/include/cpp-client/api/votes/votes.h b/src/api/votes/votes.h similarity index 100% rename from src/include/cpp-client/api/votes/votes.h rename to src/api/votes/votes.h diff --git a/src/include/cpp-client/api/wallets/wallets.h b/src/api/wallets/wallets.h similarity index 100% rename from src/include/cpp-client/api/wallets/wallets.h rename to src/api/wallets/wallets.h diff --git a/src/include/cpp-client/arkClient.h b/src/arkClient.h similarity index 100% rename from src/include/cpp-client/arkClient.h rename to src/arkClient.h diff --git a/src/include/cpp-client/connection/connection.h b/src/connection/connection.h similarity index 100% rename from src/include/cpp-client/connection/connection.h rename to src/connection/connection.h diff --git a/src/include/cpp-client/host/host.h b/src/host/host.h similarity index 100% rename from src/include/cpp-client/host/host.h rename to src/host/host.h diff --git a/src/http/iot/http.cpp b/src/http/http.cpp similarity index 100% rename from src/http/iot/http.cpp rename to src/http/http.cpp diff --git a/src/include/cpp-client/http/http.h b/src/http/http.h similarity index 100% rename from src/include/cpp-client/http/http.h rename to src/http/http.h diff --git a/src/http/iot/main.cpp b/src/http/iot/main.cpp deleted file mode 100644 index dcae0526..00000000 --- a/src/http/iot/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "helpers/client_helpers.h" - -#if (defined PLATFORMIO && !defined UNIT_TEST) - -void setup() {} -void loop() { - delay(1000); -} - -#endif diff --git a/src/http/os/http.cpp b/src/http/os/http.cpp deleted file mode 100644 index 3a57ea16..00000000 --- a/src/http/os/http.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "http/http.h" -#include "helpers/client_helpers.h" - -#ifndef USE_IOT - -#include -#include -#include -#include - -namespace Ark { -namespace Client { -namespace { - -class PlatformHTTP : public AbstractHTTP { - public: - PlatformHTTP() = default; - - /**/ - - static size_t WriteCallback(void *contents, size_t size, size_t nmemb, - void *userp) { - // https://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html - ((std::string *)userp)->append((char *)contents, size * nmemb); - return size * nmemb; - } - - /**/ - - std::string get( - const char *const request - ) override { - CURL *curl; - CURLcode res; - std::string readBuffer; - - curl = curl_easy_init(); - if (curl != nullptr) { - curl_easy_setopt(curl, CURLOPT_URL, request); - - 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 */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); - res = curl_easy_perform(curl); - curl_slist_free_all(header_list); - curl_easy_cleanup(curl); - } - return readBuffer; - } - /**/ - - std::string post(const char *const request, const char *body) override { - // https://curl.haxx.se/libcurl/c/http-post.html - CURL *curl; - CURLcode res; - std::string readBuffer; - - curl_global_init(CURL_GLOBAL_ALL); - curl = curl_easy_init(); - if (curl != nullptr) { - curl_easy_setopt(curl, CURLOPT_URL, request); // Set the URL that is about to receive our POST - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body); // Now specify the POST json data ex: "username=baldninja" - - /* set the header content-type */ - curl_slist *header_list = nullptr; - header_list = (body[0] == '{') - ? 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 - - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); - res = curl_easy_perform(curl); // Perform the request, res will get the return code - if (res != CURLE_OK) { // Check for errors - fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); - } - curl_easy_cleanup(curl); /* always cleanup */ - } - curl_global_cleanup(); - return readBuffer; - }; -}; -/**/ -} // namespace - -/** - * HTTP Object Factory - **/ -std::unique_ptr makeHTTP() { - return std::unique_ptr(new PlatformHTTP()); -} -/**/ -} // namespace Client -} // namespace Ark - -#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index eb542e62..00000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,69 +0,0 @@ -cmake_minimum_required(VERSION 3.2.2) - -project(Ark-Cpp-Client-tests) - -hunter_add_package(GTest) - -find_package(GTest CONFIG REQUIRED) -find_package(GMock CONFIG REQUIRED) - -include(CTest) -enable_testing() - -set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../lib") - -include_directories(${PROJECT_SOURCE_DIR}/../src) -include_directories(${PROJECT_SOURCE_DIR}/../test) -include_directories(${PROJECT_SOURCE_DIR}/lib/ArduinoJson) -include_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) - -set(TEST_CONNECTION_SRC - ${PROJECT_SOURCE_DIR}/connection/connection.cpp -) - -set(TEST_HOST_SRC - ${PROJECT_SOURCE_DIR}/host/host.cpp -) - -set(TEST_HTTP_SRC - ${PROJECT_SOURCE_DIR}/http/http.cpp -) - -set(TEST_API_PATHS_SRC - ${PROJECT_SOURCE_DIR}/api/paths.cpp -) - -set(TEST_API_SRC - ${PROJECT_SOURCE_DIR}/api/blocks.cpp - ${PROJECT_SOURCE_DIR}/api/delegates.cpp - ${PROJECT_SOURCE_DIR}/api/node.cpp - ${PROJECT_SOURCE_DIR}/api/peers.cpp - ${PROJECT_SOURCE_DIR}/api/transactions.cpp - ${PROJECT_SOURCE_DIR}/api/votes.cpp - ${PROJECT_SOURCE_DIR}/api/wallets.cpp -) - -find_library(Ark-Cpp-Client-tests PUBLIC) - -add_executable(Ark-Cpp-Client-tests - ${TEST_CONNECTION_SRC} - ${TEST_HOST_SRC} - ${TEST_HTTP_SRC} - ${TEST_API_PATHS_SRC} - ${TEST_API_SRC} -) - -target_link_libraries(Ark-Cpp-Client-tests Ark-Cpp-Client-lib GTest::gtest GMock::gmock GMock::main) - -add_test(NAME test COMMAND Ark-Cpp-Client-tests) - -if (CMAKE_BUILD_TYPE STREQUAL "Coverage") - include("${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake") - - setup_target_for_coverage(${PROJECT_NAME}_coverage Ark-Cpp-Client-tests coverage) - - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") -endif() #CMAKE_BUILD_TYPE STREQUAL "Coverage" - diff --git a/test/api/blocks.cpp b/test/api/blocks.cpp deleted file mode 100644 index 9d77bb77..00000000 --- a/test/api/blocks.cpp +++ /dev/null @@ -1,547 +0,0 @@ - -#include "arkClient.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "mocks/mock_api.h" -#include "utils/json.h" - -using testing::_; -using testing::Return; - -/* test_blocks_block - * https://dexplorer.ark.io:8443/api/v2/blocks/13114381566690093367 - * Expected Response: - { - "data": { - "id": "string", - "version": ing, - "height": uint64_t, - "previous": "string", - "forged": { - "reward": int, - "fee": int, - "total": int - }, - "payload": { - "hash": "string", - "length": int - }, - "generator": { - "username": "string", - "address": "string", - "publicKey": "string" - }, - "signature": "string", - "transactions": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - } - */ -TEST(api, test_block) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string expected_response = R"({ - "data": { - "id": "58328125061111756", - "version": 0, - "height": 3035362, - "previous": "3741191868092856237", - "forged": { - "reward": 200000000, - "fee": 0, - "total": 200000000 - }, - "payload": { - "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "length": 0 - }, - "generator": { - "username": "genesis_6", - "address": "D5e2FzTPqdEHridjzpFZCCVyepAu6Vpmk4", - "publicKey": "023e577a7b3362e0aba70e6911d230e86d729b4cb640f0e0b25637b812a3e38b53" - }, - "signature": "3044022047aeb0c9cfbb5709aba4c177009bfdc7804ef597073fb9ca6cb614d7e3d1af2d02207234119d02ca26600ece045c59266945081b4c8237370576aaad7c61a09fe0ad", - "transactions": 0, - "timestamp": { - "epoch": 32816544, - "unix": 1522917744, - "human": "2018-04-05T08:42:24Z" - } - } - })"; - - EXPECT_CALL(connection.api.blocks, get(_)).Times(1).WillOnce(Return(expected_response)); - - const auto blockResponse = connection.api.blocks.get("58328125061111756"); - - DynamicJsonBuffer jsonBuffer(blockResponse.size()); - JsonObject& root = jsonBuffer.parseObject(blockResponse); - - JsonObject& data = root["data"]; - - const char* id = data["id"]; - ASSERT_STREQ("58328125061111756", id); - - int version = data["version"]; - ASSERT_EQ(0, version); - - int height = data["height"]; - ASSERT_EQ(3035362, height); - - JsonObject& forged = data["forged"]; - - uint64_t reward = forged["reward"]; - ASSERT_TRUE(reward == 200000000); - - uint64_t fee = forged["fee"]; - ASSERT_TRUE(fee == 0); - - uint64_t total = forged["total"]; - ASSERT_TRUE(total == 200000000); - - JsonObject& payload = data["payload"]; - - const char* hash = payload["hash"]; - ASSERT_STREQ("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", hash); - - int length = payload["length"]; - ASSERT_EQ(0, length); - - JsonObject& generator = data["generator"]; - - const char* username = generator["username"]; - ASSERT_STREQ("genesis_6", username); - - const char* address = generator["address"]; - ASSERT_STREQ("D5e2FzTPqdEHridjzpFZCCVyepAu6Vpmk4", address); - - const char* publicKey = generator["publicKey"]; - ASSERT_STREQ("023e577a7b3362e0aba70e6911d230e86d729b4cb640f0e0b25637b812a3e38b53", publicKey); - - const char* signature = data["signature"]; - ASSERT_STREQ( - "3044022047aeb0c9cfbb5709aba4c177009bfdc7804ef597073fb9ca6cb614d7e3d1af2d02207234119d02ca26600ece045c59266945081b" - "4c8237370576aaad7c61a09fe0ad", - signature); - - int transactions = data["transactions"]; - ASSERT_EQ(0, transactions); - - JsonObject& timestamp = data["timestamp"]; - - int epoch = timestamp["epoch"]; - ASSERT_EQ(32816544, epoch); - - int timestampUnix = timestamp["unix"]; - ASSERT_EQ(1522917744, timestampUnix); - - const char* human = timestamp["human"]; - ASSERT_STREQ("2018-04-05T08:42:24Z", human); -} - -/* test_blocks_block_transactions - * https://dexplorer.ark.io:8443/api/v2/blocks/9269622721511437262/transactions - * Espected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": null, - "previous": null, - "self": "\/api\/v2\/blocks\/13114381566690093367\/transactions?page=1&limit=100", - "first": "\/api\/v2\/blocks\/13114381566690093367\/transactions?page=1&limit=100", - "last": "\/api\/v2\/blocks\/13114381566690093367\/transactions?page=1&limit=100" - }, - "data": [ - { - "id": "string", - "blockId": "string", - "type": int, - "amount": uint64_t, - "fee": uint64_t, - "sender": "string", - "recipient": "string", - "signature": "string", - "confirmations": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - ] - } - */ -TEST(api, test_block_transactions) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string expected_response = R"({ - "meta": { - "count": 1, - "pageCount": 1, - "totalCount": 1, - "next": null, - "previous": null, - "self": "/v2/blocks/14126007750611341900/transactions?page=1", - "first": "/v2/blocks/14126007750611341900/transactions?page=1", - "last": "/v2/blocks/14126007750611341900/transactions?page=1" - }, - "data": [ - { - "id": "57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", - "blockId": "14126007750611341900", - "type": 0, - "amount": 1000000000000000, - "fee": 10000000, - "sender": "DGihocTkwDygiFvmg6aG8jThYTic47GzU9", - "recipient": "DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", - "signature": "3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1c34df8a46afe655b021930b03e214e", - "vendorField": "yo", - "confirmations": 3034848, - "timestamp": { - "epoch": 3909196, - "unix": 1494010396, - "human": "2017-05-05T18:53:16Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.blocks, transactions(_)).Times(1).WillOnce(Return(expected_response)); - - const auto blockTransactionsResponse = connection.api.blocks.transactions("14126007750611341900"); - - DynamicJsonBuffer jsonBuffer(blockTransactionsResponse.size()); - JsonObject& root = jsonBuffer.parseObject(blockTransactionsResponse); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_EQ(1, count); - - int pageCount = meta["pageCount"]; - ASSERT_EQ(1, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_EQ(1, totalCount); - - JsonObject& dataZero = root["data"][0]; - - const char* id = dataZero["id"]; - ASSERT_STREQ("57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", id); - - const char* blockId = dataZero["blockId"]; - ASSERT_STREQ("14126007750611341900", blockId); - - int type = dataZero["type"]; - ASSERT_EQ(0, type); - - uint64_t amount = dataZero["amount"]; - ASSERT_TRUE(amount = 1000000000000000); - - uint64_t fee = dataZero["fee"]; - ASSERT_TRUE(fee == 10000000); - - const char* sender = dataZero["sender"]; - ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", sender); - - const char* signature = dataZero["signature"]; - ASSERT_STREQ( - "3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1" - "c34df8a46afe655b021930b03e214e", - signature); - - int confirmations = dataZero["confirmations"]; - ASSERT_EQ(3034848, confirmations); - - JsonObject& timestamp = dataZero["timestamp"]; - - int epoch = timestamp["epoch"]; - ASSERT_EQ(3909196, epoch); - - int timestampUnix = timestamp["unix"]; - ASSERT_EQ(1494010396, timestampUnix); - - const char* human = timestamp["human"]; - ASSERT_STREQ("2017-05-05T18:53:16Z", human); -} - -/* test_blocks_blocks - * https://dexplorer.ark.io:8443/api/v2/blocks - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/blocks?limit=10&page=1", - "first": "/api/v2/blocks?limit=10&page=1", - "last": "/api/v2/blocks?limit=10&page=1" - }, - "data": [ - { - "id": "string", - "version": int, - "height": int, - "previous": "string", - "forged": { - "reward": uint64_t, - "fee": uint64_t, - "total": uint64_t - }, - "payload": { - "hash": "string", - "length": int - }, - "generator": { - "username": "string", - "address": "string", - "publicKey": "string" - }, - "signature": "string", - "transactions": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - ] - } - */ -TEST(api, test_blocks) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string expected_response = R"({ - "meta": { - "count": 2, - "pageCount": 1517682, - "totalCount": 3035363, - "next": "/v2/blocks?limit=2&page=2", - "previous": null, - "self": "/v2/blocks?limit=2&page=1", - "first": "/v2/blocks?limit=2&page=1", - "last": "/v2/blocks?limit=2&page=1517682" - }, - "data": [ - { - "id": "6402736103893238690", - "version": 0, - "height": 3035363, - "previous": "58328125061111756", - "forged": { - "reward": 200000000, - "fee": 0, - "total": 200000000 - }, - "payload": { - "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "length": 0 - }, - "generator": { - "username": "shawmishrak", - "address": "D7P41dV7s259L3P7BVPNyqExqNDC7vdfx9", - "publicKey": "030fa94238eb63db0247a9bd6a3fd810f690b449ee9ce4eb654b94b22875a9a612" - }, - "signature": "304402204d0dbeb4e71a99a0f128a3480350014f0a9f250818dae908edd15bce99f49be00220257bf240c5d8578e9ffe144e7dbf0c2259d34e6571e6a83402edc01daec6228e", - "transactions": 0, - "timestamp": { - "epoch": 32816552, - "unix": 1522917752, - "human": "2018-04-05T08:42:32Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.blocks, all(5, 1)).Times(1).WillOnce(Return(expected_response)); - - const auto blocksResponse = connection.api.blocks.all(5, 1); - - DynamicJsonBuffer jsonBuffer(blocksResponse.size()); - JsonObject& root = jsonBuffer.parseObject(blocksResponse); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - int version = dataZero["version"]; - ASSERT_EQ(0, version); -} - -/* test_blocks_search - * - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": "1", - "next": "string", - "previous": "string", - "self": "/api/v2/blocks/search?limit=5&page=1", - "first": "/api/v2/blocks/search?limit=5&page=1", - "last": "/api/v2/blocks/search?limit=5&page=1" - }, - "data": [ - { - "id": "8337447655053578871", - "version": 0, - "height": 118783, - "previous": "6440284271011893973", - "forged": { - "reward": 200000000, - "fee": 0, - "total": 200000000 - }, - "payload": { - "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "length": 0 - }, - "generator": { - "username": "genesis_46", - "address": "DGKgCQ1srb8HZyr47RqQqMvGZ4cDyr4eMo", - "publicKey": "029a20963b506afabb2bd805830a46cef8d59218cd88c0dca9d2a0158045b1c3e0" - }, - "signature": - "304402201ec15a9bec30bad58c7d9f5ccf1447bccb36b39901d0b91f09217bb4c3efcf6a02207232bdfe9ab6e4d80eb2668d642b431ca704cf4ba8ce9958cfd202070e31f2c8", - "transactions": 0, - "timestamp": { - "epoch": 45988754, - "unix": 1536089954, - "human": "2018-09-04T19:39:14Z" - } - } - ] - } - */ -TEST(api, test_blocks_search) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string expected_response = R"({ - "meta": { - "count": 1, - "pageCount": 1, - "totalCount": 1, - "next": null, - "previous": null, - "self": "/v2/blocks/14126007750611341900/transactions/search?page=1", - "first": "/v2/blocks/14126007750611341900/transactions/search?page=1", - "last": "/v2/blocks/14126007750611341900/transactions/search?page=1" - }, - "data": [ - { - "id": "57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", - "blockId": "14126007750611341900", - "type": 0, - "amount": 1000000000000000, - "fee": 10000000, - "sender": "DGihocTkwDygiFvmg6aG8jThYTic47GzU9", - "recipient": "DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", - "signature": "3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1c34df8a46afe655b021930b03e214e", - "vendorField": "yo", - "confirmations": 3034848, - "timestamp": { - "epoch": 3909196, - "unix": 1494010396, - "human": "2017-05-05T18:53:16Z" - } - } - ] - })"; - - const std::map body = { - {"id", "8337447655053578871"}, {"previousBlock", "6440284271011893973"}, {"version", "0"}}; - - EXPECT_CALL(connection.api.blocks, search(_, _, _)).Times(1).WillOnce(Return(expected_response)); - - const auto walletsSearch = connection.api.blocks.search(body, 5, 1); - - DynamicJsonBuffer jsonBuffer(walletsSearch.size()); - JsonObject& root = jsonBuffer.parseObject(walletsSearch); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - const char* id = dataZero["id"]; - ASSERT_STREQ("57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", id); - - const char* blockId = dataZero["blockId"]; - ASSERT_STREQ("14126007750611341900", blockId); - - int type = dataZero["type"]; - ASSERT_EQ(0, type); - - uint64_t amount = dataZero["amount"]; - ASSERT_TRUE(1000000000000000ull == amount); - - uint64_t fee = dataZero["fee"]; - ASSERT_TRUE(10000000ull == fee); - - const char* sender = dataZero["sender"]; - ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", sender); - - const char* recipient = dataZero["recipient"]; - ASSERT_STREQ("DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", recipient); - - const char* signature = dataZero["signature"]; - ASSERT_STREQ( - "3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1" - "c34df8a46afe655b021930b03e214e", - signature); - - const char* vendorField = dataZero["vendorField"]; - ASSERT_STREQ("yo", vendorField); - - int confirmations = dataZero["confirmations"]; - ASSERT_EQ(3034848, confirmations); - - JsonObject& timestamp = dataZero["timestamp"]; - - uint64_t epoch = timestamp["epoch"]; - ASSERT_TRUE(3909196ull == epoch); - - uint64_t unix_timestamp = timestamp["unix"]; - ASSERT_TRUE(1494010396ull == unix_timestamp); - - const char* human = timestamp["human"]; - ASSERT_STREQ("2017-05-05T18:53:16Z", human); -} diff --git a/test/api/delegates.cpp b/test/api/delegates.cpp deleted file mode 100644 index d7207d53..00000000 --- a/test/api/delegates.cpp +++ /dev/null @@ -1,467 +0,0 @@ - -#include "arkClient.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "mocks/mock_api.h" -#include "utils/json.h" - -using testing::_; -using testing::Return; - -/* test_delegates_delegate - * https://dexplorer.ark.io:8443/api/v2/delegates/boldninja - * Expected Response: - { - "data": { - "username": "string", - "address": "string", - "publicKey": "string", - "votes": uint64_t, - "rank": ing, - "blocks": { - "produced": int, - "missed": int, - "last": { - "id": "string", - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - }, - "production": { - "approval": double, - "productivity": double - } - } - } - */ -TEST(api, test_delegate) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string expected_response = R"({ - "data": { - "username": "boldninja", - "address": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "publicKey": "022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", - "votes": 0, - "rank": 29, - "blocks": { - "produced": 0, - "missed": 0, - "last": { - "id": "10652480998435361357", - "timestamp": { - "epoch": 32816112, - "unix": 1522917312, - "human": "2018-04-05T08:35:12Z" - } - } - }, - "production": { - "approval": "0.10", - "productivity": "0.00" - } - } - })"; - - EXPECT_CALL(connection.api.delegates, get(_)).Times(1).WillOnce(Return(expected_response)); - - const auto delegateResponse = connection.api.delegates.get("boldninja"); - - DynamicJsonBuffer jsonBuffer(delegateResponse.size()); - JsonObject& root = jsonBuffer.parseObject(delegateResponse); - - JsonObject& data = root["data"]; - - const char* username = data["username"]; - ASSERT_STREQ("boldninja", username); - - const char* address = data["address"]; - ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", address); - - const char* publicKey = data["publicKey"]; - ASSERT_STREQ("022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", publicKey); - - uint64_t votes = data["votes"]; - ASSERT_EQ(0, votes); - - int rank = data["rank"]; - ASSERT_EQ(29, rank); - - JsonObject& blocks = data["blocks"]; - - int produced = blocks["produced"]; - ASSERT_EQ(0, produced); - - int missed = blocks["missed"]; - ASSERT_EQ(0, missed); - - JsonObject& last = blocks["last"]; - - const char* last_id = last["id"]; - ASSERT_STREQ("10652480998435361357", last_id); - - JsonObject& timestamp = last["timestamp"]; - - uint64_t epoch = timestamp["epoch"]; - ASSERT_TRUE(32816112ull == epoch); - - uint64_t unix_timestamp = timestamp["unix"]; - ASSERT_TRUE(1522917312ull == unix_timestamp); - - const char* human = timestamp["human"]; - ASSERT_STREQ("2018-04-05T08:35:12Z", human); - - JsonObject& production = data["production"]; - - double approval = production["approval"]; - ASSERT_EQ(0.10, approval); - - double productivity = production["productivity"]; - ASSERT_EQ(0.0, productivity); -} - -/* test_delegates_delegate_blocks - * https://dexplorer.ark.io:8443/api/v2/delegates/boldninja/blocks?limit=3&page=1 - * - * currently returning: - * { - * "statusCode": 500, - * "error": "Internal Server Error", - * "message": "An internal server error occurred" - * } - * - * - - * - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/delegates/boldninja/blocks?limit=3&page=1", - "first": "/api/v2/delegates/boldninja/blocks?limit=3&page=1", - "last": "/api/v2/delegates/boldninja/blocks?limit=3&page=1" - }, - "data": [ - { - "id": "string", - "version": int, - "height": uint64_t, - "previous": "string", - "forged": { - "reward": uint64_t, - "fee": uint64_t, - "total": uint64_t - }, - "payload": { - "hash": "string", - "length": int - }, - "generator": { - "username": "string", - "address": "string", - "publicKey": "string" - }, - "signature": "string", - "transactions": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - ] - } - */ -TEST(api, test_delegate_blocks) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - const std::string expected_response = R"({ - "meta": { - "count": 2, - "pageCount": 29919, - "totalCount": 59838, - "next": "/v2/delegates/boldninja/blocks?page=2", - "previous": null, - "self": "/v2/delegates/boldninja/blocks?page=1", - "first": "/v2/delegates/boldninja/blocks?page=1", - "last": "/v2/delegates/boldninja/blocks?page=29919" - }, - "data": [ - { - "id": "10652480998435361357", - "version": 0, - "height": 3035318, - "previous": "12548322724277171379", - "forged": { - "reward": 200000000, - "fee": 0, - "total": 200000000 - }, - "payload": { - "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "length": 0 - }, - "generator": { - "username": "boldninja", - "address": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "publicKey": "022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d" - }, - "signature": "3044022034e754a3ff70adba6323517e1297c6a9f30176df2ac589661e9206fe60a203120220182c38da201fee20e803bb7725fe9618d6707547e6d7b757d4108f546934fe1c", - "transactions": 0, - "timestamp": { - "epoch": 32816112, - "unix": 1522917312, - "human": "2018-04-05T08:35:12Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.delegates, blocks(_, _, _)).Times(1).WillOnce(Return(expected_response)); - - const auto delegateBlocksResponse = connection.api.delegates.blocks("boldninja", 3, 1); - - DynamicJsonBuffer jsonBuffer(delegateBlocksResponse.size()); - JsonObject& root = jsonBuffer.parseObject(delegateBlocksResponse); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_EQ(2, count); - - int pageCount = meta["pageCount"]; - ASSERT_EQ(29919, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_EQ(59838, totalCount); - - const char* id = root["data"][0]["id"]; - ASSERT_STREQ("10652480998435361357", id); - - int version = root["data"][0]["version"]; - ASSERT_EQ(0, version); - - uint64_t height = root["data"][0]["height"]; - ASSERT_TRUE(3035318ull == height); - - const char* previous = root["data"][0]["previous"]; - ASSERT_STREQ("12548322724277171379", previous); - - const char* username = root["data"][0]["generator"]["username"]; - ASSERT_STREQ("boldninja", username); - - const char* address = root["data"][0]["generator"]["address"]; - ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", address); - - const char* publicKey = root["data"][0]["generator"]["publicKey"]; - ASSERT_STREQ("022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", publicKey); -} - -/* test_delegates_delegate_voters - * https://dexplorer.ark.io:8443/api/v2/delegates/boldninja/voters?limit=5&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/delegates/boldninja/voters?limit=5&page=1", - "first": "/api/v2/delegates/boldninja/voters?limit=5&page=1", - "last": "/api/v2/delegates/boldninja/voters?limit=5&page=1" - }, - "data": [ - { - "address": "string", - "publicKey": "string", - "secondPublicKey": "string", - "balance": uint64_t, - "isDelegate": bool - } - ] - } - */ -TEST(api, test_delegate_voters) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string expected_response = R"({ - "meta": { - "count": 2, - "pageCount": 10, - "totalCount": 19, - "next": "/v2/delegates/boldninja/voters?page=2", - "previous": null, - "self": "/v2/delegates/boldninja/voters?page=1", - "first": "/v2/delegates/boldninja/voters?page=1", - "last": "/v2/delegates/boldninja/voters?page=10" - }, - "data": [ - { - "address": "D5mbS6mpP5UheuciNscpDLgC127kYjRtkK", - "publicKey": "03f7e0b1ab14985990416f72ed0b206c20b9efa35156e4528c8ff749fa0eea5d5a", - "balance": 400000000, - "isDelegate": false - } - ] - })"; - - EXPECT_CALL(connection.api.delegates, voters(_, _, _)).Times(1).WillOnce(Return(expected_response)); - - const auto delegateVotersResponse = connection.api.delegates.voters("boldninja", 5, 1); - - DynamicJsonBuffer jsonBuffer(delegateVotersResponse.size()); - JsonObject& root = jsonBuffer.parseObject(delegateVotersResponse); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - const char* address = dataZero["address"]; - ASSERT_STREQ("D5mbS6mpP5UheuciNscpDLgC127kYjRtkK", address); - - const char* publicKey = dataZero["publicKey"]; - ASSERT_STREQ("03f7e0b1ab14985990416f72ed0b206c20b9efa35156e4528c8ff749fa0eea5d5a", publicKey); - - bool isDelegate = dataZero["isDelegate"]; - ASSERT_FALSE(isDelegate); -} - -/* test_delegates_delegates - * https://dexplorer.ark.io:8443/api/v2/delegates?limit=5&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "/api/v2/delegates?limit=5&page=2", - "previous": null, - "self": "/api/v2/delegates?limit=5&page=1", - "first": "/api/v2/delegates?limit=5&page=1", - "last": "/api/v2/delegates?limit=5&page=23" - }, - "data": [ - { - "username": "string", - "address": "string", - "publicKey": "string", - "votes": uint64_t, - "rank": int, - "blocks": { - "produced": int, - "missed": int, - "last": { - "id": "string", - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - }, - "production": { - "approval": double, - "productivity": double - } - } - ] - } - */ -TEST(api, test_delegates) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string expected_response = R"({ - "meta": { - "count": 2, - "pageCount": 99, - "totalCount": 197, - "next": "/v2/delegates?page=2", - "previous": null, - "self": "/v2/delegates?page=1", - "first": "/v2/delegates?page=1", - "last": "/v2/delegates?page=99" - }, - "data": [ - { - "username": "dark_jmc", - "address": "D5PXQVeJmchVrZFHL7cALZK8mWWzjCaVfz", - "publicKey": "02a9a0ac34a94f9d27fd9b4b56eb3c565a9a3f61e660f269775fb456f7f3301586", - "votes": 0, - "rank": 1, - "blocks": { - "produced": 0, - "missed": 0, - "last": { - "id": "12383884455448354193", - "timestamp": { - "epoch": 31784600, - "unix": 1521885800, - "human": "2018-03-24T10:03:20Z" - } - } - }, - "production": { - "approval": "0.08", - "productivity": "0.00" - } - } - ] - })"; - - EXPECT_CALL(connection.api.delegates, all(5, 1)).Times(1).WillOnce(Return(expected_response)); - - const auto delegates = connection.api.delegates.all(5, 1); - - DynamicJsonBuffer jsonBuffer(delegates.size()); - JsonObject& root = jsonBuffer.parseObject(delegates); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - const char* username = dataZero["username"]; - ASSERT_STREQ("dark_jmc", username); - - const char* address = dataZero["address"]; - ASSERT_STREQ("D5PXQVeJmchVrZFHL7cALZK8mWWzjCaVfz", address); - - const char* publicKey = dataZero["publicKey"]; - ASSERT_STREQ("02a9a0ac34a94f9d27fd9b4b56eb3c565a9a3f61e660f269775fb456f7f3301586", publicKey); - - uint64_t votes = dataZero["votes"]; - ASSERT_TRUE(0ull == votes); -} diff --git a/test/api/node.cpp b/test/api/node.cpp deleted file mode 100644 index 360ff594..00000000 --- a/test/api/node.cpp +++ /dev/null @@ -1,281 +0,0 @@ - -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include "mocks/mock_api.h" - -#include "arkClient.h" -#include "utils/json.h" - -using testing::Return; - -/* test_node_configuration - * https://dexplorer.ark.io:8443/api/v2/node/configuration - * Expected Response: - { - "data": { - "nethash": "string", - "token": "string", - "symbol": "string", - "explorer": "string", - "version": int, - "ports": { - "@arkecosystem\/core-p2p": "int", - "@arkecosystem\/core-api": "int" - }, - "constants": { - "height": uint64_t, - "reward": uint64_t, - "activeDelegates": int, - "blocktime": 8, - "block": { - "version": int, - "maxTransactions": int, - "maxPayload": int - }, - "epoch": "string", - "fees": { - "dynamic": bool, - "transfer": uint64_t, - "secondSignature": uint64_t, - "delegateRegistration": uint64_t, - "vote": uint64_t, - "multiSignature": uint64_t, - "ipfs": int, - "timelockTransfer": int, - "multiPayment": int, - "delegateResignation": int - }, - "dynamicOffsets": { - "transfer": int, - "secondSignature": int, - "delegateRegistration": int, - "vote": int, - "multiSignature": int, - "ipfs": int, - "timelockTransfer": int, - "multiPayment": int, - "delegateResignation": int - } - }, - "feeStatistics": [ - { - "type": 0, - "fees": { - "minFee": uint64_t, - "maxFee": uint64_t, - "avgFee": uint64_t - } - }, - { - "type": 3, - "fees": { - "minFee": uint64_t, - "maxFee": uint64_t, - "avgFee": uint64_t - } - }, - { - "type": 1, - "fees": { - "minFee": uint64_t, - "maxFee": uint64_t, - "avgFee": uint64_t - } - }, - { - "type": 2, - "fees": { - "minFee": uint64_t, - "maxFee": uint64_t, - "avgFee": uint64_t - } - }, - { - "type": 4, - "fees": { - "minFee": uint64_t, - "maxFee": uint64_t, - "avgFee": uint64_t - } - } - ] - } - } -*/ -TEST(api, test_node_configuration) { // NOLINT - Ark::Client::Connection connection("167.114.29.54", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "nethash": "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23", - "token" : "DARK", - "symbol" : "DΡ¦", - "explorer" : "https://dexplorer.ark.io", - "version" : 30, - "ports" : { - "@arkecosystem/core-p2p": 4000, - "@arkecosystem/core-api" : 4003, - "@arkecosystem/core-graphql" : 4005, - "@arkecosystem/core-json-rpc" : 8080 - }, - "feeStatistics": [ - { - "type": 0, - "fees" : { - "minFee": 268421, - "maxFee" : 597781, - "avgFee" : 404591 - } - } - ], - "constants": { - "height": 75600, - "reward" : 200000000, - "activeDelegates" : 51, - "blocktime" : 8, - "block" : { - "version": 0, - "maxTransactions" : 50, - "maxPayload" : 2097152 - }, - "epoch" : "2017-03-21T13:00:00.000Z", - "fees" : { - "send": 10000000, - "vote" : 100000000, - "secondsignature" : 500000000, - "delegate" : 2500000000, - "multisignature" : 500000000 - } - } - } - })"; - - EXPECT_CALL(connection.api.node, configuration()).Times(1).WillOnce(Return(response)); - - const auto nodeConfiguration = connection.api.node.configuration(); - - DynamicJsonBuffer jsonBuffer(nodeConfiguration.size()); - JsonObject& root = jsonBuffer.parseObject(nodeConfiguration); - - JsonObject& data = root["data"]; - - const char* nethash = data["nethash"]; - ASSERT_STREQ("578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23", nethash); - - const char* token = data["token"]; - ASSERT_STREQ("DARK", token); - - const char* symbol = data["symbol"]; - ASSERT_STREQ(u8"DΡ¦", symbol); - - const char* explorer = data["explorer"]; - ASSERT_STREQ("https://dexplorer.ark.io", explorer); - - int version = data["version"]; - ASSERT_EQ(30, version); - - JsonObject& ports = data["ports"]; - - int core_p2p = ports["@arkecosystem/core-p2p"]; - ASSERT_EQ(4000, core_p2p); - - int core_api = ports["@arkecosystem/core-api"]; - ASSERT_EQ(4003, core_api); -} - -/* test_node_status - * https://dexplorer.ark.io:8443/api/v2/node/status - * Expected Response: - { - "data": { - "synced": bool, - "now": int, - "blocksCount": int - } - } - */ -TEST(api, test_node_status) { // NOLINT - Ark::Client::Connection connection("167.114.29.54", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "synced": false, - "now": 3034451, - "blocksCount": 36 - } - })"; - - EXPECT_CALL(connection.api.node, status()).Times(1).WillOnce(Return(response)); - - const auto nodeStatus = connection.api.node.status(); - - DynamicJsonBuffer jsonBuffer(nodeStatus.size()); - JsonObject& root = jsonBuffer.parseObject(nodeStatus); - - JsonObject& data = root["data"]; - - bool synced = data["synced"]; - ASSERT_FALSE(synced); - - int now = data["now"]; - ASSERT_EQ(3034451, now); - - int blocksCount = data["blocksCount"]; - ASSERT_EQ(36, blocksCount); -} - -/* test_node_status - * 167.114.29.54:4003/api/v2/node/syncing - * Expected Response: - { - "data": { - "syncing": bool, - "blocks": int, - "height": uint64_t, - "id": "string" - } - } - */ -TEST(api, test_node_syncing) { // NOLINT - Ark::Client::Connection connection("167.114.29.54", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "syncing": true, - "blocks": 36, - "height": 3034451, - "id": "5444078994968869529" - } - })"; - - EXPECT_CALL(connection.api.node, syncing()).Times(1).WillOnce(Return(response)); - - const auto nodeSyncing = connection.api.node.syncing(); - - DynamicJsonBuffer jsonBuffer(nodeSyncing.size()); - JsonObject& root = jsonBuffer.parseObject(nodeSyncing); - - JsonObject& data = root["data"]; - - bool syncing = data["syncing"]; - ASSERT_TRUE(syncing); - - int blocks = data["blocks"]; - ASSERT_EQ(36, blocks); - - uint64_t height = data["height"]; - ASSERT_TRUE(3034451ull == height); - - const char* id = data["id"]; - ASSERT_STREQ("5444078994968869529", id); -} diff --git a/test/api/paths.cpp b/test/api/paths.cpp deleted file mode 100644 index 66eb73ce..00000000 --- a/test/api/paths.cpp +++ /dev/null @@ -1,174 +0,0 @@ - -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include "arkClient.h" - -namespace { -Ark::Client::Host testHost("0.0.0.0", 4003); -} - -TEST(paths, test_blocks) { // NOLINT - const auto base = Ark::Client::API::Paths::Blocks::base(); - ASSERT_STREQ("/api/v2/blocks", base); - - const auto get = Ark::Client::API::Paths::Blocks::get(testHost, "58328125061111756"); - ASSERT_STREQ("0.0.0.0:4003/api/v2/blocks/58328125061111756", get.c_str()); - - const auto all = Ark::Client::API::Paths::Blocks::all(testHost, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/blocks?limit=5&page=1", all.c_str()); - - const auto transactions = Ark::Client::API::Paths::Blocks::transactions(testHost, "58328125061111756"); - ASSERT_STREQ("0.0.0.0:4003/api/v2/blocks/58328125061111756/transactions", transactions.c_str()); - - const std::map searchBody = { - {"id", "8337447655053578871"}, {"previousBlock", "6440284271011893973"}, {"version", "0"}}; - const auto search = Ark::Client::API::Paths::Blocks::search(testHost, searchBody, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/blocks/search?limit=5&page=1", search.first.c_str()); - ASSERT_STREQ("id=8337447655053578871&previousBlock=6440284271011893973&version=0", search.second.c_str()); -} - -/***/ - -TEST(paths, test_delegates) { // NOLINT - const auto base = Ark::Client::API::Paths::Delegates::base(); - ASSERT_STREQ("/api/v2/delegates", base); - - const auto get = Ark::Client::API::Paths::Delegates::get(testHost, "boldninja"); - ASSERT_STREQ("0.0.0.0:4003/api/v2/delegates/boldninja", get.c_str()); - - const auto all = Ark::Client::API::Paths::Delegates::all(testHost, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/delegates?limit=5&page=1", all.c_str()); - - const auto blocks = Ark::Client::API::Paths::Delegates::blocks(testHost, "boldninja", 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/delegates/boldninja/blocks?limit=5&page=1", blocks.c_str()); - - const auto voters = Ark::Client::API::Paths::Delegates::voters(testHost, "boldninja", 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/delegates/boldninja/voters?limit=5&page=1", voters.c_str()); -} - -/***/ - -TEST(paths, test_node) { // NOLINT - const auto base = Ark::Client::API::Paths::Node::base(); - ASSERT_STREQ("/api/v2/node", base); - - const auto configuration = Ark::Client::API::Paths::Node::configuration(testHost); - ASSERT_STREQ("0.0.0.0:4003/api/v2/node/configuration", configuration.c_str()); - - const auto status = Ark::Client::API::Paths::Node::status(testHost); - ASSERT_STREQ("0.0.0.0:4003/api/v2/node/status", status.c_str()); - - const auto syncing = Ark::Client::API::Paths::Node::syncing(testHost); - ASSERT_STREQ("0.0.0.0:4003/api/v2/node/syncing", syncing.c_str()); -} - -/***/ - -TEST(paths, test_peers) { // NOLINT - const auto base = Ark::Client::API::Paths::Peers::base(); - ASSERT_STREQ("/api/v2/peers", base); - - const auto get = Ark::Client::API::Paths::Peers::get(testHost, "0.0.0.0"); - ASSERT_STREQ("0.0.0.0:4003/api/v2/peers/0.0.0.0", get.c_str()); - - const auto all = Ark::Client::API::Paths::Peers::all(testHost, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/peers?limit=5&page=1", all.c_str()); -} - -/***/ - -TEST(paths, test_transactions) { // NOLINT - const auto base = Ark::Client::API::Paths::Transactions::base(); - ASSERT_STREQ("/api/v2/transactions", base); - - const auto getUnconfirmed = Ark::Client::API::Paths::Transactions::getUnconfirmed( - testHost, "4bbc5433e5a4e439369f1f57825e92d07cf9cb8e07aada69c122a2125e4b9d48"); - ASSERT_STREQ( - "0.0.0.0:4003/api/v2/transactions/unconfirmed/4bbc5433e5a4e439369f1f57825e92d07cf9cb8e07aada69c122a2125e4b9d48", - getUnconfirmed.c_str()); - - const auto all = Ark::Client::API::Paths::Transactions::all(testHost, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/transactions?limit=5&page=1", all.c_str()); - - const auto get = Ark::Client::API::Paths::Transactions::get( - testHost, "4bbc5433e5a4e439369f1f57825e92d07cf9cb8e07aada69c122a2125e4b9d48"); - ASSERT_STREQ("0.0.0.0:4003/api/v2/transactions/4bbc5433e5a4e439369f1f57825e92d07cf9cb8e07aada69c122a2125e4b9d48", - get.c_str()); - - const auto allUnconfirmed = Ark::Client::API::Paths::Transactions::allUnconfirmed(testHost, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/transactions/unconfirmed?limit=5&page=1", allUnconfirmed.c_str()); - - const auto types = Ark::Client::API::Paths::Transactions::types(testHost); - ASSERT_STREQ("0.0.0.0:4003/api/v2/transactions/types", types.c_str()); - - const std::map searchBody = {{"id", "dummy"}}; - const auto search = Ark::Client::API::Paths::Transactions::search(testHost, searchBody, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/transactions/search?limit=5&page=1", search.first.c_str()); - ASSERT_STREQ("id=dummy", search.second.c_str()); - - std::string jsonTransaction = "{\"id\":\"5ab523d18ac948da82700a71fc0b3c9e764fc0cba91927cb1aa63354564ad23f\",\"signature\":\"3045022100a6da60f9b3e20c80f491d168b8c51a85e0ec56a2448f9e10fc4bcc05a2bf79b8022078fa21b7d46e14c62d38f07e408fdb52f7b6a671894c6d0762913ca4a55e7a99\",\"timestamp\":4076176416,\"type\":0,\"fee\":10000000,\"senderPublicKey\":\"02f21aca9b6d224ea86a1689f57910534af21c3cc9f80602fed252c13e275f0699\",\"amount\":1,\"recipientId\":\"DHQ4Fjsyiop3qBR4otAjAu6cBHkgRELqGA\",\"vendorField\":\"7ad0eeb302ee7d9b4e58cf52daa9ece7922ad92d14f0407e3881597bf3c9c1c6\"}"; - const auto send = Ark::Client::API::Paths::Transactions::send(testHost, jsonTransaction); - ASSERT_STREQ("0.0.0.0:4003/api/v2/transactions", send.first.c_str()); - ASSERT_STREQ(jsonTransaction.c_str(), send.second.c_str()); -} - -/***/ - -TEST(paths, test_votes) { // NOLINT - const auto base = Ark::Client::API::Paths::Votes::base(); - ASSERT_STREQ("/api/v2/votes", base); - - const auto get = - Ark::Client::API::Paths::Votes::get(testHost, "d202acbfa947acac53ada2ac8a0eb662c9f75421ede3b10a42759352968b4ed2"); - ASSERT_STREQ("0.0.0.0:4003/api/v2/votes/d202acbfa947acac53ada2ac8a0eb662c9f75421ede3b10a42759352968b4ed2", - get.c_str()); - - const auto all = Ark::Client::API::Paths::Votes::all(testHost, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/votes?limit=5&page=1", all.c_str()); -} - -/***/ - -TEST(paths, test_wallets) { // NOLINT - const auto base = Ark::Client::API::Paths::Wallets::base(); - ASSERT_STREQ("/api/v2/wallets", base); - - const auto get = Ark::Client::API::Paths::Wallets::get(testHost, "DKrACQw7ytoU2gjppy3qKeE2dQhZjfXYqu"); - ASSERT_STREQ("0.0.0.0:4003/api/v2/wallets/DKrACQw7ytoU2gjppy3qKeE2dQhZjfXYqu", get.c_str()); - - const auto all = Ark::Client::API::Paths::Wallets::all(testHost, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/wallets?limit=5&page=1", all.c_str()); - - const auto top = Ark::Client::API::Paths::Wallets::top(testHost, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/wallets/top?limit=5&page=1", top.c_str()); - - const auto transactions = - Ark::Client::API::Paths::Wallets::transactions(testHost, "DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk", 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions?limit=5&page=1", - transactions.c_str()); - - const auto sent = - Ark::Client::API::Paths::Wallets::transactionsSent(testHost, "DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk", 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions/sent?limit=5&page=1", - sent.c_str()); - - const auto received = - Ark::Client::API::Paths::Wallets::transactionsReceived(testHost, "DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk", 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions/received?limit=5&page=1", - received.c_str()); - - const auto votes = Ark::Client::API::Paths::Wallets::votes(testHost, "DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk", 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/votes?limit=5&page=1", votes.c_str()); - - const std::map searchBody = { - {"username", "baldninja"}, - {"address", "DFJ5Z51F1euNNdRUQJKQVdG4h495LZkc6T"}, - {"publicKey", "03d3c6889608074b44155ad2e6577c3368e27e6e129c457418eb3e5ed029544e8d"}}; - const auto search = Ark::Client::API::Paths::Wallets::search(testHost, searchBody, 5, 1); - ASSERT_STREQ("0.0.0.0:4003/api/v2/wallets/search?limit=5&page=1", search.first.c_str()); - ASSERT_STREQ( - "address=DFJ5Z51F1euNNdRUQJKQVdG4h495LZkc6T&publicKey=" - "03d3c6889608074b44155ad2e6577c3368e27e6e129c457418eb3e5ed029544e8d&username=baldninja", - search.second.c_str()); -} diff --git a/test/api/peers.cpp b/test/api/peers.cpp deleted file mode 100644 index b6a4439b..00000000 --- a/test/api/peers.cpp +++ /dev/null @@ -1,164 +0,0 @@ - -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include "mocks/mock_api.h" - -#include "arkClient.h" -#include "utils/json.h" - -using testing::_; -using testing::Return; - -/* test_peers_peer - * https://dexplorer.ark.io:8443/api/v2/peers/167.114.29.54 - * Expected Response: - { - "data": { - "ip": "string", - "port": int, - "version": "string", - "status": "string", - "os": "string", - "latency": int - } - } - */ -TEST(api, test_peer) { // NOLINT - Ark::Client::Connection 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", - "port": 4002, - "version": "1.1.1", - "status": 200, - "os": "linux", - "latency": 355 - } - })"; - - EXPECT_CALL(connection.api.peers, get(_)).Times(1).WillOnce(Return(response)); - - const auto peer = connection.api.peers.get("167.114.29.49"); - - DynamicJsonBuffer jsonBuffer(peer.size()); - JsonObject& root = jsonBuffer.parseObject(peer); - - JsonObject& data = root["data"]; - - const char* ip = data["ip"]; - ASSERT_STREQ("167.114.29.55", ip); - - int port = data["port"]; - ASSERT_EQ(4002, port); - - const char* version = data["version"]; - ASSERT_STREQ("1.1.1", version); - - int status = data["status"]; - ASSERT_EQ(200, status); - - const char* os = data["os"]; - ASSERT_STREQ("linux", os); - - int latency = data["latency"]; - ASSERT_EQ(355, latency); -} - -/* test_peers_peers - * https://dexplorer.ark.io:8443/api/v2/peers?limit=5&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/peers?limit=5&page=1", - "first": "/api/v2/peers?limit=5&page=1", - "last": "/api/v2/peers?limit=5&page=1" - }, - "data": [ - { - "ip": "string", - "port": "string", - "version": "string", - "status": "string", - "os": "string", - "latency": int - } - ] - } - */ -TEST(api, test_peers) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 1, - "totalCount": 2, - "next": null, - "previous": null, - "self": "/v2/peers?page=1", - "first": "/v2/peers?page=1", - "last": "/v2/peers?page=1" - }, - "data": [ - { - "ip": "167.114.29.53", - "port": 4002, - "version": "1.1.1", - "status": 200, - "os": "linux", - "latency": 1390 - } - ] - })"; - - EXPECT_CALL(connection.api.peers, all(_, _)).Times(1).WillOnce(Return(response)); - - const auto peers = connection.api.peers.all(5, 1); - - DynamicJsonBuffer jsonBuffer(peers.size()); - JsonObject& root = jsonBuffer.parseObject(peers); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - const char* ip = dataZero["ip"]; - ASSERT_STREQ("167.114.29.53", ip); - - int port = dataZero["port"]; - ASSERT_EQ(4002, port); - - const char* version = dataZero["version"]; - ASSERT_STREQ("1.1.1", version); - - int status = dataZero["status"]; - ASSERT_EQ(200, status); - - const char* os = dataZero["os"]; - ASSERT_STREQ("linux", os); - - int latency = dataZero["latency"]; - ASSERT_EQ(1390, latency); -} diff --git a/test/api/transactions.cpp b/test/api/transactions.cpp deleted file mode 100644 index 8a1dc78b..00000000 --- a/test/api/transactions.cpp +++ /dev/null @@ -1,641 +0,0 @@ -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include "mocks/mock_api.h" - -#include "arkClient.h" -#include "utils/json.h" - -using testing::_; -using testing::Return; - -/* test_two_transactions_transaction - * https://dexplorer.ark.io:8443/api/v2/transactions/b324cea5c5a6c15e6ced3ec9c3135a8022eeadb8169f7ba66c80ebc82b0ac850 - * Expected Response: - { - "data": { - "id": "string", - "blockId": "string", - "type": int, - "amount": uint64_t, - "fee": uint64_t, - "sender": "string", - "recipient": "string", - "signature": "string", - "asset": { - "votes": [ - "string" - ] - }, - "confirmations": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - } - */ -TEST(api, test_transaction) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "id": "5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa", - "blockId": "4271682877946294396", - "type": 0, - "amount": 32106400000, - "fee": 10000000, - "sender": "DDiTHZ4RETZhGxcyAi1VruCXZKxBFqXMeh", - "recipient": "DQnQNoJuNCvpjYhxL7fsnGepHBqrumgsyP", - "signature": "3044022047c39f6f45a46a87f91ca867f9551dbebf0035adcfcbdc1370222c7a1517fc0002206fb5ecc10460e0352a8b626a508e2fcc76e39e490b0a2581dd772ebc8079696e", - "confirmations": 1928, - "timestamp": { - "epoch": 32794053, - "unix": 1522895253, - "human": "2018-04-05T02:27:33Z" - } - } - })"; - - EXPECT_CALL(connection.api.transactions, get(_)).Times(1).WillOnce(Return(response)); - - const auto transaction = - connection.api.transactions.get("5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa"); - - DynamicJsonBuffer jsonBuffer(transaction.size()); - JsonObject& root = jsonBuffer.parseObject(transaction); - - JsonObject& data = root["data"]; - - const char* id = data["id"]; - ASSERT_STREQ("5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa", id); - - const char* blockId = data["blockId"]; - ASSERT_STREQ("4271682877946294396", blockId); - - int type = data["type"]; - ASSERT_EQ(0, type); - - uint64_t amount = data["amount"]; - ASSERT_TRUE(amount == 32106400000); - - uint64_t fee = data["fee"]; - ASSERT_TRUE(fee == 10000000); - - const char* sender = data["sender"]; - ASSERT_STREQ("DDiTHZ4RETZhGxcyAi1VruCXZKxBFqXMeh", sender); - - const char* recipient = data["recipient"]; - ASSERT_STREQ("DQnQNoJuNCvpjYhxL7fsnGepHBqrumgsyP", recipient); - - const char* signature = data["signature"]; - ASSERT_STREQ( - "3044022047c39f6f45a46a87f91ca867f9551dbebf0035adcfcbdc1370222c7a1517fc0002206fb5ecc10460e0352a8b626a508e2fcc76e3" - "9e490b0a2581dd772ebc8079696e", - signature); - - int confirmations = data["confirmations"]; - ASSERT_EQ(confirmations, 1928); - - JsonObject& timestamp = data["timestamp"]; - - int epoch = timestamp["epoch"]; - ASSERT_EQ(32794053, epoch); - - int timestampUnix = timestamp["unix"]; - ASSERT_EQ(1522895253, timestampUnix); - - const char* human = timestamp["human"]; - ASSERT_STREQ("2018-04-05T02:27:33Z", human); -} - -/* test_transactions_transaction_types - * https://dexplorer.ark.io:8443/api/v2/transactions/types - * Expected Response: - { - "data": { - "Transfer": 0, - "SecondSignature": 1, - "DelegateRegistration": 2, - "Vote": 3, - "MultiSignature": 4, - "Ipfs": 5, - "TimelockTransfer": 6, - "MultiPayment": 7, - "DelegateResignation": 8 - } - } - */ -TEST(api, test_transaction_types) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "Transfer": 0, - "SecondSignature": 1, - "DelegateRegistration": 2, - "Vote": 3, - "MultiSignature": 4, - "Ipfs": 5, - "TimelockTransfer": 6, - "MultiPayment": 7, - "DelegateResignation": 8 - } - })"; - - EXPECT_CALL(connection.api.transactions, types()).Times(1).WillOnce(Return(response)); - - const auto types = connection.api.transactions.types(); - - DynamicJsonBuffer jsonBuffer(types.size()); - JsonObject& root = jsonBuffer.parseObject(types); - - JsonObject& data = root["data"]; - - int Transfer = data["Transfer"]; - ASSERT_EQ(0, Transfer); - - int SecondSignature = data["SecondSignature"]; - ASSERT_EQ(1, SecondSignature); - - int DelegateRegistration = data["DelegateRegistration"]; - ASSERT_EQ(2, DelegateRegistration); - - int Vote = data["Vote"]; - ASSERT_EQ(3, Vote); - - int MultiSignature = data["MultiSignature"]; - ASSERT_EQ(4, MultiSignature); - - int Ipfs = data["Ipfs"]; - ASSERT_EQ(5, Ipfs); - - int TimelockTransfer = data["TimelockTransfer"]; - ASSERT_EQ(6, TimelockTransfer); - - int MultiPayment = data["MultiPayment"]; - ASSERT_EQ(7, MultiPayment); - - int DelegateResignation = data["DelegateResignation"]; - ASSERT_EQ(8, DelegateResignation); -} - -/* test_transactions_transaction_unconfirmed - * - https://dexplorer.ark.io:8443/api/v2/transactions/unconfirmed?id=4bbc5433e5a4e439369f1f57825e92d07cf9cb8e07aada69c122a2125e4b9d48 - * Expected Response (if unconfirmed tx is not found): - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": - "/api/v2/transactions/unconfirmed?id=4bbc5433e5a4e439369f1f57825e92d07cf9cb8e07aada69c122a2125e4b9d48&page=1&limit=100", - "first": - "/api/v2/transactions/unconfirmed?id=4bbc5433e5a4e439369f1f57825e92d07cf9cb8e07aada69c122a2125e4b9d48&page=1&limit=100", - "last": null - }, - "data": [ - - - ] - } - */ -TEST(api, test_transaction_unconfirmed) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "id": "dummy", - "blockId": "dummy", - "type": 0, - "amount": 10000000, - "fee": 10000000, - "sender": "dummy", - "recipient": "dummy", - "signature": "dummy", - "vendorField": "dummy", - "confirmations": 10, - "timestamp": { - "epoch": 40505460, - "unix": 1530606660, - "human": "2018-07-03T08:31:00Z" - } - } - })"; - - EXPECT_CALL(connection.api.transactions, getUnconfirmed(_)).Times(1).WillOnce(Return(response)); - - const auto transactionUnconfirmed = connection.api.transactions.getUnconfirmed("dummy"); - - DynamicJsonBuffer jsonBuffer(transactionUnconfirmed.size()); - JsonObject& root = jsonBuffer.parseObject(transactionUnconfirmed); - - JsonObject& data = root["data"]; - - const char* id = data["id"]; - ASSERT_STREQ("dummy", id); - - const char* blockId = data["blockId"]; - ASSERT_STREQ("dummy", blockId); - - int type = data["type"]; - ASSERT_EQ(0, type); - - uint64_t amount = data["amount"]; - ASSERT_TRUE(10000000ull == amount); - - uint64_t fee = data["fee"]; - ASSERT_TRUE(10000000ull == fee); - - const char* sender = data["sender"]; - ASSERT_STREQ("dummy", sender); - - const char* recipient = data["recipient"]; - ASSERT_STREQ("dummy", recipient); - - const char* signature = data["signature"]; - ASSERT_STREQ("dummy", signature); - - const char* vendorField = data["vendorField"]; - ASSERT_STREQ("dummy", vendorField); - - int confirmations = data["confirmations"]; - ASSERT_EQ(10, confirmations); - - JsonObject& timestamp = data["timestamp"]; - - uint64_t epoch = timestamp["epoch"]; - ASSERT_TRUE(40505460ull == epoch); - - uint64_t unix_timestamp = timestamp["unix"]; - ASSERT_TRUE(1530606660ull == unix_timestamp); - - const char* human = timestamp["human"]; - ASSERT_STREQ("2018-07-03T08:31:00Z", human); -} - -/* test_transactions_transactions - * https://dexplorer.ark.io:8443/api/v2/transactions?limit=2&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/transactions?limit=2&page=1", - "first": "/api/v2/transactions?limit=2&page=1", - "last": "/api/v2/transactions?limit=2&page=1" - }, - "data": [ - { - "id": "string", - "blockId": "string", - "type": ing, - "amount": uint64_t, - "fee": uint64_t, - "sender": "string", - "recipient": "string", - "signature": "string", - "vendorField": "string", - "confirmations": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - ] - } - */ - -TEST(api, test_transactions) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 127430, - "totalCount": 254860, - "next": "/v2/transactions?page=2", - "previous": null, - "self": "/v2/transactions?page=1", - "first": "/v2/transactions?page=1", - "last": "/v2/transactions?page=127430" - }, - "data": [ - { - "id": "5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa", - "blockId": "4271682877946294396", - "type": 0, - "amount": 32106400000, - "fee": 10000000, - "sender": "DDiTHZ4RETZhGxcyAi1VruCXZKxBFqXMeh", - "recipient": "DQnQNoJuNCvpjYhxL7fsnGepHBqrumgsyP", - "signature": "3044022047c39f6f45a46a87f91ca867f9551dbebf0035adcfcbdc1370222c7a1517fc0002206fb5ecc10460e0352a8b626a508e2fcc76e39e490b0a2581dd772ebc8079696e", - "confirmations": 1924, - "timestamp": { - "epoch": 32794053, - "unix": 1522895253, - "human": "2018-04-05T02:27:33Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.transactions, all(_, _)).Times(1).WillOnce(Return(response)); - - const auto transactions = connection.api.transactions.all(2, 1); - - DynamicJsonBuffer jsonBuffer(transactions.size()); - JsonObject& root = jsonBuffer.parseObject(transactions); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - int type = dataZero["type"]; - ASSERT_EQ(0, type); - - uint64_t fee = dataZero["fee"]; - ASSERT_TRUE(fee >= 0); -} - -/* test_transactions_transactions_unconfirmed - * https://dexplorer.ark.io:8443/api/v2/transactions/unconfirmed?limit=2&page=1 - * Expected Response (if unconfirmed tx is not found): - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/transactions/unconfirmed?limit=2&page=1", - "first": "/api/v2/transactions/unconfirmed?limit=2&page=1", - "last": "string" - }, - "data": [ - - - ] - } - */ -TEST(api, test_transactions_unconfirmed) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 1, - "pageCount": 1, - "totalCount": 1, - "next": null, - "previous": null, - "self": "/api/transactions/unconfirmed?page=1&limit=1", - "first": "/api/transactions/unconfirmed?page=1&limit=1", - "last": "/api/transactions/unconfirmed?page=1&limit=1" - }, - "data": [ - { - "id": "dummy", - "blockId": "dummy", - "type": 0, - "amount": 10000000, - "fee": 10000000, - "sender": "dummy", - "recipient": "dummy", - "signature": "dummy", - "vendorField": "dummy", - "confirmations": 10, - "timestamp": { - "epoch": 40505460, - "unix": 1530606660, - "human": "2018-07-03T08:31:00Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.transactions, allUnconfirmed(_, _)).Times(1).WillOnce(Return(response)); - - const auto transactionsUnconfirmed = connection.api.transactions.allUnconfirmed(5, 1); - - DynamicJsonBuffer jsonBuffer(transactionsUnconfirmed.size()); - JsonObject& root = jsonBuffer.parseObject(transactionsUnconfirmed); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_TRUE(count >= 0); - - int pageCount = meta["pageCount"]; - ASSERT_TRUE(pageCount >= 0); - - int totalCount = meta["totalCount"]; - ASSERT_TRUE(totalCount >= 0); -} - -/* test_transactions_transactions_search - * - * Expected Response: - { - "meta":{ - "count":1, - "pageCount":1, - "totalCount":1, - "next":null, - "previous":null, - "self":"/api/v2/transactions/search?limit=5&page=1", - "first":"/api/v2/transactions/search?limit=5&page=1", - "last":"/api/v2/transactions/search?limit=5&page=1"}, - "data":[ - { - "id":"927ab6da141cc4fa9f1a4b5765ee9ecdf92d47a9cd3aada35aa136ad7d3d3e37", - "blockId":"13624088937920625389", - "version":1, - "type":3, - "amount":0, - "fee":84219776, - "sender":"DMdq8j6uzxErZxESGu7JfkaCFt3qx11fqj", - "recipient":"DMdq8j6uzxErZxESGu7JfkaCFt3qx11fqj", - "signature":"3044022073337aefa7727cc1cf39e478ffe65cf5c66c5761b5848418d87307df250a68a5022053d4d5264b329e63cadad84fc6ec479fe5e430eaabd6177db1e9c283027ec2fa", - "asset": - { - "votes":["+0389301207e25addec690be9efa3b2ca2d111b86386da7ff5fcc1c0344954b2acc"] - }, - "confirmations":871, - "timestamp":{"epoch":55498801,"unix":1545600001,"human":"2018-12-23T21:20:01.000Z"} - } - ] -} - */ -TEST(api, test_transactions_search) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 1, - "pageCount": 1, - "totalCount": 1, - "next": null, - "previous": null, - "self": "/api/transactions/search?page=1&limit=1", - "first": "/api/transactions/search?page=1&limit=1", - "last": "/api/transactions/search?page=1&limit=1" - }, - "data": [ - { - "id": "dummy", - "blockId": "dummy", - "type": 0, - "amount": 10000000, - "fee": 10000000, - "sender": "dummy", - "recipient": "dummy", - "signature": "dummy", - "vendorField": "dummy", - "confirmations": 10, - "timestamp": { - "epoch": 40505460, - "unix": 1530606660, - "human": "2018-07-03T08:31:00Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.transactions, search(_, _, _)).Times(1).WillOnce(Return(response)); - - const std::map body = {{"id", "dummy"}}; - const auto transactions = connection.api.transactions.search(body, 5, 1); - - DynamicJsonBuffer jsonBuffer(transactions.size()); - JsonObject& root = jsonBuffer.parseObject(transactions); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_TRUE(count >= 0); - - int pageCount = meta["pageCount"]; - ASSERT_TRUE(pageCount >= 0); - - int totalCount = meta["totalCount"]; - ASSERT_TRUE(totalCount >= 0); - - JsonObject& data = root["data"][0]; - - const char* id = data["id"]; - ASSERT_STREQ("dummy", id); - - const char* blockId = data["blockId"]; - ASSERT_STREQ("dummy", blockId); - - int type = data["type"]; - ASSERT_EQ(0, type); - - const char* sender = data["sender"]; - ASSERT_STREQ("dummy", sender); - - const char* recipient = data["recipient"]; - ASSERT_STREQ("dummy", recipient); - - const char* signature = data["signature"]; - ASSERT_STREQ("dummy", signature); -} - -/* test_transactions_transactions_send - * - * Expected Response: - * { - * "data": { - * "accept": [ - * "dummy" - * ], - * "broadcast": [ - * "dummy" - * ], - * "excess": [], - * "invalid": [] - * }, - * "errors": null - * } - */ -TEST(api, test_transactions_send) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "accept": [ - "dummy" - ], - "broadcast": [ - "dummy" - ], - "excess": [], - "invalid": [] - }, - "errors": null - })"; - - EXPECT_CALL(connection.api.transactions, send(_)).Times(1).WillOnce(Return(response)); - - std::string jsonTransaction = "{\"transactions\":[{\"type\":0,\"amount\":1,\"fee\":10000000,\"id\":\"bc5bb5cd23521c041fca17b5f78d6f3621fc07ab8f6581aff1b6eb86fa4bafe2\",\"recipientId\":\"DNSrsDUq5injGBdNXPV7v7u1Qy9LZfWEdM\",\"senderPublicKey\":\"0216fa03d378b6ad01325e186ad2cbb9d18976d5b27d0ca74b4f92bb6bf9a6d4d9\",\"signature\":\"3044022014204515b82cdd47513377d3e80e6b5f4fd1ab0fb6b4c181e09a7a30428d542502205ba076a332997053e1d31b506777a99f93bcb11294cd678ebe2da313eb02cae2\",\"timestamp\":58351951,\"vendorField\":\"7ad0eeb302ee7d9b4e58cf52daa9ece7922ad92d14f0407e3881597bf3c9c1c6\"}]}"; - - const auto transaction = connection.api.transactions.send(jsonTransaction); - - DynamicJsonBuffer jsonBuffer(transaction.size()); - JsonObject& root = jsonBuffer.parseObject(transaction); - - JsonObject& data = root["data"]; - - std::string accept = data["accept"]; - ASSERT_TRUE(accept.length() != 0); - - std::string broadcast = data["broadcast"]; - ASSERT_TRUE(broadcast.length() != 0); - - std::string excess = data["excess"]; - ASSERT_TRUE(excess.length() == 2); - - std::string invalid = data["invalid"]; - ASSERT_TRUE(invalid.length() == 2); - - std::string errors = data["errors"]; - ASSERT_TRUE(errors.length() == 0 ); -} diff --git a/test/api/votes.cpp b/test/api/votes.cpp deleted file mode 100644 index 9e74e79c..00000000 --- a/test/api/votes.cpp +++ /dev/null @@ -1,229 +0,0 @@ -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include "mocks/mock_api.h" - -#include "arkClient.h" -#include "utils/json.h" - -using testing::_; -using testing::Return; - -/* test_vote - * https://dexplorer.ark.io:8443/api/v2/votes/d202acbfa947acac53ada2ac8a0eb662c9f75421ede3b10a42759352968b4ed2 - * Expected Response: - { - "data": { - "id": "string", - "blockId": "string", - "type": int, - "amount": uint64_t, - "fee": uint64_t, - "sender": "string", - "recipient": "string", - "signature": "string", - "asset": { - "votes": [ - "string" - ] - }, - "confirmations": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - } - */ -TEST(api, test_vote) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "id": "beb8dd43c640f562704090159154b2742afba7eacada9e8edee447e34e7675c6", - "blockId": "13661015019049808045", - "type": 3, - "amount": 0, - "fee": 100000000, - "sender": "DAp7JjULVgqzd4jLofkUyLRovHRPUTQwiZ", - "recipient": "DAp7JjULVgqzd4jLofkUyLRovHRPUTQwiZ", - "signature": "3045022100e9a743c5aa0df427f49af61d35fe617182479f7e8d368ce23b7ec43ab6d269c80220193aafd4ccb3eedbd76ded7ea99f31629013dc3af60540029fe98b274d42d284", - "asset": { - "votes": [ - "+032fe001dff675a6edfe3d0e51201b2900d3b5050a46d770306aefaa574c022672" - ] - }, - "confirmations": 48189, - "timestamp": { - "epoch": 32338609, - "unix": 1522439809, - "human": "2018-03-30T19:56:49Z" - } - } - })"; - - EXPECT_CALL(connection.api.votes, get(_)).Times(1).WillOnce(Return(response)); - - const auto vote = connection.api.votes.get("beb8dd43c640f562704090159154b2742afba7eacada9e8edee447e34e7675c6"); - - DynamicJsonBuffer jsonBuffer(vote.size()); - JsonObject& root = jsonBuffer.parseObject(vote); - - JsonObject& data = root["data"]; - - const char* id = data["id"]; - ASSERT_STREQ("beb8dd43c640f562704090159154b2742afba7eacada9e8edee447e34e7675c6", id); - - const char* blockId = data["blockId"]; - ASSERT_STREQ("13661015019049808045", blockId); - - int type = data["type"]; - ASSERT_EQ(3, type); - - uint64_t amount = data["amount"]; - ASSERT_TRUE(amount == 0); - - uint64_t fee = data["fee"]; - ASSERT_TRUE(fee == 100000000); - - const char* sender = data["sender"]; - ASSERT_STREQ("DAp7JjULVgqzd4jLofkUyLRovHRPUTQwiZ", sender); - - const char* recipient = data["recipient"]; - ASSERT_STREQ("DAp7JjULVgqzd4jLofkUyLRovHRPUTQwiZ", recipient); - - const char* signature = data["signature"]; - ASSERT_STREQ( - "3045022100e9a743c5aa0df427f49af61d35fe617182479f7e8d368ce23b7ec43ab6d269c80220193aafd4ccb3eedbd76ded7ea99f316290" - "13dc3af60540029fe98b274d42d284", - signature); - - int confirmations = data["confirmations"]; - ASSERT_EQ(48189, confirmations); - - JsonObject& timestamp = data["timestamp"]; - - int epoch = timestamp["epoch"]; - ASSERT_EQ(32338609, epoch); - - int timestampUnix = timestamp["unix"]; - ASSERT_EQ(1522439809, timestampUnix); - - const char* human = timestamp["human"]; - ASSERT_STREQ("2018-03-30T19:56:49Z", human); -} - -/* test_votes - * https://dexplorer.ark.io:8443/api/v2/votes?limit=5&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/votes?limit=5&page=1", - "first": "/api/v2/votes?limit=5&page=1", - "last": "/api/v2/votes?limit=5&page=1" - }, - "data": [ - { - "id": "string", - "blockId": "string", - "type": int, - "amount": uint64_t, - "fee": uint64_t, - "sender": "string", - "recipient": "string", - "signature": "string", - "asset": { - "votes": [ - "+string" - ] - }, - "confirmations": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - ] - } - */ -TEST(api, test_votes) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 658, - "totalCount": 1315, - "next": "/v2/votes?page=2", - "previous": null, - "self": "/v2/votes?page=1", - "first": "/v2/votes?page=1", - "last": "/v2/votes?page=658" - }, - "data": [ - { - "id": "560959e435cbf8eec60691890f3dd55d141e76077e1fe803f65d137c91099240", - "blockId": "12872155462883631430", - "type": 3, - "amount": 0, - "fee": 100000000, - "sender": "DAp7JjULVgqzd4jLofkUyLRovHRPUTQwiZ", - "recipient": "DAp7JjULVgqzd4jLofkUyLRovHRPUTQwiZ", - "signature": "30440220522eadff84b5b4b2fc6a3ef611bf093dbd0a06963c32c767ee28729898d0a1d302203f851594e5b2271a987e98daa4fc8b5f384fac65c41eb1c43739af2d4b5dc902", - "asset": { - "votes": [ - "-032fe001dff675a6edfe3d0e51201b2900d3b5050a46d770306aefaa574c022672" - ] - }, - "confirmations": 39989, - "timestamp": { - "epoch": 32414926, - "unix": 1522516126, - "human": "2018-03-31T17:08:46Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.votes, all(_, _)).Times(1).WillOnce(Return(response)); - - const auto votes = connection.api.votes.all(5, 1); - - DynamicJsonBuffer jsonBuffer(votes.size()); - JsonObject& root = jsonBuffer.parseObject(votes); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - int type = dataZero["type"]; - ASSERT_EQ(3, type); - - uint64_t fee = dataZero["fee"]; - ASSERT_GT(fee, 0); - - int confirmations = dataZero["confirmations"]; - ASSERT_NE(0, confirmations); -} diff --git a/test/api/wallets.cpp b/test/api/wallets.cpp deleted file mode 100644 index 468c1993..00000000 --- a/test/api/wallets.cpp +++ /dev/null @@ -1,726 +0,0 @@ -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include "mocks/mock_api.h" - -#include "arkClient.h" -#include "utils/json.h" - -using testing::_; -using testing::Return; - -/* test_vote_identifier - * https://dexplorer.ark.io:8443/api/v2/wallets/DKrACQw7ytoU2gjppy3qKeE2dQhZjfXYqu - * Expected Response: - { - "data": { - "address": "string", - "publicKey": "string", - "secondPublicKey": "string", - "balance": uint64_t, - "isDelegate": bool - } - } - */ -TEST(api, test_wallet) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "data": { - "address": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "publicKey": "022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", - "balance": 12534670000000, - "isDelegate": true - } - })"; - - EXPECT_CALL(connection.api.wallets, get(_)).Times(1).WillOnce(Return(response)); - - const auto wallet = connection.api.wallets.get("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN"); - - DynamicJsonBuffer jsonBuffer(wallet.size()); - JsonObject& root = jsonBuffer.parseObject(wallet); - - JsonObject& data = root["data"]; - - const char* address = data["address"]; - ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", address); - - const char* publicKey = data["publicKey"]; - ASSERT_STREQ("022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", publicKey); - - uint64_t balance = data["balance"]; - ASSERT_TRUE(balance == 12534670000000); - - bool isDelegate = data["isDelegate"]; - ASSERT_TRUE(isDelegate); -} - -/* test_wallets - * https://dexplorer.ark.io:8443/api/v2/wallets?limit=5&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "/api/v2/wallets?limit=5&page=2", - "previous": "string", - "self": "/api/v2/wallets?limit=5&page=1", - "first": "/api/v2/wallets?limit=5&page=1", - "last": "/api/v2/wallets?limit=5&page=19" - }, - "data": [ - { - "address": "string", - "publicKey": "string", - "secondPublicKey": "string", - "balance": uint64_t, - "isDelegate": bool - } - ] - } - */ -TEST(api, test_wallets) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 421, - "totalCount": 841, - "next": "/v2/wallets?page=2", - "previous": null, - "self": "/v2/wallets?page=1", - "first": "/v2/wallets?page=1", - "last": "/v2/wallets?page=421" - }, - "data": [ - { - "address": "D59NTfV92ca9QevUydvMiFMFdubbCaAVCV", - "publicKey": "037d035f08b3bad0d5bb605232c7aa41555693c480044dbeb797270a44c339da5a", - "balance": 1023145260990, - "isDelegate": false - } - ] - })"; - - EXPECT_CALL(connection.api.wallets, all(_, _)).Times(1).WillOnce(Return(response)); - - const auto wallets = connection.api.wallets.all(5, 1); - - DynamicJsonBuffer jsonBuffer(wallets.size()); - JsonObject& root = jsonBuffer.parseObject(wallets); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - const char* address = dataZero["address"]; - ASSERT_STREQ("D59NTfV92ca9QevUydvMiFMFdubbCaAVCV", address); - - const char* publicKey = dataZero["publicKey"]; - ASSERT_STREQ("037d035f08b3bad0d5bb605232c7aa41555693c480044dbeb797270a44c339da5a", publicKey); - - uint64_t balance = dataZero["balance"]; - ASSERT_TRUE(balance >= 0); - - bool isDelegate = dataZero["isDelegate"]; - ASSERT_FALSE(isDelegate); -} - -/* test_wallets_search - * - * Expected Response: - { - "meta": { - "count": 1, - "pageCount": 1, - "totalCount": 1, - "next": null, - "previous": null, - "self": "\/api\/v2\/wallets\/search?limit=5&page=1", - "first": "\/api\/v2\/wallets\/search?limit=5&page=1", - "last": "\/api\/v2\/wallets\/search?limit=5&page=1" - }, - "data": [ - { - "address": "DFJ5Z51F1euNNdRUQJKQVdG4h495LZkc6T", - "publicKey": "03d3c6889608074b44155ad2e6577c3368e27e6e129c457418eb3e5ed029544e8d", - "secondPublicKey": null, - "balance": 532210000000, - "isDelegate": true - } - ] - } - */ -TEST(api, test_wallets_search) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 2, - "totalCount": 3, - "next": "/v2/wallets/search?page=2", - "previous": null, - "self": "/v2/wallets/search?page=1", - "first": "/v2/wallets/search?page=1", - "last": "/v2/wallets/search?page=2" - }, - "data": [ - { - "id": "08c6b23f9edd97b613f17153fb97a316a4fb83136e9842655dafc8262f363e0e", - "blockId": "14847399772737279404", - "type": 3, - "amount": 0, - "fee": 100000000, - "sender": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "recipient": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "signature": "304402207ba0e8aaee93695360081b7ce713f13d62b544038ac440bd46357398af86cae6022059ac74586738be1ef622e0baba992d0e417d9aed7ab980f374eb0c9d53e25f8e", - "asset": { - "votes": [ - "+0257b7724e97cd832e0c28533a86da5220656f9b5122141daab20e8526decce01f" - ] - }, - "confirmations": 1636029, - "timestamp": { - "epoch": 17094358, - "unix": 1507195558, - "human": "2017-10-05T09:25:58Z" - } - } - ] - })"; - - const std::map body_parameters = { - {"username", "baldninja"}, - {"address", "DFJ5Z51F1euNNdRUQJKQVdG4h495LZkc6T"}, - {"publicKey", "03d3c6889608074b44155ad2e6577c3368e27e6e129c457418eb3e5ed029544e8d"}}; - - EXPECT_CALL(connection.api.wallets, search(_, _, _)).Times(1).WillOnce(Return(response)); - - const auto walletsSearch = connection.api.wallets.search(body_parameters, 5, 1); - - DynamicJsonBuffer jsonBuffer(walletsSearch.size()); - JsonObject& root = jsonBuffer.parseObject(walletsSearch); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - ; - - const char* id = dataZero["id"]; - ASSERT_STREQ("08c6b23f9edd97b613f17153fb97a316a4fb83136e9842655dafc8262f363e0e", id); - - const char* blockId = dataZero["blockId"]; - ASSERT_STREQ("14847399772737279404", blockId); - - int type = dataZero["type"]; - ASSERT_EQ(3, type); - - uint64_t amount = dataZero["amount"]; - ASSERT_TRUE(0ull == amount); - - uint64_t fee = dataZero["fee"]; - ASSERT_TRUE(100000000ull == fee); - - const char* sender = dataZero["sender"]; - ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", sender); - - const char* recipient = dataZero["recipient"]; - ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", recipient); - - const char* signature = dataZero["signature"]; - ASSERT_STREQ( - "304402207ba0e8aaee93695360081b7ce713f13d62b544038ac440bd46357398af86cae6022059ac74586738be1ef622e0baba992d0e417d" - "9aed7ab980f374eb0c9d53e25f8e", - signature); - - int confirmations = dataZero["confirmations"]; - ASSERT_EQ(1636029, confirmations); - - JsonObject& timestamp = dataZero["timestamp"]; - - int epoch = timestamp["epoch"]; - ASSERT_EQ(17094358, epoch); - - int timestampUnix = timestamp["unix"]; - ASSERT_EQ(1507195558, timestampUnix); - - const char* human = timestamp["human"]; - ASSERT_STREQ("2017-10-05T09:25:58Z", human); -} - -/* test_wallets_top_limit_page - * https://dexplorer.ark.io:8443/api/v2/wallets/top?limit=5&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "/api/v2/wallets/top?limit=5&page=2", - "previous": "string", - "self": "/api/v2/wallets/top?limit=5&page=1", - "first": "/api/v2/wallets/top?limit=5&page=1", - "last": "/api/v2/wallets/top?limit=5&page=19" - }, - "data": [ - { - "address": "string", - "publicKey": "string", - "secondPublicKey": "string", - "balance": uint64_t, - "isDelegate": bool - } - ] - } - */ -TEST(api, test_wallets_top) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 1, - "totalCount": 2, - "next": "/api/v2/wallets/top?limit=5&page=1", - "previous": null, - "self": "/api/v2/wallets/top?limit=5&page=1", - "first": "/api/v2/wallets/top?limit=5&page=1", - "last": "/api/v2/wallets/top?limit=5&page=1" - }, - "data": [ - { - "address": "DGihocTkwDygiFvmg6aG8jThYTic47GzU9", - "publicKey": "024c8247388a02ecd1de2a3e3fd5b7c61ecc2797fa3776599d558333ef1802d231", - "balance": 11499593462120632, - "isDelegate": false - }, - { - "address": "DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", - "publicKey": "0374e9a97611540a9ce4812b0980e62d3c5141ea964c2cab051f14a78284570dcd", - "balance": 554107676293547, - "isDelegate": false - }, - ] - })"; - - EXPECT_CALL(connection.api.wallets, top(_, _)).Times(1).WillOnce(Return(response)); - - const auto walletsTop = connection.api.wallets.top(5, 1); - - DynamicJsonBuffer jsonBuffer(walletsTop.size()); - JsonObject& root = jsonBuffer.parseObject(walletsTop); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); - - JsonObject& dataZero = root["data"][0]; - - const char* address = dataZero["address"]; - ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", address); - - const char* publicKey = dataZero["publicKey"]; - ASSERT_STREQ("024c8247388a02ecd1de2a3e3fd5b7c61ecc2797fa3776599d558333ef1802d231", publicKey); - - uint64_t balance = dataZero["balance"]; - ASSERT_TRUE(balance == 11499593462120632ull); - - bool isDelegate = dataZero["isDelegate"]; - ASSERT_FALSE(isDelegate); - - JsonObject& dataOne = root["data"][1]; - - address = dataOne["address"]; - ASSERT_STREQ("DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", address); - - publicKey = dataOne["publicKey"]; - ASSERT_STREQ("0374e9a97611540a9ce4812b0980e62d3c5141ea964c2cab051f14a78284570dcd", publicKey); - - balance = dataOne["balance"]; - ASSERT_TRUE(balance == 554107676293547ull); - - isDelegate = dataOne["isDelegate"]; - ASSERT_FALSE(isDelegate); -} - -/* test_wallets_transactions - * https://dexplorer.ark.io:8443/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions?limit=2&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": "string", - "next": "/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions?limit=2&page=2", - "previous": "string", - "self": "/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions?limit=2&page=1", - "first": "/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions?limit=2&page=1", - "last": "/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk\transactions?limit=2&page=3" - }, - "data": [ - { - "id": "string", - "blockId": "string", - "type": int, - "amount": uint64_t, - "fee": uint64_t, - "sender": "string", - "recipient": "string", - "signature": "string", - "confirmations": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - ] - } - */ -TEST(api, test_wallets_transactions) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 127430, - "totalCount": 254860, - "next": "/v2/wallets/boldninja/transactions?page=2", - "previous": null, - "self": "/v2/wallets/boldninja/transactions?page=1", - "first": "/v2/wallets/boldninja/transactions?page=1", - "last": "/v2/wallets/boldninja/transactions?page=127430" - }, - "data": [ - { - "id": "5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa", - "blockId": "4271682877946294396", - "type": 0, - "amount": 32106400000, - "fee": 10000000, - "sender": "DDiTHZ4RETZhGxcyAi1VruCXZKxBFqXMeh", - "recipient": "DQnQNoJuNCvpjYhxL7fsnGepHBqrumgsyP", - "signature": "3044022047c39f6f45a46a87f91ca867f9551dbebf0035adcfcbdc1370222c7a1517fc0002206fb5ecc10460e0352a8b626a508e2fcc76e39e490b0a2581dd772ebc8079696e", - "confirmations": 1683, - "timestamp": { - "epoch": 32794053, - "unix": 1522895253, - "human": "2018-04-05T02:27:33Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.wallets, transactions(_, _, _)).Times(1).WillOnce(Return(response)); - - const auto walletsTransactions = connection.api.wallets.transactions("DDiTHZ4RETZhGxcyAi1VruCXZKxBFqXMeh", 2, 1); - - DynamicJsonBuffer jsonBuffer(walletsTransactions.size()); - JsonObject& root = jsonBuffer.parseObject(walletsTransactions); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_EQ(2, count); -} - -/* test_wallets_transactions_received - * https://dexplorer.ark.io:8443/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions/received?limit=2&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions/received?limit=2&page=1", - "first": "/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions/received?limit=2&page=1", - "last": "string" - }, - "data": [ - - ] - } - */ -TEST(api, test_wallets_transactions_received) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 4, - "totalCount": 8, - "next": "/v2/wallets/boldninja/transactions/received?page=2", - "previous": null, - "self": "/v2/wallets/boldninja/transactions/received?page=1", - "first": "/v2/wallets/boldninja/transactions/received?page=1", - "last": "/v2/wallets/boldninja/transactions/received?page=4" - }, - "data": [ - { - "id": "c46a6a83f7a358f269691c16f050beeab669767643634086bc12ad1182d54413", - "blockId": "17271524574301696572", - "type": 0, - "amount": 5000000000, - "fee": 10000000, - "sender": "DK6Q1Lufhb939H9EshLViYbaaKUkswMiUz", - "recipient": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "signature": "304402204b81411e507273f2a27e6135510abda5bff00a0d3121977df09363227c8fd2360220503cab4484a7db785d91a7adcfad681811e3d73f2d00b4dab7e4190ecd41cb34", - "vendorField": "More monopoly money for EVERYONE!!", - "confirmations": 1482069, - "timestamp": { - "epoch": 18382414, - "unix": 1508483614, - "human": "2017-10-20T07:13:34Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.wallets, transactionsReceived(_, _, _)).Times(1).WillOnce(Return(response)); - - const auto walletsTransactionsReceived = - connection.api.wallets.transactionsReceived("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", 2, 1); - - DynamicJsonBuffer jsonBuffer(walletsTransactionsReceived.size()); - JsonObject& root = jsonBuffer.parseObject(walletsTransactionsReceived); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); -} - -/* test_wallets_transactions_sent - * https://dexplorer.ark.io:8443/api/v2/wallets/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk/transactions/sent?limit=2&page=1 - * Expected Response: - { - "meta": { - "count": 0, - "pageCount": 0, - "totalCount": 0, - "next": null, - "previous": null, - "self": "\/api\/v2\/wallets\/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk\/transactions\/sent?limit=2&page=1", - "first": "\/api\/v2\/wallets\/DNv1iScT2DJBWzpJd1AFYkTx1xkAZ9XVJk\/transactions\/sent?limit=2&page=1", - "last": null - }, - "data": [ - - ] - } - */ -TEST(api, test_wallets_transactions_sent) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 2, - "totalCount": 4, - "next": "/v2/wallets/boldninja/transactions/sent?page=2", - "previous": null, - "self": "/v2/wallets/boldninja/transactions/sent?page=1", - "first": "/v2/wallets/boldninja/transactions/sent?page=1", - "last": "/v2/wallets/boldninja/transactions/sent?page=2" - }, - "data": [ - { - "id": "08c6b23f9edd97b613f17153fb97a316a4fb83136e9842655dafc8262f363e0e", - "blockId": "14847399772737279404", - "type": 3, - "amount": 0, - "fee": 100000000, - "sender": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "recipient": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "signature": "304402207ba0e8aaee93695360081b7ce713f13d62b544038ac440bd46357398af86cae6022059ac74586738be1ef622e0baba992d0e417d9aed7ab980f374eb0c9d53e25f8e", - "asset": { - "votes": [ - "+0257b7724e97cd832e0c28533a86da5220656f9b5122141daab20e8526decce01f" - ] - }, - "confirmations": 1636232, - "timestamp": { - "epoch": 17094358, - "unix": 1507195558, - "human": "2017-10-05T09:25:58Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.wallets, transactionsSent(_, _, _)).Times(1).WillOnce(Return(response)); - - const auto walletsTransactionsSent = - connection.api.wallets.transactionsSent("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", 2, 1); - - DynamicJsonBuffer jsonBuffer(walletsTransactionsSent.size()); - JsonObject& root = jsonBuffer.parseObject(walletsTransactionsSent); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_NE(0, count); - - int pageCount = meta["pageCount"]; - ASSERT_NE(0, pageCount); - - int totalCount = meta["totalCount"]; - ASSERT_NE(0, totalCount); -} - -/* test_wallets_votes - * https://dexplorer.ark.io:8443/api/v2/wallets/DNjuJEDQkhrJ7cA9FZ2iVXt5anYiM8Jtc9/votes?limit=1&page=1 - * Expected Response: - { - "meta": { - "count": int, - "pageCount": int, - "totalCount": int, - "next": "string", - "previous": "string", - "self": "/api/v2/wallets/DNjuJEDQkhrJ7cA9FZ2iVXt5anYiM8Jtc9/votes?limit=2&page=1", - "first": "/api/v2/wallets/DNjuJEDQkhrJ7cA9FZ2iVXt5anYiM8Jtc9/votes?limit=2&page=1", - "last": "/api/v2/wallets/DNjuJEDQkhrJ7cA9FZ2iVXt5anYiM8Jtc9/votes?limit=2&page=1" - }, - "data": [ - { - "id": "string", - "blockId": "string", - "type": int, - "amount": uint64_t, - "fee": uint64_t, - "sender": "string", - "recipient": "string", - "signature": "string", - "asset": { - "votes": [ - "string" - ] - }, - "confirmations": int, - "timestamp": { - "epoch": int, - "unix": int, - "human": "string" - } - } - ] - } - */ -TEST(api, test_wallets_votes) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - - auto apiVersion = connection.api.version(); - ASSERT_EQ(2, apiVersion); - - const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 2, - "totalCount": 3, - "next": "/v2/wallets/boldninja/votes?page=2", - "previous": null, - "self": "/v2/wallets/boldninja/votes?page=1", - "first": "/v2/wallets/boldninja/votes?page=1", - "last": "/v2/wallets/boldninja/votes?page=2" - }, - "data": [ - { - "id": "08c6b23f9edd97b613f17153fb97a316a4fb83136e9842655dafc8262f363e0e", - "blockId": "14847399772737279404", - "type": 3, - "amount": 0, - "fee": 100000000, - "sender": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "recipient": "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", - "signature": "304402207ba0e8aaee93695360081b7ce713f13d62b544038ac440bd46357398af86cae6022059ac74586738be1ef622e0baba992d0e417d9aed7ab980f374eb0c9d53e25f8e", - "asset": { - "votes": [ - "+0257b7724e97cd832e0c28533a86da5220656f9b5122141daab20e8526decce01f" - ] - }, - "confirmations": 1636029, - "timestamp": { - "epoch": 17094358, - "unix": 1507195558, - "human": "2017-10-05T09:25:58Z" - } - } - ] - })"; - - EXPECT_CALL(connection.api.wallets, votes(_, _, _)).Times(1).WillOnce(Return(response)); - - const auto walletsVotes = connection.api.wallets.votes("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", 1, 1); - - DynamicJsonBuffer jsonBuffer(walletsVotes.size()); - JsonObject& root = jsonBuffer.parseObject(walletsVotes); - - JsonObject& meta = root["meta"]; - - int count = meta["count"]; - ASSERT_GT(count, 0); - - JsonObject& data = root["data"][0]; - - const char* sender = data["sender"]; - ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", sender); -} diff --git a/test/connection/connection.cpp b/test/connection/connection.cpp deleted file mode 100644 index e7c1eaf2..00000000 --- a/test/connection/connection.cpp +++ /dev/null @@ -1,17 +0,0 @@ - -#include "arkClient.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "mocks/mock_api.h" - -TEST(api, test_connection) { // NOLINT - Ark::Client::Connection connection("167.114.29.55", 4003); - int version = connection.api.version(); - ASSERT_EQ(2, version); - - const char* ip = connection.host.ip(); - ASSERT_STREQ("167.114.29.55", ip); - - int port = connection.host.port(); - ASSERT_EQ(4003, port); -} diff --git a/test/host/host.cpp b/test/host/host.cpp deleted file mode 100644 index 3380af57..00000000 --- a/test/host/host.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "host/host.h" -#include "gtest/gtest.h" - -TEST(api, test_host) { // NOLINT - Ark::Client::Host host("167.114.29.55", 4003); - - const char* ip = host.ip(); - ASSERT_STREQ("167.114.29.55", ip); - - int port = host.port(); - ASSERT_EQ(4003, port); - - const auto host_string = host.toString().c_str(); - ASSERT_STREQ("167.114.29.55:4003", host_string); -} diff --git a/test/http/http.cpp b/test/http/http.cpp deleted file mode 100644 index 9d0a199e..00000000 --- a/test/http/http.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "gtest/gtest.h" -#include "http/http.h" -#include "utils/json.h" - -// Note: These test HTTP against a live node - -TEST(api, test_http_get) { // NOLINT - // Create the HTTP object - const auto http = Ark::Client::makeHTTP(); - - // Get the response using HTTP - const auto response = http->get("167.114.29.55:4003/api/node/status"); - - // Create a JSON object of the result - DynamicJsonBuffer jsonBuffer(response.length()); - JsonObject& obj = jsonBuffer.parseObject(response.c_str()); - - // Test JSON object for the "data" key. - // The correct response will include this key. - ASSERT_TRUE(obj.containsKey("data")); -} - -// Tests POSTing of HTTP body. -TEST(api, test_http_post_body) { // NOLINT - // Create the HTTP object - const auto http = Ark::Client::makeHTTP(); - - // 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"; - - // Post the 'request' and 'body' for a response using HTTP - const auto response = http->post(request, body); - - // Create a JSON object of the result - DynamicJsonBuffer jsonBuffer(response.length()); - JsonObject& obj = jsonBuffer.parseObject(response.c_str()); - - // Test JSON object for the "meta" key. - // The correct response will include this key - ASSERT_TRUE(obj.containsKey("meta")); -} - -// Tests POSTing of JSON. -TEST(api, test_http_post_json) { // NOLINT - // Create the HTTP object - const auto http = Ark::Client::makeHTTP(); - - // Create a Request URL and an empty Transaction JSON. - const auto request = "167.114.29.55:4003/api/v2/transactions"; - const auto txJson = "{\"transactions\":[]}"; - - // Post the 'request' and 'txJson' for a response using HTTP - const auto response = http->post(request, txJson); - - // Create a JSON object of the result - DynamicJsonBuffer jsonBuffer(response.length()); - JsonObject& obj = jsonBuffer.parseObject(response.c_str()); - - // Test JSON object for the "message" key. - // The correct response will include the following - ASSERT_STREQ("child \"transactions\" fails because [\"transactions\" must contain at least 1 items]", obj["message"]); -} - -// 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 - }; - - // Create the HTTP object - const auto http = Ark::Client::makeHTTP(); - - for (int i = 0; i < 3; ++i) { - // Get the response using HTTP - const auto response = http->get(requests[i]); - - // Create a JSON object of the result - DynamicJsonBuffer jsonBuffer(response.length()); - JsonObject& obj = jsonBuffer.parseObject(response.c_str()); - - // Test JSON object for the "data" key. - // HTTPS is NOT supported and should fail to parse. - if (std::string(requests[i]).find("https://") == 0) { - ASSERT_FALSE(obj.containsKey("data")); - } else { - ASSERT_TRUE(obj.containsKey("data")); - }; - } -} - -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/iot/test_main.cpp b/test/iot/test_main.cpp deleted file mode 100644 index 56f0fac0..00000000 --- a/test/iot/test_main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#if (defined PLATFORMIO && defined UNIT_TEST) - -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include - -void setup() { - Serial.begin(115200); - while (!Serial); // for the Arduino Leonardo/Micro only - delay(100); - testing::InitGoogleMock(); - delay(1000); - - RUN_ALL_TESTS(); -} - -void loop() { - // do nothing - delay(1000); -} - -#endif diff --git a/test/lib/ArduinoJson b/test/lib/ArduinoJson deleted file mode 160000 index 0d4a9301..00000000 --- a/test/lib/ArduinoJson +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0d4a93018b061ce20238a9d81c17913cb0e7bfe4 diff --git a/test/lib/googletest b/test/lib/googletest deleted file mode 160000 index 3cf8f514..00000000 --- a/test/lib/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3cf8f514d859d65b7202e51c662a03a92887b8e2 diff --git a/test/mocks/mock_api.h b/test/mocks/mock_api.h deleted file mode 100644 index 6b882e3b..00000000 --- a/test/mocks/mock_api.h +++ /dev/null @@ -1,113 +0,0 @@ -/** - * This file is part of Ark Cpp Client. - * - * (c) Ark Ecosystem - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - **/ - -#ifndef MOCK_API_H -#define MOCK_API_H - -#include "gmock/gmock.h" - -#include "arkClient.h" -#include "host/host.h" -#include "http/http.h" -#include "mocks/mock_http.h" - -class MockBlocks : public Ark::Client::API::IBlocks { - public: - MockBlocks(Ark::Client::Host& host, Ark::Client::IHTTP& http) : IBlocks(host, http) {} - - MOCK_METHOD1(get, std::string(const char* const)); - MOCK_METHOD2(all, std::string(int, int)); - MOCK_METHOD1(transactions, std::string(const char* const)); - MOCK_METHOD3(search, std::string(const std::map&, int, int)); -}; - -class MockDelegates : public Ark::Client::API::IDelegates { - public: - MockDelegates(Ark::Client::Host& host, Ark::Client::IHTTP& http) : IDelegates(host, http) {} - - MOCK_METHOD1(get, std::string(const char* const)); - MOCK_METHOD2(all, std::string(int, int)); - MOCK_METHOD3(blocks, std::string(const char* const, int, int)); - MOCK_METHOD3(voters, std::string(const char* const, int, int)); -}; - -class MockNode : public Ark::Client::API::INode { - public: - MockNode(Ark::Client::Host& host, Ark::Client::IHTTP& http) : INode(host, http) {} - - MOCK_METHOD0(configuration, std::string()); - MOCK_METHOD0(status, std::string()); - MOCK_METHOD0(syncing, std::string()); -}; - -class MockPeers : public Ark::Client::API::IPeers { - public: - MockPeers(Ark::Client::Host& host, Ark::Client::IHTTP& http) : IPeers(host, http) {} - - MOCK_METHOD1(get, std::string(const char* const)); - MOCK_METHOD2(all, std::string(int, int)); -}; - -class MockTransactions : public Ark::Client::API::ITransactions { - public: - MockTransactions(Ark::Client::Host& host, Ark::Client::IHTTP& http) : ITransactions(host, http) {} - - MOCK_METHOD1(getUnconfirmed, std::string(const char* const)); - MOCK_METHOD1(get, std::string(const char* const)); - MOCK_METHOD2(all, std::string(int, int)); - MOCK_METHOD2(allUnconfirmed, std::string(int, int)); - MOCK_METHOD0(types, std::string()); - MOCK_METHOD3(search, std::string(const std::map&, int, int)); - MOCK_METHOD1(send, std::string(std::string&)); -}; - -class MockVotes : public Ark::Client::API::IVotes { - public: - MockVotes(Ark::Client::Host& host, Ark::Client::IHTTP& http) : IVotes(host, http) {} - - MOCK_METHOD1(get, std::string(const char* const)); - MOCK_METHOD2(all, std::string(int, int)); -}; - -class MockWallets : public Ark::Client::API::IWallets { - public: - MockWallets(Ark::Client::Host& host, Ark::Client::IHTTP& http) : IWallets(host, http) {} - - MOCK_METHOD1(get, std::string(const char* const)); - MOCK_METHOD2(all, std::string(int, int)); - MOCK_METHOD2(top, std::string(int, int)); - MOCK_METHOD3(transactions, std::string(const char* const, int, int)); - MOCK_METHOD3(transactionsReceived, std::string(const char* const, int, int)); - MOCK_METHOD3(transactionsSent, std::string(const char* const, int, int)); - MOCK_METHOD3(votes, std::string(const char* const, int, int)); - MOCK_METHOD3(search, std::string(const std::map&, int, int)); -}; - -class MockApi : public Ark::Client::API::Abstract { - public: - MockBlocks blocks; - MockDelegates delegates; - MockNode node; - MockPeers peers; - MockTransactions transactions; - MockVotes votes; - MockWallets wallets; - - MockApi() - : Abstract(new MockHTTP(), 2), - blocks(host_, *http_), - delegates(host_, *http_), - node(host_, *http_), - peers(host_, *http_), - transactions(host_, *http_), - votes(host_, *http_), - wallets(host_, *http_) {} -}; - -#endif diff --git a/test/mocks/mock_http.h b/test/mocks/mock_http.h deleted file mode 100644 index b25ac818..00000000 --- a/test/mocks/mock_http.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __MOCK_HTTP_H__ -#define __MOCK_HTTP_H__ - -#include "http/http.h" - -#include "gmock/gmock.h" - -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)); -}; - -#endif diff --git a/test/platformio.ini b/test/platformio.ini deleted file mode 100644 index 5dcfb969..00000000 --- a/test/platformio.ini +++ /dev/null @@ -1,46 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; http://docs.platformio.org/page/projectconf.html - -[platformio] -description = "Unit Tests for Ark-Cpp-Client" -src_dir = .. -lib_dir = .. - -[common] -lib_ldf_mode = deep -lib_deps = ArduinoJson, googletest -# ignore the 'test' lib. This isn't real but the build system somehow thinks that the test directory is also a library and does some double compiling of files -lib_ignore = test -build_flags = -I../src -I../src/include/cpp-client -I./test -I. -I.. -DUNIT_TEST -src_filter = +<*> -<.git/> - - - -<_3rdParty> - - - - #ignore live HTTP tests on IoT -upload_speed = 921600 - -# esp8266 unit tests disabled until GTest/GMock support is worked out -#[env:esp8266] -#platform = espressif8266 -#board = huzzah -#framework = arduino -#lib_ldf_mode = ${common.lib_ldf_mode} -#lib_deps = ${common.lib_deps} -#lib_ignore = ${common.lib_ignore} -#build_flags = ${common.build_flags} -#src_filter = ${common.src_filter} -#upload_speed = ${common.upload_speed} - -[env:esp32] -platform = espressif32 -board = esp32dev -framework = arduino -lib_ldf_mode = ${common.lib_ldf_mode} -lib_ignore = ${common.lib_ignore} -lib_deps = ${common.lib_deps} -build_flags = ${common.build_flags} -src_filter = ${common.src_filter} -upload_speed = ${common.upload_speed} diff --git a/test/utils/json.h b/test/utils/json.h deleted file mode 100644 index a81f9f25..00000000 --- a/test/utils/json.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef JSON_H -#define JSON_H - -/* ArduinoJson Presets */ -#define ARDUINOJSON_USE_LONG_LONG 1 -#define ARDUINOJSON_ENABLE_STD_STRING 1 // Enable 'std::string' -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 // disable 'String' - -/* ArduinoJson Header */ -#include "ArduinoJson.h" - -#endif