Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ci unit tests #29

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/pr-momoka-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build, Lint and Unit Tests for Momoka NODE

on:
pull_request:
types: [labeled, opened, synchronize, unlabeled]
# Run only when some modifications are perform in the momoka-node directory
paths:
- 'momoka-node/**'

jobs:
build-lint-test:
name: Build-Lint-Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8

- name: Install dependencies
run: cd momoka-node && pnpm install

- name: Lint the code
run: cd momoka-node && pnpm run lint

- name: Build the packages
run: cd momoka-node && pnpm run build

- name: Run the unit tests
run: cd momoka-node && pnpm run test:ci
22 changes: 22 additions & 0 deletions .github/workflows/pr-momoka-rs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build, Lint and Unit Tests for Momoka RUST

on:
pull_request:
types: [labeled, opened, synchronize, unlabeled]
# Run only when some modifications are perform in the momoka-rs directory
paths:
- 'momoka-rs/**'

jobs:
build-lint-test:
name: Build-Lint-Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build
run: cd momoka-rs && cargo build

- name: Run the unit tests
run: cd momoka-rs && cargo test
3 changes: 3 additions & 0 deletions momoka-node/.env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ETHEREUM_NETWORK=MUMBAI
NODE_URL="https://polygon-mumbai.g.alchemy.com/v2/s1Hq6Tyswh1mDXOlgawIqSCndvsNfYb6"
CONCURRENCY=3
4 changes: 3 additions & 1 deletion momoka-node/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
const { resolve } = require('path');

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
coverageDirectory: 'coverage',
testRegex: [resolve(__dirname, '/src/__TESTS__/*/.*\\.test\\.ts$')],
setupFiles: ['<rootDir>/src/__TESTS__/config/jest.setup.js'],
coveragePathIgnorePatterns: [
'node_modules',
Expand Down
7 changes: 4 additions & 3 deletions momoka-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
"README.md"
],
"scripts": {
"build": "tsc",
"build": "rm -rf lib/ && tsc",
"eslint:fix": "eslint \"src/**/*.ts\" --quiet --fix",
"eslint": "eslint \"src/**/*.ts\" --quiet",
"start:fork": "REQ_TIMEOUT=100000 anvil --fork-url NODE_URL --silent",
"start": "env-cmd -f .env node lib/runnable/da-verifier-node.runnable.js",
"start:failed": "env-cmd -f .env ts-node src/failed-submissons.runnable.ts",
"debug:playground": "npm run build && env-cmd -f .env node lib/__PLAYGROUND__/index.js",
"debug:playground": "pnpm run build && env-cmd -f .env node lib/__PLAYGROUND__/index.js",
"generate": "graphql-codegen",
"test": "npm run build && env-cmd -f .env.test jest",
"test": "env-cmd -f .env.test jest --forceExit --coverage",
"test:ci": "env-cmd -f .env.ci jest --forceExit",
"lint": "pnpm run prettier && pnpm run tsc",
"lint:fix": "pnpm run prettier:fix && pnpm run eslint",
"prettier:fix": "prettier --write .",
Expand Down
41 changes: 23 additions & 18 deletions momoka-node/src/__TESTS__/comment.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// apply mocks!
jest.setTimeout(3000);
jest.mock('../input-output/db');
jest.mock('../input-output/bundlr/get-bundlr-by-id.api');
jest.mock('../submitters');
Expand All @@ -16,15 +15,15 @@ describe('comment', () => {
describe('with delegate', () => {
let baseMock = commentCreatedDelegateArweaveResponse;

beforeEach(() => {
beforeAll(() => {
baseMock = commentCreatedDelegateArweaveResponse;
sharedMocks.mockGetDAPublicationByIdAPI.mockImplementation(async () =>
deepClone(commentCreatedDelegateArweaveResponse)
);
});

describe('should return success when', () => {
test('signed by delegate is true', async () => {
test('signed by delegate is true', () => {
expect(baseMock.chainProofs.thisPublication.signedByDelegate).toBe(true);
});

Expand All @@ -43,13 +42,11 @@ describe('comment', () => {
describe('should return failure when', () => {
test('NO_SIGNATURE_SUBMITTER', async () => {
sharedMocks.mockImpl__NO_SIGNATURE_SUBMITTER(baseMock);

await sharedMocks.checkAndValidateDAProof(MomokaValidatorError.NO_SIGNATURE_SUBMITTER);
});

xtest('INVALID_SIGNATURE_SUBMITTER', async () => {
sharedMocks.mockIsValidSubmitter.mockImplementationOnce(() => false);

await sharedMocks.checkAndValidateDAProof(MomokaValidatorError.INVALID_SIGNATURE_SUBMITTER);
});

Expand Down Expand Up @@ -116,11 +113,12 @@ describe('comment', () => {
await sharedMocks.checkAndValidateDAProof(MomokaValidatorError.PUBLICATION_NONCE_INVALID);
});

xtest('PUBLICATION_SIGNER_NOT_ALLOWED', async () => {});
xtest('PUBLICATION_SIGNER_NOT_ALLOWED', () => {
// TODO: implement
});

test('INVALID_FORMATTED_TYPED_DATA', async () => {
sharedMocks.mockImpl__INVALID_FORMATTED_TYPED_DATA(baseMock);

await sharedMocks.checkAndValidateDAProof(
MomokaValidatorError.INVALID_FORMATTED_TYPED_DATA
);
Expand Down Expand Up @@ -252,29 +250,33 @@ describe('comment', () => {
await sharedMocks.checkAndValidateDAProof(MomokaValidatorError.EVENT_MISMATCH);
});

xtest('SIMULATION_NODE_COULD_NOT_RUN', async () => {});
xtest('SIMULATION_NODE_COULD_NOT_RUN', () => {
// TODO: implement
});

xtest('UNKNOWN', () => {});
xtest('UNKNOWN', () => {
// TODO: implement
});
});
});

describe('without delegate', () => {
let baseMock = commentCreatedWithoutDelegateArweaveResponse;

beforeEach(() => {
beforeAll(() => {
baseMock = commentCreatedWithoutDelegateArweaveResponse;
sharedMocks.mockGetDAPublicationByIdAPI.mockImplementation(async () =>
deepClone(commentCreatedWithoutDelegateArweaveResponse)
);
});

describe('should return success when', () => {
test('signed by delegate is false', async () => {
test('signed by delegate is false', () => {
expect(baseMock.chainProofs.thisPublication.signedByDelegate).toBe(false);
});

test('txExists in the db already', async () => {
sharedMocks.mockGetTxDb.mockImplementationOnce(async () => mockTxValidationResult);
sharedMocks.mockGetTxDb.mockImplementationOnce(async () => await mockTxValidationResult);
const result = await sharedMocks.callCheckDAProof();
expect(result.isSuccess()).toBe(true);
});
Expand Down Expand Up @@ -361,11 +363,12 @@ describe('comment', () => {
await sharedMocks.checkAndValidateDAProof(MomokaValidatorError.PUBLICATION_NONCE_INVALID);
});

xtest('PUBLICATION_SIGNER_NOT_ALLOWED', async () => {});
xtest('PUBLICATION_SIGNER_NOT_ALLOWED', async () => {
// TODO: implement
});

test('INVALID_FORMATTED_TYPED_DATA', async () => {
sharedMocks.mockImpl__INVALID_FORMATTED_TYPED_DATA(baseMock);

await sharedMocks.checkAndValidateDAProof(
MomokaValidatorError.INVALID_FORMATTED_TYPED_DATA
);
Expand All @@ -381,7 +384,6 @@ describe('comment', () => {
},
};
});

await sharedMocks.checkAndValidateDAProof(MomokaValidatorError.EVENT_MISMATCH);
});

Expand All @@ -395,7 +397,6 @@ describe('comment', () => {
},
};
});

await sharedMocks.checkAndValidateDAProof(MomokaValidatorError.EVENT_MISMATCH);
});

Expand Down Expand Up @@ -497,9 +498,13 @@ describe('comment', () => {
await sharedMocks.checkAndValidateDAProof(MomokaValidatorError.EVENT_MISMATCH);
});

xtest('SIMULATION_NODE_COULD_NOT_RUN', async () => {});
xtest('SIMULATION_NODE_COULD_NOT_RUN', () => {
// TODO: implement
});

xtest('UNKNOWN', () => {});
xtest('UNKNOWN', () => {
// TODO: implement
});
});
});
});
2 changes: 1 addition & 1 deletion momoka-node/src/__TESTS__/config/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Object.defineProperty(globalThis, 'crypto', {
});

// eslint-disable-next-line no-undef
jest.setTimeout(15000);
jest.setTimeout(30000);
Loading