fix: add test dependencies

This commit is contained in:
Tim Man
2023-07-17 16:27:33 +08:00
parent e117af9a3d
commit 1a6e3bc2e6
5 changed files with 5671 additions and 14 deletions

7
jest.config.js Normal file
View File

@@ -0,0 +1,7 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
setupFilesAfterEnv: ["<rootDir>/tests/jest.setup.ts"],
roots: ["<rootDir>/tests"],
};

5654
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -26,6 +26,7 @@
"node-cache": "^5.1.2"
},
"devDependencies": {
"@types/jest": "^29.5.3",
"@types/node": "^12.12.6",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
@@ -35,9 +36,11 @@
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.6.1",
"nock": "^13.2.0",
"nodemon": "^2.0.15",
"prettier": "^2.8.7",
"ts-jest": "^29.1.1",
"ts-node": "^10.8.1",
"typescript": "^4.2.3"
}

View File

@@ -2,7 +2,7 @@ import { PayloadType, ContractCallPayload, getAbi, addressToString, StacksTransa
// rules for transaction sponsorship eligibility
// customize this if you are forking this repo
export async function validateTransaction(transaction: StacksTransaction) {
export async function validateTransaction(transaction: StacksTransaction): Promise<boolean> {
if (transaction.payload.payloadType !== PayloadType.ContractCall) {
throw new Error('Transaction is not a contract call');
}

19
tests/jest.setup.ts Normal file
View File

@@ -0,0 +1,19 @@
//mocking the use of env variables, even if .env file changes, it won't affect tests
jest.mock("../config/config", () => {
return {
seed: "xxx",
password: "xxx",
numAddresses: 3,
maxFee: 10,
};
});
jest.mock("@stacks/transactions", () => {
return Object.assign(
{},
{
...jest.requireActual("@stacks/transactions"),
callReadOnlyFunction: jest.fn(),
}
);
});