Skip to content

Commit

Permalink
test: fix all broken validations in packages folder 
Browse files Browse the repository at this point in the history
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 <ashnashahgrover777@gmail.com>
  • Loading branch information
ashnashahgrover committed Sep 21, 2024
1 parent f2c27ea commit 1e35f55
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ describe("Ethereum persistence PostgreSQL PostgresDatabaseClient tests", () => {
},
],
}),
).rejects.toThrow();
).rejects.toThrow();

// Assert no data was added
const blocksResponse = await getDbBlocks();
Expand Down

0 comments on commit 1e35f55

Please sign in to comment.