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

814 sri extend the e2e test to verify the cah was created from the public inputs payload and accompanying witness #822

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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../../../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../../../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/a7326b529c767f8dc53ea81689820584.json"
"buildInfo": "../../build-info/189c1ee8bdf5b684eaab5cd99ba5c880.json"
}
31 changes: 0 additions & 31 deletions examples/bri-3/src/bri/transactions/agents/transactions.agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,34 +344,3 @@ export class TransactionAgent {
return hashFn(`${merkelizedInvoiceRoot}${witnessHash}`).toString('hex');
}
}
// TODO: Example input preparation for other workstep circuits from the example use-case, to be used
// to properly setup dynamic mappings and to delete afterwards
// private async workstep2(inputs: {
// tx: Transaction;
// merkelizedPayload: MerkleTree;
// }): Promise<object> {
// //1. Eddsa signature

// const payload = JSON.parse(inputs.tx.payload);

// const preparedInputs = {
// invoiceStatus: payload.status,
// };

// return preparedInputs;
// }

// private async workstep3(inputs: {
// tx: Transaction;
// merkelizedPayload: MerkleTree;
// }): Promise<object> {
// //1. Eddsa signature

// const payload = JSON.parse(inputs.tx.payload);

// const preparedInputs = {
// invoiceStatus: payload.status,
// };

// return preparedInputs;
// }
8 changes: 8 additions & 0 deletions examples/bri-3/test/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ run_command() {
fi
}

# Check if port 8545 is in use
EXISTING_PID=$(lsof -ti:8545)
if [ ! -z "$EXISTING_PID" ]; then
log_message "Port 8545 is in use. Killing process $EXISTING_PID"
kill $EXISTING_PID
fi

# Change to ccsm directory
log_message "Changing to ccsm directory"
run_command "cd ../ccsm"
Expand Down Expand Up @@ -47,5 +54,6 @@ run_command "npm run test:e2e"
# Stop Hardhat node
log_message "Stopping Hardhat node"
kill $HARDHAT_PID
wait $HARDHAT_PID

log_message "Script execution completed"
85 changes: 75 additions & 10 deletions examples/bri-3/test/sriUseCase.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { ethers } from 'ethers';
import { ethers, JsonRpcProvider } from 'ethers';
import MerkleTree from 'merkletreejs';
import * as request from 'supertest';
import { v4 } from 'uuid';
Expand Down Expand Up @@ -37,6 +37,9 @@ let createdWorkstep3Id: string;
let createdWorkflowId: string;
let createdBpiSubjectAccountSupplierId: string;
let createdBpiSubjectAccountBuyerId: string;
let createdTransaction1Id: string;
let createdTransaction2Id: string;
let createdTransaction3Id: string;

describe('SRI use-case end-to-end test', () => {
beforeAll(async () => {
Expand Down Expand Up @@ -225,7 +228,7 @@ describe('SRI use-case end-to-end test', () => {
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
await createTransactionAndReturnId(
createdTransaction1Id = await createTransactionAndReturnId(
v4(),
1,
createdWorkflowId,
Expand All @@ -249,7 +252,7 @@ describe('SRI use-case end-to-end test', () => {
);
});

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 () => {
it('Waits for a single VSM cycle and then verifies that transaction 1 has been executed and that the state has been properly stored on chain and off chain', async () => {
await new Promise((r) => setTimeout(r, 50000));
const resultWorkflow = await fetchWorkflow(createdWorkflowId);
const resultBpiAccount = await fetchBpiAccount(resultWorkflow.bpiAccountId);
Expand All @@ -276,15 +279,29 @@ describe('SRI use-case end-to-end test', () => {
historyBpiMerkleTree.getLeafIndex(stateBpiMerkleTree.getRoot()),
).toBe(0);

const resultTransaction = await fetchTransaction(createdTransaction1Id);
const resultWorkstepInstanceId = resultTransaction.workstepInstanceId;

const contract = getContractFromLocalNode();
const contentAddressableHash = await contract.getAnchorHash(
resultWorkstepInstanceId,
);

expect(contentAddressableHash).toBeTruthy();
expect(contentAddressableHash.length).toBeGreaterThan(0);

expect(stateBpiMerkleTree.getLeaf(0)).toEqual(contentAddressableHash);

const stateTreeLeafValue = await fetchStateTreeLeafViaCAH(
stateBpiMerkleTree.getLeaf(0),
contentAddressableHash,
);

expect(stateTreeLeafValue).toBeTruthy();
expect(stateTreeLeafValue.leafIndex).toBe(0);
});

it('Submits transaction 2 for execution of the workstep 2', async () => {
await createTransactionAndReturnId(
createdTransaction2Id = await createTransactionAndReturnId(
v4(),
1,
createdWorkflowId,
Expand All @@ -308,7 +325,7 @@ describe('SRI use-case end-to-end test', () => {
);
});

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 () => {
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 on chain and off chain', async () => {
await new Promise((r) => setTimeout(r, 50000));
const resultWorkflow = await fetchWorkflow(createdWorkflowId);
const resultBpiAccount = await fetchBpiAccount(resultWorkflow.bpiAccountId);
Expand All @@ -335,15 +352,29 @@ describe('SRI use-case end-to-end test', () => {
historyBpiMerkleTree.getLeafIndex(stateBpiMerkleTree.getRoot()),
).toBe(1);

const resultTransaction = await fetchTransaction(createdTransaction2Id);
const resultWorkstepInstanceId = resultTransaction.workstepInstanceId;

const contract = getContractFromLocalNode();
const contentAddressableHash = await contract.getAnchorHash(
resultWorkstepInstanceId,
);

expect(contentAddressableHash).toBeTruthy();
expect(contentAddressableHash.length).toBeGreaterThan(0);

expect(stateBpiMerkleTree.getLeaf(1)).toEqual(contentAddressableHash);

const stateTreeLeafValue = await fetchStateTreeLeafViaCAH(
stateBpiMerkleTree.getLeaf(1),
contentAddressableHash,
);

expect(stateTreeLeafValue).toBeTruthy();
expect(stateTreeLeafValue.leafIndex).toBe(1);
});

it('Submits transaction 3 for execution of the workstep 3', async () => {
await createTransactionAndReturnId(
createdTransaction3Id = await createTransactionAndReturnId(
v4(),
2,
createdWorkflowId,
Expand All @@ -367,7 +398,7 @@ describe('SRI use-case end-to-end test', () => {
);
});

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 () => {
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 on chain and off chain', async () => {
await new Promise((r) => setTimeout(r, 50000));
const resultWorkflow = await fetchWorkflow(createdWorkflowId);
const resultBpiAccount = await fetchBpiAccount(resultWorkflow.bpiAccountId);
Expand All @@ -394,10 +425,24 @@ describe('SRI use-case end-to-end test', () => {
historyBpiMerkleTree.getLeafIndex(stateBpiMerkleTree.getRoot()),
).toBe(2);

const resultTransaction = await fetchTransaction(createdTransaction3Id);
const resultWorkstepInstanceId = resultTransaction.workstepInstanceId;

const contract = getContractFromLocalNode();
const contentAddressableHash = await contract.getAnchorHash(
resultWorkstepInstanceId,
);

expect(contentAddressableHash).toBeTruthy();
expect(contentAddressableHash.length).toBeGreaterThan(0);

expect(stateBpiMerkleTree.getLeaf(2)).toEqual(contentAddressableHash);

const stateTreeLeafValue = await fetchStateTreeLeafViaCAH(
stateBpiMerkleTree.getLeaf(2),
contentAddressableHash,
);

expect(stateTreeLeafValue).toBeTruthy();
expect(stateTreeLeafValue.leafIndex).toBe(2);
});
});
Expand Down Expand Up @@ -607,6 +652,26 @@ async function fetchBpiAccount(bpiAccountId: string): Promise<any> {
return JSON.parse(getBpiAccountResponse.text);
}

async function fetchTransaction(txId: string): Promise<any> {
const getTransactionResponse = await request(server)
.get(`/transactions/${txId}`)
.set('Authorization', `Bearer ${accessToken}`)
.expect(200);

return JSON.parse(getTransactionResponse.text);
}

function getContractFromLocalNode(): ethers.Contract {
const provider = new JsonRpcProvider('http://127.0.0.1:8545');
const contractAddress = `${process.env.CCSM_BPI_STATE_ANCHOR_CONTRACT_ADDRESS}`;

const contractABI = [
'function getAnchorHash(string calldata _workstepInstanceId) external view returns (string memory)',
];

return new ethers.Contract(contractAddress, contractABI, provider);
}

async function fetchStateTreeLeafViaCAH(cah: string): Promise<any> {
const fetchStateTreeLeafResponse = await request(server)
.get(`/state`)
Expand Down
Loading