Skip to content

Commit

Permalink
fix: e2e tests improvement (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo committed Feb 27, 2024
1 parent ce7669f commit eb6a5ab
Show file tree
Hide file tree
Showing 9 changed files with 1,433 additions and 435 deletions.
2 changes: 1 addition & 1 deletion integration-tests/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"homepage": "https://github.com/input-output-hk/atala-prism-wallet-sdk-ts-e2e",
"dependencies": {
"@atala/prism-wallet-sdk": "^4.0.0",
"@atala/prism-wallet-sdk": "../..",
"@cucumber/cucumber": "^10.3.1",
"@cucumber/pretty-formatter": "^1.0.0",
"@hyperledger-labs/open-enterprise-agent-ts-client": "^1.19.1",
Expand Down
33 changes: 18 additions & 15 deletions integration-tests/e2e-tests/src/abilities/WalletSdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {Ability, Discardable, Initialisable, Interaction, Question, QuestionAdapter} from "@serenity-js/core"
import {
import { Ability, Discardable, Initialisable, Interaction, Question, QuestionAdapter } from "@serenity-js/core"
import SDK from "@atala/prism-wallet-sdk"
import { Message } from "@atala/prism-wallet-sdk/build/typings/domain"
import axios from "axios"
import { CloudAgentConfiguration } from "../configuration/CloudAgentConfiguration"
import { Utils } from "../Utils"
import { InMemoryStore } from "../configuration/InMemoryStore"
const {
Agent,
ApiImpl,
Apollo,
Expand All @@ -10,25 +16,20 @@ import {
Domain, ListenerKey,
Mercury,
PublicMediatorStore
} from "@atala/prism-wallet-sdk"
import {Message} from "@atala/prism-wallet-sdk/build/typings/domain"
import axios from "axios"
import {PlutoInMemory} from "../configuration/PlutoInMemory"
import {CloudAgentConfiguration} from "../configuration/CloudAgentConfiguration"
import { Utils } from "../Utils"
} = SDK;

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

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

constructor(sdk: Agent) {
constructor(sdk: SDK.Agent) {
super()
this.sdk = sdk
}
Expand All @@ -51,7 +52,7 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {
})
}

static execute(callback: (sdk: Agent, messages: {
static execute(callback: (sdk: SDK.Agent, messages: {
credentialOfferStack: Message[],
issuedCredentialStack: Message[],
proofRequestStack: Message[]
Expand All @@ -71,7 +72,7 @@ export class WalletSdk extends Ability implements Initialisable, Discardable {

async initialise(): Promise<void> {
this.sdk.addListener(
ListenerKey.MESSAGE, (messages: Domain.Message[]) => {
ListenerKey.MESSAGE, (messages: SDK.Domain.Message[]) => {
for (const message of messages) {
this.messages.enqueue(message)
}
Expand All @@ -96,8 +97,10 @@ class WalletSdkBuilder {

static async createInstance() {
const apollo = new Apollo()
const castor = new Castor(apollo)
const pluto = new PlutoInMemory()
const castor = new Castor(apollo);
const store = new InMemoryStore()
const pluto = new SDK.Pluto(store, apollo);
await pluto.start()

const api = new ApiImpl()
const didcomm = new DIDCommWrapper(apollo, castor, pluto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class CloudAgentConfiguration {
version: "1.0.0",
tag: "automation-test",
author: this.publishedDid,
schemaId: `${this.agentUrl}schema-registry/schemas/${newSchemaGuid}`,
schemaId: `${this.agentUrl}schema-registry/schemas/${newSchemaGuid}/schema`,
signatureType: "CL",
supportRevocation: false,
description: "Test Automation Auto-Generated TS"
Expand Down
63 changes: 63 additions & 0 deletions integration-tests/e2e-tests/src/configuration/InMemoryStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import SDK from "@atala/prism-wallet-sdk"

import { MangoQuery } from "rxdb";

/**
* WARNING: Do not use this Pluto Store implementation, its for test purposes only.
* Persistence is inMemory and totally unprotected.
* Functionality isn't 100% covered - only handling what is necessary
*/
export class InMemoryStore implements SDK.Pluto.Store {

private store = new Map<string, any[]>();

async query<T>(table: string, query?: MangoQuery<T>): Promise<T[]> {
const items = this.get(table);
const selector = { ...query?.selector ?? {} };

const filtered = items.filter(item => {
if (Object.keys(selector).length === 0) return true;

const { $or, $and, ...props } = selector;
const matchProps = this.match(props, item);
const matchOr = ($or ?? []).reduce((acc, x) => acc || this.match(x, item), false);
const matchAnd = $and?.length > 0 ? ($and ?? []).reduce((acc, x) => acc && this.match(x, item), true) : false
return matchOr || matchAnd || matchProps;
});

return filtered;
}

async insert(table: string, model: any): Promise<void> {
const items = this.get(table);
items.push(model);
}

private get(key: string) {
const current = this.store.get(key);

if (!current) {
this.store.set(key, []);
}

return this.store.get(key)!;
}

private match(query: Record<string, any>, item: any) {
const keys = Object.keys(query);
if (keys.length <= 0) {
return false
}
const match = keys.every(key => item[key] == query[key]);
return match;
}


update<T extends SDK.Domain.Pluto.Storable>(table: string, model: T): Promise<void> {
throw new Error("Method not implemented.");
}

delete(table: string, uuid: string): Promise<void> {
throw new Error("Method not implemented.");
}
}
Loading

2 comments on commit eb6a5ab

@github-actions
Copy link

Choose a reason for hiding this comment

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

Lines Statements Branches Functions
Coverage: 67%
67.07% (1691/2521) 53.37% (648/1214) 69.75% (512/734)

JUnit

Tests Skipped Failures Errors Time
383 2 💤 0 ❌ 0 🔥 57.784s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

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

Lines Statements Branches Functions
Coverage: 67%
67.07% (1691/2521) 53.37% (648/1214) 69.75% (512/734)

JUnit

Tests Skipped Failures Errors Time
383 2 💤 0 ❌ 0 🔥 56.629s ⏱️

Please sign in to comment.