Skip to content

Commit

Permalink
test: major refactor + retry (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
amagyar-iohk committed Feb 5, 2024
1 parent 24ecc04 commit 4770233
Show file tree
Hide file tree
Showing 25 changed files with 668 additions and 2,141 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,13 @@ jobs:
working-directory: integration-tests/e2e-tests
run: yarn test:sdk

- name: Generate end-to-end report
working-directory: integration-tests/e2e-tests
run: yarn test:sdk:report

- name: Add notes to summary
working-directory: integration-tests/e2e-tests
run: cat notes >> $GITHUB_STEP_SUMMARY

- name: Publish Serenity report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: atala-prism-sdk-ts
path: integration-tests/e2e-tests/target/site/wallet-sdk-ts
name: sdk-ts-e2e-results
path: integration-tests/e2e-tests/target/sdk-ts-e2e-results.html
if-no-files-found: error
3 changes: 2 additions & 1 deletion integration-tests/e2e-tests/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ root: true
ignorePatterns:
- target
env:
es2021: true
esnext: true
node: true
extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
parser: '@typescript-eslint/parser'
parserOptions:
Expand Down
12 changes: 0 additions & 12 deletions integration-tests/e2e-tests/config/cucumber.sdk.js

This file was deleted.

18 changes: 18 additions & 0 deletions integration-tests/e2e-tests/cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
default: {
format: [
"@serenity-js/cucumber",
["html", "target/sdk-ts-e2e-results.html"],
],
formatOptions: {
junit: {
suiteName: "E2E: Prism Wallet SDK - TS"
}
},
requireModule: ["ts-node/register"],
require: [
"src/**/*.ts"
],
retry: 1
}
}
17 changes: 17 additions & 0 deletions integration-tests/e2e-tests/features/create_connection.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@connection
Feature: Create connection
The Edge Agent should be able to create a connection to prism-agent

Scenario Outline: Create connection
Given Cloud Agent has a connection invitation with '<label>', '<goalCode>' and '<goal>' parameters
And Cloud Agent shares invitation to Edge Agent
And Edge Agent connects through the invite
Then Cloud Agent should have the connection status updated to 'ConnectionResponseSent'
Examples:
| label | goalCode | goal |
| alice | automation | automation description |
| | | |
| alice | null | null |
| null | automation | null |
| null | null | automation description |
| null | null | null |
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Feature: Provide proof of request
@proof
Feature: Provide proof
The Edge Agent should provide proof to Cloud Agent

Scenario: Edge Agent with a credential should provide proof to Cloud Agent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Feature: Receive anonymous credential
@anoncred
@credential
Feature: Receive Anoncred Credential
The Edge Agent should be able to receive an anonymous credential from Cloud Agent

Scenario: Receive one anonymous credential
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Feature: Receive verifiable credential
@jwt
@credential
Feature: Receive JWT Credential
The Edge Agent should be able to receive a verifiable credential from Cloud Agent

Scenario: Receive one verifiable credential
Expand Down
52 changes: 25 additions & 27 deletions integration-tests/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
"version": "1.0.0",
"main": "index.ts",
"scripts": {
"postinstall": "serenity-bdd update",
"clean": "rimraf target",
"test:sdk": "failsafe clean test:sdk:run test:sdk:report",
"test:sdk:run": "cucumber-js --config config/cucumber.sdk.js tests/sdk/features -b --exit",
"test:sdk:report": "serenity-bdd run --features tests/sdk/features --destination target/site/wallet-sdk-ts"
"test:sdk": "yarn clean && cucumber-js -b"
},
"repository": {
"type": "git",
Expand All @@ -16,38 +13,39 @@
"author": "Allain Magyar",
"license": "ISC",
"bugs": {
"url": "https://github.com/amagyar-iohk/atala-prism-wallet-sdk-ts-e2e/issues"
"url": "https://github.com/input-output-hk/atala-prism-wallet-sdk-ts-e2e/issues"
},
"homepage": "https://github.com/amagyar-iohk/atala-prism-wallet-sdk-ts-e2e#readme",
"homepage": "https://github.com/input-output-hk/atala-prism-wallet-sdk-ts-e2e",
"dependencies": {
"@atala/prism-wallet-sdk": "^3.1.0",
"@cucumber/cucumber": "^9.6.0",
"@hyperledger-labs/open-enterprise-agent-ts-client": "^1.18.0",
"@serenity-js/assertions": "^3.13.0",
"@serenity-js/console-reporter": "^3.13.0",
"@serenity-js/core": "^3.13.0",
"@serenity-js/cucumber": "^3.13.0",
"@serenity-js/rest": "^3.13.0",
"@serenity-js/serenity-bdd": "^3.13.0",
"@types/node": "^20.4.7",
"axios": "^1.6.0",
"dotenv": "^16.3.1",
"eslint": "^8.48.0",
"npm-check": "^6.0.1",
"npm-failsafe": "^1.0.0",
"rimraf": "^5.0.0",
"sql.js": "^1.8.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"@atala/prism-wallet-sdk": "^4.0.0",
"@cucumber/cucumber": "^10.3.1",
"@cucumber/pretty-formatter": "^1.0.0",
"@hyperledger-labs/open-enterprise-agent-ts-client": "^1.19.1",
"@serenity-js/assertions": "^3.16.0",
"@serenity-js/console-reporter": "^3.16.0",
"@serenity-js/core": "^3.16.0",
"@serenity-js/cucumber": "^3.16.0",
"@serenity-js/rest": "^3.16.0"
},
"devDependencies": {
"@types/lodash": "^4.14.202",
"@types/node": "^18.19.14",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"axios": "^1.6.7",
"cliui": "^8.0.1",
"dotenv": "^16.4.1",
"eslint": "^8.56.0",
"eslint-config-standard-with-typescript": "^39.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
"eslint-plugin-promise": "^6.0.0",
"esm": "^3.2.25",
"typescript": "^5.2.2"
"lodash": "^4.17.21",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"resolutions": {
"wrap-ansi": "^7.0.0"
}
}
37 changes: 37 additions & 0 deletions integration-tests/e2e-tests/src/Utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {appendFile, writeFileSync} from "fs"

export class Utils {
static prepareNotes() {
writeFileSync("notes", "### End-to-end notes:\n\n")
}

static appendToNotes(message: string) {
console.info("Adding to notes:", message)
appendFile("notes", message + "\n", (err) => {
if(err) console.error(err)
})
}

static async repeat(times: number, callback: () => Promise<void>) {
for (let i = 0; i < times; i++) {
await callback()
}
}

static async retry<T>(times: number, callback: () => Promise<T>) {
let retry = 0
let delegateError = null
while (retry < times) {
try {
return await callback()
} catch (err) {
Utils.appendToNotes(`Failure: ${err.message}. Trying to run again.`)
delegateError = err
}
retry++
}
let error = Error(`${delegateError.message} afer retrying [${times}] times`)
error.stack = delegateError.stack
throw error
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import {
} from "@atala/prism-wallet-sdk"
import {Message} from "@atala/prism-wallet-sdk/build/typings/domain"
import axios from "axios"
import {PlutoInMemory} from "./src/PlutoInMemory"
import {CloudAgentConfiguration} from "./configuration/CloudAgentConfiguration"
import {PlutoInMemory} from "../configuration/PlutoInMemory"
import {CloudAgentConfiguration} from "../configuration/CloudAgentConfiguration"
import { Utils } from "../Utils"

export class WalletSdk extends Ability implements Initialisable, Discardable {
sdk!: Agent
messages: MessageQueue = new MessageQueue()

static async withANewInstance(): Promise<Ability> {
return new WalletSdk(await WalletSdkBuilder.createInstance())
const instance: Agent = await Utils.retry(2, async () => {
return await WalletSdkBuilder.createInstance()
})
return new WalletSdk(instance)
}

constructor(sdk: Agent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CredentialSchemaInput,
ManagedDIDKeyTemplate
} from "@hyperledger-labs/open-enterprise-agent-ts-client"
import {Utils} from "../../Utils"
import {Utils} from "../Utils"
import {randomUUID} from "crypto"
import * as fs from "fs"
import assert from "assert"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ BeforeAll(async function () {
// Configure Serenity/JS
configure({
crew: [
"@serenity-js/console-reporter",
"@serenity-js/serenity-bdd",
[
"@serenity-js/core:ArtifactArchiver",
{ outputDirectory: "target/site/serenity" },
],
"@serenity-js/console-reporter"
]
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {Given, Then, When} from "@cucumber/cucumber"
import {Actor, Notepad} from "@serenity-js/core"
import {CloudAgentWorkflow} from "../src/CloudAgentWorkflow"
import {EdgeAgentWorkflow} from "../src/EdgeAgentWorkflow"
import {CloudAgentWorkflow} from "../workflow/CloudAgentWorkflow"
import {EdgeAgentWorkflow} from "../workflow/EdgeAgentWorkflow"

Given("{actor} has a connection invitation", async function (cloudAgent: Actor) {
await CloudAgentWorkflow.createConnection(cloudAgent)
})
Given("{actor} has a connection invitation with '{}', '{}' and '{}' parameters",
async function (cloudAgent: Actor, rawLabel: string, rawGoalCode: string, rawGoal: string) {
const label = rawLabel == "null" ? undefined : rawLabel
const goalCode = rawGoalCode == "null" ? undefined : rawGoalCode
const goal = rawGoal == "null" ? undefined : rawGoal
await CloudAgentWorkflow.createConnection(cloudAgent, label, goalCode, goal)
})

Given("{actor} is connected to {actor}", async function (cloudAgent: Actor, edgeAgent: Actor) {
await CloudAgentWorkflow.createConnection(cloudAgent)
Expand All @@ -30,8 +34,8 @@ When("{actor} asks for present-proof", async function (cloudAgent: Actor) {
await CloudAgentWorkflow.askForPresentProof(cloudAgent)
})

Then("{actor} should have its status updated", async (cloudAgent: Actor) => {
await CloudAgentWorkflow.waitForConnectionState(cloudAgent, "ConnectionResponseSent")
Then("{actor} should have the connection status updated to '{}'", async (cloudAgent: Actor, expectedStatus: string) => {
await CloudAgentWorkflow.waitForConnectionState(cloudAgent, expectedStatus)
})

Then("{actor} should see the credential was accepted", async (cloudAgent: Actor) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Given, Then, When } from "@cucumber/cucumber"
import { Actor, Notepad } from "@serenity-js/core"
import { EdgeAgentWorkflow } from "../src/EdgeAgentWorkflow"
import { CloudAgentWorkflow } from "../src/CloudAgentWorkflow"
import { Utils } from "../../Utils"
import { EdgeAgentWorkflow } from "../workflow/EdgeAgentWorkflow"
import { CloudAgentWorkflow } from "../workflow/CloudAgentWorkflow"
import { Utils } from "../Utils"

Given("{actor} has {int} credentials issued by {actor}",
async function (edgeAgent: Actor, numberOfIssuedCredentials: number, cloudAgent: Actor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import {Before, BeforeAll} from "@cucumber/cucumber"
import {Actor, actorCalled, Cast, engage, TakeNotes} from "@serenity-js/core"
import {CallAnApi} from "@serenity-js/rest"
import {Utils} from "../../Utils"
import {WalletSdk} from "../WalletSdk"
import {Utils} from "../Utils"
import {WalletSdk} from "../abilities/WalletSdk"
import {axiosInstance, CloudAgentConfiguration} from "../configuration/CloudAgentConfiguration"
import nodeCrypto from "crypto"

Object.defineProperty(globalThis, "crypto", {
value: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getRandomValues: (arr: any) => nodeCrypto.getRandomValues(arr),
},
})

BeforeAll(async () => {
Utils.prepareNotes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {Actor, Duration, Notepad, Wait} from "@serenity-js/core"
import {LastResponse, PostRequest, Send} from "@serenity-js/rest"
import {Ensure, equals} from "@serenity-js/assertions"
import {HttpStatusCode} from "axios"
import {Expectations} from "../../Expectations"
import {Questions} from "../../Questions"
import {Expectations} from "../screenplay/Expectations"
import {Questions} from "../screenplay/Questions"
import {randomUUID} from "crypto"
import {
CreateConnectionRequest,
Expand All @@ -15,9 +15,12 @@ import {
import {CloudAgentConfiguration} from "../configuration/CloudAgentConfiguration"

export class CloudAgentWorkflow {
static async createConnection(cloudAgent: Actor) {
static async createConnection(cloudAgent: Actor, label?: string, goalCode?: string, goal?: string) {
const createConnection = new CreateConnectionRequest()
createConnection.label = "Alice"
createConnection.label = label
createConnection.goalCode = goalCode
createConnection.goal = goal

await cloudAgent.attemptsTo(
Send.a(PostRequest.to("connections").with(createConnection)),
Ensure.that(LastResponse.status(), equals(HttpStatusCode.Created)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {IssueCredential, OfferCredential, RequestPresentation,} from "@atala/prism-wallet-sdk"
import {Actor, Duration, Notepad, Wait} from "@serenity-js/core"
import {equals} from "@serenity-js/assertions"
import {WalletSdk} from "../WalletSdk"
import {Utils} from "../../Utils"
import {WalletSdk} from "../abilities/WalletSdk"
import {Utils} from "../Utils"

export class EdgeAgentWorkflow {
static async connect(edgeAgent: Actor) {
Expand Down
20 changes: 0 additions & 20 deletions integration-tests/e2e-tests/tests/Utils.ts

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4770233

Please sign in to comment.