diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5b9451e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# all-encompassing default settings unless otherwise specified +[*] +end_of_line = lf +charset = utf-8 + +# Yaml +[{*.yml, *.yaml}] +indent_size = 2 +indent_style = space + +# Property files +[*.properties] +indent_size = 2 +indent_style = space + + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ccc6fb5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,41 @@ +# Handle line endings automatically for files detected as text +# and leave all files detected as binary untouched. +* text=auto + +# +# The above will handle all files NOT found below +# +# These files are text and should be normalized (Convert crlf => lf) +*.bash text eol=lf +*.css text diff=css +*.df text +*.htm text diff=html +*.html text diff=html eol=lf +*.java text diff=java eol=lf +*.js text +*.json text eol=lf +*.jsp text eol=lf +*.jspf text eol=lf +*.jspx text eol=lf +*.properties text eol=lf +*.sh text eol=lf +*.tld text +*.txt text eol=lf +*.tag text +*.tagx text +*.xml text +*.yml text eol=lf + +# These files are binary and should be left untouched +# (binary is a macro for -text -diff) +*.class binary +*.dll binary +*.ear binary +*.gif binary +*.ico binary +*.jar binary +*.jpg binary +*.jpeg binary +*.png binary +*.so binary +*.war binary \ No newline at end of file diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..6e68558 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,37 @@ +name: Java CI + +on: + schedule: + - cron: "0 12 1 * *" + pull_request: + branches: + - master + - dev + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: [ '11' ] + name: Java ${{ matrix.java }} setup + + steps: + - uses: actions/checkout@v1 + - name: Set up JDK + uses: actions/setup-java@v1 + + with: + java-version: ${{ matrix.java }} + + - name: Build with Gradle + run: ./gradlew build jacocoTestReport + env: + API_KEY: ${{ secrets.API_KEY }} + + - name: Analyze with SonarQube + run: ./gradlew sonarqube + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + API_KEY: ${{ secrets.API_KEY }} diff --git a/.gitignore b/.gitignore index 1062418..c48c7a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ -.idea/ +/.settings/ +.idea +.idea/httpRequests *.iml +.gradle +build +target/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ea1440d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: java - -dist: trusty -sudo: false - -script: - - "mvn cobertura:cobertura" - -after_success: - - bash <(curl -s https://codecov.io/bash) - -jdk: - - oraclejdk8 - - openjdk8 diff --git a/README.md b/README.md index f62f766..733a2ed 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # java-etherscan-api -![travis](https://travis-ci.org/GoodforGod/java-etherscan-api.svg?branch=master) -[![Maintainability](https://api.codeclimate.com/v1/badges/808997be2e69ff1ae8fe/maintainability)](https://codeclimate.com/github/GoodforGod/java-etherscan-api/maintainability) -[![codecov](https://codecov.io/gh/GoodforGod/java-etherscan-api/branch/master/graph/badge.svg)](https://codecov.io/gh/GoodforGod/java-etherscan-api) +[![Jitpack](https://jitpack.io/v/iSnow/java-etherscan-api.svg)](https://jitpack.io/#GoodforGod/java-etherscan-api) [Etherscan](https://etherscan.io/apis) Java API implementation. @@ -14,14 +12,14 @@ Library supports all available EtherScan *API* calls for all available *Ethereum com.github.goodforgod java-etherscan-api - 1.0.2 + 1.1.0 ``` **Gradle** ```groovy dependencies { - compile 'com.github.goodforgod:java-etherscan-api:1.0.2' + compile 'com.github.goodforgod:java-etherscan-api:1.1.0' } ``` diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..1d07a61 --- /dev/null +++ b/build.gradle @@ -0,0 +1,135 @@ +plugins { + id 'jacoco' + id 'java-library' + id 'maven-publish' + + id 'org.sonarqube' version '3.0' + id 'com.diffplug.gradle.spotless' version '4.4.0' +} + +repositories { + mavenLocal() + mavenCentral() + jcenter() +} + +group = groupId +version = artifactVersion + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +spotless { + java { + encoding 'UTF-8' + removeUnusedImports() + eclipse().configFile "${projectDir}/config/codestyle.xml" + } +} + +sonarqube { + properties { + property 'sonar.host.url', 'https://sonarcloud.io' + property 'sonar.organization', 'goodforgod' + property 'sonar.projectKey', 'GoodforGod_java-etherscan-api' + } +} + +dependencies { + implementation 'org.jetbrains:annotations:20.1.0' + implementation 'com.google.code.gson:gson:2.8.6' + + testImplementation 'junit:junit:4.13.1' +} + +test { + failFast = true + + useJUnit() + testLogging { + events "passed", "skipped", "failed" + exceptionFormat "full" + } +} + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' + options.incremental = true + options.fork = true +} + +tasks.withType(Test) { + reports.html.enabled = false + reports.junitXml.enabled = false +} + +java { + withJavadocJar() + withSourcesJar() +} + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + + pom { + name = 'Java Etherscan API' + url = 'https://github.com/GoodforGod/java-etherscan-api' + description = 'Library is a wrapper for EtherScan API.' + + license { + name = 'MIT License' + url = 'https://github.com/GoodforGod/java-etherscan-api/blob/master/LICENSE' + distribution = 'repo' + } + + developer { + id = 'GoodforGod' + name = 'Anton Kurako' + email = 'goodforgod.dev@gmail.com' + url = 'https://github.com/GoodforGod' + } + + scm { + connection = 'scm:git:git://github.com/GoodforGod/java-etherscan-api.git' + developerConnection = 'scm:git:ssh://GoodforGod/java-etherscan-api.git' + url = 'https://github.com/GoodforGod/java-etherscan-api/tree/master' + } + } + } + } + repositories { + maven { + def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" + def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/" + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + credentials { + username System.getenv("OSS_USERNAME") + password System.getenv("OSS_PASSWORD") + } + } + } +} + +check.dependsOn jacocoTestReport +jacocoTestReport { + reports { + xml.enabled true + html.destination file("${buildDir}/jacocoHtml") + } +} + +if (project.hasProperty("signing.keyId")) { + apply plugin: 'signing' + signing { + sign publishing.publications.mavenJava + } +} + +javadoc { + options.encoding = "UTF-8" + if (JavaVersion.current().isJava9Compatible()) { + options.addBooleanOption('html5', true) + } +} \ No newline at end of file diff --git a/config/codestyle.xml b/config/codestyle.xml new file mode 100644 index 0000000..0c19beb --- /dev/null +++ b/config/codestyle.xml @@ -0,0 +1,348 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..0c89028 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,12 @@ +groupId=com.github.goodforgod +artifactId=java-etherscan-api +artifactVersion=1.1.0-SNAPSHOT +buildNumber=1 + + +##### GRADLE ##### +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.configureondemand=true +org.gradle.caching=true +org.gradle.jvmargs=-Dfile.encoding=UTF-8 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..be52383 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/pom.xml b/pom.xml deleted file mode 100644 index a9bcfa8..0000000 --- a/pom.xml +++ /dev/null @@ -1,190 +0,0 @@ - - - 4.0.0 - - com.github.goodforgod - java-etherscan-api - 1.0.2 - jar - - ${project.groupId}:${project.artifactId} - Library is a wrapper for EtherScan API. - http://maven.apache.org - - - - MIT License - https://github.com/GoodforGod/java-etherscan-api/blob/master/LICENSE - repo - - - - - - Anton Kurako - goodforgod.dev@gmail.com - https://github.com/GoodforGod - - - - - scm:git:git://github.com/GoodforGod/java-etherscan-api.git - scm:git:ssh://GoodforGod/java-etherscan-api.git - https://github.com/GoodforGod/java-etherscan-api/tree/master - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - UTF-8 - 1.8 - 1.8 - - 3.0.2 - 1.6 - 3.0.1 - 3.0.1 - 1.6.8 - 2.7 - - 4.12 - 2.8.5 - - - - - junit - junit - ${junit-version} - test - - - - com.google.code.gson - gson - ${gson-version} - - - - org.jetbrains - annotations - 13.0 - - - - - - release - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${maven-nexus-staging-maven-plugin-version} - true - - ossrh - https://oss.sonatype.org/ - true - - - - - - - - sign - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin-version} - - - sign-artifacts - verify - - sign - - - - - - - - - - build-extras - - true - - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin-version} - - - attach-sources - - jar-no-fork - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin-version} - - - attach-javadocs - - jar - - - - - -html5 - - - - - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura-plugin-version} - - - html - xml - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-build-plugin-version} - - - - diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..8e004bc --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = artifactId diff --git a/settings.xml b/settings.xml deleted file mode 100644 index ab979c3..0000000 --- a/settings.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - ossrh - ${env.OSSRH_JIRA_USERNAME} - ${env.OSSRH_JIRA_PASSWORD} - - - - - - ossrh - - true - - - gpg - ${env.GPG_KEY_NAME} - ${env.GPG_PASSPHRASE} - - - - \ No newline at end of file diff --git a/src/main/java/io/api/etherscan/core/IAccountApi.java b/src/main/java/io/api/etherscan/core/IAccountApi.java index 7d44d15..6eda869 100644 --- a/src/main/java/io/api/etherscan/core/IAccountApi.java +++ b/src/main/java/io/api/etherscan/core/IAccountApi.java @@ -7,8 +7,7 @@ import java.util.List; /** - * EtherScan - API Descriptions - * https://etherscan.io/apis#accounts + * EtherScan - API Descriptions https://etherscan.io/apis#accounts * * @author GoodforGod * @since 28.10.2018 @@ -17,79 +16,107 @@ public interface IAccountApi { /** * Address ETH balance + * * @param address get balance for * @return balance * @throws ApiException parent exception class */ - @NotNull Balance balance(String address) throws ApiException; + @NotNull + Balance balance(String address) throws ApiException; /** * ERC20 token balance for address - * @param address get balance for + * + * @param address get balance for * @param contract token contract * @return token balance for address * @throws ApiException parent exception class */ - @NotNull TokenBalance balance(String address, String contract) throws ApiException; + @NotNull + TokenBalance balance(String address, String contract) throws ApiException; /** - * Maximum 20 address for single batch request - * If address MORE THAN 20, then there will be more than 1 request performed + * Maximum 20 address for single batch request If address MORE THAN 20, then + * there will be more than 1 request performed + * * @param addresses addresses to get balances for * @return list of balances * @throws ApiException parent exception class */ - @NotNull List balances(List addresses) throws ApiException; + @NotNull + List balances(List addresses) throws ApiException; /** * All txs for given address - * @param address get txs for + * + * @param address get txs for * @param startBlock tx from this blockNumber - * @param endBlock tx to this blockNumber + * @param endBlock tx to this blockNumber * @return txs for address * @throws ApiException parent exception class */ - @NotNull List txs(String address, long startBlock, long endBlock) throws ApiException; - @NotNull List txs(String address, long startBlock) throws ApiException; - @NotNull List txs(String address) throws ApiException; + @NotNull + List txs(String address, long startBlock, long endBlock) throws ApiException; + + @NotNull + List txs(String address, long startBlock) throws ApiException; + + @NotNull + List txs(String address) throws ApiException; /** * All internal txs for given address - * @param address get txs for + * + * @param address get txs for * @param startBlock tx from this blockNumber - * @param endBlock tx to this blockNumber + * @param endBlock tx to this blockNumber * @return txs for address * @throws ApiException parent exception class */ - @NotNull List txsInternal(String address, long startBlock, long endBlock) throws ApiException; - @NotNull List txsInternal(String address, long startBlock) throws ApiException; - @NotNull List txsInternal(String address) throws ApiException; + @NotNull + List txsInternal(String address, long startBlock, long endBlock) throws ApiException; + + @NotNull + List txsInternal(String address, long startBlock) throws ApiException; + + @NotNull + List txsInternal(String address) throws ApiException; /** * All internal tx for given transaction hash + * * @param txhash transaction hash * @return internal txs list * @throws ApiException parent exception class */ - @NotNull List txsInternalByHash(String txhash) throws ApiException; + @NotNull + List txsInternalByHash(String txhash) throws ApiException; /** * All token txs for given address - * @param address get txs for + * + * @param address get txs for * @param startBlock tx from this blockNumber - * @param endBlock tx to this blockNumber + * @param endBlock tx to this blockNumber * @return txs for address * @throws ApiException parent exception class */ - @NotNull List txsToken(String address, long startBlock, long endBlock) throws ApiException; - @NotNull List txsToken(String address, long startBlock) throws ApiException; - @NotNull List txsToken(String address) throws ApiException; + @NotNull + List txsToken(String address, long startBlock, long endBlock) throws ApiException; + + @NotNull + List txsToken(String address, long startBlock) throws ApiException; + + @NotNull + List txsToken(String address) throws ApiException; /** * All blocks mined by address + * * @param address address to search for * @return blocks mined * @throws ApiException parent exception class */ - @NotNull List minedBlocks(String address) throws ApiException; + @NotNull + List minedBlocks(String address) throws ApiException; } diff --git a/src/main/java/io/api/etherscan/core/IBlockApi.java b/src/main/java/io/api/etherscan/core/IBlockApi.java index e33b0d7..7381ac0 100644 --- a/src/main/java/io/api/etherscan/core/IBlockApi.java +++ b/src/main/java/io/api/etherscan/core/IBlockApi.java @@ -7,8 +7,7 @@ import java.util.Optional; /** - * EtherScan - API Descriptions - * https://etherscan.io/apis#blocks + * EtherScan - API Descriptions https://etherscan.io/apis#blocks * * @author GoodforGod * @since 30.10.2018 @@ -17,9 +16,11 @@ public interface IBlockApi { /** * Return uncle blocks + * * @param blockNumber block number form 0 to last * @return optional uncle blocks * @throws ApiException parent exception class */ - @NotNull Optional uncles(long blockNumber) throws ApiException; + @NotNull + Optional uncles(long blockNumber) throws ApiException; } diff --git a/src/main/java/io/api/etherscan/core/IContractApi.java b/src/main/java/io/api/etherscan/core/IContractApi.java index 5e3c771..3e9388d 100644 --- a/src/main/java/io/api/etherscan/core/IContractApi.java +++ b/src/main/java/io/api/etherscan/core/IContractApi.java @@ -5,8 +5,7 @@ import org.jetbrains.annotations.NotNull; /** - * EtherScan - API Descriptions - * https://etherscan.io/apis#contracts + * EtherScan - API Descriptions https://etherscan.io/apis#contracts * * @author GoodforGod * @since 28.10.2018 @@ -15,9 +14,11 @@ public interface IContractApi { /** * Get Verified Contract Sources + * * @param address to verify * @return ABI verified * @throws ApiException parent exception class */ - @NotNull Abi contractAbi(String address) throws ApiException; + @NotNull + Abi contractAbi(String address) throws ApiException; } diff --git a/src/main/java/io/api/etherscan/core/ILogsApi.java b/src/main/java/io/api/etherscan/core/ILogsApi.java index d1901dd..dc7d8d8 100644 --- a/src/main/java/io/api/etherscan/core/ILogsApi.java +++ b/src/main/java/io/api/etherscan/core/ILogsApi.java @@ -8,8 +8,7 @@ import java.util.List; /** - * EtherScan - API Descriptions - * https://etherscan.io/apis#logs + * EtherScan - API Descriptions https://etherscan.io/apis#logs * * @author GoodforGod * @since 30.10.2018 @@ -17,13 +16,15 @@ public interface ILogsApi { /** - * alternative to the native eth_getLogs - * Read at EtherScan API description for full info! + * alternative to the native eth_getLogs Read at EtherScan API description for + * full info! + * * @param query build log query * @return logs according to query * @throws ApiException parent exception class * * @see io.api.etherscan.model.query.impl.LogQueryBuilder */ - @NotNull List logs(LogQuery query) throws ApiException; + @NotNull + List logs(LogQuery query) throws ApiException; } diff --git a/src/main/java/io/api/etherscan/core/IProxyApi.java b/src/main/java/io/api/etherscan/core/IProxyApi.java index 171c752..58a70ed 100644 --- a/src/main/java/io/api/etherscan/core/IProxyApi.java +++ b/src/main/java/io/api/etherscan/core/IProxyApi.java @@ -10,8 +10,7 @@ import java.util.Optional; /** - * EtherScan - API Descriptions - * https://etherscan.io/apis#proxy + * EtherScan - API Descriptions https://etherscan.io/apis#proxy * * @author GoodforGod * @since 30.10.2018 @@ -19,54 +18,62 @@ public interface IProxyApi { /** - * Returns the number of most recent block - * eth_blockNumber + * Returns the number of most recent block eth_blockNumber + * * @return last block number * @throws ApiException parent exception class */ long blockNoLast(); /** - * Returns information about a block by block number - * eth_getBlockByNumber + * Returns information about a block by block number eth_getBlockByNumber + * * @param blockNo block number from 0 to last * @return optional block result * @throws ApiException parent exception class */ - @NotNull Optional block(long blockNo) throws ApiException; + @NotNull + Optional block(long blockNo) throws ApiException; /** * Returns information about a uncle by block number * eth_getUncleByBlockNumberAndIndex + * * @param blockNo block number from 0 to last - * @param index uncle block index + * @param index uncle block index * @return optional block result * @throws ApiException parent exception class */ - @NotNull Optional blockUncle(long blockNo, long index) throws ApiException; + @NotNull + Optional blockUncle(long blockNo, long index) throws ApiException; /** * Returns the information about a transaction requested by transaction hash * eth_getTransactionByHash + * * @param txhash transaction hash * @return optional tx result * @throws ApiException parent exception class */ - @NotNull Optional tx(String txhash) throws ApiException; + @NotNull + Optional tx(String txhash) throws ApiException; /** - * Returns information about a transaction by block number and transaction index position - * eth_getTransactionByBlockNumberAndIndex + * Returns information about a transaction by block number and transaction index + * position eth_getTransactionByBlockNumberAndIndex + * * @param blockNo block number from 0 to last - * @param index tx index in block + * @param index tx index in block * @return optional tx result * @throws ApiException parent exception class */ - @NotNull Optional tx(long blockNo, long index) throws ApiException; + @NotNull + Optional tx(long blockNo, long index) throws ApiException; /** - * Returns the number of transactions in a block from a block matching the given block number - * eth_getBlockTransactionCountByNumber + * Returns the number of transactions in a block from a block matching the given + * block number eth_getBlockTransactionCountByNumber + * * @param blockNo block number from 0 to last * @return transaction amount in block * @throws ApiException parent exception class @@ -76,6 +83,7 @@ public interface IProxyApi { /** * Returns the number of transactions sent from an address * eth_getTransactionCount + * * @param address eth address * @return transactions send amount from address * @throws ApiException parent exception class @@ -83,70 +91,82 @@ public interface IProxyApi { int txSendCount(String address) throws ApiException; /** - * Creates new message call transaction or a contract creation for signed transactions - * eth_sendRawTransaction + * Creates new message call transaction or a contract creation for signed + * transactions eth_sendRawTransaction + * * @param hexEncodedTx encoded hex data to send * @return optional string response * @throws ApiException parent exception class */ - @NotNull Optional txSendRaw(String hexEncodedTx) throws ApiException; + @NotNull + Optional txSendRaw(String hexEncodedTx) throws ApiException; /** * Returns the receipt of a transaction by transaction hash * eth_getTransactionReceipt + * * @param txhash transaction hash * @return optional tx receipt * @throws ApiException parent exception class */ - @NotNull Optional txReceipt(String txhash) throws ApiException; + @NotNull + Optional txReceipt(String txhash) throws ApiException; /** - * Executes a new message call immediately without creating a transaction on the block chain - * eth_call + * Executes a new message call immediately without creating a transaction on the + * block chain eth_call + * * @param address to call - * @param data data to call address + * @param data data to call address * @return optional the return value of executed contract. * @throws ApiException parent exception class */ - @NotNull Optional call(String address, String data) throws ApiException; + @NotNull + Optional call(String address, String data) throws ApiException; /** - * Returns code at a given address - * eth_getCode + * Returns code at a given address eth_getCode + * * @param address get code from * @return optional the code from the given address * @throws ApiException parent exception class */ - @NotNull Optional code(String address) throws ApiException; + @NotNull + Optional code(String address) throws ApiException; /** - * (**experimental) - * Returns the value from a storage position at a given address + * (**experimental) Returns the value from a storage position at a given address * eth_getStorageAt - * @param address to get storage + * + * @param address to get storage * @param position storage position * @return optional the value at this storage position * @throws ApiException parent exception class */ - @NotNull Optional storageAt(String address, long position) throws ApiException; + @NotNull + Optional storageAt(String address, long position) throws ApiException; /** - * Returns the current price per gas in wei - * eth_gasPrice + * Returns the current price per gas in wei eth_gasPrice + * * @return estimated gas price * @throws ApiException parent exception class */ - @NotNull BigInteger gasPrice() throws ApiException; - + @NotNull + BigInteger gasPrice() throws ApiException; /** - * Makes a call or transaction, which won't be added to the blockchain and returns the used gas, - * which can be used for estimating the used gas + * Makes a call or transaction, which won't be added to the blockchain and + * returns the used gas, which can be used for estimating the used gas * eth_estimateGas + * * @param hexData data to calc gas usage for * @return estimated gas usage * @throws ApiException parent exception class */ - @NotNull BigInteger gasEstimated(String hexData) throws ApiException; - @NotNull BigInteger gasEstimated() throws ApiException; + @NotNull + BigInteger gasEstimated(String hexData) throws ApiException; + + @NotNull + BigInteger gasEstimated() throws ApiException; } diff --git a/src/main/java/io/api/etherscan/core/IStatisticApi.java b/src/main/java/io/api/etherscan/core/IStatisticApi.java index c0b838e..1b7ef59 100644 --- a/src/main/java/io/api/etherscan/core/IStatisticApi.java +++ b/src/main/java/io/api/etherscan/core/IStatisticApi.java @@ -8,8 +8,7 @@ import java.math.BigInteger; /** - * EtherScan - API Descriptions - * https://etherscan.io/apis#stats + * EtherScan - API Descriptions https://etherscan.io/apis#stats * * @author GoodforGod * @since 30.10.2018 @@ -18,23 +17,29 @@ public interface IStatisticApi { /** * ERC20 token total Supply + * * @param contract contract address * @return token supply for specified contract * @throws ApiException parent exception class */ - @NotNull BigInteger supply(String contract) throws ApiException; + @NotNull + BigInteger supply(String contract) throws ApiException; /** * Eth total supply + * * @return total ETH supply for moment * @throws ApiException parent exception class */ - @NotNull Supply supply() throws ApiException; + @NotNull + Supply supply() throws ApiException; /** * Eth last USD and BTC price + * * @return last usd/btc price for ETH * @throws ApiException parent exception class */ - @NotNull Price lastPrice() throws ApiException; + @NotNull + Price lastPrice() throws ApiException; } diff --git a/src/main/java/io/api/etherscan/core/ITransactionApi.java b/src/main/java/io/api/etherscan/core/ITransactionApi.java index 3c248f3..51c108c 100644 --- a/src/main/java/io/api/etherscan/core/ITransactionApi.java +++ b/src/main/java/io/api/etherscan/core/ITransactionApi.java @@ -7,8 +7,7 @@ import java.util.Optional; /** - * EtherScan - API Descriptions - * https://etherscan.io/apis#transactions + * EtherScan - API Descriptions https://etherscan.io/apis#transactions * * @author GoodforGod * @since 30.10.2018 @@ -16,18 +15,24 @@ public interface ITransactionApi { /** - * Check Contract Execution Status (if there was an error during contract execution) + * Check Contract Execution Status (if there was an error during contract + * execution) + * * @param txhash transaction hash * @return optional status result * @throws ApiException parent exception class */ - @NotNull Optional execStatus(String txhash) throws ApiException; + @NotNull + Optional execStatus(String txhash) throws ApiException; /** - * Check Transaction Receipt Status (Only applicable for Post Byzantium fork transactions) + * Check Transaction Receipt Status (Only applicable for Post Byzantium fork + * transactions) + * * @param txhash transaction hash * @return 0 = Fail, 1 = Pass, empty value for pre-byzantium fork * @throws ApiException parent exception class */ - @NotNull Optional receiptStatus(String txhash) throws ApiException; + @NotNull + Optional receiptStatus(String txhash) throws ApiException; } diff --git a/src/main/java/io/api/etherscan/core/impl/AccountApiProvider.java b/src/main/java/io/api/etherscan/core/impl/AccountApiProvider.java index 195d0f0..b512019 100644 --- a/src/main/java/io/api/etherscan/core/impl/AccountApiProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/AccountApiProvider.java @@ -62,7 +62,7 @@ public Balance balance(final String address) throws ApiException { final String urlParams = ACT_BALANCE_ACTION + TAG_LATEST_PARAM + ADDRESS_PARAM + address; final StringResponseTO response = getRequest(urlParams, StringResponseTO.class); if (response.getStatus() != 1) - throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus()); + throw new EtherScanException(response); return new Balance(address, new BigInteger(response.getResult())); } @@ -76,7 +76,7 @@ public TokenBalance balance(final String address, final String contract) throws final String urlParams = ACT_TOKEN_BALANCE_PARAM + ADDRESS_PARAM + address + CONTRACT_PARAM + contract; final StringResponseTO response = getRequest(urlParams, StringResponseTO.class); if (response.getStatus() != 1) - throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus()); + throw new EtherScanException(response); return new TokenBalance(address, new BigInteger(response.getResult()), contract); } @@ -97,7 +97,7 @@ public List balances(final List addresses) throws ApiException final String urlParams = ACT_BALANCE_MULTI_ACTION + TAG_LATEST_PARAM + ADDRESS_PARAM + toAddressParam(batch); final BalanceResponseTO response = getRequest(urlParams, BalanceResponseTO.class); if (response.getStatus() != 1) - throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus()); + throw new EtherScanException(response); if (!BasicUtils.isEmpty(response.getResult())) balances.addAll(response.getResult().stream() @@ -138,8 +138,7 @@ public List txs(final String address, final long startBlock, final long endB } /** - * Generic search for txs using offset api param - * To avoid 10k limit per response + * Generic search for txs using offset api param To avoid 10k limit per response * * @param urlParams Url params for #getRequest() * @param tClass responseListTO class @@ -147,8 +146,8 @@ public List txs(final String address, final long startBlock, final long endB * @param responseListTO type * @return List of T values */ - private List getRequestUsingOffset(final String urlParams, Class tClass) - throws ApiException { + private List getRequestUsingOffset(final String urlParams, + Class tClass) throws ApiException { final List result = new ArrayList<>(); int page = 1; while (true) { diff --git a/src/main/java/io/api/etherscan/core/impl/BasicProvider.java b/src/main/java/io/api/etherscan/core/impl/BasicProvider.java index 5b95f68..cf16337 100644 --- a/src/main/java/io/api/etherscan/core/impl/BasicProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/BasicProvider.java @@ -1,12 +1,17 @@ package io.api.etherscan.core.impl; import com.google.gson.Gson; +import io.api.etherscan.error.ApiException; import io.api.etherscan.error.EtherScanException; import io.api.etherscan.error.ParseException; +import io.api.etherscan.error.RateLimitException; import io.api.etherscan.executor.IHttpExecutor; import io.api.etherscan.manager.IQueueManager; +import io.api.etherscan.model.utility.StringResponseTO; import io.api.etherscan.util.BasicUtils; +import java.util.Map; + /** * Base provider for API Implementations * @@ -16,7 +21,7 @@ */ abstract class BasicProvider { - static final int MAX_END_BLOCK = 999999999; + static final int MAX_END_BLOCK = Integer.MAX_VALUE; static final int MIN_START_BLOCK = 0; static final String ACT_PREFIX = "&action="; @@ -40,9 +45,27 @@ abstract class BasicProvider { T convert(final String json, final Class tClass) { try { - return gson.fromJson(json, tClass); + final T t = gson.fromJson(json, tClass); + if (t instanceof StringResponseTO) { + if (((StringResponseTO) t).getResult().startsWith("Max rate limit reached")) { + throw new RateLimitException(((StringResponseTO) t).getResult()); + } + } + + return t; } catch (Exception e) { - throw new ParseException(e.getMessage(), e.getCause()); + try { + final Map map = gson.fromJson(json, Map.class); + final Object result = map.get("result"); + if (result instanceof String && ((String) result).startsWith("Max rate limit reached")) + throw new RateLimitException(((String) result)); + + throw new ParseException(e.getMessage() + ", for response: " + json, e.getCause(), json); + } catch (ApiException ex) { + throw ex; + } catch (Exception ex) { + throw new ParseException(e.getMessage() + ", for response: " + json, e.getCause(), json); + } } } diff --git a/src/main/java/io/api/etherscan/core/impl/BlockApiProvider.java b/src/main/java/io/api/etherscan/core/impl/BlockApiProvider.java index d076e18..9f386a7 100644 --- a/src/main/java/io/api/etherscan/core/impl/BlockApiProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/BlockApiProvider.java @@ -36,7 +36,7 @@ public class BlockApiProvider extends BasicProvider implements IBlockApi { public Optional uncles(long blockNumber) throws ApiException { final String urlParam = ACT_BLOCK_PARAM + BLOCKNO_PARAM + blockNumber; final String response = getRequest(urlParam); - if(BasicUtils.isEmpty(response) || response.contains("NOTOK")) + if (BasicUtils.isEmpty(response) || response.contains("NOTOK")) return Optional.empty(); final UncleBlockResponseTO responseTO = convert(response, UncleBlockResponseTO.class); diff --git a/src/main/java/io/api/etherscan/core/impl/ContractApiProvider.java b/src/main/java/io/api/etherscan/core/impl/ContractApiProvider.java index 83a6e0a..125087f 100644 --- a/src/main/java/io/api/etherscan/core/impl/ContractApiProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/ContractApiProvider.java @@ -37,8 +37,8 @@ public Abi contractAbi(final String address) throws ApiException { final String urlParam = ACT_ABI_PARAM + ADDRESS_PARAM + address; final StringResponseTO response = getRequest(urlParam, StringResponseTO.class); - if (response.getStatus() != 1 && !"NOTOK".equals(response.getMessage())) - throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus()); + if (response.getStatus() != 1 && "NOTOK".equals(response.getMessage())) + throw new EtherScanException(response); return (response.getResult().startsWith("Contract sou")) ? Abi.nonVerified() diff --git a/src/main/java/io/api/etherscan/core/impl/EtherScanApi.java b/src/main/java/io/api/etherscan/core/impl/EtherScanApi.java index a3979df..8cd5d46 100644 --- a/src/main/java/io/api/etherscan/core/impl/EtherScanApi.java +++ b/src/main/java/io/api/etherscan/core/impl/EtherScanApi.java @@ -15,8 +15,7 @@ import java.util.function.Supplier; /** - * EtherScan full API Description - * https://etherscan.io/apis + * EtherScan full API Description https://etherscan.io/apis * * @author GoodforGod * @since 28.10.2018 @@ -25,6 +24,8 @@ public class EtherScanApi { private static final Supplier DEFAULT_SUPPLIER = HttpExecutor::new; + public static final String DEFAULT_KEY = "YourApiKeyToken"; + private final IAccountApi account; private final IBlockApi block; private final IContractApi contract; @@ -34,11 +35,11 @@ public class EtherScanApi { private final ITransactionApi txs; public EtherScanApi() { - this("YourApiKeyToken", EthNetwork.MAINNET); + this(DEFAULT_KEY, EthNetwork.MAINNET); } public EtherScanApi(final EthNetwork network) { - this("YourApiKeyToken", network); + this(DEFAULT_KEY, network); } public EtherScanApi(final String apiKey) { @@ -47,7 +48,13 @@ public EtherScanApi(final String apiKey) { public EtherScanApi(final EthNetwork network, final Supplier executorSupplier) { - this("YourApiKeyToken", network, executorSupplier); + this(DEFAULT_KEY, network, executorSupplier); + } + + public EtherScanApi(final String apiKey, + final EthNetwork network, + final IQueueManager queue) { + this(apiKey, network, DEFAULT_SUPPLIER, queue); } public EtherScanApi(final String apiKey, @@ -58,29 +65,35 @@ public EtherScanApi(final String apiKey, public EtherScanApi(final String apiKey, final EthNetwork network, final Supplier executorSupplier) { + this(apiKey, network, executorSupplier, + DEFAULT_KEY.equals(apiKey) + ? QueueManager.DEFAULT_KEY_QUEUE + : new FakeQueueManager()); + } + + public EtherScanApi(final String apiKey, + final EthNetwork network, + final Supplier executorSupplier, + final IQueueManager queue) { if (BasicUtils.isBlank(apiKey)) throw new ApiKeyException("API key can not be null or empty"); - if(network == null) + if (network == null) throw new ApiException("Ethereum Network is set to NULL value"); - // EtherScan 5request\sec limit support by queue manager - final IQueueManager masterQueue = "YourApiKeyToken".equals(apiKey) - ? new FakeQueueManager() - : new QueueManager(5, 1); - + // EtherScan 1request\5sec limit support by queue manager final IHttpExecutor executor = executorSupplier.get(); - final String ending = (EthNetwork.TOBALABA.equals(network)) ? "com" : "io"; + final String ending = EthNetwork.TOBALABA.equals(network) ? "com" : "io"; final String baseUrl = "https://" + network.getDomain() + ".etherscan." + ending + "/api" + "?apikey=" + apiKey; - this.account = new AccountApiProvider(masterQueue, baseUrl, executor); - this.block = new BlockApiProvider(masterQueue, baseUrl, executor); - this.contract = new ContractApiProvider(masterQueue, baseUrl, executor); - this.logs = new LogsApiProvider(masterQueue, baseUrl, executor); - this.proxy = new ProxyApiProvider(masterQueue, baseUrl, executor); - this.stats = new StatisticApiProvider(masterQueue, baseUrl, executor); - this.txs = new TransactionApiProvider(masterQueue, baseUrl, executor); + this.account = new AccountApiProvider(queue, baseUrl, executor); + this.block = new BlockApiProvider(queue, baseUrl, executor); + this.contract = new ContractApiProvider(queue, baseUrl, executor); + this.logs = new LogsApiProvider(queue, baseUrl, executor); + this.proxy = new ProxyApiProvider(queue, baseUrl, executor); + this.stats = new StatisticApiProvider(queue, baseUrl, executor); + this.txs = new TransactionApiProvider(queue, baseUrl, executor); } @NotNull diff --git a/src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java b/src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java index f2376d6..cb0c6a5 100644 --- a/src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java @@ -62,7 +62,7 @@ public class ProxyApiProvider extends BasicProvider implements IProxyApi { ProxyApiProvider(final IQueueManager queue, final String baseUrl, final IHttpExecutor executor) { - super(queue, "proxy", baseUrl,executor); + super(queue, "proxy", baseUrl, executor); } @Override @@ -111,7 +111,8 @@ public Optional tx(final long blockNo, final long index) throws ApiExce final long compBlockNo = BasicUtils.compensateMinBlock(blockNo); final long compIndex = (index < 1) ? 1 : index; - final String urlParams = ACT_TX_BY_BLOCKNOINDEX_PARAM + TAG_PARAM + compBlockNo + INDEX_PARAM + "0x" + Long.toHexString(compIndex); + final String urlParams = ACT_TX_BY_BLOCKNOINDEX_PARAM + TAG_PARAM + compBlockNo + INDEX_PARAM + "0x" + + Long.toHexString(compIndex); final TxProxyTO response = getRequest(urlParams, TxProxyTO.class); return Optional.ofNullable(response.getResult()); } @@ -136,12 +137,12 @@ public int txSendCount(final String address) throws ApiException { @Override @NotNull public Optional txSendRaw(final String hexEncodedTx) throws ApiException { - if(BasicUtils.isNotHex(hexEncodedTx)) + if (BasicUtils.isNotHex(hexEncodedTx)) throw new InvalidDataHexException("Data is not encoded in hex format - " + hexEncodedTx); final String urlParams = ACT_SEND_RAW_TX_PARAM + HEX_PARAM + hexEncodedTx; final StringProxyTO response = postRequest(urlParams, "", StringProxyTO.class); - if(response.getError() != null) + if (response.getError() != null) throw new EtherScanException("Error occurred with code " + response.getError().getCode() + " with message " + response.getError().getMessage() + ", error id " + response.getId() + ", jsonRPC " + response.getJsonrpc()); @@ -163,12 +164,12 @@ public Optional txReceipt(final String txhash) throws ApiException @Override public Optional call(final String address, final String data) throws ApiException { BasicUtils.validateAddress(address); - if(BasicUtils.isNotHex(data)) + if (BasicUtils.isNotHex(data)) throw new InvalidDataHexException("Data is not hex encoded."); final String urlParams = ACT_CALL_PARAM + TO_PARAM + address + DATA_PARAM + data + TAG_LAST_PARAM; final StringProxyTO response = getRequest(urlParams, StringProxyTO.class); - return Optional.ofNullable (response.getResult()); + return Optional.ofNullable(response.getResult()); } @NotNull @@ -212,7 +213,7 @@ public BigInteger gasEstimated() throws ApiException { @NotNull @Override public BigInteger gasEstimated(final String hexData) throws ApiException { - if(!BasicUtils.isEmpty(hexData) && BasicUtils.isNotHex(hexData)) + if (!BasicUtils.isEmpty(hexData) && BasicUtils.isNotHex(hexData)) throw new InvalidDataHexException("Data is not in hex format."); final String urlParams = ACT_ESTIMATEGAS_PARAM + DATA_PARAM + hexData + GAS_PARAM + "2000000000000000"; diff --git a/src/main/java/io/api/etherscan/core/impl/StatisticApiProvider.java b/src/main/java/io/api/etherscan/core/impl/StatisticApiProvider.java index 0125850..d178a81 100644 --- a/src/main/java/io/api/etherscan/core/impl/StatisticApiProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/StatisticApiProvider.java @@ -41,7 +41,7 @@ public class StatisticApiProvider extends BasicProvider implements IStatisticApi public Supply supply() throws ApiException { final StringResponseTO response = getRequest(ACT_SUPPLY_PARAM, StringResponseTO.class); if (response.getStatus() != 1) - throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus()); + throw new EtherScanException(response); return new Supply(new BigInteger(response.getResult())); } @@ -54,7 +54,7 @@ public BigInteger supply(final String contract) throws ApiException { final String urlParams = ACT_TOKEN_SUPPLY_PARAM + CONTRACT_ADDRESS_PARAM + contract; final StringResponseTO response = getRequest(urlParams, StringResponseTO.class); if (response.getStatus() != 1) - throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus()); + throw new EtherScanException(response); return new BigInteger(response.getResult()); } @@ -64,7 +64,7 @@ public BigInteger supply(final String contract) throws ApiException { public Price lastPrice() throws ApiException { final PriceResponseTO response = getRequest(ACT_LASTPRICE_PARAM, PriceResponseTO.class); if (response.getStatus() != 1) - throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus()); + throw new EtherScanException(response); return response.getResult(); } diff --git a/src/main/java/io/api/etherscan/error/ApiException.java b/src/main/java/io/api/etherscan/error/ApiException.java index 087758e..33e4228 100644 --- a/src/main/java/io/api/etherscan/error/ApiException.java +++ b/src/main/java/io/api/etherscan/error/ApiException.java @@ -1,8 +1,6 @@ package io.api.etherscan.error; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 30.10.2018 */ diff --git a/src/main/java/io/api/etherscan/error/ApiKeyException.java b/src/main/java/io/api/etherscan/error/ApiKeyException.java index 0e2f81a..4e22934 100644 --- a/src/main/java/io/api/etherscan/error/ApiKeyException.java +++ b/src/main/java/io/api/etherscan/error/ApiKeyException.java @@ -1,8 +1,6 @@ package io.api.etherscan.error; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 05.11.2018 */ diff --git a/src/main/java/io/api/etherscan/error/ApiTimeoutException.java b/src/main/java/io/api/etherscan/error/ApiTimeoutException.java index 803731b..39b6e93 100644 --- a/src/main/java/io/api/etherscan/error/ApiTimeoutException.java +++ b/src/main/java/io/api/etherscan/error/ApiTimeoutException.java @@ -1,8 +1,6 @@ package io.api.etherscan.error; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 12.11.2018 */ diff --git a/src/main/java/io/api/etherscan/error/ConnectionException.java b/src/main/java/io/api/etherscan/error/ConnectionException.java index ec4bd8e..96a881c 100644 --- a/src/main/java/io/api/etherscan/error/ConnectionException.java +++ b/src/main/java/io/api/etherscan/error/ConnectionException.java @@ -6,6 +6,10 @@ */ public class ConnectionException extends ApiException { + public ConnectionException(String message) { + super(message); + } + public ConnectionException(String message, Throwable cause) { super(message, cause); } diff --git a/src/main/java/io/api/etherscan/error/EtherScanException.java b/src/main/java/io/api/etherscan/error/EtherScanException.java index 3865572..cb7dd7f 100644 --- a/src/main/java/io/api/etherscan/error/EtherScanException.java +++ b/src/main/java/io/api/etherscan/error/EtherScanException.java @@ -1,13 +1,22 @@ package io.api.etherscan.error; +import io.api.etherscan.model.utility.BaseResponseTO; +import io.api.etherscan.model.utility.StringResponseTO; + /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 29.10.2018 */ public class EtherScanException extends ApiException { + public EtherScanException(BaseResponseTO response) { + this(response.getMessage() + ", with status: " + response.getStatus()); + } + + public EtherScanException(StringResponseTO response) { + this(response.getResult() + ", with status: " + response.getStatus() + ", with message: " + response.getMessage()); + } + public EtherScanException(String message) { super(message); } diff --git a/src/main/java/io/api/etherscan/error/EventModelException.java b/src/main/java/io/api/etherscan/error/EventModelException.java new file mode 100644 index 0000000..feb60be --- /dev/null +++ b/src/main/java/io/api/etherscan/error/EventModelException.java @@ -0,0 +1,12 @@ +package io.api.etherscan.error; + +public class EventModelException extends ApiException { + + public EventModelException(String message) { + super(message); + } + + public EventModelException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/src/main/java/io/api/etherscan/error/InvalidAddressException.java b/src/main/java/io/api/etherscan/error/InvalidAddressException.java index b6a448c..9a0c143 100644 --- a/src/main/java/io/api/etherscan/error/InvalidAddressException.java +++ b/src/main/java/io/api/etherscan/error/InvalidAddressException.java @@ -1,8 +1,6 @@ package io.api.etherscan.error; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 29.10.2018 */ diff --git a/src/main/java/io/api/etherscan/error/InvalidDataHexException.java b/src/main/java/io/api/etherscan/error/InvalidDataHexException.java index 5b5952d..dd12cb9 100644 --- a/src/main/java/io/api/etherscan/error/InvalidDataHexException.java +++ b/src/main/java/io/api/etherscan/error/InvalidDataHexException.java @@ -1,8 +1,6 @@ package io.api.etherscan.error; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 02.11.2018 */ diff --git a/src/main/java/io/api/etherscan/error/InvalidTxHashException.java b/src/main/java/io/api/etherscan/error/InvalidTxHashException.java index fb18578..aba32c1 100644 --- a/src/main/java/io/api/etherscan/error/InvalidTxHashException.java +++ b/src/main/java/io/api/etherscan/error/InvalidTxHashException.java @@ -1,8 +1,6 @@ package io.api.etherscan.error; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 02.11.2018 */ diff --git a/src/main/java/io/api/etherscan/error/LogQueryException.java b/src/main/java/io/api/etherscan/error/LogQueryException.java index c72cd3e..504219f 100644 --- a/src/main/java/io/api/etherscan/error/LogQueryException.java +++ b/src/main/java/io/api/etherscan/error/LogQueryException.java @@ -1,8 +1,6 @@ package io.api.etherscan.error; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 31.10.2018 */ diff --git a/src/main/java/io/api/etherscan/error/ParseException.java b/src/main/java/io/api/etherscan/error/ParseException.java index 81974df..5dc6199 100644 --- a/src/main/java/io/api/etherscan/error/ParseException.java +++ b/src/main/java/io/api/etherscan/error/ParseException.java @@ -1,14 +1,19 @@ package io.api.etherscan.error; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 29.10.2018 */ public class ParseException extends ApiException { - public ParseException(String message, Throwable cause) { + private final String json; + + public ParseException(String message, Throwable cause, String json) { super(message, cause); + this.json = json; + } + + public String getJson() { + return json; } } diff --git a/src/main/java/io/api/etherscan/error/RateLimitException.java b/src/main/java/io/api/etherscan/error/RateLimitException.java new file mode 100644 index 0000000..c29f54d --- /dev/null +++ b/src/main/java/io/api/etherscan/error/RateLimitException.java @@ -0,0 +1,12 @@ +package io.api.etherscan.error; + +/** + * @author iSnow + * @since 2020-10-06 + */ +public class RateLimitException extends ApiException { + + public RateLimitException(String message) { + super(message); + } +} diff --git a/src/main/java/io/api/etherscan/executor/IHttpExecutor.java b/src/main/java/io/api/etherscan/executor/IHttpExecutor.java index 0a47714..0c80282 100644 --- a/src/main/java/io/api/etherscan/executor/IHttpExecutor.java +++ b/src/main/java/io/api/etherscan/executor/IHttpExecutor.java @@ -19,7 +19,7 @@ public interface IHttpExecutor { /** * Performs a Http POST request * - * @param url as string + * @param url as string * @param data to post * @return result as string */ diff --git a/src/main/java/io/api/etherscan/executor/impl/HttpExecutor.java b/src/main/java/io/api/etherscan/executor/impl/HttpExecutor.java index 6b1d1e1..5ba39f2 100644 --- a/src/main/java/io/api/etherscan/executor/impl/HttpExecutor.java +++ b/src/main/java/io/api/etherscan/executor/impl/HttpExecutor.java @@ -18,8 +18,7 @@ import java.util.zip.GZIPInputStream; import java.util.zip.InflaterInputStream; -import static java.net.HttpURLConnection.HTTP_MOVED_PERM; -import static java.net.HttpURLConnection.HTTP_MOVED_TEMP; +import static java.net.HttpURLConnection.*; /** * Http client implementation @@ -66,8 +65,8 @@ public HttpExecutor(final int connectTimeout, final int readTimeout) { public HttpExecutor(final int connectTimeout, final int readTimeout, final Map headers) { - this.connectTimeout = (connectTimeout < 0) ? 0 : connectTimeout; - this.readTimeout = (readTimeout < 0) ? 0 : readTimeout; + this.connectTimeout = Math.max(connectTimeout, 0); + this.readTimeout = Math.max(readTimeout, 0); this.headers = headers; } @@ -88,6 +87,10 @@ public String get(final String urlAsString) { final int status = connection.getResponseCode(); if (status == HTTP_MOVED_TEMP || status == HTTP_MOVED_PERM) { return get(connection.getHeaderField("Location")); + } else if ((status >= HTTP_BAD_REQUEST) && (status < HTTP_INTERNAL_ERROR)) { + throw new ConnectionException("Protocol error: " + connection.getResponseMessage()); + } else if (status >= HTTP_INTERNAL_ERROR) { + throw new ConnectionException("Server error: " + connection.getResponseMessage()); } final String data = readData(connection); @@ -118,6 +121,10 @@ public String post(final String urlAsString, final String dataToPost) { final int status = connection.getResponseCode(); if (status == HTTP_MOVED_TEMP || status == HTTP_MOVED_PERM) { return post(connection.getHeaderField("Location"), dataToPost); + } else if ((status >= HTTP_BAD_REQUEST) && (status < HTTP_INTERNAL_ERROR)) { + throw new ConnectionException("Protocol error: " + connection.getResponseMessage()); + } else if (status >= HTTP_INTERNAL_ERROR) { + throw new ConnectionException("Server error: " + connection.getResponseMessage()); } final String data = readData(connection); diff --git a/src/main/java/io/api/etherscan/manager/IQueueManager.java b/src/main/java/io/api/etherscan/manager/IQueueManager.java index 3fddf19..3a65240 100644 --- a/src/main/java/io/api/etherscan/manager/IQueueManager.java +++ b/src/main/java/io/api/etherscan/manager/IQueueManager.java @@ -1,9 +1,8 @@ package io.api.etherscan.manager; /** - * Queue manager to support API limits (EtherScan 5request\sec limit) - * Managers grants turn if the limit is not exhausted - * And resets queue each set period + * Queue manager to support API limits (EtherScan 5request\sec limit) Managers + * grants turn if the limit is not exhausted And resets queue each set period * * @author GoodforGod * @since 30.10.2018 @@ -12,7 +11,6 @@ public interface IQueueManager { /** * Waits in queue for chance to take turn - * @return can or can not rake turn */ - boolean takeTurn(); + void takeTurn(); } diff --git a/src/main/java/io/api/etherscan/manager/impl/FakeQueueManager.java b/src/main/java/io/api/etherscan/manager/impl/FakeQueueManager.java index 45241af..d8bc048 100644 --- a/src/main/java/io/api/etherscan/manager/impl/FakeQueueManager.java +++ b/src/main/java/io/api/etherscan/manager/impl/FakeQueueManager.java @@ -11,7 +11,5 @@ public class FakeQueueManager implements IQueueManager { @Override - public boolean takeTurn() { - return true; - } + public void takeTurn() {} } diff --git a/src/main/java/io/api/etherscan/manager/impl/QueueManager.java b/src/main/java/io/api/etherscan/manager/impl/QueueManager.java index f1d9f1a..517883c 100644 --- a/src/main/java/io/api/etherscan/manager/impl/QueueManager.java +++ b/src/main/java/io/api/etherscan/manager/impl/QueueManager.java @@ -2,15 +2,11 @@ import io.api.etherscan.manager.IQueueManager; -import java.util.List; import java.util.concurrent.*; -import java.util.logging.Logger; -import java.util.stream.Collectors; -import java.util.stream.IntStream; /** - * Queue implementation - * With size and reset time as params + * Queue Semaphore implementation with size and reset time as params + * * @see IQueueManager * * @author GoodforGod @@ -18,55 +14,27 @@ */ public class QueueManager implements IQueueManager { - private static final Logger logger = Logger.getLogger(QueueManager.class.getName()); + public static final QueueManager DEFAULT_KEY_QUEUE = new QueueManager(1, 7); + public static final QueueManager PERSONAL_KEY_QUEUE = new QueueManager(2, 1); - private final int queueSize; - private final BlockingQueue queue; - private final List queueValues; + private final Semaphore semaphore; - private final ScheduledExecutorService queueExecutor; - - public QueueManager(int queueSize, int queueResetTimeInSec) { - this(queueSize, queueResetTimeInSec, 0); + public QueueManager(int size, int resetInSec) { + this(size, resetInSec, resetInSec); } - public QueueManager(int queueSize, int queueResetTimeInSec, int delayInSec) { - this.queueSize = queueSize; - this.queueValues = generateList(queueSize); - this.queue = new ArrayBlockingQueue<>(queueSize); - - this.queueExecutor = Executors.newSingleThreadScheduledExecutor(); - this.queueExecutor.scheduleAtFixedRate(createTask(), delayInSec, queueResetTimeInSec, TimeUnit.SECONDS); + public QueueManager(int size, int queueResetTimeInSec, int delayInSec) { + this.semaphore = new Semaphore(size); + Executors.newSingleThreadScheduledExecutor() + .scheduleAtFixedRate(releaseLocks(size), delayInSec, queueResetTimeInSec, TimeUnit.SECONDS); } @Override - public boolean takeTurn() { - try { - queue.take(); - return true; - } catch (InterruptedException e) { - logger.warning(e.getLocalizedMessage()); - return false; - } - } - - private Runnable createTask() { - return () -> { - try { - if(queue.size() == queueSize) - return; - - queue.clear(); - queue.addAll(queueValues); - } catch (Exception e) { - logger.warning(e.getLocalizedMessage()); - } - }; + public void takeTurn() { + semaphore.acquireUninterruptibly(); } - private List generateList(int size) { - return IntStream.range(0, size) - .boxed() - .collect(Collectors.toList()); + private Runnable releaseLocks(int toRelease) { + return () -> semaphore.release(toRelease); } } diff --git a/src/main/java/io/api/etherscan/model/Abi.java b/src/main/java/io/api/etherscan/model/Abi.java index b5203bc..a48a11d 100644 --- a/src/main/java/io/api/etherscan/model/Abi.java +++ b/src/main/java/io/api/etherscan/model/Abi.java @@ -9,6 +9,7 @@ * @since 31.10.2018 */ public class Abi { + private String contractAbi; private boolean isVerified; @@ -39,12 +40,15 @@ public boolean isVerified() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Abi abi = (Abi) o; - if (isVerified != abi.isVerified) return false; + if (isVerified != abi.isVerified) + return false; return contractAbi != null ? contractAbi.equals(abi.contractAbi) : abi.contractAbi == null; } diff --git a/src/main/java/io/api/etherscan/model/Balance.java b/src/main/java/io/api/etherscan/model/Balance.java index 30cc676..5529a90 100644 --- a/src/main/java/io/api/etherscan/model/Balance.java +++ b/src/main/java/io/api/etherscan/model/Balance.java @@ -26,7 +26,7 @@ public static Balance of(BalanceTO balance) { return new Balance(balance.getAccount(), new BigInteger(balance.getBalance())); } - // + // public String getAddress() { return address; } @@ -50,16 +50,19 @@ public BigInteger getGwei() { public BigInteger getEther() { return balance.asEther(); } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Balance balance1 = (Balance) o; - if (!balance.equals(balance1.balance)) return false; + if (!balance.equals(balance1.balance)) + return false; return address != null ? address.equals(balance1.address) : balance1.address == null; } diff --git a/src/main/java/io/api/etherscan/model/BaseTx.java b/src/main/java/io/api/etherscan/model/BaseTx.java index af2286f..5aea827 100644 --- a/src/main/java/io/api/etherscan/model/BaseTx.java +++ b/src/main/java/io/api/etherscan/model/BaseTx.java @@ -26,13 +26,13 @@ abstract class BaseTx { private BigInteger gas; private BigInteger gasUsed; - // + // public long getBlockNumber() { return blockNumber; } public LocalDateTime getTimeStamp() { - if(_timeStamp == null && !BasicUtils.isEmpty(timeStamp)) + if (_timeStamp == null && !BasicUtils.isEmpty(timeStamp)) _timeStamp = LocalDateTime.ofEpochSecond(Long.valueOf(timeStamp), 0, ZoneOffset.UTC); return _timeStamp; } @@ -68,20 +68,27 @@ public BigInteger getGas() { public BigInteger getGasUsed() { return gasUsed; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BaseTx)) return false; + if (this == o) + return true; + if (!(o instanceof BaseTx)) + return false; BaseTx baseTx = (BaseTx) o; - if (blockNumber != baseTx.blockNumber) return false; - if (timeStamp != null ? !timeStamp.equals(baseTx.timeStamp) : baseTx.timeStamp != null) return false; - if (hash != null ? !hash.equals(baseTx.hash) : baseTx.hash != null) return false; - if (from != null ? !from.equals(baseTx.from) : baseTx.from != null) return false; - if (to != null ? !to.equals(baseTx.to) : baseTx.to != null) return false; + if (blockNumber != baseTx.blockNumber) + return false; + if (timeStamp != null ? !timeStamp.equals(baseTx.timeStamp) : baseTx.timeStamp != null) + return false; + if (hash != null ? !hash.equals(baseTx.hash) : baseTx.hash != null) + return false; + if (from != null ? !from.equals(baseTx.from) : baseTx.from != null) + return false; + if (to != null ? !to.equals(baseTx.to) : baseTx.to != null) + return false; return value != null ? value.equals(baseTx.value) : baseTx.value == null; } diff --git a/src/main/java/io/api/etherscan/model/Block.java b/src/main/java/io/api/etherscan/model/Block.java index 0406e4e..2e9b96b 100644 --- a/src/main/java/io/api/etherscan/model/Block.java +++ b/src/main/java/io/api/etherscan/model/Block.java @@ -19,13 +19,13 @@ public class Block { private String timeStamp; private LocalDateTime _timeStamp; - // + // public long getBlockNumber() { return blockNumber; } public LocalDateTime getTimeStamp() { - if(_timeStamp == null && !BasicUtils.isEmpty(timeStamp)) + if (_timeStamp == null && !BasicUtils.isEmpty(timeStamp)) _timeStamp = LocalDateTime.ofEpochSecond(Long.valueOf(timeStamp), 0, ZoneOffset.UTC); return _timeStamp; } @@ -33,12 +33,14 @@ public LocalDateTime getTimeStamp() { public BigInteger getBlockReward() { return blockReward; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Block block = (Block) o; diff --git a/src/main/java/io/api/etherscan/model/EthNetwork.java b/src/main/java/io/api/etherscan/model/EthNetwork.java index d10aead..f7b91de 100644 --- a/src/main/java/io/api/etherscan/model/EthNetwork.java +++ b/src/main/java/io/api/etherscan/model/EthNetwork.java @@ -7,6 +7,7 @@ * @since 28.10.2018 */ public enum EthNetwork { + MAINNET("api"), ROPSTEN("api-ropsten"), KOVAN("api-kovan"), diff --git a/src/main/java/io/api/etherscan/model/Log.java b/src/main/java/io/api/etherscan/model/Log.java index cf485fd..2a7cc09 100644 --- a/src/main/java/io/api/etherscan/model/Log.java +++ b/src/main/java/io/api/etherscan/model/Log.java @@ -32,9 +32,9 @@ public class Log { private String logIndex; private Long _logIndex; - // + // public Long getBlockNumber() { - if(_blockNumber == null && !BasicUtils.isEmpty(blockNumber)){ + if (_blockNumber == null && !BasicUtils.isEmpty(blockNumber)) { _blockNumber = BasicUtils.parseHex(blockNumber).longValue(); } return _blockNumber; @@ -49,7 +49,7 @@ public String getTransactionHash() { } public Long getTransactionIndex() { - if(_transactionIndex == null && !BasicUtils.isEmpty(transactionIndex)){ + if (_transactionIndex == null && !BasicUtils.isEmpty(transactionIndex)) { _transactionIndex = BasicUtils.parseHex(transactionIndex).longValue(); } @@ -57,21 +57,38 @@ public Long getTransactionIndex() { } public LocalDateTime getTimeStamp() { - if(_timeStamp == null && !BasicUtils.isEmpty(timeStamp)) { + if (_timeStamp == null && !BasicUtils.isEmpty(timeStamp)) { long formatted = (timeStamp.charAt(0) == '0' && timeStamp.charAt(1) == 'x') ? BasicUtils.parseHex(timeStamp).longValue() - : Long.valueOf(timeStamp); + : Long.parseLong(timeStamp); _timeStamp = LocalDateTime.ofEpochSecond(formatted, 0, ZoneOffset.UTC); } return _timeStamp; } + /** + * Return the "timeStamp" field of the event record as a long-int representing + * the milliseconds since the Unix epoch (1970-01-01 00:00:00). + * + * @return milliseconds between Unix epoch and `timeStamp`. If field is empty or + * null, returns null + */ + public Long getTimeStampAsMillis() { + if (BasicUtils.isEmpty(timeStamp)) { + return null; + } + long tsSecs = (timeStamp.charAt(0) == '0' && timeStamp.charAt(1) == 'x') + ? BasicUtils.parseHex(timeStamp).longValue() + : Long.parseLong(timeStamp); + return tsSecs * 1000; + } + public String getData() { return data; } public BigInteger getGasPrice() { - if(!BasicUtils.isEmpty(gasPrice)){ + if (!BasicUtils.isEmpty(gasPrice)) { _gasPrice = BasicUtils.parseHex(gasPrice); } @@ -79,7 +96,7 @@ public BigInteger getGasPrice() { } public BigInteger getGasUsed() { - if(!BasicUtils.isEmpty(gasUsed)){ + if (!BasicUtils.isEmpty(gasUsed)) { _gasUsed = BasicUtils.parseHex(gasUsed); } @@ -91,25 +108,30 @@ public List getTopics() { } public Long getLogIndex() { - if(_logIndex == null && !BasicUtils.isEmpty(logIndex)){ + if (_logIndex == null && !BasicUtils.isEmpty(logIndex)) { _logIndex = BasicUtils.parseHex(logIndex).longValue(); } return _logIndex; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Log log = (Log) o; - if (blockNumber != null ? !blockNumber.equals(log.blockNumber) : log.blockNumber != null) return false; - if (address != null ? !address.equals(log.address) : log.address != null) return false; + if (blockNumber != null ? !blockNumber.equals(log.blockNumber) : log.blockNumber != null) + return false; + if (address != null ? !address.equals(log.address) : log.address != null) + return false; if (transactionHash != null ? !transactionHash.equals(log.transactionHash) : log.transactionHash != null) return false; - if (timeStamp != null ? !timeStamp.equals(log.timeStamp) : log.timeStamp != null) return false; + if (timeStamp != null ? !timeStamp.equals(log.timeStamp) : log.timeStamp != null) + return false; return logIndex != null ? logIndex.equals(log.logIndex) : log.logIndex == null; } diff --git a/src/main/java/io/api/etherscan/model/Price.java b/src/main/java/io/api/etherscan/model/Price.java index f9839e2..9a37592 100644 --- a/src/main/java/io/api/etherscan/model/Price.java +++ b/src/main/java/io/api/etherscan/model/Price.java @@ -27,26 +27,30 @@ public double inBtc() { } public LocalDateTime usdTimestamp() { - if(_ethusd_timestamp == null) + if (_ethusd_timestamp == null) _ethusd_timestamp = LocalDateTime.ofEpochSecond(Long.valueOf(ethusd_timestamp), 0, ZoneOffset.UTC); return _ethusd_timestamp; } public LocalDateTime btcTimestamp() { - if(_ethbtc_timestamp == null) + if (_ethbtc_timestamp == null) _ethbtc_timestamp = LocalDateTime.ofEpochSecond(Long.valueOf(ethbtc_timestamp), 0, ZoneOffset.UTC); return _ethbtc_timestamp; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Price price = (Price) o; - if (Double.compare(price.ethusd, ethusd) != 0) return false; - if (Double.compare(price.ethbtc, ethbtc) != 0) return false; + if (Double.compare(price.ethusd, ethusd) != 0) + return false; + if (Double.compare(price.ethbtc, ethbtc) != 0) + return false; if (ethusd_timestamp != null ? !ethusd_timestamp.equals(price.ethusd_timestamp) : price.ethusd_timestamp != null) return false; return (ethbtc_timestamp != null ? !ethbtc_timestamp.equals(price.ethbtc_timestamp) : price.ethbtc_timestamp != null); diff --git a/src/main/java/io/api/etherscan/model/Status.java b/src/main/java/io/api/etherscan/model/Status.java index 71a4ebb..4a1fe18 100644 --- a/src/main/java/io/api/etherscan/model/Status.java +++ b/src/main/java/io/api/etherscan/model/Status.java @@ -24,12 +24,15 @@ public String getErrDescription() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Status status = (Status) o; - if (isError != status.isError) return false; + if (isError != status.isError) + return false; return errDescription != null ? errDescription.equals(status.errDescription) : status.errDescription == null; } diff --git a/src/main/java/io/api/etherscan/model/TokenBalance.java b/src/main/java/io/api/etherscan/model/TokenBalance.java index b40ae0c..e198079 100644 --- a/src/main/java/io/api/etherscan/model/TokenBalance.java +++ b/src/main/java/io/api/etherscan/model/TokenBalance.java @@ -23,9 +23,12 @@ public String getContract() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + if (!super.equals(o)) + return false; TokenBalance that = (TokenBalance) o; diff --git a/src/main/java/io/api/etherscan/model/Tx.java b/src/main/java/io/api/etherscan/model/Tx.java index 68f00f1..6fce75b 100644 --- a/src/main/java/io/api/etherscan/model/Tx.java +++ b/src/main/java/io/api/etherscan/model/Tx.java @@ -21,7 +21,7 @@ public class Tx extends BaseTx { private String isError; private String txreceipt_status; - // + // public long getNonce() { return nonce; } @@ -53,19 +53,25 @@ public BigInteger getCumulativeGasUsed() { public long getConfirmations() { return confirmations; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + if (!super.equals(o)) + return false; Tx tx = (Tx) o; - if (nonce != tx.nonce) return false; - if (transactionIndex != tx.transactionIndex) return false; - if (blockHash != null ? !blockHash.equals(tx.blockHash) : tx.blockHash != null) return false; + if (nonce != tx.nonce) + return false; + if (transactionIndex != tx.transactionIndex) + return false; + if (blockHash != null ? !blockHash.equals(tx.blockHash) : tx.blockHash != null) + return false; return isError != null ? isError.equals(tx.isError) : tx.isError == null; } diff --git a/src/main/java/io/api/etherscan/model/TxInternal.java b/src/main/java/io/api/etherscan/model/TxInternal.java index 1d9d8a8..e7b75d9 100644 --- a/src/main/java/io/api/etherscan/model/TxInternal.java +++ b/src/main/java/io/api/etherscan/model/TxInternal.java @@ -13,7 +13,7 @@ public class TxInternal extends BaseTx { private int isError; private String errCode; - // + // public String getType() { return type; } @@ -29,17 +29,21 @@ public boolean haveError() { public String getErrCode() { return errCode; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TxInternal)) return false; - if (!super.equals(o)) return false; + if (this == o) + return true; + if (!(o instanceof TxInternal)) + return false; + if (!super.equals(o)) + return false; TxInternal that = (TxInternal) o; - if (traceId != that.traceId) return false; + if (traceId != that.traceId) + return false; return errCode != null ? errCode.equals(that.errCode) : that.errCode == null; } diff --git a/src/main/java/io/api/etherscan/model/TxToken.java b/src/main/java/io/api/etherscan/model/TxToken.java index 985066b..8f5e36f 100644 --- a/src/main/java/io/api/etherscan/model/TxToken.java +++ b/src/main/java/io/api/etherscan/model/TxToken.java @@ -18,7 +18,7 @@ public class TxToken extends BaseTx { private long cumulativeGasUsed; private long confirmations; - // + // public long getNonce() { return nonce; } @@ -54,7 +54,7 @@ public long getCumulativeGasUsed() { public long getConfirmations() { return confirmations; } - // + // @Override public String toString() { diff --git a/src/main/java/io/api/etherscan/model/Uncle.java b/src/main/java/io/api/etherscan/model/Uncle.java index bf5145d..2ee206b 100644 --- a/src/main/java/io/api/etherscan/model/Uncle.java +++ b/src/main/java/io/api/etherscan/model/Uncle.java @@ -14,7 +14,7 @@ public class Uncle { private BigInteger blockreward; private int unclePosition; - // + // public String getMiner() { return miner; } @@ -26,17 +26,21 @@ public BigInteger getBlockreward() { public int getUnclePosition() { return unclePosition; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Uncle uncle = (Uncle) o; - if (unclePosition != uncle.unclePosition) return false; - if (miner != null ? !miner.equals(uncle.miner) : uncle.miner != null) return false; + if (unclePosition != uncle.unclePosition) + return false; + if (miner != null ? !miner.equals(uncle.miner) : uncle.miner != null) + return false; return blockreward != null ? blockreward.equals(uncle.blockreward) : uncle.blockreward == null; } diff --git a/src/main/java/io/api/etherscan/model/UncleBlock.java b/src/main/java/io/api/etherscan/model/UncleBlock.java index 6b7eb4f..88c975d 100644 --- a/src/main/java/io/api/etherscan/model/UncleBlock.java +++ b/src/main/java/io/api/etherscan/model/UncleBlock.java @@ -16,7 +16,7 @@ public class UncleBlock extends Block { private List uncles; private String uncleInclusionReward; - // + // public boolean isEmpty() { return getBlockNumber() == 0 && getBlockReward() == null && getTimeStamp() == null @@ -34,13 +34,16 @@ public List getUncles() { public String getUncleInclusionReward() { return uncleInclusionReward; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + if (!super.equals(o)) + return false; UncleBlock that = (UncleBlock) o; diff --git a/src/main/java/io/api/etherscan/model/Wei.java b/src/main/java/io/api/etherscan/model/Wei.java index cf5f465..35f90d0 100644 --- a/src/main/java/io/api/etherscan/model/Wei.java +++ b/src/main/java/io/api/etherscan/model/Wei.java @@ -16,7 +16,7 @@ public Wei(BigInteger value) { this.result = value; } - // + // public BigInteger getValue() { return result; } @@ -36,12 +36,14 @@ public BigInteger asGwei() { public BigInteger asEther() { return result.divide(BigInteger.valueOf(1000000000000000L)); } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Wei wei = (Wei) o; diff --git a/src/main/java/io/api/etherscan/model/proxy/BlockProxy.java b/src/main/java/io/api/etherscan/model/proxy/BlockProxy.java index 414a797..3d7ddd3 100644 --- a/src/main/java/io/api/etherscan/model/proxy/BlockProxy.java +++ b/src/main/java/io/api/etherscan/model/proxy/BlockProxy.java @@ -44,9 +44,9 @@ public class BlockProxy { private String transactionsRoot; private List transactions; - // + // public Long getNumber() { - if(_number == null && !BasicUtils.isEmpty(number)) + if (_number == null && !BasicUtils.isEmpty(number)) _number = BasicUtils.parseHex(number).longValue(); return _number; } @@ -64,7 +64,7 @@ public String getStateRoot() { } public Long getSize() { - if(_size == null && !BasicUtils.isEmpty(size)) + if (_size == null && !BasicUtils.isEmpty(size)) _size = BasicUtils.parseHex(size).longValue(); return _size; } @@ -78,7 +78,7 @@ public String getTotalDifficulty() { } public LocalDateTime getTimeStamp() { - if(_timestamp == null && !BasicUtils.isEmpty(timestamp)) + if (_timestamp == null && !BasicUtils.isEmpty(timestamp)) _timestamp = LocalDateTime.ofEpochSecond(BasicUtils.parseHex(timestamp).longValue(), 0, ZoneOffset.UTC); return _timestamp; } @@ -104,13 +104,13 @@ public String getMixHash() { } public BigInteger getGasUsed() { - if(_gasUsed == null && !BasicUtils.isEmpty(gasUsed)) + if (_gasUsed == null && !BasicUtils.isEmpty(gasUsed)) _gasUsed = BasicUtils.parseHex(gasUsed); return _gasUsed; } public BigInteger getGasLimit() { - if(_gasLimit == null && !BasicUtils.isEmpty(gasLimit)) + if (_gasLimit == null && !BasicUtils.isEmpty(gasLimit)) _gasLimit = BasicUtils.parseHex(gasLimit); return _gasLimit; } @@ -134,17 +134,21 @@ public String getTransactionsRoot() { public List getTransactions() { return transactions; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; BlockProxy that = (BlockProxy) o; - if (number != null ? !number.equals(that.number) : that.number != null) return false; - if (hash != null ? !hash.equals(that.hash) : that.hash != null) return false; + if (number != null ? !number.equals(that.number) : that.number != null) + return false; + if (hash != null ? !hash.equals(that.hash) : that.hash != null) + return false; return parentHash != null ? parentHash.equals(that.parentHash) : that.parentHash == null; } diff --git a/src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java b/src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java index b6e2bcc..d69a627 100644 --- a/src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java +++ b/src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java @@ -32,7 +32,7 @@ public class ReceiptProxy { private List logs; private String logsBloom; - // + // public String getRoot() { return root; } @@ -46,7 +46,7 @@ public String getTo() { } public Long getBlockNumber() { - if(_blockNumber == null && !BasicUtils.isEmpty(blockNumber)) + if (_blockNumber == null && !BasicUtils.isEmpty(blockNumber)) _blockNumber = BasicUtils.parseHex(blockNumber).longValue(); return _blockNumber; } @@ -60,19 +60,19 @@ public String getTransactionHash() { } public Long getTransactionIndex() { - if(_transactionIndex == null && !BasicUtils.isEmpty(transactionIndex)) + if (_transactionIndex == null && !BasicUtils.isEmpty(transactionIndex)) _transactionIndex = BasicUtils.parseHex(transactionIndex).longValue(); return _transactionIndex; } public BigInteger getGasUsed() { - if(_gasUsed == null && !BasicUtils.isEmpty(gasUsed)) + if (_gasUsed == null && !BasicUtils.isEmpty(gasUsed)) _gasUsed = BasicUtils.parseHex(gasUsed); return _gasUsed; } public BigInteger getCumulativeGasUsed() { - if(_cumulativeGasUsed == null && !BasicUtils.isEmpty(cumulativeGasUsed)) + if (_cumulativeGasUsed == null && !BasicUtils.isEmpty(cumulativeGasUsed)) _cumulativeGasUsed = BasicUtils.parseHex(cumulativeGasUsed); return _cumulativeGasUsed; } @@ -88,16 +88,19 @@ public List getLogs() { public String getLogsBloom() { return logsBloom; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; ReceiptProxy that = (ReceiptProxy) o; - if (blockNumber != null ? !blockNumber.equals(that.blockNumber) : that.blockNumber != null) return false; + if (blockNumber != null ? !blockNumber.equals(that.blockNumber) : that.blockNumber != null) + return false; if (transactionHash != null ? !transactionHash.equals(that.transactionHash) : that.transactionHash != null) return false; return transactionIndex != null ? transactionIndex.equals(that.transactionIndex) : that.transactionIndex == null; diff --git a/src/main/java/io/api/etherscan/model/proxy/TxProxy.java b/src/main/java/io/api/etherscan/model/proxy/TxProxy.java index c45e679..25b50c8 100644 --- a/src/main/java/io/api/etherscan/model/proxy/TxProxy.java +++ b/src/main/java/io/api/etherscan/model/proxy/TxProxy.java @@ -32,7 +32,7 @@ public class TxProxy { private String blockNumber; private Long _blockNumber; - // + // public String getTo() { return to; } @@ -42,7 +42,7 @@ public String getHash() { } public Long getTransactionIndex() { - if(_transactionIndex == null && !BasicUtils.isEmpty(transactionIndex)) + if (_transactionIndex == null && !BasicUtils.isEmpty(transactionIndex)) _transactionIndex = BasicUtils.parseHex(transactionIndex).longValue(); return _transactionIndex; } @@ -52,7 +52,7 @@ public String getFrom() { } public BigInteger getGas() { - if(_gas == null && !BasicUtils.isEmpty(gas)) + if (_gas == null && !BasicUtils.isEmpty(gas)) _gas = BasicUtils.parseHex(gas); return _gas; } @@ -74,7 +74,7 @@ public String getR() { } public Long getNonce() { - if(_nonce == null && !BasicUtils.isEmpty(nonce)) + if (_nonce == null && !BasicUtils.isEmpty(nonce)) _nonce = BasicUtils.parseHex(nonce).longValue(); return _nonce; } @@ -84,7 +84,7 @@ public String getValue() { } public BigInteger getGasPrice() { - if(_gasPrice == null && !BasicUtils.isEmpty(gasPrice)) + if (_gasPrice == null && !BasicUtils.isEmpty(gasPrice)) _gasPrice = BasicUtils.parseHex(gasPrice); return _gasPrice; } @@ -94,21 +94,25 @@ public String getBlockHash() { } public Long getBlockNumber() { - if(_blockNumber == null && !BasicUtils.isEmpty(blockNumber)) + if (_blockNumber == null && !BasicUtils.isEmpty(blockNumber)) _blockNumber = BasicUtils.parseHex(blockNumber).longValue(); return _blockNumber; } - // + // @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; TxProxy txProxy = (TxProxy) o; - if (hash != null ? !hash.equals(txProxy.hash) : txProxy.hash != null) return false; - if (blockHash != null ? !blockHash.equals(txProxy.blockHash) : txProxy.blockHash != null) return false; + if (hash != null ? !hash.equals(txProxy.hash) : txProxy.hash != null) + return false; + if (blockHash != null ? !blockHash.equals(txProxy.blockHash) : txProxy.blockHash != null) + return false; return blockNumber != null ? blockNumber.equals(txProxy.blockNumber) : txProxy.blockNumber == null; } diff --git a/src/main/java/io/api/etherscan/model/query/IQueryBuilder.java b/src/main/java/io/api/etherscan/model/query/IQueryBuilder.java index 17bc2f9..6a76c62 100644 --- a/src/main/java/io/api/etherscan/model/query/IQueryBuilder.java +++ b/src/main/java/io/api/etherscan/model/query/IQueryBuilder.java @@ -10,5 +10,6 @@ * @since 31.10.2018 */ public interface IQueryBuilder { + LogQuery build() throws LogQueryException; } diff --git a/src/main/java/io/api/etherscan/model/query/LogOp.java b/src/main/java/io/api/etherscan/model/query/LogOp.java index 5c6138c..0c0ebee 100644 --- a/src/main/java/io/api/etherscan/model/query/LogOp.java +++ b/src/main/java/io/api/etherscan/model/query/LogOp.java @@ -7,6 +7,7 @@ * @since 31.10.2018 */ public enum LogOp { + AND("and"), OR("or"); diff --git a/src/main/java/io/api/etherscan/model/query/impl/LogQuery.java b/src/main/java/io/api/etherscan/model/query/impl/LogQuery.java index ae429b0..3ba6c4f 100644 --- a/src/main/java/io/api/etherscan/model/query/impl/LogQuery.java +++ b/src/main/java/io/api/etherscan/model/query/impl/LogQuery.java @@ -5,8 +5,7 @@ /** * Final builded container for The Event Log API * - * EtherScan - API Descriptions - * https://etherscan.io/apis#logs + * EtherScan - API Descriptions https://etherscan.io/apis#logs * * @see LogQueryBuilder * @see ILogsApi diff --git a/src/main/java/io/api/etherscan/model/query/impl/LogQueryBuilder.java b/src/main/java/io/api/etherscan/model/query/impl/LogQueryBuilder.java index d4e10be..bd8a9fc 100644 --- a/src/main/java/io/api/etherscan/model/query/impl/LogQueryBuilder.java +++ b/src/main/java/io/api/etherscan/model/query/impl/LogQueryBuilder.java @@ -2,6 +2,7 @@ import io.api.etherscan.core.ILogsApi; import io.api.etherscan.error.LogQueryException; +import io.api.etherscan.model.query.IQueryBuilder; import io.api.etherscan.util.BasicUtils; /** @@ -12,7 +13,7 @@ * @author GoodforGod * @since 31.10.2018 */ -public class LogQueryBuilder { +public class LogQueryBuilder implements IQueryBuilder { private static final long MIN_BLOCK = 0; private static final long MAX_BLOCK = 99999999999L; @@ -40,39 +41,44 @@ public static LogQueryBuilder with(String address, long startBlock, long endBloc } public LogTopicSingle topic(String topic0) { - if(BasicUtils.isNotHex(topic0)) + if (BasicUtils.isNotHex(topic0)) throw new LogQueryException("topic0 can not be empty or non hex."); return new LogTopicSingle(address, startBlock, endBlock, topic0); } public LogTopicTuple topic(String topic0, String topic1) { - if(BasicUtils.isNotHex(topic0)) + if (BasicUtils.isNotHex(topic0)) throw new LogQueryException("topic0 can not be empty or non hex."); - if(BasicUtils.isNotHex(topic1)) + if (BasicUtils.isNotHex(topic1)) throw new LogQueryException("topic1 can not be empty or non hex."); return new LogTopicTuple(address, startBlock, endBlock, topic0, topic1); } public LogTopicTriple topic(String topic0, String topic1, String topic2) { - if(BasicUtils.isNotHex(topic0)) + if (BasicUtils.isNotHex(topic0)) throw new LogQueryException("topic0 can not be empty or non hex."); - if(BasicUtils.isNotHex(topic1)) + if (BasicUtils.isNotHex(topic1)) throw new LogQueryException("topic1 can not be empty or non hex."); - if(BasicUtils.isNotHex(topic2)) + if (BasicUtils.isNotHex(topic2)) throw new LogQueryException("topic2 can not be empty or non hex."); return new LogTopicTriple(address, startBlock, endBlock, topic0, topic1, topic2); } public LogTopicQuadro topic(String topic0, String topic1, String topic2, String topic3) { - if(BasicUtils.isNotHex(topic0)) + if (BasicUtils.isNotHex(topic0)) throw new LogQueryException("topic0 can not be empty or non hex."); - if(BasicUtils.isNotHex(topic1)) + if (BasicUtils.isNotHex(topic1)) throw new LogQueryException("topic1 can not be empty or non hex."); - if(BasicUtils.isNotHex(topic2)) + if (BasicUtils.isNotHex(topic2)) throw new LogQueryException("topic2 can not be empty or non hex."); - if(BasicUtils.isNotHex(topic3)) + if (BasicUtils.isNotHex(topic3)) throw new LogQueryException("topic3 can not be empty or non hex."); return new LogTopicQuadro(address, startBlock, endBlock, topic0, topic1, topic2, topic3); } + + @Override + public LogQuery build() throws LogQueryException { + return new LogQuery("&address=" + this.address + "&fromBlock=" + this.startBlock + "&toBlock=" + this.endBlock); + } } diff --git a/src/main/java/io/api/etherscan/model/utility/BlockParam.java b/src/main/java/io/api/etherscan/model/utility/BlockParam.java index 22774f2..cbc5a3e 100644 --- a/src/main/java/io/api/etherscan/model/utility/BlockParam.java +++ b/src/main/java/io/api/etherscan/model/utility/BlockParam.java @@ -7,6 +7,7 @@ * @since 31.10.2018 */ public class BlockParam { + private long startBlock; private long endBlock; diff --git a/src/main/java/io/api/etherscan/util/BasicUtils.java b/src/main/java/io/api/etherscan/util/BasicUtils.java index cec41e5..0d2a654 100644 --- a/src/main/java/io/api/etherscan/util/BasicUtils.java +++ b/src/main/java/io/api/etherscan/util/BasicUtils.java @@ -108,9 +108,10 @@ public static void validateTxResponse(T response) { if (response.getStatus() != 1) { if (response.getMessage() == null) { - throw new EtherScanException("Unexpected Etherscan exception, no information from server about error, code " + response.getStatus()); + throw new EtherScanException( + "Unexpected Etherscan exception, no information from server about error, code " + response.getStatus()); } else if (!response.getMessage().startsWith("No tra") && !response.getMessage().startsWith("No rec")) { - throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus()); + throw new EtherScanException(response); } } } diff --git a/src/test/java/io/api/ApiRunner.java b/src/test/java/io/api/ApiRunner.java new file mode 100644 index 0000000..6f608d8 --- /dev/null +++ b/src/test/java/io/api/ApiRunner.java @@ -0,0 +1,51 @@ +package io.api; + +import io.api.etherscan.core.impl.EtherScanApi; +import io.api.etherscan.manager.impl.QueueManager; +import io.api.etherscan.model.EthNetwork; +import org.junit.Assert; + +public class ApiRunner extends Assert { + + private static final EtherScanApi api; + private static final EtherScanApi apiRopsten; + private static final EtherScanApi apiRinkeby; + private static final EtherScanApi apiKovan; + private static final String key; + + static { + final String apiKey = System.getenv("API_KEY"); + key = (apiKey == null || apiKey.isEmpty()) + ? EtherScanApi.DEFAULT_KEY + : apiKey; + + final QueueManager queue = key.equals(EtherScanApi.DEFAULT_KEY) + ? QueueManager.DEFAULT_KEY_QUEUE + : new QueueManager(1, 2); + + api = new EtherScanApi(key, EthNetwork.MAINNET, queue); + apiRopsten = new EtherScanApi(key, EthNetwork.ROPSTEN, queue); + apiRinkeby = new EtherScanApi(key, EthNetwork.RINKEBY, queue); + apiKovan = new EtherScanApi(key, EthNetwork.KOVAN, queue); + } + + public static String getKey() { + return key; + } + + public static EtherScanApi getApi() { + return api; + } + + public static EtherScanApi getApiRopsten() { + return apiRopsten; + } + + public static EtherScanApi getApiRinkeby() { + return apiRinkeby; + } + + public static EtherScanApi getApiKovan() { + return apiKovan; + } +} diff --git a/src/test/java/io/api/etherscan/EtherScanApiTest.java b/src/test/java/io/api/etherscan/EtherScanApiTest.java index 2d0d978..5071a68 100644 --- a/src/test/java/io/api/etherscan/EtherScanApiTest.java +++ b/src/test/java/io/api/etherscan/EtherScanApiTest.java @@ -1,5 +1,6 @@ package io.api.etherscan; +import io.api.ApiRunner; import io.api.etherscan.core.impl.EtherScanApi; import io.api.etherscan.error.ApiException; import io.api.etherscan.error.ApiKeyException; @@ -9,22 +10,20 @@ import io.api.etherscan.model.Balance; import io.api.etherscan.model.Block; import io.api.etherscan.model.EthNetwork; -import org.junit.Assert; import org.junit.Test; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.function.Supplier; /** - * ! NO DESCRIPTION ! - * * @author GoodforGod * @since 05.11.2018 */ -public class EtherScanApiTest extends Assert { +public class EtherScanApiTest extends ApiRunner { - private EthNetwork network = EthNetwork.KOVAN; - private String validKey = "YourKey"; + private final EthNetwork network = EthNetwork.KOVAN; + private final String validKey = "YourKey"; @Test public void validKey() { @@ -59,31 +58,28 @@ public void noTimeoutOnRead() { @Test public void noTimeoutOnReadGroli() { Supplier supplier = () -> new HttpExecutor(300); - EtherScanApi api = new EtherScanApi(EthNetwork.GORLI, supplier); - Balance balance = api.account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7"); + Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7"); assertNotNull(balance); } @Test public void noTimeoutOnReadTobalala() { Supplier supplier = () -> new HttpExecutor(30000); - EtherScanApi api = new EtherScanApi(EthNetwork.TOBALABA, supplier); - Balance balance = api.account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7"); + Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7"); assertNotNull(balance); } @Test public void noTimeoutUnlimitedAwait() { - Supplier supplier = () -> new HttpExecutor(-30, -300); - EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET, supplier); - Balance balance = api.account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7"); + Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7"); assertNotNull(balance); } @Test(expected = ApiTimeoutException.class) - public void timeout() { + public void timeout() throws InterruptedException { + TimeUnit.SECONDS.sleep(5); Supplier supplier = () -> new HttpExecutor(300, 300); - EtherScanApi api = new EtherScanApi(EthNetwork.KOVAN, supplier); + EtherScanApi api = new EtherScanApi(getKey(), EthNetwork.KOVAN, supplier); List blocks = api.account().minedBlocks("0x0010f94b296A852aAac52EA6c5Ac72e03afD032D"); assertNotNull(blocks); } diff --git a/src/test/java/io/api/etherscan/account/AccountBalanceListTest.java b/src/test/java/io/api/etherscan/account/AccountBalanceListTest.java index 3dac0c0..fdeb1e9 100644 --- a/src/test/java/io/api/etherscan/account/AccountBalanceListTest.java +++ b/src/test/java/io/api/etherscan/account/AccountBalanceListTest.java @@ -1,10 +1,9 @@ package io.api.etherscan.account; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.model.Balance; import io.api.support.AddressUtil; -import org.junit.Assert; import org.junit.Test; import java.math.BigInteger; @@ -17,9 +16,7 @@ * @author GoodforGod * @since 03.11.2018 */ -public class AccountBalanceListTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class AccountBalanceListTest extends ApiRunner { @Test public void correct() { @@ -27,13 +24,13 @@ public void correct() { addresses.add("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); addresses.add("0xC9F32CE1127e44C51cbD182D6364F3D707Fd0d47"); - List balances = api.account().balances(addresses); + List balances = getApi().account().balances(addresses); assertNotNull(balances); assertFalse(balances.isEmpty()); assertEquals(2, balances.size()); assertNotEquals(balances.get(0), balances.get(1)); assertNotEquals(balances.get(0).hashCode(), balances.get(1).hashCode()); - for(Balance balance : balances) { + for (Balance balance : balances) { assertNotNull(balance.getAddress()); assertNotNull(balance.getGwei()); assertNotNull(balance.getKwei()); @@ -50,20 +47,15 @@ public void correct() { public void correctMoreThat20Addresses() { List addresses = AddressUtil.genRealAddresses(); - List balances = api.account().balances(addresses); + List balances = getApi().account().balances(addresses); assertNotNull(balances); assertFalse(balances.isEmpty()); assertEquals(25, balances.size()); - for(Balance balance : balances) { + for (Balance balance : balances) { assertNotNull(balance.getAddress()); - assertNotEquals(0, balance.getWei()); - assertNotEquals(0, balance.getKwei()); - assertNotEquals(0, balance.getMwei()); - assertNotEquals(0, balance.getEther()); - assertNotEquals(0, balance.getGwei()); } - assertFalse(balances.get(0).equals(balances.get(1))); + assertNotEquals(balances.get(0), balances.get(1)); } @Test(expected = InvalidAddressException.class) @@ -72,13 +64,13 @@ public void invalidParamWithError() { addresses.add("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); addresses.add("C9F32CE1127e44C51cbD182D6364F3D707Fd0d47"); - api.account().balances(addresses); + getApi().account().balances(addresses); } @Test public void emptyParamList() { List addresses = new ArrayList<>(); - List balances = api.account().balances(addresses); + List balances = getApi().account().balances(addresses); assertNotNull(balances); assertTrue(balances.isEmpty()); } @@ -89,11 +81,11 @@ public void correctParamWithEmptyExpectedResult() { addresses.add("0x1327cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); addresses.add("0xC1F32CE1127e44C51cbD182D6364F3D707Fd0d47"); - List balances = api.account().balances(addresses); + List balances = getApi().account().balances(addresses); assertNotNull(balances); assertFalse(balances.isEmpty()); assertEquals(2, balances.size()); - for(Balance balance : balances) { + for (Balance balance : balances) { assertNotNull(balance.getAddress()); assertEquals(0, balance.getWei().intValue()); } diff --git a/src/test/java/io/api/etherscan/account/AccountBalanceTest.java b/src/test/java/io/api/etherscan/account/AccountBalanceTest.java index 2aaa0cb..76aca68 100644 --- a/src/test/java/io/api/etherscan/account/AccountBalanceTest.java +++ b/src/test/java/io/api/etherscan/account/AccountBalanceTest.java @@ -1,16 +1,14 @@ package io.api.etherscan.account; +import io.api.ApiRunner; import io.api.etherscan.core.impl.EtherScanApi; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.model.Balance; -import io.api.etherscan.model.EthNetwork; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import java.math.BigInteger; import java.util.Arrays; import java.util.Collection; @@ -21,12 +19,12 @@ * @since 03.11.2018 */ @RunWith(Parameterized.class) -public class AccountBalanceTest extends Assert { +public class AccountBalanceTest extends ApiRunner { - private EtherScanApi api; - private String addressCorrect; - private String addressInvalid; - private String addressNoResponse; + private final EtherScanApi api; + private final String addressCorrect; + private final String addressInvalid; + private final String addressNoResponse; public AccountBalanceTest(EtherScanApi api, String addressCorrect, String addressInvalid, String addressNoResponse) { this.api = api; @@ -37,31 +35,13 @@ public AccountBalanceTest(EtherScanApi api, String addressCorrect, String addres @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ + return Arrays.asList(new Object[][] { { - new EtherScanApi(), + getApi(), "0x8d4426f94e42f721C7116E81d6688cd935cB3b4F", "8d4426f94e42f721C7116E81d6688cd935cB3b4F", "0x1d4426f94e42f721C7116E81d6688cd935cB3b4F" - }, - { - new EtherScanApi(EthNetwork.ROPSTEN), - "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a", - "xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a", - "0x1dbd2b932c763ba5b1b7ae3b362eac3e8d40121a" - }, - { - new EtherScanApi(EthNetwork.RINKEBY), - "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a", - "xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a", - "0x1dbd2b932c763ba5b1b7ae3b362eac3e8d40121a" - }, - { - new EtherScanApi(EthNetwork.KOVAN), - "0xB9F36EE9df7E2A24B61b1738F4127BFDe8bA1A87", - "xB9F36EE9df7E2A24B61b1738F4127BFDe8bA1A87", - "0xB1F36EE9df7E2A24B61b1738F4127BFDe8bA1A87" - }, + } }); } @@ -75,13 +55,12 @@ public void correct() { assertNotNull(balance.getGwei()); assertNotNull(balance.getEther()); assertNotNull(balance.getAddress()); - assertNotEquals(BigInteger.ZERO, balance.getWei()); assertNotNull(balance.toString()); } @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - Balance balance = api.account().balance(addressInvalid); + Balance balance = getApi().account().balance(addressInvalid); } @Test diff --git a/src/test/java/io/api/etherscan/account/AccountMinedBlocksTest.java b/src/test/java/io/api/etherscan/account/AccountMinedBlocksTest.java index 5f44b68..3a46858 100644 --- a/src/test/java/io/api/etherscan/account/AccountMinedBlocksTest.java +++ b/src/test/java/io/api/etherscan/account/AccountMinedBlocksTest.java @@ -1,10 +1,9 @@ package io.api.etherscan.account; +import io.api.ApiRunner; import io.api.etherscan.core.impl.EtherScanApi; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.model.Block; -import io.api.etherscan.model.EthNetwork; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -21,13 +20,13 @@ * @since 03.11.2018 */ @RunWith(Parameterized.class) -public class AccountMinedBlocksTest extends Assert { +public class AccountMinedBlocksTest extends ApiRunner { - private EtherScanApi api; - private int blocksMined; - private String addressCorrect; - private String addressInvalid; - private String addressNoResponse; + private final EtherScanApi api; + private final int blocksMined; + private final String addressCorrect; + private final String addressInvalid; + private final String addressNoResponse; public AccountMinedBlocksTest(EtherScanApi api, int blocksMined, @@ -43,22 +42,14 @@ public AccountMinedBlocksTest(EtherScanApi api, @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ + return Arrays.asList(new Object[][] { { - new EtherScanApi(), + getApi(), 223, "0xE4C6175183029A0f039bf2DFffa5C6e8F3cA9B23", "xE4C6175183029A0f039bf2DFffa5C6e8F3cA9B23", "0xE1C6175183029A0f039bf2DFffa5C6e8F3cA9B23", - }, - { - new EtherScanApi(EthNetwork.ROPSTEN), - 1, - "0x0923DafEB5A5d11a83E188d5dbCdEd14f9b161a7", - "00923DafEB5A5d11a83E188d5dbCdEd14f9b161a7", - "0x1923DafEB5A5d11a83E188d5dbCdEd14f9b161a7", } - // Other netWorks not presented due to 30k+ mined blocks, tests runs forever }); } @@ -71,7 +62,7 @@ public void correct() { assertBlocks(blocks); assertNotNull(blocks.get(0).toString()); - if(blocks.size() > 1) { + if (blocks.size() > 1) { assertNotEquals(blocks.get(0), blocks.get(1)); assertNotEquals(blocks.get(0).hashCode(), blocks.get(1).hashCode()); } @@ -79,7 +70,7 @@ public void correct() { @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - List txs = api.account().minedBlocks(addressInvalid); + List txs = getApi().account().minedBlocks(addressInvalid); } @Test diff --git a/src/test/java/io/api/etherscan/account/AccountTokenBalanceTest.java b/src/test/java/io/api/etherscan/account/AccountTokenBalanceTest.java index 2c747a0..2794e95 100644 --- a/src/test/java/io/api/etherscan/account/AccountTokenBalanceTest.java +++ b/src/test/java/io/api/etherscan/account/AccountTokenBalanceTest.java @@ -1,11 +1,10 @@ package io.api.etherscan.account; +import io.api.ApiRunner; import io.api.etherscan.core.impl.EtherScanApi; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.model.Balance; -import io.api.etherscan.model.EthNetwork; import io.api.etherscan.model.TokenBalance; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -21,14 +20,14 @@ * @since 03.11.2018 */ @RunWith(Parameterized.class) -public class AccountTokenBalanceTest extends Assert { +public class AccountTokenBalanceTest extends ApiRunner { - private EtherScanApi api; - private String contractValid; - private String addressValid; - private String contractInvalid; - private String addressInvalid; - private String addressEmpty; + private final EtherScanApi api; + private final String contractValid; + private final String addressValid; + private final String contractInvalid; + private final String addressInvalid; + private final String addressEmpty; public AccountTokenBalanceTest(EtherScanApi api, String contractValid, @@ -46,39 +45,15 @@ public AccountTokenBalanceTest(EtherScanApi api, @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ + return Arrays.asList(new Object[][] { { - new EtherScanApi(), + getApi(), "0x5EaC95ad5b287cF44E058dCf694419333b796123", "0x5d807e7F124EC2103a59c5249187f772c0b8D6b2", "0xEaC95ad5b287cF44E058dCf694419333b796123", "0x5807e7F124EC2103a59c5249187f772c0b8D6b2", "0x1d807e7F124EC2103a59c5249187f772c0b8D6b2", - }, - { - new EtherScanApi(EthNetwork.ROPSTEN), - "0x60a5aa08619bd5f71c6d20bfaefb5ac2c2806745", - "0x0923dafeb5a5d11a83e188d5dbcded14f9b161a7", - "0x0a5aa08619bd5f71c6d20bfaefb5ac2c2806745", - "0x923dafeb5a5d11a83e188d5dbcded14f9b161a7", - "0x1923dafeb5a5d11a83e188d5dbcded14f9b161a7", - }, - { - new EtherScanApi(EthNetwork.RINKEBY), - "0xb8b6f3fb67403c90652dc5f085ba4a62ab1ef5ce", - "0x7ffc57839b00206d1ad20c69a1981b489f772031", - "0x8b6f3fb67403c90652dc5f085ba4a62ab1ef5ce", - "0x7fc57839b00206d1ad20c69a1981b489f772031", - "0x1ffc57839b00206d1ad20c69a1981b489f772031", - }, - { - new EtherScanApi(EthNetwork.KOVAN), - "0xde0eaa632f071069214f1c1ad7eb609ff8152dfe", - "0x00e6d2b931f55a3f1701c7389d592a7778897879", - "0xd0eaa632f071069214f1c1ad7eb609ff8152dfe", - "0x0e6d2b931f55a3f1701c7389d592a7778897879", - "0x10e6d2b931f55a3f1701c7389d592a7778897879", - }, + } }); } @@ -89,7 +64,6 @@ public void correct() { assertNotNull(balance.getWei()); assertNotNull(balance.getAddress()); assertNotNull(balance.getContract()); - assertNotEquals(0, balance.getWei()); assertNotNull(balance.toString()); TokenBalance balance2 = new TokenBalance("125161", balance.getWei(), balance.getContract()); diff --git a/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java b/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java index 4727317..d1ed2bc 100644 --- a/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java +++ b/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java @@ -1,11 +1,10 @@ package io.api.etherscan.account; +import io.api.ApiRunner; import io.api.etherscan.core.impl.EtherScanApi; import io.api.etherscan.error.InvalidTxHashException; -import io.api.etherscan.model.EthNetwork; import io.api.etherscan.model.TxInternal; import io.api.etherscan.util.BasicUtils; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -22,13 +21,13 @@ * @since 03.11.2018 */ @RunWith(Parameterized.class) -public class AccountTxInternalByHashTest extends Assert { +public class AccountTxInternalByHashTest extends ApiRunner { - private EtherScanApi api; - private int txAmount; - private String validTx; - private String invalidTx; - private String emptyTx; + private final EtherScanApi api; + private final int txAmount; + private final String validTx; + private final String invalidTx; + private final String emptyTx; public AccountTxInternalByHashTest(EtherScanApi api, int txAmount, String validTx, String invalidTx, String emptyTx) { this.api = api; @@ -40,35 +39,14 @@ public AccountTxInternalByHashTest(EtherScanApi api, int txAmount, String validT @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ + return Arrays.asList(new Object[][] { { - new EtherScanApi(), + getApi(), 1, "0x1b513dd971aad228eb31f54489803639de167309ac72de68ecdaeb022a7ab42b", "0xb513dd971aad228eb31f54489803639de167309ac72de68ecdaeb022a7ab42b", "0x2b513dd971aad228eb31f54489803639de167309ac72de68ecdaeb022a7ab42b", - }, - { - new EtherScanApi(EthNetwork.ROPSTEN), - 1, - "0x8bc5504517d40ad7b4f32d008d82436cc118e856593f61d23c70eec73c10322a", - "0x8c5504517d40ad7b4f32d008d82436cc118e856593f61d23c70eec73c10322a", - "0x7bc5504517d40ad7b4f32d008d82436cc118e856593f61d23c70eec73c10322a", - }, - { - new EtherScanApi(EthNetwork.RINKEBY), - 10, - "0x4be697e735f594038e2e70e051948896bdfd6193fc399e38d6113e96f96e8567", - "0x4e697e735f594038e2e70e051948896bdfd6193fc399e38d6113e96f96e8567", - "0x3be697e735f594038e2e70e051948896bdfd6193fc399e38d6113e96f96e8567", - }, - { - new EtherScanApi(EthNetwork.KOVAN), - 1, - "0x3b85c47f2a8c5efd639a85f5233097af834c9ab6ab7965cf7cfc3ab3c8bae285", - "0x385c47f2a8c5efd639a85f5233097af834c9ab6ab7965cf7cfc3ab3c8bae285", - "0x2b85c47f2a8c5efd639a85f5233097af834c9ab6ab7965cf7cfc3ab3c8bae285", - }, + } }); } @@ -89,7 +67,7 @@ public void correct() { assertTrue(BasicUtils.isEmpty(txs.get(0).getErrCode())); assertNotNull(txs.get(0).toString()); - if(txs.size() > 9) { + if (txs.size() > 9) { assertNotEquals(txs.get(0), txs.get(9)); assertNotEquals(txs.get(0).hashCode(), txs.get(9).hashCode()); } diff --git a/src/test/java/io/api/etherscan/account/AccountTxInternalTest.java b/src/test/java/io/api/etherscan/account/AccountTxInternalTest.java index a80be28..f993c39 100644 --- a/src/test/java/io/api/etherscan/account/AccountTxInternalTest.java +++ b/src/test/java/io/api/etherscan/account/AccountTxInternalTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.account; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.model.TxInternal; -import org.junit.Assert; import org.junit.Test; import java.util.List; @@ -14,13 +13,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class AccountTxInternalTest extends Assert { - - private EtherScanApi api = new EtherScanApi(); +public class AccountTxInternalTest extends ApiRunner { @Test public void correct() { - List txs = api.account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51A3"); + List txs = getApi().account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51A3"); assertNotNull(txs); assertEquals(66, txs.size()); assertTxs(txs); @@ -29,7 +26,7 @@ public void correct() { @Test public void correctStartBlock() { - List txs = api.account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51A3", 2558775); + List txs = getApi().account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51A3", 2558775); assertNotNull(txs); assertEquals(24, txs.size()); assertTxs(txs); @@ -37,7 +34,7 @@ public void correctStartBlock() { @Test public void correctStartBlockEndBlock() { - List txs = api.account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51A3", 2558775, 2685504); + List txs = getApi().account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51A3", 2558775, 2685504); assertNotNull(txs); assertEquals(21, txs.size()); assertTxs(txs); @@ -45,12 +42,12 @@ public void correctStartBlockEndBlock() { @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - List txs = api.account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51"); + List txs = getApi().account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51"); } @Test public void correctParamWithEmptyExpectedResult() { - List txs = api.account().txsInternal("0x2C1ba59D6F58433FB2EaEe7d20b26Ed83bDA51A3"); + List txs = getApi().account().txsInternal("0x2C1ba59D6F58433FB2EaEe7d20b26Ed83bDA51A3"); assertNotNull(txs); assertTrue(txs.isEmpty()); } diff --git a/src/test/java/io/api/etherscan/account/AccountTxTokenTest.java b/src/test/java/io/api/etherscan/account/AccountTxTokenTest.java index 7bdf2d6..b82d4d1 100644 --- a/src/test/java/io/api/etherscan/account/AccountTxTokenTest.java +++ b/src/test/java/io/api/etherscan/account/AccountTxTokenTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.account; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.model.TxToken; -import org.junit.Assert; import org.junit.Test; import java.util.List; @@ -14,13 +13,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class AccountTxTokenTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class AccountTxTokenTest extends ApiRunner { @Test public void correct() { - List txs = api.account().txsToken("0xE376F69ED2218076682e2b3B7b9099eC50aD68c4"); + List txs = getApi().account().txsToken("0xE376F69ED2218076682e2b3B7b9099eC50aD68c4"); assertNotNull(txs); assertEquals(3, txs.size()); assertTxs(txs); @@ -39,7 +36,7 @@ public void correct() { @Test public void correctStartBlock() { - List txs = api.account().txsToken("0x36ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7", 5578167); + List txs = getApi().account().txsToken("0x36ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7", 5578167); assertNotNull(txs); assertEquals(11, txs.size()); assertTxs(txs); @@ -47,7 +44,7 @@ public void correctStartBlock() { @Test public void correctStartBlockEndBlock() { - List txs = api.account().txsToken("0x36ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7", 5578167, 5813576); + List txs = getApi().account().txsToken("0x36ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7", 5578167, 5813576); assertNotNull(txs); assertEquals(5, txs.size()); assertTxs(txs); @@ -55,12 +52,12 @@ public void correctStartBlockEndBlock() { @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - api.account().txsToken("0x6ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7"); + getApi().account().txsToken("0x6ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7"); } @Test public void correctParamWithEmptyExpectedResult() { - List txs = api.account().txsToken("0x31ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7"); + List txs = getApi().account().txsToken("0x31ec53A8fBa6358d59B3C4476D82cc60A2B0FaD7"); assertNotNull(txs); assertTrue(txs.isEmpty()); } @@ -74,9 +71,9 @@ private void assertTxs(List txs) { assertNotNull(tx.getTo()); assertNotNull(tx.getTimeStamp()); assertNotNull(tx.getTokenDecimal()); - assertNotEquals(-1,(tx.getConfirmations())); + assertNotEquals(-1, (tx.getConfirmations())); assertNotNull(tx.getGasUsed()); - assertNotEquals(-1 ,tx.getCumulativeGasUsed()); + assertNotEquals(-1, tx.getCumulativeGasUsed()); assertNotEquals(-1, tx.getTransactionIndex()); } } diff --git a/src/test/java/io/api/etherscan/account/AccountTxsTest.java b/src/test/java/io/api/etherscan/account/AccountTxsTest.java index 5c0ad48..66a95e4 100644 --- a/src/test/java/io/api/etherscan/account/AccountTxsTest.java +++ b/src/test/java/io/api/etherscan/account/AccountTxsTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.account; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.model.Tx; -import org.junit.Assert; import org.junit.Test; import java.util.List; @@ -14,13 +13,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class AccountTxsTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class AccountTxsTest extends ApiRunner { @Test public void correct() { - List txs = api.account().txs("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); + List txs = getApi().account().txs("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); assertNotNull(txs); assertEquals(5, txs.size()); assertTxs(txs); @@ -43,7 +40,7 @@ public void correct() { @Test public void correctStartBlock() { - List txs = api.account().txs("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9", 3892842); + List txs = getApi().account().txs("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9", 3892842); assertNotNull(txs); assertEquals(4, txs.size()); assertTxs(txs); @@ -51,7 +48,7 @@ public void correctStartBlock() { @Test public void correctStartBlockEndBlock() { - List txs = api.account().txs("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9", 3892842, 3945741); + List txs = getApi().account().txs("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9", 3892842, 3945741); assertNotNull(txs); assertEquals(3, txs.size()); assertTxs(txs); @@ -60,12 +57,12 @@ public void correctStartBlockEndBlock() { @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - List txs = api.account().txs("9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); + List txs = getApi().account().txs("9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); } @Test public void correctParamWithEmptyExpectedResult() { - List txs = api.account().txs("0x9321cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); + List txs = getApi().account().txs("0x9321cb34984c3992ec1EA0eAE98Ccf80A74f95B9"); assertNotNull(txs); assertTrue(txs.isEmpty()); } diff --git a/src/test/java/io/api/etherscan/block/BlockApiTest.java b/src/test/java/io/api/etherscan/block/BlockApiTest.java index c459b1a..34b9de5 100644 --- a/src/test/java/io/api/etherscan/block/BlockApiTest.java +++ b/src/test/java/io/api/etherscan/block/BlockApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.block; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.model.UncleBlock; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -13,13 +12,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class BlockApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class BlockApiTest extends ApiRunner { @Test public void correct() { - Optional uncle = api.block().uncles(2165403); + Optional uncle = getApi().block().uncles(2165403); assertTrue(uncle.isPresent()); assertFalse(uncle.get().isEmpty()); assertNotNull(uncle.get().getBlockMiner()); @@ -36,13 +33,13 @@ public void correct() { assertNotEquals(uncle.get(), empty); assertTrue(empty.isEmpty()); - if(uncle.get().getUncles().size() > 0) { + if (uncle.get().getUncles().size() > 0) { assertNotEquals(-1, uncle.get().getUncles().get(0).getUnclePosition()); assertEquals(uncle.get().getUncles().get(0), uncle.get().getUncles().get(0)); assertEquals(uncle.get().getUncles().get(0).hashCode(), uncle.get().getUncles().get(0).hashCode()); } - if(uncle.get().getUncles().size() > 1) { + if (uncle.get().getUncles().size() > 1) { assertNotEquals(uncle.get().getUncles().get(1), uncle.get().getUncles().get(0)); assertNotEquals(uncle.get().getUncles().get(1).hashCode(), uncle.get().getUncles().get(0).hashCode()); } @@ -50,14 +47,14 @@ public void correct() { @Test public void correctNoUncles() { - Optional uncles = api.block().uncles(34); + Optional uncles = getApi().block().uncles(34); assertTrue(uncles.isPresent()); assertTrue(uncles.get().getUncles().isEmpty()); } @Test public void correctParamWithEmptyExpectedResult() { - Optional uncles = api.block().uncles(99999999934L); + Optional uncles = getApi().block().uncles(99999999934L); assertFalse(uncles.isPresent()); } } diff --git a/src/test/java/io/api/etherscan/contract/ContractApiTest.java b/src/test/java/io/api/etherscan/contract/ContractApiTest.java index 7ecf26f..6b4d7d8 100644 --- a/src/test/java/io/api/etherscan/contract/ContractApiTest.java +++ b/src/test/java/io/api/etherscan/contract/ContractApiTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.contract; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.model.Abi; -import org.junit.Assert; import org.junit.Test; /** @@ -12,13 +11,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ContractApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ContractApiTest extends ApiRunner { @Test public void correct() { - Abi abi = api.contract().contractAbi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"); + Abi abi = getApi().contract().contractAbi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"); assertNotNull(abi); assertTrue(abi.isVerified()); assertTrue(abi.haveAbi()); @@ -32,13 +29,13 @@ public void correct() { @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - api.contract().contractAbi("0xBBbc244D798123fDe783fCc1C72d3Bb8C189413"); + getApi().contract().contractAbi("0xBBbc244D798123fDe783fCc1C72d3Bb8C189413"); } @Test public void correctParamWithEmptyExpectedResult() { - Abi abi = api.contract().contractAbi("0xBB1bc244D798123fDe783fCc1C72d3Bb8C189413"); + Abi abi = getApi().contract().contractAbi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"); assertNotNull(abi); - assertFalse(abi.isVerified()); + assertTrue(abi.isVerified()); } } diff --git a/src/test/java/io/api/etherscan/logs/LogQueryBuilderTest.java b/src/test/java/io/api/etherscan/logs/LogQueryBuilderTest.java index 058f592..85b35e8 100644 --- a/src/test/java/io/api/etherscan/logs/LogQueryBuilderTest.java +++ b/src/test/java/io/api/etherscan/logs/LogQueryBuilderTest.java @@ -1,12 +1,12 @@ package io.api.etherscan.logs; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.error.LogQueryException; import io.api.etherscan.model.query.LogOp; import io.api.etherscan.model.query.impl.LogQuery; import io.api.etherscan.model.query.impl.LogQueryBuilder; import io.api.etherscan.model.query.impl.LogTopicQuadro; -import org.junit.Assert; import org.junit.Test; /** @@ -15,7 +15,7 @@ * @author GoodforGod * @since 03.11.2018 */ -public class LogQueryBuilderTest extends Assert { +public class LogQueryBuilderTest extends ApiRunner { @Test public void singleCorrect() { diff --git a/src/test/java/io/api/etherscan/logs/LogsApiTest.java b/src/test/java/io/api/etherscan/logs/LogsApiTest.java index 4a3f9e1..7143a83 100644 --- a/src/test/java/io/api/etherscan/logs/LogsApiTest.java +++ b/src/test/java/io/api/etherscan/logs/LogsApiTest.java @@ -1,11 +1,10 @@ package io.api.etherscan.logs; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.model.Log; import io.api.etherscan.model.query.LogOp; import io.api.etherscan.model.query.impl.LogQuery; import io.api.etherscan.model.query.impl.LogQueryBuilder; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -22,12 +21,10 @@ * @since 03.11.2018 */ @RunWith(Parameterized.class) -public class LogsApiTest extends Assert { +public class LogsApiTest extends ApiRunner { - private final EtherScanApi api = new EtherScanApi(); - - private LogQuery query; - private int logsSize; + private final LogQuery query; + private final int logsSize; public LogsApiTest(LogQuery query, int logsSize) { this.query = query; @@ -56,21 +53,21 @@ public static Collection data() { .setOpTopic0_1(LogOp.OR) .build(); - return Arrays.asList(new Object[][]{ - {single, 423}, - {singleInvalidAddr, 0}, - {tupleAnd, 1}, - {tupleOr, 425} + return Arrays.asList(new Object[][] { + { single, 423 }, + { singleInvalidAddr, 0 }, + { tupleAnd, 1 }, + { tupleOr, 425 } }); } @Test public void validateQuery() { - List logs = api.logs().logs(query); + List logs = getApi().logs().logs(query); assertEquals(logsSize, logs.size()); if (logsSize > 0) { - if(logsSize > 1) { + if (logsSize > 1) { assertNotEquals(logs.get(0), logs.get(1)); assertNotEquals(logs.get(0).hashCode(), logs.get(1).hashCode()); } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyBlockApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyBlockApiTest.java index 43b4851..181a68d 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyBlockApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyBlockApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.model.proxy.BlockProxy; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -13,13 +12,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ProxyBlockApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyBlockApiTest extends ApiRunner { @Test public void correct() { - Optional block = api.proxy().block(5120); + Optional block = getApi().proxy().block(5120); assertTrue(block.isPresent()); BlockProxy proxy = block.get(); assertNotNull(proxy.getHash()); @@ -52,13 +49,13 @@ public void correct() { @Test public void correctParamWithEmptyExpectedResult() { - Optional block = api.proxy().block(99999999999L); + Optional block = getApi().proxy().block(99999999999L); assertFalse(block.isPresent()); } @Test public void correctParamNegativeNo() { - Optional block = api.proxy().block(-1); + Optional block = getApi().proxy().block(-1); assertTrue(block.isPresent()); assertNotNull(block.get().getHash()); } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyBlockLastNoApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyBlockLastNoApiTest.java index b981a42..5485391 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyBlockLastNoApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyBlockLastNoApiTest.java @@ -1,7 +1,6 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; -import org.junit.Assert; +import io.api.ApiRunner; import org.junit.Test; /** @@ -10,13 +9,11 @@ * @author GoodforGod * @since 13.11.2018 */ -public class ProxyBlockLastNoApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyBlockLastNoApiTest extends ApiRunner { @Test public void correct() { - long noLast = api.proxy().blockNoLast(); + long noLast = getApi().proxy().blockNoLast(); assertNotEquals(0, noLast); } } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyBlockUncleApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyBlockUncleApiTest.java index 3ccac29..474c5bb 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyBlockUncleApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyBlockUncleApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.model.proxy.BlockProxy; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -13,13 +12,11 @@ * @author GoodforGod * @since 13.11.2018 */ -public class ProxyBlockUncleApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyBlockUncleApiTest extends ApiRunner { @Test public void correct() { - Optional block = api.proxy().blockUncle(603183, 0); + Optional block = getApi().proxy().blockUncle(603183, 0); assertTrue(block.isPresent()); assertNotNull(block.get().getHash()); assertNotNull(block.get().toString()); @@ -27,13 +24,13 @@ public void correct() { @Test public void correctParamWithEmptyExpectedResult() { - Optional block = api.proxy().blockUncle(5120, 1); + Optional block = getApi().proxy().blockUncle(5120, 1); assertFalse(block.isPresent()); } @Test public void correctParamNegativeNo() { - Optional block = api.proxy().blockUncle(-603183, 0); + Optional block = getApi().proxy().blockUncle(-603183, 0); assertFalse(block.isPresent()); } } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyCallApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyCallApiTest.java index 159ed9c..c90850c 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyCallApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyCallApiTest.java @@ -1,10 +1,9 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.error.InvalidDataHexException; import io.api.etherscan.util.BasicUtils; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -15,13 +14,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ProxyCallApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyCallApiTest extends ApiRunner { @Test public void correct() { - Optional call = api.proxy().call("0xAEEF46DB4855E25702F8237E8f403FddcaF931C0", + Optional call = getApi().proxy().call("0xAEEF46DB4855E25702F8237E8f403FddcaF931C0", "0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724"); assertTrue(call.isPresent()); assertFalse(BasicUtils.isNotHex(call.get())); @@ -29,19 +26,19 @@ public void correct() { @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - Optional call = api.proxy().call("0xEEF46DB4855E25702F8237E8f403FddcaF931C0", + Optional call = getApi().proxy().call("0xEEF46DB4855E25702F8237E8f403FddcaF931C0", "0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724"); } @Test(expected = InvalidDataHexException.class) public void invalidParamNotHex() { - Optional call = api.proxy().call("0xAEEF46DB4855E25702F8237E8f403FddcaF931C0", + Optional call = getApi().proxy().call("0xAEEF46DB4855E25702F8237E8f403FddcaF931C0", "7-0a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724"); } @Test public void correctParamWithEmptyExpectedResult() { - Optional call = api.proxy().call("0xAEEF16DB4855E25702F8237E8f403FddcaF931C0", + Optional call = getApi().proxy().call("0xAEEF16DB4855E25702F8237E8f403FddcaF931C0", "0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724"); assertTrue(call.isPresent()); assertFalse(BasicUtils.isNotHex(call.get())); diff --git a/src/test/java/io/api/etherscan/proxy/ProxyCodeApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyCodeApiTest.java index 3c47171..3120503 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyCodeApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyCodeApiTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.util.BasicUtils; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -14,25 +13,23 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ProxyCodeApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyCodeApiTest extends ApiRunner { @Test public void correct() { - Optional call = api.proxy().code("0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c"); + Optional call = getApi().proxy().code("0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c"); assertTrue(call.isPresent()); assertFalse(BasicUtils.isNotHex(call.get())); } @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - Optional call = api.proxy().code("0f75e354c5edc8efed9b59ee9f67a80845ade7d0c"); + Optional call = getApi().proxy().code("0f75e354c5edc8efed9b59ee9f67a80845ade7d0c"); } @Test public void correctParamWithEmptyExpectedResult() { - Optional call = api.proxy().code("0xf15e354c5edc8efed9b59ee9f67a80845ade7d0c"); + Optional call = getApi().proxy().code("0xf15e354c5edc8efed9b59ee9f67a80845ade7d0c"); assertTrue(call.isPresent()); assertFalse(BasicUtils.isNotHex(call.get())); } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyGasApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyGasApiTest.java index 2665175..63e476c 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyGasApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyGasApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidDataHexException; -import org.junit.Assert; import org.junit.Test; import java.math.BigInteger; @@ -13,20 +12,18 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ProxyGasApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyGasApiTest extends ApiRunner { @Test public void correctPrice() { - BigInteger price = api.proxy().gasPrice(); + BigInteger price = getApi().proxy().gasPrice(); assertNotNull(price); assertNotEquals(0, price.intValue()); } @Test public void correctEstimated() { - BigInteger price = api.proxy().gasEstimated(); + BigInteger price = getApi().proxy().gasEstimated(); assertNotNull(price); assertNotEquals(0, price.intValue()); } @@ -34,8 +31,8 @@ public void correctEstimated() { @Test public void correctEstimatedWithData() { String dataCustom = "606060405260728060106000396000f360606040526000606060405260728060106000396000f360606040526000"; - BigInteger price = api.proxy().gasEstimated(); - BigInteger priceCustom = api.proxy().gasEstimated(dataCustom); + BigInteger price = getApi().proxy().gasEstimated(); + BigInteger priceCustom = getApi().proxy().gasEstimated(dataCustom); assertNotNull(price); assertNotNull(priceCustom); assertNotEquals(price, priceCustom); @@ -44,6 +41,6 @@ public void correctEstimatedWithData() { @Test(expected = InvalidDataHexException.class) public void invalidParamWithError() { String dataCustom = "280&60106000396000f360606040526000"; - BigInteger priceCustom = api.proxy().gasEstimated(dataCustom); + BigInteger priceCustom = getApi().proxy().gasEstimated(dataCustom); } } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java index a96ddb3..fbfcf80 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; import io.api.etherscan.util.BasicUtils; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -14,25 +13,23 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ProxyStorageApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyStorageApiTest extends ApiRunner { @Test public void correct() { - Optional call = api.proxy().storageAt("0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 0); + Optional call = getApi().proxy().storageAt("0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 0); assertTrue(call.isPresent()); assertFalse(BasicUtils.isNotHex(call.get())); } @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - Optional call = api.proxy().storageAt("0xe03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 0); + Optional call = getApi().proxy().storageAt("0xe03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 0); } @Test public void correctParamWithEmptyExpectedResult() { - Optional call = api.proxy().storageAt("0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 100); + Optional call = getApi().proxy().storageAt("0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 100); assertFalse(call.isPresent()); } } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java index 1a36372..2779120 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidTxHashException; import io.api.etherscan.model.proxy.TxProxy; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -14,13 +13,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ProxyTxApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyTxApiTest extends ApiRunner { @Test public void correctByHash() { - Optional tx = api.proxy().tx("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); + Optional tx = getApi().proxy().tx("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); assertTrue(tx.isPresent()); assertNotNull(tx.get().getBlockHash()); assertNotNull(tx.get().getFrom()); @@ -37,7 +34,7 @@ public void correctByHash() { @Test public void correctByBlockNo() { - Optional tx = api.proxy().tx(637368, 0); + Optional tx = getApi().proxy().tx(637368, 0); assertTrue(tx.isPresent()); assertNotNull(tx.get().getBlockHash()); assertNotNull(tx.get().getFrom()); @@ -57,18 +54,18 @@ public void correctByBlockNo() { @Test(expected = InvalidTxHashException.class) public void invalidParamWithError() { - Optional tx = api.proxy().tx("0xe2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); + Optional tx = getApi().proxy().tx("0xe2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); } @Test public void correctParamWithEmptyExpectedResultBlockNoExist() { - Optional tx = api.proxy().tx(99999999L, 0); + Optional tx = getApi().proxy().tx(99999999L, 0); assertFalse(tx.isPresent()); } @Test public void correctParamWithEmptyExpectedResult() { - Optional tx = api.proxy().tx("0x2e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); + Optional tx = getApi().proxy().tx("0x2e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); assertFalse(tx.isPresent()); } } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyTxCountApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyTxCountApiTest.java index 7ab1100..6a0778c 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyTxCountApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyTxCountApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; -import org.junit.Assert; import org.junit.Test; /** @@ -11,36 +10,34 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ProxyTxCountApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyTxCountApiTest extends ApiRunner { @Test public void correctSended() { - int count = api.proxy().txSendCount("0x2910543af39aba0cd09dbb2d50200b3e800a63d2"); + int count = getApi().proxy().txSendCount("0x2910543af39aba0cd09dbb2d50200b3e800a63d2"); assertNotEquals(0, count); } @Test public void correctByBlockNo() { - int count = api.proxy().txCount(6137420); + int count = getApi().proxy().txCount(6137420); assertNotEquals(0, count); } @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - int count = api.proxy().txSendCount("0xe03d9cce9d60f3e9f2597e13cd4c54c55330cfd"); + int count = getApi().proxy().txSendCount("0xe03d9cce9d60f3e9f2597e13cd4c54c55330cfd"); } @Test public void correctParamWithEmptyExpectedResultBlockNoExist() { - int count = api.proxy().txCount(99999999999L); + int count = getApi().proxy().txCount(99999999999L); assertEquals(0, count); } @Test public void correctParamWithEmptyExpectedResult() { - int count = api.proxy().txSendCount("0x1e03d9cce9d60f3e9f2597e13cd4c54c55330cfd"); + int count = getApi().proxy().txSendCount("0x1e03d9cce9d60f3e9f2597e13cd4c54c55330cfd"); assertEquals(0, count); } } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java index a530bdb..c4a3383 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidTxHashException; import io.api.etherscan.model.proxy.ReceiptProxy; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -14,13 +13,12 @@ * @author GoodforGod * @since 03.11.2018 */ -public class ProxyTxReceiptApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class ProxyTxReceiptApiTest extends ApiRunner { @Test public void correct() { - Optional infoProxy = api.proxy().txReceipt("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); + Optional infoProxy = getApi().proxy() + .txReceipt("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); assertTrue(infoProxy.isPresent()); assertNotNull(infoProxy.get().getBlockHash()); assertNotNull(infoProxy.get().getRoot()); @@ -44,12 +42,14 @@ public void correct() { @Test(expected = InvalidTxHashException.class) public void invalidParamWithError() { - Optional infoProxy = api.proxy().txReceipt("0xe2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); + Optional infoProxy = getApi().proxy() + .txReceipt("0xe2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); } @Test public void correctParamWithEmptyExpectedResult() { - Optional infoProxy = api.proxy().txReceipt("0x2e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); + Optional infoProxy = getApi().proxy() + .txReceipt("0x2e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); assertFalse(infoProxy.isPresent()); } } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyTxSendRawApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyTxSendRawApiTest.java index a5eb5eb..40e79a6 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyTxSendRawApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyTxSendRawApiTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.proxy; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.EtherScanException; import io.api.etherscan.error.InvalidDataHexException; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -14,28 +13,27 @@ * @author GoodforGod * @since 03.11.2018 */ -//TODO contact etherscan and ask about method behavior -public class ProxyTxSendRawApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +// TODO contact etherscan and ask about method behavior +public class ProxyTxSendRawApiTest extends ApiRunner { public void correct() { - Optional sendRaw = api.proxy().txSendRaw("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); + Optional sendRaw = getApi().proxy() + .txSendRaw("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); assertTrue(sendRaw.isPresent()); } @Test(expected = InvalidDataHexException.class) public void invalidParamWithError() { - Optional sendRaw = api.proxy().txSendRaw("5151=0561"); + Optional sendRaw = getApi().proxy().txSendRaw("5151=0561"); } @Test(expected = EtherScanException.class) public void invalidParamEtherScanDataException() { - Optional sendRaw = api.proxy().txSendRaw("0x1"); + Optional sendRaw = getApi().proxy().txSendRaw("0x1"); } public void correctParamWithEmptyExpectedResult() { - Optional sendRaw = api.proxy().txSendRaw("0x000000"); + Optional sendRaw = getApi().proxy().txSendRaw("0x000000"); assertFalse(sendRaw.isPresent()); } } diff --git a/src/test/java/io/api/etherscan/statistic/StatisticPriceApiTest.java b/src/test/java/io/api/etherscan/statistic/StatisticPriceApiTest.java index f92755e..3245b17 100644 --- a/src/test/java/io/api/etherscan/statistic/StatisticPriceApiTest.java +++ b/src/test/java/io/api/etherscan/statistic/StatisticPriceApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.statistic; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.model.Price; -import org.junit.Assert; import org.junit.Test; /** @@ -11,13 +10,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class StatisticPriceApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class StatisticPriceApiTest extends ApiRunner { @Test public void correct() { - Price price = api.stats().lastPrice(); + Price price = getApi().stats().lastPrice(); assertNotNull(price); assertNotNull(price.btcTimestamp()); assertNotNull(price.usdTimestamp()); diff --git a/src/test/java/io/api/etherscan/statistic/StatisticSupplyApiTest.java b/src/test/java/io/api/etherscan/statistic/StatisticSupplyApiTest.java index 4d1eecb..a705a31 100644 --- a/src/test/java/io/api/etherscan/statistic/StatisticSupplyApiTest.java +++ b/src/test/java/io/api/etherscan/statistic/StatisticSupplyApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.statistic; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.model.Supply; -import org.junit.Assert; import org.junit.Test; import java.math.BigInteger; @@ -13,13 +12,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class StatisticSupplyApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class StatisticSupplyApiTest extends ApiRunner { @Test public void correct() { - Supply supply = api.stats().supply(); + Supply supply = getApi().stats().supply(); assertNotNull(supply); assertNotNull(supply.getValue()); assertNotNull(supply.asGwei()); diff --git a/src/test/java/io/api/etherscan/statistic/StatisticTokenSupplyApiTest.java b/src/test/java/io/api/etherscan/statistic/StatisticTokenSupplyApiTest.java index 53aede7..0a84d01 100644 --- a/src/test/java/io/api/etherscan/statistic/StatisticTokenSupplyApiTest.java +++ b/src/test/java/io/api/etherscan/statistic/StatisticTokenSupplyApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.statistic; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidAddressException; -import org.junit.Assert; import org.junit.Test; import java.math.BigInteger; @@ -13,25 +12,23 @@ * @author GoodforGod * @since 03.11.2018 */ -public class StatisticTokenSupplyApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class StatisticTokenSupplyApiTest extends ApiRunner { @Test public void correct() { - BigInteger supply = api.stats().supply("0x57d90b64a1a57749b0f932f1a3395792e12e7055"); + BigInteger supply = getApi().stats().supply("0x57d90b64a1a57749b0f932f1a3395792e12e7055"); assertNotNull(supply); - assertNotEquals(0, supply); + assertNotEquals(BigInteger.ZERO, supply); } @Test(expected = InvalidAddressException.class) public void invalidParamWithError() { - BigInteger supply = api.stats().supply("0x7d90b64a1a57749b0f932f1a3395792e12e7055"); + BigInteger supply = getApi().stats().supply("0x7d90b64a1a57749b0f932f1a3395792e12e7055"); } @Test public void correctParamWithEmptyExpectedResult() { - BigInteger supply = api.stats().supply("0x51d90b64a1a57749b0f932f1a3395792e12e7055"); + BigInteger supply = getApi().stats().supply("0x51d90b64a1a57749b0f932f1a3395792e12e7055"); assertNotNull(supply); assertEquals(0, supply.intValue()); } diff --git a/src/test/java/io/api/etherscan/transaction/TransactionExecApiTest.java b/src/test/java/io/api/etherscan/transaction/TransactionExecApiTest.java index 2f36d79..25320cc 100644 --- a/src/test/java/io/api/etherscan/transaction/TransactionExecApiTest.java +++ b/src/test/java/io/api/etherscan/transaction/TransactionExecApiTest.java @@ -1,9 +1,8 @@ package io.api.etherscan.transaction; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidTxHashException; import io.api.etherscan.model.Status; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -14,13 +13,11 @@ * @author GoodforGod * @since 03.11.2018 */ -public class TransactionExecApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class TransactionExecApiTest extends ApiRunner { @Test public void correct() { - Optional status = api.txs().execStatus("0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a"); + Optional status = getApi().txs().execStatus("0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a"); assertTrue(status.isPresent()); assertTrue(status.get().haveError()); assertNotNull(status.get().getErrDescription()); @@ -33,12 +30,12 @@ public void correct() { @Test(expected = InvalidTxHashException.class) public void invalidParamWithError() { - api.txs().execStatus("0xb513dd971aad228eb31f54489803639de167309ac72de68ecdaeb022a7ab42b"); + getApi().txs().execStatus("0xb513dd971aad228eb31f54489803639de167309ac72de68ecdaeb022a7ab42b"); } @Test public void correctParamWithEmptyExpectedResult() { - Optional status = api.txs().execStatus("0x55f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a"); + Optional status = getApi().txs().execStatus("0x55f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a"); assertTrue(status.isPresent()); assertFalse(status.get().haveError()); } diff --git a/src/test/java/io/api/etherscan/transaction/TransactionReceiptApiTest.java b/src/test/java/io/api/etherscan/transaction/TransactionReceiptApiTest.java index c716c8a..a459355 100644 --- a/src/test/java/io/api/etherscan/transaction/TransactionReceiptApiTest.java +++ b/src/test/java/io/api/etherscan/transaction/TransactionReceiptApiTest.java @@ -1,8 +1,7 @@ package io.api.etherscan.transaction; -import io.api.etherscan.core.impl.EtherScanApi; +import io.api.ApiRunner; import io.api.etherscan.error.InvalidTxHashException; -import org.junit.Assert; import org.junit.Test; import java.util.Optional; @@ -13,25 +12,25 @@ * @author GoodforGod * @since 03.11.2018 */ -public class TransactionReceiptApiTest extends Assert { - - private final EtherScanApi api = new EtherScanApi(); +public class TransactionReceiptApiTest extends ApiRunner { @Test public void correct() { - Optional status = api.txs().receiptStatus("0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76"); + Optional status = getApi().txs() + .receiptStatus("0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76"); assertTrue(status.isPresent()); assertTrue(status.get()); } @Test(expected = InvalidTxHashException.class) public void invalidParamWithError() { - api.txs().receiptStatus("0x13c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76"); + getApi().txs().receiptStatus("0x13c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76"); } @Test public void correctParamWithEmptyExpectedResult() { - Optional status = api.txs().receiptStatus("0x113c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76"); + Optional status = getApi().txs() + .receiptStatus("0x113c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76"); assertFalse(status.isPresent()); } } diff --git a/src/test/java/io/api/manager/QueueManagerTest.java b/src/test/java/io/api/manager/QueueManagerTest.java index 19b2ea9..acc7b43 100644 --- a/src/test/java/io/api/manager/QueueManagerTest.java +++ b/src/test/java/io/api/manager/QueueManagerTest.java @@ -1,9 +1,9 @@ package io.api.manager; +import io.api.ApiRunner; import io.api.etherscan.manager.IQueueManager; import io.api.etherscan.manager.impl.FakeQueueManager; import io.api.etherscan.manager.impl.QueueManager; -import org.junit.Assert; import org.junit.Test; /** @@ -12,40 +12,40 @@ * @author GoodforGod * @since 03.11.2018 */ -public class QueueManagerTest extends Assert { +public class QueueManagerTest extends ApiRunner { @Test public void fakeManager() { IQueueManager fakeManager = new FakeQueueManager(); - assertTrue(fakeManager.takeTurn()); - assertTrue(fakeManager.takeTurn()); - assertTrue(fakeManager.takeTurn()); - assertTrue(fakeManager.takeTurn()); - assertTrue(fakeManager.takeTurn()); - assertTrue(fakeManager.takeTurn()); + fakeManager.takeTurn(); + fakeManager.takeTurn(); + fakeManager.takeTurn(); + fakeManager.takeTurn(); + fakeManager.takeTurn(); + fakeManager.takeTurn(); } @Test(timeout = 3500) public void queueManager() { IQueueManager queueManager = new QueueManager(1, 3); - assertTrue(queueManager.takeTurn()); + queueManager.takeTurn(); queueManager.takeTurn(); } @Test(timeout = 4500) public void queueManagerWithDelay() { IQueueManager queueManager = new QueueManager(1, 2, 2); - assertTrue(queueManager.takeTurn()); + queueManager.takeTurn(); queueManager.takeTurn(); } @Test public void queueManagerTimeout() { IQueueManager queueManager = new QueueManager(1, 3); - assertTrue(queueManager.takeTurn()); + queueManager.takeTurn(); long start = System.currentTimeMillis(); queueManager.takeTurn(); long end = System.currentTimeMillis(); - assertEquals(3, Math.round((double)(end - start)/1000)); + assertEquals(3, Math.round((double) (end - start) / 1000)); } } diff --git a/src/test/java/io/api/util/BasicUtilsTests.java b/src/test/java/io/api/util/BasicUtilsTests.java index 1b1753e..c35bada 100644 --- a/src/test/java/io/api/util/BasicUtilsTests.java +++ b/src/test/java/io/api/util/BasicUtilsTests.java @@ -1,10 +1,10 @@ package io.api.util; import com.google.gson.Gson; +import io.api.ApiRunner; import io.api.etherscan.error.EtherScanException; import io.api.etherscan.error.ParseException; import io.api.etherscan.model.utility.StringResponseTO; -import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; @@ -18,7 +18,7 @@ * @author GoodforGod * @since 13.11.2018 */ -public class BasicUtilsTests extends Assert { +public class BasicUtilsTests extends ApiRunner { @Test(expected = EtherScanException.class) public void responseValidateEmpty() { @@ -98,6 +98,6 @@ public void isResponseNullThrows() { @Test(expected = ParseException.class) public void isThrowParseException() { - throw new ParseException("Test", null); + throw new ParseException("Test", null, null); } }