Skip to content

Commit

Permalink
test: fix e2e proof flow
Browse files Browse the repository at this point in the history
Signed-off-by: Allain Magyar <allain.magyar@iohk.io>
  • Loading branch information
amagyar-iohk committed Apr 29, 2024
1 parent 4c13919 commit 00dc829
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 162 deletions.
4 changes: 2 additions & 2 deletions E2E/e2eTests/Source/Abilities/Sdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Sdk: Ability {
),
keychain: KeychainMock()
)).build()
let pollux = PolluxBuilder(pluto: pluto).build()
let pollux = PolluxBuilder(pluto: pluto, castor: castor).build()
let mercury = MercuryBuilder(
castor: castor,
secretsStream: Client.createSecretsStream(
Expand All @@ -62,7 +62,7 @@ class Sdk: Ability {
).build()

PrismAgent.setupLogging(logLevels: [
.prismAgent: .info
.prismAgent: .warning
])

prismAgent = PrismAgent(
Expand Down
3 changes: 0 additions & 3 deletions E2E/e2eTests/Source/Features/AnoncredFeature.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import Foundation
import XCTest

class AnoncredFeature: Feature {
override func title() -> String {
"Receive anonymous credential"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import XCTest

final class AnoncredProofOfRequestFeature: Feature {
override func title() -> String {
"Provide anonymous proof of request"
Expand All @@ -9,12 +7,12 @@ final class AnoncredProofOfRequestFeature: Feature {
"The Edge Agent should provide anonymous proof to Cloud Agent"
}

func testRespondToProofOfRequest() async throws {
func testRespondToAnoncredProofOfRequest() async throws {
currentScenario = Scenario("Respond to anonymous request proof")
.given("Cloud Agent is connected to Edge Agent")
.and("Edge Agent has '1' anonymous credentials issued by Cloud Agent")
.when("Cloud Agent asks for anonymous present-proof")
.and("Edge Agent sends the present-proof")
.and("Edge Agent sends the present-proof using anoncreds credential type")
.then("Cloud Agent should see the present-proof is verified")
}
}
1 change: 0 additions & 1 deletion E2E/e2eTests/Source/Features/ConnectionFeature.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

final class ConnectionFeature: Feature {
override func title() -> String {
"Create connection"
Expand Down
2 changes: 0 additions & 2 deletions E2E/e2eTests/Source/Features/CredentialFeature.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import XCTest

final class CredentialTests: Feature {
override func title() -> String {
"Receive verifiable credential"
Expand Down
4 changes: 1 addition & 3 deletions E2E/e2eTests/Source/Features/ProofOfRequestFeature.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import XCTest

final class ProofOfRequestFeature: Feature {
override func title() -> String {
"Provide proof of request"
Expand All @@ -14,7 +12,7 @@ final class ProofOfRequestFeature: Feature {
.given("Cloud Agent is connected to Edge Agent")
.and("Edge Agent has '1' credentials issued by Cloud Agent")
.when("Cloud Agent asks for present-proof")
.and("Edge Agent sends the present-proof")
.and("Edge Agent sends the present-proof using JWT credential type")
.then("Cloud Agent should see the present-proof is verified")
}
}
6 changes: 3 additions & 3 deletions E2E/e2eTests/Source/Steps/EdgeAgentSteps.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

class EdgeAgentSteps: Steps {
@Step("{actor} sends the present-proof")
var edgeAgentSendsThePresentProof = { (edgeAgent: Actor) in
@Step("{actor} sends the present-proof using {} credential type")
var edgeAgentSendsThePresentProof = { (edgeAgent: Actor, credentialType: String) in
try await EdgeAgentWorkflow.waitForProofRequest(edgeAgent: edgeAgent)
try await EdgeAgentWorkflow.presentProof(edgeAgent: edgeAgent)
try await EdgeAgentWorkflow.presentProof(edgeAgent: edgeAgent, credentialType: credentialType)
}

@Step("{actor} has '{int}' credentials issued by {actor}")
Expand Down
60 changes: 24 additions & 36 deletions E2E/e2eTests/Source/Workflows/CloudAgentWorkflow.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation

typealias CredentialProtocolState = Components.Schemas.IssueCredentialRecord.protocolStatePayload

class CloudAgentWorkflow {
static func isConnectedToEdgeAgent(cloudAgent: Actor, edgeAgent: Actor) async throws{
try await hasAConnectionInvitation(cloudAgent: cloudAgent)
Expand All @@ -9,10 +11,9 @@ class CloudAgentWorkflow {
}

static func hasAConnectionInvitation(cloudAgent: Actor) async throws {
let connection = try await cloudAgent.using(
ability: OpenEnterpriseAPI.self,
action: "create a connection"
).createConnection()
let connection = try await cloudAgent.using(OpenEnterpriseAPI.self, "create a connection") {
try await $0.createConnection()
}
try cloudAgent.remember(key: "invitation", value: connection.invitation.invitationUrl)
try cloudAgent.remember(key: "connectionId", value: connection.connectionId)
}
Expand All @@ -24,67 +25,54 @@ class CloudAgentWorkflow {

static func shouldHaveTheConnectionStatusUpdated(cloudAgent: Actor, expectedState: Components.Schemas.Connection.statePayload) async throws {
let connectionId: String = try cloudAgent.recall(key: "connectionId")
try await cloudAgent.waitUsingAbility(
ability: OpenEnterpriseAPI.self,
action: "connection state to be \(expectedState.rawValue)"
) { ability in
return try await ability.getConnection(connectionId).state == expectedState
try await cloudAgent.waitUsingAbility(OpenEnterpriseAPI.self, "connection state to be \(expectedState.rawValue)") {
try await $0.getConnection(connectionId).state == expectedState
}
}

static func offersACredential(cloudAgent: Actor) async throws {
let connectionId: String = try cloudAgent.recall(key: "connectionId")
let credentialOfferRecord = try await cloudAgent.using(
ability: OpenEnterpriseAPI.self,
action: "offers a credential to \(connectionId)"
).offerCredential(connectionId)
let credentialOfferRecord = try await cloudAgent.using(OpenEnterpriseAPI.self, "offers a credential to \(connectionId)") {
try await $0.offerCredential(connectionId)
}
try cloudAgent.remember(key: "recordId", value: credentialOfferRecord.recordId)
}

static func offersAnonymousCredential(cloudAgent: Actor) async throws {
let connectionId: String = try cloudAgent.recall(key: "connectionId")
let credentialOfferRecord = try await cloudAgent.using(
ability: OpenEnterpriseAPI.self,
action: "offers an anonymous credential to \(connectionId)"
).offerAnonymousCredential(connectionId)
let credentialOfferRecord = try await cloudAgent.using(OpenEnterpriseAPI.self, "offers an anonymous credential to \(connectionId)") {
try await $0.offerAnonymousCredential(connectionId)
}
try cloudAgent.remember(key: "recordId", value: credentialOfferRecord.recordId)
}

static func asksForPresentProof(cloudAgent: Actor) async throws {
let connectionId: String = try cloudAgent.recall(key: "connectionId")
let presentation = try await cloudAgent.using(
ability: OpenEnterpriseAPI.self,
action: "ask a presentation proof to \(connectionId)"
).requestPresentProof(connectionId)
let presentation = try await cloudAgent.using(OpenEnterpriseAPI.self, "ask a presentation proof to \(connectionId)") {
try await $0.requestPresentProof(connectionId)
}
try cloudAgent.remember(key: "presentationId", value: presentation.presentationId)
}

static func asksForAnonymousPresentProof(cloudAgent: Actor) async throws {
let connectionId: String = try cloudAgent.recall(key: "connectionId")
let presentation = try await cloudAgent.using(
ability: OpenEnterpriseAPI.self,
action: "ask an anonymous presentation proof to \(connectionId)"
).requestAnonymousPresentProof(connectionId)
let presentation = try await cloudAgent.using(OpenEnterpriseAPI.self, "ask an anonymous presentation proof to \(connectionId)") {
try await $0.requestAnonymousPresentProof(connectionId)
}
try cloudAgent.remember(key: "presentationId", value: presentation.presentationId)
}

static func verifyCredentialState(cloudAgent: Actor, recordId: String, expectedState: Components.Schemas.IssueCredentialRecord.protocolStatePayload) async throws {
try await cloudAgent.waitUsingAbility(
ability: OpenEnterpriseAPI.self,
action: "credential state is \(expectedState.rawValue)"
) { ability in
let credentialRecord = try await ability.getCredentialRecord(recordId)
static func verifyCredentialState(cloudAgent: Actor, recordId: String, expectedState: CredentialProtocolState) async throws {
try await cloudAgent.waitUsingAbility(OpenEnterpriseAPI.self, "credential state is \(expectedState.rawValue)") {
let credentialRecord = try await $0.getCredentialRecord(recordId)
return credentialRecord.protocolState == expectedState
}
}

static func verifyPresentProof(cloudAgent: Actor, expectedState: Components.Schemas.PresentationStatus.statusPayload) async throws {
let presentationId: String = try cloudAgent.recall(key: "presentationId")
try await cloudAgent.waitUsingAbility(
ability: OpenEnterpriseAPI.self,
action: "present proof state is \(expectedState.rawValue)"
) { ability in
let presentationStatus = try await ability.getPresentation(presentationId)
try await cloudAgent.waitUsingAbility(OpenEnterpriseAPI.self, "present proof state is \(expectedState.rawValue)") {
let presentationStatus = try await $0.getPresentation(presentationId)
return presentationStatus.status == expectedState
}
}
Expand Down
136 changes: 53 additions & 83 deletions E2E/e2eTests/Source/Workflows/EdgeAgentWorkflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@ class EdgeAgentWorkflow {
let invitation: String = try edgeAgent.recall(key: "invitation")
let url = URL(string: invitation)!

let oob = try edgeAgent.using(
ability: Sdk.self,
action: "parses an OOB invitation"
).prismAgent.parseOOBInvitation(url: url)
let oob = try await edgeAgent.using(Sdk.self, "parses an OOB invitation") {
try $0.prismAgent.parseOOBInvitation(url: url)
}

try await edgeAgent.using(
ability: Sdk.self,
action: "accepts an invitation"
).prismAgent.acceptDIDCommInvitation(invitation: oob)
try await edgeAgent.using(Sdk.self, "accepts an invitation") {
try await $0.prismAgent.acceptDIDCommInvitation(invitation: oob)
}
}

static func waitToReceiveCredentialsOffer(edgeAgent: Actor, numberOfCredentials: Int) async throws {
try await edgeAgent.waitUsingAbility(
ability: Sdk.self,
action: "credential offer count to be \(numberOfCredentials)"
) { ability in
return ability.credentialOfferStack.count == numberOfCredentials
try await edgeAgent.waitUsingAbility(Sdk.self, "credential offer count to be \(numberOfCredentials)") {
$0.credentialOfferStack.count == numberOfCredentials
}
}

Expand Down Expand Up @@ -52,101 +47,76 @@ class EdgeAgentWorkflow {
}

static func acceptsTheCredentialOffer(edgeAgent: Actor) async throws {
let message: Message = try edgeAgent.using(
ability: Sdk.self,
action: "gets the first credential offer"
).credentialOfferStack.first!
let message: Message = try await edgeAgent.using(Sdk.self, "gets the first credential offer") {
$0.credentialOfferStack.first!
}

try edgeAgent.using(
ability: Sdk.self,
action: "removes it from list"
).credentialOfferStack.removeFirst()
try await edgeAgent.using(Sdk.self, "removes it from list") {
$0.credentialOfferStack.removeFirst()
}

let acceptOfferMessage = try OfferCredential3_0.init(fromMessage: message)
let did = try await edgeAgent.using(
ability: Sdk.self,
action: "create a new prism DID"
).prismAgent.createNewPrismDID()
let did = try await edgeAgent.using(Sdk.self, "create a new prism DID") {
try await $0.prismAgent.createNewPrismDID()
}

let requestCredential = try await edgeAgent
.using(
ability: Sdk.self,
action: "request a credential"
)
.prismAgent
.prepareRequestCredentialWithIssuer(
let requestCredential = try await edgeAgent.using(Sdk.self, "request a credential") {
try await $0.prismAgent.prepareRequestCredentialWithIssuer(
did: did,
offer: acceptOfferMessage
)!.makeMessage()
}

_ = try await edgeAgent.using(
ability: Sdk.self,
action: "send a message"
).prismAgent.sendMessage(message: requestCredential)
try await edgeAgent.using(Sdk.self, "send a message") {
try await $0.prismAgent.sendMessage(message: requestCredential)
}
}

static func waitToReceiveIssuedCredentials(edgeAgent: Actor, numberOfCredentials: Int) async throws {
try await edgeAgent.waitUsingAbility(
ability: Sdk.self,
action: "wait for issued credentials to be \(numberOfCredentials)"
) { ability in
return ability.issueCredentialStack.count == numberOfCredentials
try await edgeAgent.waitUsingAbility(Sdk.self, "wait for issued credentials to be \(numberOfCredentials)") { ability in
ability.issueCredentialStack.count == numberOfCredentials
}
}

static func processIssuedCredentials(edgeAgent: Actor, numberOfCredentials: Int) async throws {
for _ in 0..<numberOfCredentials {
let message = try edgeAgent.using(
ability: Sdk.self,
action: "get an issued credential"
).issueCredentialStack.first!
try edgeAgent.using(
ability: Sdk.self,
action: "remove it from list"
).issueCredentialStack.removeFirst()
let message = try await edgeAgent.using(Sdk.self, "get an issued credential") {
$0.issueCredentialStack.first!
}
try await edgeAgent.using(Sdk.self, "remove it from list") {
$0.issueCredentialStack.removeFirst()
}
let issuedCredential = try IssueCredential3_0(fromMessage: message)
_ = try await edgeAgent.using(
ability: Sdk.self,
action: "process the credential"
).prismAgent.processIssuedCredentialMessage(message: issuedCredential)
try await edgeAgent.using(Sdk.self, "process the credential") {
try await $0.prismAgent.processIssuedCredentialMessage(message: issuedCredential)
}
}
}

static func waitForProofRequest(edgeAgent: Actor) async throws {
try await edgeAgent.waitUsingAbility(
ability: Sdk.self,
action: "wait for present proof request"
) { ability in
return ability.proofOfRequestStack.count == 1
try await edgeAgent.waitUsingAbility(Sdk.self, "wait for present proof request") {
$0.proofOfRequestStack.count == 1
}
}

static func presentProof(edgeAgent: Actor) async throws {
let credential = try await edgeAgent.using(
ability: Sdk.self,
action: "get a verifiable credential"
).prismAgent.verifiableCredentials().map { $0.first }.first().await()

let message = try edgeAgent.using(
ability: Sdk.self,
action: "get proof request"
).proofOfRequestStack.first!
try edgeAgent.using(
ability: Sdk.self,
action: "remove it from list"
).proofOfRequestStack.removeFirst()
static func presentProof(edgeAgent: Actor, credentialType: String) async throws {
let credential = try await edgeAgent.using(Sdk.self, "get a verifiable credential") {
try await $0.prismAgent.verifiableCredentials()
.map { $0.filter { $0.credentialType == credentialType } }
.map { $0.first }.first().await()
}
let message = try await edgeAgent.using(Sdk.self, "get proof request") {
$0.proofOfRequestStack.first!
}
try await edgeAgent.using(Sdk.self, "remove it from list") {
$0.proofOfRequestStack.removeFirst()
}
let requestPresentationMessage = try RequestPresentation(fromMessage: message)
let sendProofMessage = try await edgeAgent.using(
ability: Sdk.self,
action: "make message"
).prismAgent.createPresentationForRequestProof(request: requestPresentationMessage, credential: credential!).makeMessage()
do {
_ = try await edgeAgent.using(
ability: Sdk.self,
action: "send message"
).prismAgent.sendMessage(message: sendProofMessage)
} catch {
print("error", error)
let sendProofMessage = try await edgeAgent.using(Sdk.self, "make message") {
try await $0.prismAgent.createPresentationForRequestProof(request: requestPresentationMessage, credential: credential!).makeMessage()
}
try await edgeAgent.using(Sdk.self, "send message") {
try await $0.prismAgent.sendMessage(message: sendProofMessage)
}
}
}
1 change: 0 additions & 1 deletion E2E/e2eTests/TestFramework/BDD/Feature.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import Foundation
import XCTest
import SwiftHamcrest
Expand Down
6 changes: 5 additions & 1 deletion E2E/e2eTests/TestFramework/Outcome/ActionOutcome.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Foundation

class ActionOutcome {
class ActionOutcome: CustomStringConvertible {
var description: String {
return "[action=\(action); executed=\(executed); error=\(String(describing: error))]"
}

var action = ""
var executed = false
var error: Error? = nil
Expand Down

0 comments on commit 00dc829

Please sign in to comment.