Skip to content

Commit

Permalink
feat: run all test locally
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigopavezi committed Nov 26, 2024
1 parent ccfaf0d commit dd116d9
Show file tree
Hide file tree
Showing 21 changed files with 182 additions and 40 deletions.
18 changes: 11 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
FROM node:16-alpine
FROM node:18-alpine
RUN apk add --no-cache git
RUN npm install -g solc

WORKDIR /app
## Warning! This Docker config is meant to be used for development and debugging, not in prod.

RUN apk add --virtual .build-deps git python g++ bash make
WORKDIR /base

COPY package.json .
COPY yarn.lock .

RUN yarn
RUN yarn install

COPY . .
RUN yarn
RUN yarn install
RUN yarn clean
RUN yarn build

RUN apk del .build-deps
# Port configuration
ENV PORT 3000
EXPOSE 3000
13 changes: 13 additions & 0 deletions Dockerfile.graph-deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:18-alpine
RUN apk add --no-cache git

WORKDIR /base/storage-subgraph

RUN git clone https://github.com/RequestNetwork/storage-subgraph /base/storage-subgraph
RUN npm -g install @graphprotocol/graph-cli
RUN yarn
RUN yarn codegen subgraph-private.yaml

#CMD yarn create-local ; yarn deploy-local ./subgraph-private.yaml

CMD graph create --node http://graph-node:8020/ RequestNetwork/request-storage && graph deploy --node http://graph-node:8020/ --ipfs http://ipfs:5001 --version-label $(git rev-parse --short HEAD) RequestNetwork/request-storage ./subgraph-private.yaml
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ yarn run lint

Test all the packages in the monorepo.

Some tests will require services to be running locally

```bash
docker compose up
```

Deploy Smart Contracts

```bash
yarn run deploy:contracts
```

Run request-node locally

```bash
cp ./packages/request-node/.env.example ./packages/request-node/.env
yarn run start:request-node
```

Run all tests

```bash
yarn run test
```
Expand All @@ -89,6 +110,12 @@ Test a specific package by replacing `@requestnetwork/request-client.js` with th
yarn workspace @requestnetwork/request-client.js test
```

Clean Docker Volumes

```bash
dcoker compose down -v
```

## License

[MIT](https://github.com/RequestNetwork/requestNetwork/blob/master/LICENSE)
Expand Down
62 changes: 62 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Warning! This Docker config is meant to be used for development and debugging, specially for running tests, not in prod.
services:
graph-node:
image: graphprotocol/graph-node:v0.25.0
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- ipfs
- postgres
- ganache
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'private:http://ganache:8545'
RUST_LOG: info
GRAPH_ALLOW_NON_DETERMINISTIC_IPFS: 1
ipfs:
image: requestnetwork/request-ipfs:v0.13.0
ports:
- '5001:5001'
restart: on-failure:20
# volumes:
# - ./data/ipfs:/data/ipfs
ganache:
image: trufflesuite/ganache:v7.6.0
ports:
- 8545:8545
command:
- '-l'
- '90000000'
- '-m'
- 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat'
- '-k'
- 'london'
restart: on-failure:20
postgres:
image: postgres
ports:
- '5432:5432'
command: ['postgres', '-cshared_preload_libraries=pg_stat_statements']
environment:
POSTGRES_USER: graph-node
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
restart: on-failure:20
graph-deploy:
build:
context: .
dockerfile: Dockerfile.graph-deploy
depends_on:
- ipfs
- postgres
- graph-node
- ganache
restart: on-failure:20
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"lerna": "3.2.1",
"lerna": "6.6.2",
"useWorkspaces": true,
"packages": ["packages/*"],
"version": "independent",
"npmClient": "yarn"
Expand Down
18 changes: 18 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "test"]
}
}
},
"targetDefaults": {
"build": {
"dependsOn": ["^build"]
},
"test": {
"dependsOn": ["build"]
}
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"publish-npm": "lerna publish --conventional-commits --exact",
"publish-manual-prerelease": "lerna publish prerelease --conventional-commits --exact",
"publish-prerelease": "yarn lerna publish --preid development --skip-git --yes --canary",
"test": "lerna run test",
"deploy:contracts": "yarn workspace @requestnetwork/smart-contracts deploy",
"start:request-node": "yarn workspace @requestnetwork/request-node start",
"test": "lerna run test --concurrency=1",
"format": "prettier . -w",
"format:check": "prettier . -c",
"link:all": "for d in packages/*; do cd $d; yarn link; cd -; done",
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"clean": "rm -rf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
"lint": "eslint . --fix",
"lint:check": "eslint .",
"test": "jest",
"test": "jest --maxWorkers=1",
"test:watch": "yarn test --watch",
"init-ipfs": "node scripts/init-ipfs.js"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/ethereum-storage/test/gas-fee-definer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const gasFeeDefiner = new GasFeeDefiner({ provider, logger: console });

describe('Gas fee estimation', () => {
it('Should not be undefined', async () => {
provider.send('evm_increaseTime', [-60]);
provider.send('evm_mine', []);
const estimation = await gasFeeDefiner.getGasFees();
expect(estimation.maxFeePerGas).toBeDefined();
expect(estimation.maxPriorityFeePerGas).toBeDefined();
Expand All @@ -49,7 +51,7 @@ describe('Gas fee estimation', () => {
await provider.send('evm_mine', []);
const secondEstimation = await gasFeeDefiner.getGasFees();

expect(firstEstimation.maxFeePerGas?.toNumber()).toBeGreaterThan(
expect(firstEstimation.maxFeePerGas?.toNumber()).toBeGreaterThanOrEqual(
secondEstimation.maxFeePerGas?.toNumber() || 0,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('api/erc20/address-based-info-retriever', () => {
describe('on localhost', () => {
const paymentAddress = '0xf17f52151EbEF6C7334FAD080c5704D77216b732';
const payerAddress = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57';
const emptyAddress = '0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef';
const emptyAddress = '0x56dDdAA262139112d2490b50BE328D237a499A14';

it('can get the localhost balance of an address', async () => {
const infoRetriever = new ERC20InfoRetriever(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ describe('batch-proxy', () => {
).toEqual(ETHTotal.toString());
expect(toNewBalanceETH.sub(toOldBalanceETH)).toEqual(ETHAmount);
expect(feeNewBalanceETH.sub(feeOldBalanceETH).toString()).toEqual(ETHFeesTotal.toString());
});
}, 20000);
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/request-client.js/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { http, HttpResponse } from 'msw';
import { setupServer, SetupServer } from 'msw/node';
import config from '../src/http-config-defaults';

jest.setTimeout(20000);
const httpConfig: Partial<ClientTypes.IHttpDataAccessConfig> = {
getConfirmationDeferDelay: 0,
};
Expand Down
3 changes: 2 additions & 1 deletion packages/request-node/test/getChannelsByTopic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RequestNode } from '../src/requestNode';
import { normalizeKeccak256Hash } from '@requestnetwork/utils';
import { providers } from 'ethers';

jest.setTimeout(30000);
// enable re-running these tests on local environment by having a different channel ID each time.
const time = Date.now();
const channelId = `01aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa${time}`;
Expand Down Expand Up @@ -116,7 +117,7 @@ describe('getChannelsByTopic', () => {
});
};
await Promise.all([confirm(transactionData), confirm(otherTransactionData)]);
}, 10000);
});

it('responds with no transaction to requests with a non-existent topic', async () => {
const serverResponse = await request(server)
Expand Down
14 changes: 7 additions & 7 deletions packages/request-node/test/getConfirmedTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { getRequestNode } from '../src/server';
import { RequestNode } from '../src/requestNode';
import { providers } from 'ethers';

const channelId = '010aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
const time = Date.now();
const channelId = `01aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa${time}`;

const transactionData = { data: `this is sample data for a transaction ${Date.now()}` };
const transactionData = { data: `this is sample data for a transaction ${time}` };
const transactionHash = normalizeKeccak256Hash(transactionData).value;
const provider = new providers.JsonRpcProvider('http://localhost:8545');

Expand Down Expand Up @@ -41,14 +42,13 @@ describe('getConfirmedTransaction', () => {
.set('Accept', 'application/json')
.expect(StatusCodes.NOT_FOUND);

// mining is required for TheGraph to index data
await provider.send('evm_mine', []);

let serverResponse: request.Response | undefined;
// retry mechanism to account for ganache delay
for (let i = 0; i < 10; i++) {
for (let i = 0; i < 20; i++) {
// wait a bit for the confirmation
await new Promise((resolve): any => setTimeout(resolve, 1000));
// mining is required for TheGraph to index data
await provider.send('evm_mine', []);

serverResponse = await request(server)
.get('/getConfirmedTransaction')
Expand All @@ -64,7 +64,7 @@ describe('getConfirmedTransaction', () => {
expect(serverResponse!.body.result).toMatchObject({});
// 'getConfirmedTransaction request meta'
expect(serverResponse!.body.meta.storageMeta.state).toBe('confirmed');
}, 30000);
}, 40000);

it('responds with status 422 to requests with no value', async () => {
await request(server)
Expand Down
14 changes: 8 additions & 6 deletions packages/request-node/test/getTransactionsByChannelId.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import request from 'supertest';
import { getRequestNode } from '../src/server';
import { RequestNode } from '../src/requestNode';

const channelId = '01aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab';
const anotherChannelId = '01bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc';
const nonExistentChannelId = '01cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccd';
jest.setTimeout(20000);
const time = Date.now();
const channelId = `01aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa${time}`;
const anotherChannelId = `01bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb${time}`;
const nonExistentChannelId = `01ccccccccccccccccccccccccccccccccccccccccccccccccccc${time}`;
const transactionData = {
data: `this is sample data for a transaction to test getTransactionsByChannelId ${Date.now()}`,
data: `this is sample data for a transaction to test getTransactionsByChannelId ${time}`,
};
const otherTransactionData = {
data: 'this is other sample data for a transaction to test getTransactionsByChannelId',
data: `this is other sample data for a transaction to test getTransactionsByChannelId ${time}`,
};

let requestNodeInstance: RequestNode;
Expand Down Expand Up @@ -41,7 +43,7 @@ describe('getTransactionsByChannelId', () => {

let serverResponse = await request(server)
.get('/getTransactionsByChannelId')
.query({ channelId })
.query({ channelId: channelId })
.set('Accept', 'application/json')
.expect(StatusCodes.OK);

Expand Down
1 change: 1 addition & 0 deletions packages/request-node/test/requestNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import request from 'supertest';
import { getRequestNode } from '../src/server';
import { RequestNode } from '../src/requestNode';

jest.setTimeout(20000);
const packageJson = require('../package.json');
const requestNodeVersion = packageJson.version;

Expand Down
2 changes: 1 addition & 1 deletion packages/smart-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default {
hardfork: 'london',
},
private: {
url: 'http://127.0.0.1:8545',
url: url('private'),
accounts: undefined,
},
mainnet: {
Expand Down
5 changes: 5 additions & 0 deletions packages/thegraph-data-access/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('the test', () => {
it('should pass', () => {
expect(true).toBe(true);
});
});
Loading

0 comments on commit dd116d9

Please sign in to comment.