From a65480da5f77c51912e3c1d3240b8198ebf1d22c Mon Sep 17 00:00:00 2001 From: ashnashahgrover Date: Mon, 26 Aug 2024 21:58:35 +0000 Subject: [PATCH] =?UTF-8?q?test:=20fix=20all=20broken=20validations=20in?= =?UTF-8?q?=20packages=20folder=C2=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Primary Changes --------------- 1. Fixed broken assertions in deploy-contract-from-json-xdai.test.ts so they assert that “Nonce is too low” as expected. Fixes #3493 Signed-off-by: ashnashahgrover --- .../deploy-contract-from-json-xdai.test.ts | 72 ++++++------------- ...ence-ethereum-postgresql-db-client.test.ts | 2 +- 2 files changed, 21 insertions(+), 53 deletions(-) diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai.test.ts b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai.test.ts index 7536c5f8235..bb21e172e2f 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai.test.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai.test.ts @@ -238,10 +238,11 @@ describe(testCase, () => { }); expect(setNameOut).toBeTruthy(); - //This is saying the function should NOT fail with a message containing "None too low" - //But the returned error message does contain that string. - try { - await connector.invokeContract({ + // Originally we had it so the statement below was expecting the error NOT to contain "Nonce to low" + // But actually it should contain that because the nonce for this account is already 1, as seen immediately above? + + await expect( + connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.Send, @@ -254,31 +255,8 @@ describe(testCase, () => { type: Web3SigningCredentialType.PrivateKeyHex, }, nonce: 1, - }); - fail("It should not reach here"); - } catch (error) { - console.log(error.message); - //error.message is Returned error: Nonce too low, below is not failing because it checks for an exact match - //And also it checks the error, not error.message - expect(error).not.toBe("Nonce too low"); - } - - // const contractInvocation = connector.invokeContract({ - // contractName, - // keychainId: keychainPlugin.getKeychainId(), - // invocationType: EthContractInvocationType.Send, - // methodName: "setName", - // params: [newName], - // gas: 1000000, - // web3SigningCredential: { - // ethAccount: testEthAccount.address, - // secret: testEthAccount.privateKey, - // type: Web3SigningCredentialType.PrivateKeyHex, - // }, - // nonce: 1, - // }); - - // await expect(contractInvocation).rejects.not.toThrow("Returned error: Nonce too low"); + }), + ).rejects.toThrow("Nonce too low"); const { callOutput: getNameOut } = await connector.invokeContract({ contractName, @@ -364,35 +342,25 @@ describe(testCase, () => { }); expect(setNameOut).toBeTruthy(); - try { - await connector.invokeContract({ + // Again, originally we had it so the statement below was expecting the error NOT to contain "Nonce to low" + // But actually it should contain that because the nonce for this account is already now 4, as seen immediately above? + + await expect( + connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.Send, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential, - nonce: 4, - }); - fail("It should not reach here"); - } catch (error) { - //the actual error message here also contains "Nonce too low" in the body - expect(error).not.toBe("Nonce too low"); - } - - // const contractInvocation = connector.invokeContract({ - // contractName, - // keychainId: keychainPlugin.getKeychainId(), - // invocationType: EthContractInvocationType.Send, - // methodName: "setName", - // params: [newName], - // gas: 1000000, - // web3SigningCredential, - // nonce: 4, - // }); - - // await expect(contractInvocation).rejects.not.toThrow("Nonce too low"); + web3SigningCredential: { + ethAccount: testEthAccount.address, + secret: testEthAccount.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + nonce: 1, + }), + ).rejects.toThrow("Nonce too low"); const { callOutput: getNameOut } = await connector.invokeContract({ contractName, diff --git a/packages/cactus-plugin-persistence-ethereum/src/test/typescript/integration/persistence-ethereum-postgresql-db-client.test.ts b/packages/cactus-plugin-persistence-ethereum/src/test/typescript/integration/persistence-ethereum-postgresql-db-client.test.ts index 4dbfbb83775..e6ae4cb83a4 100644 --- a/packages/cactus-plugin-persistence-ethereum/src/test/typescript/integration/persistence-ethereum-postgresql-db-client.test.ts +++ b/packages/cactus-plugin-persistence-ethereum/src/test/typescript/integration/persistence-ethereum-postgresql-db-client.test.ts @@ -417,7 +417,7 @@ describe("Ethereum persistence PostgreSQL PostgresDatabaseClient tests", () => { }, ], }), - ).rejects.toThrow(); + ).rejects.toThrow(); // Assert no data was added const blocksResponse = await getDbBlocks();