Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/216 - Import e2e cucumber tests into casper-java-sdk #217

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a37bfb8
issues/216 - Moved over cucumber step definition classes into casper-…
meywood Aug 16, 2023
1601e1d
issues/216 - Added [email protected]:stormeye2000/cspr-standard-tests-re…
meywood Aug 16, 2023
e018714
issues/216 - Updated CasperTransferHelperTests and CasperServiceTest…
meywood Aug 16, 2023
7ef9ba1
issues/216 - Added script to debug e2e tests
meywood Aug 16, 2023
91987f9
issues/216 - Fix warnings detected by static code analysis
meywood Aug 16, 2023
862227b
issues/216 - Tidy up of branch prior to PR
meywood Aug 16, 2023
fe6813c
issues/216 - Update github gradle.yml action to use new docker-copy-a…
meywood Aug 16, 2023
413b0f2
issues/216 - Update github gradle.yml to use cspr-nctl:linux-1.5.2
meywood Aug 16, 2023
40f8e88
issues/216 - Moved reports into standard gradle reports folder
meywood Aug 18, 2023
ce4c5a0
issues/216 - Fixed state_get_balance to work with changes to nctl.
meywood Aug 18, 2023
cec2b4b
issues/216 - Added github actions to execute e2e tests and publish re…
meywood Aug 21, 2023
b801bba
issues/216 - Added bootstrap script to GitHub action prior to executi…
meywood Aug 21, 2023
257b95d
issues/216 - Added bootstrap script to GitHub action prior to executi…
meywood Aug 21, 2023
e914f86
issues/216 - Added submodules recursive checkout
meywood Aug 21, 2023
6755c7d
issues/216 - Reduced logging for event handling and added 'continue-o…
meywood Aug 21, 2023
87cb931
issues/216 - Code review updates
meywood Aug 22, 2023
874a38c
issues/216 - Added more info to e2e-remote-debug script description
meywood Aug 22, 2023
4acf624
issues/216 - Added symbolic link to the features folder to allow Inte…
meywood Aug 22, 2023
56c6ea8
issues/216 - Added symbolic link to the features folder to allow Inte…
meywood Aug 22, 2023
bdb2e1a
issues/216 - Added symbolic link to the features folder to allow Inte…
meywood Aug 22, 2023
c8ef511
issues/216 - Remove old git submodule cspr-standard-tests-resources i…
meywood Aug 30, 2023
0f4c95a
issues/216 - Updated git submodule to https://github.com/casper-netwo…
meywood Aug 30, 2023
0919157
issues/216 - Fixed errors in bootstrap script
meywood Aug 30, 2023
8eedab3
issues/216 - Updated gradle project to support new git submodule sdk-…
meywood Aug 30, 2023
62c47f7
issues/216 - Fixed incorrect feature regex in DeployGeneratedKeys
meywood Sep 22, 2023
d8d648a
issues/216 - Change json resource path
meywood Sep 22, 2023
4eb2b30
issues-216 - Fixed typo in bootstrap
meywood Sep 25, 2023
74119e6
Merge remote-tracking branch 'origin/issues/216' into issues/216
meywood Sep 25, 2023
3610f8a
issues/222 - query_balance.feature
meywood Sep 26, 2023
f2681db
issues/222 - query_balance.feature
meywood Sep 26, 2023
454e0ec
issues/222 - tidy up for review
meywood Sep 26, 2023
6a0a206
Merge pull request #223 from casper-network/issues/222
cnorburn Sep 26, 2023
62a91d8
issues/222 - implemented missing scenarios for state identifiers
meywood Sep 26, 2023
cea0bf1
issues/222 - implemented missing scenarios for state identifiers
meywood Sep 26, 2023
02a74a4
Merge pull request #224 from casper-network/issues/222
cnorburn Sep 26, 2023
32365c9
issues/222 - implemented missing scenarios for state identifiers
meywood Sep 26, 2023
447bede
Merge branch 'issues/222' into issues/216
meywood Sep 26, 2023
e4a3e05
Update QueryBalanceStepDefinitions.java
meywood Oct 2, 2023
eca374c
issues/225 - speculative_execution.feature
meywood Oct 10, 2023
182c2da
Merge pull request #226 from casper-network/issues/225
cnorburn Oct 10, 2023
c77e14d
issues/225 - speculative_execution.feature improvement
meywood Oct 11, 2023
68ce4f9
Merge pull request #227 from casper-network/issues/225
cnorburn Oct 11, 2023
6a8c805
issues/228 - Nested CLTuples
meywood Oct 25, 2023
00f56f3
issues/228 - Tidy up for review of nested CLTuples
meywood Oct 25, 2023
6e2dc6b
issues/228 - Tidy up for review of nested CLTuples
meywood Oct 30, 2023
f785776
issues/228 - Reformat private functions to end of file
meywood Oct 31, 2023
de15ceb
Merge pull request #229 from casper-network/issues/228
cnorburn Oct 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This workflow will build a Java project with Gradle
# This workflow will build a Java project with Gradle and run e2e cucumber tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
Expand All @@ -15,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a step by step description of what the action is doing

services:
nctl:
image: stormeye2000/cspr-nctl:1.5
image: stormeye2000/cspr-nctl:linux-1.5.2
options: --name cspr-nctl
env:
PREDEFINED_ACCOUNTS: 'true'
Expand All @@ -36,6 +35,8 @@ jobs:

- name: Checkout code
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up JDK 11
uses: actions/setup-java@v2
Expand All @@ -49,12 +50,15 @@ jobs:
# Copy the assets from the NCTL docker image and build
- name: Build and test with Gradle
run: |
cd sh && chmod +x docker-copy-assets.sh && ./docker-copy-assets.sh && cd ..
cd script && chmod +x docker-copy-assets && ./docker-copy-assets && cd ..
./gradlew clean build

- name: Export project version
run: echo "PROJECT_VERSION=$(./gradlew properties -q | grep "version:" | awk '{print $2}')" >> $GITHUB_ENV

- name: Export Cspr Node Version
run: echo "CSRP_NODE_VERSION=$(./gradlew properties -q | grep "csprNodeVersion:" | awk '{print $2}')" >> $GITHUB_ENV

- name: Generate Javadoc
run: ./gradlew javadoc

Expand All @@ -74,6 +78,11 @@ jobs:
folder: build/reports/jacoco
target-folder: docs/latest/jacoco

# Runs all the e2e cucumber tests against the docker container cspr-nctl
- name: e2e tests
run: ./script/e2e-test
continue-on-error: true

- name: Deploy to GitHub Pages
uses: JamesIves/[email protected]
with:
Expand Down Expand Up @@ -106,4 +115,8 @@ jobs:
folder: build/docs/javadoc
target-folder: docs/${{ env.PROJECT_VERSION }}/javadoc


- name: Publish e2e tests
uses: deblockt/[email protected]
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
path: "**/cucumber-report.json"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ out/
.vscode/*
!.vscode/tasks.json
!.vscode/launch.json
/assets/
/reports/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cspr-standard-tests-resources"]
path = cspr-standard-tests-resources
url = [email protected]:stormeye2000/cspr-standard-tests-resources.git
58 changes: 48 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ apply plugin: 'java'

group = 'network.casper'
// Version number update for release
version='2.4.1'
version = '2.4.1'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
mavenCentral()
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
}

Expand Down Expand Up @@ -50,6 +50,18 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter:${jupiterVersion}"
// Used to compare json strings while testing
testImplementation "org.skyscreamer:jsonassert:${jsonassertVersion}"
// Use for e2e cucumber testing against a node
testImplementation "io.cucumber:cucumber-java:${cucumberVersion}"
// Path to assests used by e2e testing
testImplementation files('assets')
// path to features and other standard test resources from git submodule
testImplementation files('cspr-standard-tests-resources')
}

configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}

java {
Expand Down Expand Up @@ -89,9 +101,9 @@ test {
//showStandardStreams true
// set options for log level LIFECYCLE
events TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED
//TestLogEvent.STANDARD_OUT
TestLogEvent.PASSED,
TestLogEvent.SKIPPED
//TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
Expand All @@ -100,11 +112,11 @@ test {
// set options for log level DEBUG and INFO
debug {
events TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR
TestLogEvent.STANDARD_OUT
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
}
//info.events = debug.events
Expand All @@ -121,6 +133,32 @@ test {
}
}

task cucumberCli() {

ext.cucmmber_name = System.getProperty('cucumber.name')
if (ext.cucmmber_name == null) {
ext.cucmmber_name = ''
}
println 'ext.cucmmber_name=' + ext.cucmmber_name;

dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = [
'--plugin', 'pretty',
'--plugin', 'html:build/reports/e2e/cucumber-report.html',
'--plugin', 'junit:build/reports/e2e/cucumber-report.xml',
'--plugin', 'json:build/reports/e2e/cucumber-report.json',
'--glue', 'com.stormeye.evaluation',
'--glue', 'com.casper.sdk',
'--name', ext.cucmmber_name,
'cspr-standard-tests-resources/features']
}
}
}

jacocoTestReport {
dependsOn test

Expand Down
1 change: 1 addition & 0 deletions cspr-standard-tests-resources
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sbs4jVersion=0.1.8
commonsIoVersion=2.11.0
cucumberVersion=7.11.1
cryptokeyVersion=0.4.0
cxfRtRsSseVersion=3.5.5
lombokPluginVersion=6.2.0
Expand Down
39 changes: 39 additions & 0 deletions script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Scripts
This readme describes the usage of scripts in this folder.
## bootstrap
The bootstrap script fetches the lasted from the 'cspr-standard-test-resources' git submodule that contains the e2e
cucumber features and associated test resources.

## docker-bash
Opens a bash terminal to the cspr-nctl docker container

## docker-copy-assets
Copies the required assent such a account key pairs from a running casper-nctl docker container
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such as


## docker-run
Runs the casper-nctl docker container

## docker-stop
Stops a running casper-nctl docker container

## e2e-remote-debug
Remote debugs one or more cucumber e2e tests, the 1st parameter is the cucumber name regex eg:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain a bit more what remote-debug is doing


```./script/e2e-remote-debug info_get_peers```

The above example will start the JVM in debug mode and only execute the info_get_peers scenario.

## e2e-test
Executes the cucumber e2e tests against a docker instance. To run tests filtered by regex use the following:

```./script/e2e-test -Dcucumber.name=info_get_status```

where info_get_status is the pattern to filter on

## remote-test-resources
Deletes the git submodule 'cspr-standard-test-resources'.

**IMPORTANT NOTE**: DO NOT RUN UNLESS YOU REALLY WANT TO DELETE SUBMODULES

## test
Executes the JUnit tests
14 changes: 14 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
cd "$(dirname "$0")" || exit
echo "Bootstrap installs all dependencies."

echo "Installing features from [email protected]:stormeye2000/cspr-standard-tests-resources.git"

if [ -d "../cspr-standard-test-resources" ]
then
echo "cspr-standard-test-resources exists fetching submodules."
git submodule update --init --recursive
else
echo "Cloning cspr-standard-test-resources as submodule."
git submodule add [email protected]:stormeye2000/cspr-standard-tests-resources.git ../cspr-standard-tests-resources
fi
3 changes: 3 additions & 0 deletions script/docker-bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# opens a bash shell against the casper nctl docker container
docker exec -it cspr-nctl bash
11 changes: 11 additions & 0 deletions script/docker-copy-assets
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
BASEDIR=$(builtin cd .. || exit 1; pwd)
# clear the assets folder
rm -rf "${BASEDIR}/assets"
mkdir "${BASEDIR}/assets"
# copy net-1 users
docker cp cspr-nctl:/home/casper/casper-node/utils/nctl/assets/net-1/users "${BASEDIR}/assets/net-1"
# copy net-1 chainspec
docker cp cspr-nctl:/home/casper/casper-node/utils/nctl/assets/net-1/chainspec "${BASEDIR}/assets/net-1"
# copy faucet keys
docker cp cspr-nctl:/home/casper/casper-node/utils/nctl/assets/net-1/faucet "${BASEDIR}/assets/net-1"
3 changes: 3 additions & 0 deletions script/docker-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# run the cspr-nctl container in docker
docker run --rm -it --name cspr-nctl -d -p 25101:25101 -p 11101:11101 -p 14101:14101 -p 18101:18101 stormeye2000/cspr-nctl:linux-1.5.2
3 changes: 3 additions & 0 deletions script/docker-stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# stop the cspr-nctl docker container
docker stop cspr-nctl
8 changes: 8 additions & 0 deletions script/e2e-remote-debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# remote debugs one or more cucumber e2e tests, the 1st parameter is the cucumber name regex eg:
# ./script/e2e-remote-debug info_get_peers
# The above example will start the JVM in debug mode and only execute the info_get_peers scenario.

cd "$(dirname "$0")/.."|| exit 1
./gradlew --stop
./gradlew cucumber -Dorg.gradle.jvmargs='-Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005;' -Dcucumber.name="${1}" --no-daemon
7 changes: 7 additions & 0 deletions script/e2e-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# executes the cucumber e2e tests against a docker instance
cd "$(dirname "$0")/.." || exit 1
# to run tests filtered by regex use the following:
# ./script/e2e-test -Dcucumber.name=info_get_status
# where info_get_status is the pattern to filter on
./gradlew cucumber "$@"
8 changes: 8 additions & 0 deletions script/remove-test-resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
cd "$(dirname "$0")" || exit
cd ..
echo "Removes all test resources git submodules."
git submodule deinit -f cspr-standard-tests-resources
rm -rf .git/modules/cspr-standard-tests-resources
git rm -f cspr-standard-tests-resources
rm .gitmodules
5 changes: 5 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# executes the JUnit tests. To execute the cucumber test use the e2e-test script
cd "$(dirname "$0")/.." || exit 1
./gradlew test "$@"

6 changes: 0 additions & 6 deletions sh/docker-copy-assets.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public <EventT extends Event<?>> AutoCloseable consumeEvents(final EventType eve
final Consumer<Throwable> onFailure) {

final URL url = urlBuilder.buildUrl(uri, eventType, startFrom);
logger.info("Targeting SSE URL {}", url);
logger.debug("Targeting SSE URL {}", url);
final WebTarget target = sssClient.target(url.toString());
final Response response = target.request("text/plain", "text/event-stream").get();
final EventBuilder eventBuilder = new EventBuilder(eventType, eventTarget, target.getUri().toString());
Expand All @@ -73,7 +73,7 @@ public <EventT extends Event<?>> AutoCloseable consumeEvents(final EventType eve
}
}
}, throwable -> {
logger.error("SSE Event Error on {}", url, throwable);
logger.debug("SSE Event Error on {}", url, throwable);
onFailure.accept(throwable);
});

Expand Down
69 changes: 69 additions & 0 deletions src/test/java/com/casper/sdk/e2e/event/EventHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.casper.sdk.e2e.event;

import com.casper.sdk.e2e.matcher.MatcherMap;
import com.casper.sdk.e2e.utils.CasperClientProvider;
import com.casper.sdk.model.event.Event;
import com.casper.sdk.model.event.EventTarget;
import com.casper.sdk.model.event.EventType;
import org.hamcrest.Matcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;


/**
* Helper class for consuming and matching events.
*
* @author [email protected]
*/
public class EventHandler {

private final Logger logger = LoggerFactory.getLogger(EventHandler.class);
private final MatcherMap matcherMap = new MatcherMap();
private final List<AutoCloseable> sseSources = new ArrayList<>();

public EventHandler(final EventTarget eventTarget) {
consume(EventType.DEPLOYS, eventTarget);
consume(EventType.MAIN, eventTarget);
consume(EventType.SIGS, eventTarget);
}

public void close() {

for (AutoCloseable sseSource : sseSources) {
try {
sseSource.close();
} catch (Exception e) {
logger.error("Error closing SSE Source", e);
}
}
}

private void consume(final EventType eventType, final EventTarget eventTarget) {

logger.info("Got {} event {}", eventType, eventTarget);
sseSources.add(
CasperClientProvider.getInstance().getEventService().consumeEvents(
eventType,
eventTarget, null,
this::handleMatchers,
throwable -> logger.error("Error processing SSE event", throwable)
)
);
}

public <T> Matcher<T> addEventMatcher(final EventType eventType, final Matcher<T> matcher) {
matcherMap.addEventMatcher(eventType, matcher);
return matcher;
}

private void handleMatchers(Event<?> event) {
matcherMap.handleEvent(event);
}

public <T> void removeEventMatcher(final EventType eventType, final Matcher<T> matcher) {
matcherMap.removeEventMatcher(eventType, matcher);
}
}
Loading