Skip to content

Commit

Permalink
test(besu): refactor jest test negative test cases
Browse files Browse the repository at this point in the history
Primary Changes
----------------
1. Refactored all negative test case exception assertions for cactus-plugin-ledger-connector-besu.
Removed try-catch blocks, replaced with declarations through jest and jest-extended's own API.
2. Noted two tests within openapi-validation.test.ts
(GetPastLogsEndpoint and GetBesuRecordEndpointV1 with empty parameters) where the status
code returned should be 400 but is 200. This could be investigated in a seperate issue.

Fixes hyperledger-cacti#3467

Signed-off-by: ashnashahgrover <ashnashahgrover777@gmail.com>
  • Loading branch information
ashnashahgrover committed Aug 18, 2024
1 parent 30cde8b commit 21d0f78
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ describe("PluginLedgerConnectorBesu", () => {
});
expect(setNameOut).toBeTruthy();

try {
await connector.invokeContract({
await expect(
connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
Expand All @@ -280,19 +280,14 @@ describe("PluginLedgerConnectorBesu", () => {
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
throw new Error("This operation should not have succeeded, but it did.");
} catch (ex: unknown) {
// 'Returned error: Nonce too low'
expect(ex).toHaveProperty(
"message",
expect.stringContaining("Nonce too low"),
);
expect(ex).toHaveProperty(
"stack",
expect.stringContaining("Nonce too low"),
);
}
}),
).rejects.toThrowError(
expect.objectContaining({
message: expect.stringContaining("Nonce too low"),
stack: expect.stringContaining("Nonce too low"),
}),
);

const req: InvokeContractV1Request = {
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ describe(testCase, () => {
});
expect(setNameOut).toBeTruthy();

try {
const setNameOutInvalid = await connector.invokeContract({
await expect(
connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
Expand All @@ -197,11 +197,12 @@ describe(testCase, () => {
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
expect(setNameOutInvalid.transactionReceipt).toBeFalsy();
} catch (error) {
expect(error.message).toMatch("Nonce too low");
}
}),
).rejects.toThrowError(
expect.objectContaining({
message: expect.stringContaining("Nonce too low"),
}),
);

const { callOutput: getNameOut } = await connector.invokeContract({
contractName,
Expand Down Expand Up @@ -286,8 +287,8 @@ describe(testCase, () => {
});
expect(setNameOut).toBeTruthy();

try {
const setNameOutInvalid = await connector.invokeContract({
await expect(
connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
Expand All @@ -296,11 +297,8 @@ describe(testCase, () => {
gas: 1000000,
signingCredential,
nonce: 4,
});
expect(setNameOutInvalid.transactionReceipt).toBeFalsy();
} catch (error) {
expect(error.message).toMatch("Nonce too low");
}
}),
).rejects.toThrow("Nonce too low");

const { callOutput: getNameOut } = await connector.invokeContract({
contractName,
Expand Down
Loading

0 comments on commit 21d0f78

Please sign in to comment.