Skip to content

Commit

Permalink
Test/bdd publish errors (#2057)
Browse files Browse the repository at this point in the history
* getting operation status from additional nodes successfully

* resolve testcase fixed. Added testcase for publishing with invalid config.

* typo in test steps

* refactor: extracted method in local-blockchain class

* exctracted ganache keys to separate file

* checking if all tests will be run now

* refactor: extracted configuration setup functio

* waiting for operation to finaliza uses for now

* resolve changed to gge result in tests

* added test tags

* default node configurations are outside of bdd test steps. workflow yml file name changed

Co-authored-by: djordjekovac <[email protected]>
  • Loading branch information
micax3000 and djordjekovac authored Aug 30, 2022
1 parent 77fccb1 commit 32e64b3
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 338 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: TEST-release
name: TEST-bdd

#todo this test should be execute when opening PR to prerelease/release branches
on: [pull_request]
Expand All @@ -9,7 +9,7 @@ env:
REPOSITORY_PASSWORD: password
jobs:

test-release:
test-bdd:
#todo think about locking the version - version should be the same as the one in official documentation
runs-on: ubuntu-latest
services:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
- run: sudo chmod -R 777 $ARTIFACTS_DIR
- run: mkdir -p $CUCUMBER_ARTIFACTS_DIR
- run: sudo chmod -R 777 $CUCUMBER_ARTIFACTS_DIR
- run: npm run test:bdd:release;
- run: npm run test:bdd;
- uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
Expand Down
124 changes: 124 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test:bdd": "cucumber-js --fail-fast --format progress --format-options '{\"colorsEnabled\": true}' test/bdd/ -r test/bdd/steps/",
"test:unit": "nyc --all mocha --exit $(find test/unit -name '*.js')",
"test:bdd:release": "cucumber-js --tags=@release --fail-fast --format progress --format-options '{\"colorsEnabled\": true}' test/bdd/ -r test/bdd/steps/",
"test:bdd:publish-errors": "cucumber-js --tags=@publish-errors --fail-fast --format progress --format-options '{\"colorsEnabled\": true}' test/bdd/ -r test/bdd/steps/",
"lint": "eslint ."
},
"repository": {
Expand Down
49 changes: 10 additions & 39 deletions test/bdd/features/publish-errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,19 @@ Feature: Publish errors test
Given the blockchain is set up
And 1 bootstrap is running

## Scenario: Node is not able to start publish on the network with valid assertion
## Given I setup 4 nodes
## When I call publish on node 1 with validAssertion
## And I wait for last publish to finalize
## And Last publish finished with status: PUBLISH_START_ERROR
#TODO: needs to be investigated; publish completes even with invalid configuration
# @publish-errors
# Scenario: Node is not able to publish on a node with invalid configuration
# Given I setup publish node 1 with invalid configuration
# Given I setup 3 nodes
# When I call publish on node 1 with validAssertion
# And Last publish finished with status: PublishStartError

##
#
@publish-errors
Scenario: Node is not able to validate assertion on the network
Given I setup 4 nodes
When I call publish on ot-node 1 directly with invalidPublishRequestBody
And I wait for 15 seconds and check operationId status
And I wait for last publish to finalize
And Last publish finished with status: PublishValidateAssertionError

## Scenario: Node is not able to store publish result in the local database
## Given I setup 4 nodes
## When I call publish on node 1 with validAssertion
## And I wait for last publish to finalize
## And Last publish failed to store publish result with error: publishLocalStoreError
##
## Scenario: Node is not able to store publish init commands during the publish process
## Given I setup 4 nodes
## When I call publish on node 1 with validAssertion
## And I wait for last publish to finalize
## And Last publish failed to store publish init commands with error: publishStoreInitError
##
## Scenario: Node is not able to store publish request during the publish process
## Given I setup 4 nodes
## When I call publish on node 1 with validAssertion
## And I wait for last publish to finalize
## And Last publish failed to store publish request with error: publishStoreRequestError
##
## Scenario: Node is not able to find node during the publish process
## Given I setup 4 nodes
## When I call publish on node 1 with validAssertion
## And I wait for last publish to finalize
## And Last publish failed to find node with error: publishFindNodesError
##
## Scenario: Node is not able to finalized publish on the network with valid assertion
## Given I setup 4 nodes
## When I call publish on node 1 with validAssertion
## And I wait for last publish to finalize
## And Last publish failed with error: publishError
##
##
##
26 changes: 10 additions & 16 deletions test/bdd/features/release.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ Feature: Release related tests
Scenario: Node is able to publish on the network, expect status completed on publish result
Given I setup 4 nodes
When I call publish on node 1 with validAssertion
And I wait for last publish to finalize
And Last publish finished with status: COMPLETED

# @release
# Scenario: Node is able to resolve assertion previously published
# Given I setup 4 nodes
# When I call publish on node 1 with validAssertion
# And I wait for last publish to finalize
# And Last publish finished with status: COMPLETED
# And I call resolve on node 1 for last published assertion
# And I wait for last resolve to finalize
# And Last resolve finished with status: COMPLETED
# And Last resolve returned valid result
## And I setup 1 additional node
## And I call resolve on node 5 for last published assertion
## And I wait for last resolve to finalize
## And Last resolve finished with status: COMPLETED
## And Last resolve returned valid result
@release
Scenario: Node is able to get result of the operation previously published
Given I setup 4 nodes
When I call publish on node 1 with validAssertion
And Last publish finished with status: COMPLETED
And I get operation result from node 1 for last published assertion
And Last operation finished with status: COMPLETED
And I setup 1 additional node
And I get operation result from node 5 for last published assertion
And Last operation finished with status: COMPLETED
57 changes: 57 additions & 0 deletions test/bdd/steps/api/datasets/privateKeys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
"3cf97be6177acdd12796b387f58f84f177d0fe20d8558004e8db9a41cf90392a",
"1e60c8e9aa35064cd2eaa4c005bda2b76ef1a858feebb6c8e131c472d16f9740",
"2c26a937a1b8b20762e2e578899b98fd48b6ab2f8798cd03ccef2bee865c2c54",
"a76e13d35326f5e06d20655d0edb2f60b8863280fabf8e3f0b1210cf0bb72eec",
"d96876d0711ed11781efe0c04c95716c2e0acabc4eba418516d76be808a2fc54",
"6be9ea24e3c2adf0ac4c6705b445827a57c80e6fefa10df3f480da8aa2c523a4",
"6627e24e68bca3b29c548789aead92b48c0f4ce669842ff7e18ca356429b804c",
"1e3bae753e15ee5e6e2548105b53736a3db7304ac7681d00c77caca0b848b0ba",
"4bc5744a30e928d162ca580f9a034dfac7edc0415e0b9ddc2d221a155f6ec4ff",
"03c5646544ea8e47174ac98e3b97338c486860897e31333318ee62d19e5ea118",
"9fe33d5460d64c2993c687b9f2b6c3503e082388f59d0fea14142d20f805fcc5",
"843c42e809fc394e1d8647cd74edee133d5faa187933dc0fc08d302f57b6333c",
"81feca24308a669408b973dc010800d93d347db851ff9fc12ba7ec4e60846ee3",
"2fbcf9435210fed8dd47dccae453df02c0159c265dc454be8a24e4189e2a3c1b",
"5a03ebd83bf32553f00f33255154158a07020ebc2921d842a5aee2ab94370969",
"13a8fc7dac578c05cbae943f220477b2abcb9954c8cb31279fce2f864558420c",
"d35889eb100eb5544ea3e9ddab1181e628dc8e167365dcf97112fab9ae0db906",
"f261d13fb3fd1f3df2f5dc75b54066d354a25aa2800b90b42900fc0db794cc41",
"a6dc4993c4a65f78ad87cf972f468fe25c1ad86f32d479f2ad27d3c8f46a6487",
"5fc5a969744f359c109b64bb41dca7e49e1086a9298c862cd0e30772908bb70c",
"c00655521fa1326b8b1831fb74b2a5e45eca0e8e886df34e9a714ae70031c502",
"feee5c36d8a9b1c65d9b0810f048d817d6cd01f95b12e3ae8940a769e2a6d217",
"edf15b05b906d2582d269d81fe85ee64325fa081aafd64de32893d4d6b03f56d",
"92f6678cdb6ce485e305d5fa926d2d157745871fc7d72f0526048f8286f28247",
"dfa44843c22ae16de69e9181e2bfe2153e36464d266e32746de82478e9674d98",
"483af28e4e11638d018a4fa02dcb454cfff8235073921aefdb5a302956c6abb0",
"8908b19e6f8ed4aabe160719cc3cb2b15aabf79cfc436ad31574eedd2432e3bc",
"6b499a1289d1945cbc232bd47da77ae10432ffb63b7f6d04b797a74f30f22c7d",
"db908900b007ba9c384b116b6d1209d4842f37e2435d7fbd62d619643bb08e08",
"f5346004b07b6059be546f02b72a29f055251471c700e799f96529b4338ad635",
"2aa43025590ae9e9fb3eaaa75358e3a6e1719570864c43a33926a19da979ced9",
"1aa051ed6f3c40a01cad84d2c05ae3a80d897a3f7b56a88447643fc9e67cc004",
"c4505f045420e9c860989349d32a7716a9c6221c8bfc17e1012b06c4b926e530",
"35fbcc677cd348dafaa2c31519f458dcc9ddbb7278e38310e974787ca378a4a8",
"90505a5408c91fc59738f12c31f14a501c431160473819c4e7e9273092ebb288",
"e2eed5df7e6f32dfb793b7324e251950a8644d409aa194de822c1e42163e947e",
"1ac1f2db31610c84f09865b308b82d6236e09acd475b4136bd86440b7aa39c41",
"77ffe9a3e5738d8fc2fa14028e5e280872f87c7dfb5df58bd21cc6f2c7ce6f72",
"eb48615474a318cbd2e6197d01bf81d168f2d21a2a8a117bc979a887ec90d2df",
"f1a9455826b46ca2f9f66457d8faa6f02a30e1c0f0b5b5f6769b769974a5cc5f",
"afa420d816b8b97b5049ce4507b1c79ee26168bc4a197385cd848dd482746e2d",
"9fd7088936411d814238aa7072dc43c28e6ae7d298db37466dc6b3236191c3de",
"03199565ef8a1421b7fa73cbb4b4e6f4cb3470affcf8b18f783e192788d23519",
"27fa0a7dd2901067308dd9f2559204006712dc2809619a922a5fc3f43199a9b9",
"7ff5132877ee3ebaeed1664e3ff5abdcc7fb7cce57b74ce8ae2f0071e7132ab9",
"5bd9b42788ec465d52598e58857bae2b592c5b5cf8678693179a687317fe7928",
"7471241aa4a8d04058279da9266f44210a4ffd4d6ff16376ad3cab733cce3e8f",
"5ad0f83dadefdeefeee58d733ba35674f151dc1a1080bfafb9fb8778285f0646",
"966658dfe2cf0dfa999ef05ca3c926c5fe776ee4cbc7673bdea69d2907030357",
"440f37a3f0fe7560db8bc00200818c743a4a381b4d6b24967c31fc47d5ab831b",
"4072914e2feb382b79d5285d293902546938aa2b0e31cd6625ce59db77a6d3d4",
"7b39d2f9dcf59d87ca683d9797ac3f8c5ba7c9bc6ec4b6b5cfd27809160b64cb",
"455d135639bfaab54ffc729a873a1cea26e438600f0ef40642abbd2a91c9eae3",
"f04349eab3a51e2e871cbfd30d2e4c9aef791ad79b90ed32e05457b40925d8b7",
"952e45854ca5470a6d0b6cb86346c0e9c4f8f3a5a459657df8c94265183b9253"
]
80 changes: 37 additions & 43 deletions test/bdd/steps/api/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ const HttpApiHelper = require('../../../utilities/http-api-helper');

When(
/^I call publish on node (\d+) with ([^"]*)/,
{ timeout: 60000 },
{ timeout: 120000 },
async function publish(node, assertionName) {
this.logger.log('I call publish route successfully');
this.logger.log(`I call publish route on node ${node}`);
expect(
!!assertions[assertionName],
`Assertion with name: ${assertionName} not found!`,
).to.be.equal(true);
const { evmOperationalWalletPublicKey, evmOperationalWalletPrivateKey } =
this.state.nodes[node - 1].configuration.modules.blockchain.implementation.ganache
.config;
const hubContract = this.state.localBlockchain.uaiRegistryContractAddress();
const hubContract = this.state.localBlockchain.getHubAddress();
const assertion = assertions[assertionName];
const result = await this.state.nodes[node - 1].client
.publish(
Expand Down Expand Up @@ -60,51 +60,45 @@ When(
nodeId: node - 1,
operationId,
};
// await setTimeout(15000);
// const status = await httpApiHelper.getOperationResult(`http://localhost:${this.state.nodes[node - 1].configuration.rpcPort}`, operationId);
// console.log(JSON.stringify(status.data,null,2));
},
);

Given('I wait for last publish to finalize', { timeout: 60000 }, async () => {
// this.logger.log('I wait for last publish to finalize');
// expect(
// !!this.state.lastPublishData,
// 'Last publish data is undefined. Publish is not started.',
// ).to.be.equal(true);
// const publishData = this.state.lastPublishData;
// let loopForPublishResult = true;
// let retryCount = 0;
// const maxRetryCount = 2;
// while (loopForPublishResult) {
// this.logger.log(
// `Getting publish result for operation id: ${publishData.operationId} on node: ${publishData.nodeId}`,
// );
// // const publishResult = await httpApiHelper.getOperationResult(`http://localhost:${this.state.nodes[publishData.nodeId].configuration.rpcPort}`, publishData.operationId);
// // eslint-disable-next-line no-await-in-loop
// const publishResult = await this.state.nodes[publishData.nodeId].client
// .getResult(publishData.UAL)
// .catch((error) => {
// assert.fail(`Error while trying to get publish result assertion. ${error}`);
// });
// if (publishResult) {
// this.state.lastPublishData.result = publishResult;
// loopForPublishResult = false;
// }
// if (retryCount === maxRetryCount) {
// loopForPublishResult = true;
// assert.fail('Unable to get publish result');
// } else {
// retryCount += 1;
// // eslint-disable-next-line no-await-in-loop
// await setTimeout(5000);
// }
// }
Given('I wait for last publish to finalize', { timeout: 80000 }, async function publishFinalize() {
this.logger.log('I wait for last publish to finalize');
expect(
!!this.state.lastPublishData,
'Last publish data is undefined. Publish is not started.',
).to.be.equal(true);
const publishData = this.state.lastPublishData;
let retryCount = 0;
const maxRetryCount = 5;
const httpApiHelper = new HttpApiHelper();
for (retryCount = 0; retryCount < maxRetryCount; retryCount += 1) {
this.logger.log(
`Getting publish result for operation id: ${publishData.operationId} on node: ${publishData.nodeId}`,
);
// const publishResult = await httpApiHelper.getOperationResult(`http://localhost:${this.state.nodes[publishData.nodeId].configuration.rpcPort}`, publishData.operationId);
// eslint-disable-next-line no-await-in-loop
const publishResult = await httpApiHelper.getOperationResult(
this.state.nodes[publishData.nodeId].nodeRpcUrl,
publishData.operationId,
);
this.logger.log(`Operation status: ${publishResult.data.status}`);
if (['COMPLETED', 'FAILED'].includes(publishResult.data.status)) {
this.state.lastPublishData.result = publishResult;
break;
}
if (retryCount === maxRetryCount - 1) {
assert.fail('Unable to get publish result');
}
// eslint-disable-next-line no-await-in-loop
await setTimeout(4000);
}
});

Given(
/Last publish finished with status: ([COMPLETED|FAILED|PublishValidateAssertionError]+)$/,
{ timeout: 120000 },
/Last publish finished with status: ([COMPLETED|FAILED|PublishValidateAssertionError,PUblishStartError]+)$/,
{ timeout: 60000 },
async function lastPublishFinished(status) {
this.logger.log(`Last publish finished with status: ${status}`);
expect(
Expand All @@ -125,7 +119,7 @@ Given(
},
);
Given(
/I wait for (\d+) seconds and check operationId status/,
/I wait for (\d+) seconds and check operation status/,
{ timeout: 120000 },
async function publishWait(numberOfSeconds) {
this.logger.log(`I wait for ${numberOfSeconds} seconds`);
Expand Down
51 changes: 29 additions & 22 deletions test/bdd/steps/api/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@ const { setTimeout } = require('timers/promises');
const sortedStringify = require('json-stable-stringify');

When(
/^I call resolve on node (\d+) for last published assertion/,
/^I get operation result from node (\d+) for last published assertion/,
{ timeout: 120000 },
async function resolveCall(node) {
this.logger.log('I call resolve route successfully');
this.logger.log('I call get result for the last operation');
expect(
!!this.state.lastPublishData,
'Last publish data is undefined. Publish is not finalized.',
).to.be.equal(true);
const assertionIds = [this.state.lastPublishData.result.assertion.id];
const result = await this.state.nodes[node - 1].client
.resolve(assertionIds)
.catch((error) => {
assert.fail(`Error while trying to resolve assertion. ${error}`);
});
const operationId = result.data.operation_id;
// const assertionIds = [this.state.lastPublishData.result.assertion.id];

this.state.lastResolveData = {
nodeId: node - 1,
operationId,
assertionIds,
};
// TODO: CALLING GET RESULT WITH WRONG UAL RETURNS UNDEFINED RESULT, IT SHOULD PROBABLY RETURN A FAILED RESULT MESSAGE OR SOMETHING LIKE THAT
try {
const result = await this.state.nodes[node - 1].client
.getResult(this.state.lastPublishData.UAL)
.catch((error) => {
assert.fail(`Error while trying to resolve assertion. ${error}`);
});
const { operationId } = result.operation;

this.state.lastResolveData = {
nodeId: node - 1,
operationId,
result,
};
} catch (e) {
this.logger.log(`Error while getting operation result: ${e}`);
}
},
);

Expand Down Expand Up @@ -68,23 +74,24 @@ Given(
);

Given(
/Last resolve finished with status: ([COMPLETED|FAILED]+)$/,
/Last operation finished with status: ([COMPLETED|FAILED]+)$/,
{ timeout: 120000 },
async function lastResolveFinishedCall(status) {
this.logger.log(`Last resolve finished with status: ${status}`);
this.logger.log(`Last get result finished with status: ${status}`);
expect(
!!this.state.lastResolveData,
'Last resolve data is undefined. Resolve is not started.',
'Last get result data is undefined. Get result not started.',
).to.be.equal(true);
expect(
!!this.state.lastResolveData.result,
'Last resolve data result is undefined. Resolve is not finished.',
!!this.state.lastResolveData.result.operation,
'Last get result data result is undefined. Get result is not finished.',
).to.be.equal(true);

const resolveData = this.state.lastResolveData;
expect(resolveData.result.status, 'Publish result status validation failed').to.be.equal(
status,
);
expect(
resolveData.result.operation.status,
'Publish result status validation failed',
).to.be.equal(status);
},
);

Expand Down
Loading

0 comments on commit 32e64b3

Please sign in to comment.