Skip to content

Commit

Permalink
fix(iroha2-connector): fix flaky tests
Browse files Browse the repository at this point in the history
- Use waitForCommit for all transactions used in test suites to prevent spurious CI test failures.

Closes: hyperledger-cacti#2370
Closes: hyperledger-cacti#2373

Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com>
  • Loading branch information
outSH committed Apr 7, 2023
1 parent 48a4133 commit ce04851
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import {
generateTestIrohaCredentials,
IrohaV2TestEnv,
waitForCommit,
} from "../test-helpers/iroha2-env-setup";
import { addRandomSuffix } from "../test-helpers/utils";

Expand Down Expand Up @@ -160,18 +159,16 @@ describe("Generate and send signed transaction tests", () => {
// 3. Send
const transactionResponse = await env.apiClient.transactV1({
signedTransaction,
waitForCommit: true,
baseConfig: env.defaultBaseConfig,
});
expect(transactionResponse).toBeTruthy();
expect(transactionResponse.status).toEqual(200);
expect(transactionResponse.data.rejectReason).toBeUndefined();
expect(transactionResponse.data.status).toEqual(
TransactionStatusV1.Submitted,
TransactionStatusV1.Committed,
);

// Sleep
await waitForCommit();

// Check if domain was created
await assertDomainExistence(domainName);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { setCrypto } from "@iroha2/client";
import {
IrohaV2TestEnv,
generateTestIrohaCredentials,
waitForCommit,
} from "../test-helpers/iroha2-env-setup";
import { addRandomSuffix } from "../test-helpers/utils";

Expand Down Expand Up @@ -112,46 +111,6 @@ describe("Setup and basic endpoint tests", () => {
expect(overwrittenConfig).toEqual(requestConfig.torii);
});

test("Simple transaction without waiting and query endpoints works", async () => {
const domainName = addRandomSuffix("singleTxTest");

// Create new domain
const transactionResponse = await env.apiClient.transactV1({
transaction: {
instruction: {
name: IrohaInstruction.RegisterDomain,
params: [domainName],
},
},
baseConfig: env.defaultBaseConfig,
});
expect(transactionResponse).toBeTruthy();
expect(transactionResponse.status).toEqual(200);
expect(transactionResponse.data.status).toBeTruthy();
expect(transactionResponse.data.status).toEqual(
TransactionStatusV1.Submitted,
);
expect(transactionResponse.data.hash).toBeTruthy();
expect(transactionResponse.data.hash.length).toEqual(64);

// Sleep
await waitForCommit();

// Query it
const queryResponse = await env.apiClient.queryV1({
query: {
query: IrohaQuery.FindDomainById,
params: [domainName],
},
baseConfig: env.defaultBaseConfig,
});
expect(queryResponse).toBeTruthy();
expect(queryResponse.data).toBeTruthy();
expect(queryResponse.data.response).toBeTruthy();
expect(queryResponse.data.response.id).toBeTruthy();
expect(queryResponse.data.response.id.name).toEqual(domainName);
});

test("Waiting for transaction commit returns it's status", async () => {
const domainName = addRandomSuffix("waitForTx");

Expand Down

0 comments on commit ce04851

Please sign in to comment.