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

804 - add workstep2 and 3 to e2e test #807

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion examples/bri-3/src/bri/merkleTree/models/bpiMerkleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export class BpiMerkleTree {
}

public getRoot(): string {
return this.tree.getRoot().toString();
return this.tree.getHexRoot();
}
}
135 changes: 125 additions & 10 deletions examples/bri-3/test/sriUseCase.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ let supplierBpiSubjectEddsaPrivateKey: string;
let buyerBpiSubjectEddsaPublicKey: string;
let buyerBpiSubjectEddsaPrivateKey: string;
let createdWorkgroupId: string;
let createdWorkstepId: string;
let createdWorkstep1Id: string;
let createdWorkstep2Id: string;
let createdWorkstep3Id: string;
let createdWorkflowId: string;
let createdBpiSubjectAccountSupplierId: string;
let createdBpiSubjectAccountBuyerId: string;
Expand Down Expand Up @@ -123,24 +125,34 @@ describe('SRI use-case end-to-end test', () => {
);
});

it('Sets up a workflow with a workstep in the previously created workgroup', async () => {
it('Sets up a workflow with 3 worksteps in the previously created workgroup', async () => {
// TODO: Auth as supplier?
// TODO: Can we listen and fire NATS messages here

createdWorkstepId = await createWorkstepAndReturnId(
createdWorkstep1Id = await createWorkstepAndReturnId(
'workstep1',
createdWorkgroupId,
);

createdWorkstep2Id = await createWorkstepAndReturnId(
'workstep2',
createdWorkgroupId,
);

createdWorkstep3Id = await createWorkstepAndReturnId(
'workstep3',
createdWorkgroupId,
);

createdWorkflowId = await createWorkflowAndReturnId(
'worksflow1',
createdWorkgroupId,
[createdWorkstepId],
[createdWorkstep1Id, createdWorkstep2Id, createdWorkstep3Id],
[createdBpiSubjectAccountSupplierId, createdBpiSubjectAccountBuyerId],
);
});

it('Add a circuit input translation schema to a workstep', async () => {
it('Add a circuit input translation schema to workstep 1', async () => {
const schema = `{
"mapping": [
{
Expand Down Expand Up @@ -175,17 +187,46 @@ describe('SRI use-case end-to-end test', () => {
}
]
}`;
await addCircuitInputsSchema(createdWorkstepId, schema);
await addCircuitInputsSchema(createdWorkstep1Id, schema);
});

it('Submits a transaction for execution of the workstep 1', async () => {
it('Add a circuit input translation schema to workstep 2', async () => {
const schema = `{
"mapping": [
{
"circuitInput": "invoiceStatus",
"description": "Invoice status",
"payloadJsonPath": "status",
"dataType": "string"
}
]
}`;
await addCircuitInputsSchema(createdWorkstep2Id, schema);
});

it('Add a circuit input translation schema to workstep 3', async () => {
// TODO: Correct err in case of missing mapping
const schema = `{
"mapping": [
{
"circuitInput": "invoiceStatus",
"description": "Invoice status",
"payloadJsonPath": "status",
"dataType": "string"
}
]
}`;
await addCircuitInputsSchema(createdWorkstep3Id, schema);
});

it('Submits transaction 1 for execution of the workstep 1', async () => {
// TODO: CheckAuthz on createTransaction and in other places
// TODO: Faking two items in the payload as the circuit is hardcoded to 4
const createdTransactionId = await createTransactionAndReturnId(
await createTransactionAndReturnId(
v4(),
1,
createdWorkflowId,
createdWorkstepId,
createdWorkstep1Id,
createdBpiSubjectAccountSupplierId,
supplierBpiSubjectEddsaPrivateKey,
createdBpiSubjectAccountBuyerId,
Expand All @@ -205,7 +246,7 @@ describe('SRI use-case end-to-end test', () => {
);
});

it('Waits for a single VSM cycle and then verifies that the transaction has been executed and that the state has been properly stored', async () => {
it('Waits for a single VSM cycle and then verifies that transaction 1 has been executed and that the state has been properly stored', async () => {
await new Promise((r) => setTimeout(r, 50000));
const resultWorkflow = await fetchWorkflow(createdWorkflowId);
const resultBpiAccount = await fetchBpiAccount(resultWorkflow.bpiAccountId);
Expand All @@ -216,6 +257,80 @@ describe('SRI use-case end-to-end test', () => {
expect(stateTree.leaves.length).toBe(1);
expect(historyTree.leaves.length).toBe(1);
});

it('Submits transaction 2 for execution of the workstep 2', async () => {
await createTransactionAndReturnId(
v4(),
1,
createdWorkflowId,
createdWorkstep2Id,
createdBpiSubjectAccountBuyerId,
buyerBpiSubjectEddsaPrivateKey,
createdBpiSubjectAccountSupplierId,
`{
"supplierInvoiceID": "INV123",
"amount": 300,
"issueDate": "2023-06-15",
"dueDate": "2023-07-15",
"status": "VERIFIED",
"items": [
{ "id": 1, "productId": "product1", "price": 100, "amount": 1 },
{ "id": 2, "productId": "product2", "price": 200, "amount": 1 },
{ "id": 3, "productId": "placeholder", "price": 0, "amount": 0 },
{ "id": 4, "productId": "placeholder", "price": 0, "amount": 0 }
]
}`,
);
});

it('Waits for a single VSM cycle and then verifies that the transaction 2 has been executed and that the state has been properly stored', async () => {
await new Promise((r) => setTimeout(r, 50000));
const resultWorkflow = await fetchWorkflow(createdWorkflowId);
const resultBpiAccount = await fetchBpiAccount(resultWorkflow.bpiAccountId);

const stateTree = JSON.parse(resultBpiAccount.stateTree.tree);
const historyTree = JSON.parse(resultBpiAccount.historyTree.tree);

expect(stateTree.leaves.length).toBe(2);
expect(historyTree.leaves.length).toBe(2);
});

it('Submits transaction 3 for execution of the workstep 3', async () => {
await createTransactionAndReturnId(
v4(),
2,
createdWorkflowId,
createdWorkstep3Id,
createdBpiSubjectAccountBuyerId,
buyerBpiSubjectEddsaPrivateKey,
createdBpiSubjectAccountSupplierId,
`{
"supplierInvoiceID": "INV123",
"amount": 300,
"issueDate": "2023-06-15",
"dueDate": "2023-07-15",
"status": "PAID",
"items": [
{ "id": 1, "productId": "product1", "price": 100, "amount": 1 },
{ "id": 2, "productId": "product2", "price": 200, "amount": 1 },
{ "id": 3, "productId": "placeholder", "price": 0, "amount": 0 },
{ "id": 4, "productId": "placeholder", "price": 0, "amount": 0 }
]
}`,
);
});

it('Waits for a single VSM cycle and then verifies that the transaction 3 has been executed and that the state has been properly stored', async () => {
await new Promise((r) => setTimeout(r, 50000));
const resultWorkflow = await fetchWorkflow(createdWorkflowId);
const resultBpiAccount = await fetchBpiAccount(resultWorkflow.bpiAccountId);

const stateTree = JSON.parse(resultBpiAccount.stateTree.tree);
const historyTree = JSON.parse(resultBpiAccount.historyTree.tree);

expect(stateTree.leaves.length).toBe(3);
expect(historyTree.leaves.length).toBe(3);
});
});

async function loginAsInternalBpiSubjectAndReturnAnAccessToken(): Promise<string> {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading