Skip to content

Commit

Permalink
test: 💍 basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
waynewyang committed Jan 2, 2024
1 parent 9a5faae commit d2c93f7
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 103 deletions.
9 changes: 9 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CALIBRATION_LOTUS_PROVIDER_URL = "https://api.calibration.node.glif.io/rpc/v1"
CALIBRATION_LOTUS_API_ENDPOINT = "https://api.calibration.node.glif.io/rpc/v1"
CALIBRATION_LOTUS_TOKEN = ""
CALIBRATION_MONGO_URL = "mongodb://127.0.0.1:27017/messagehub_calibration"

MAIN_LOTUS_PROVIDER_URL = "https://api.node.glif.io/rpc/v1"
MAIN_LOTUS_API_ENDPOINT = "https://api.node.glif.io/rpc/v1"
MAIN_LOTUS_TOKEN = ""
MAIN_MONGO_URL = "mongodb://127.0.0.1:27017/messagehub_main"
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@release-it/conventional-changelog": "^8.0.1",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"dotenv": "^16.3.1",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
Expand Down
30 changes: 15 additions & 15 deletions src/backgroundTask/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export interface Config {
* Represents a connection to a Filecoin network.
*/
export class Context implements IContext {
chain: ChainContext;
evm: EvmContext;
datastore: DatastoreContext;
chain: ChainContext = {} as ChainContext;
evm: EvmContext = {} as EvmContext;
datastore: DatastoreContext = {} as DatastoreContext;

/**
* Creates an instance of ChainNetwork.
Expand Down Expand Up @@ -87,17 +87,17 @@ export class Context implements IContext {
},
});

this.evm.roles = config.evm.roles;
this.evm.filplus = config.evm.filplus;
this.evm.escrow = config.evm.escrow;
this.evm.dataset.metadata = config.evm.dataset.metadata;
this.evm.dataset.requirement = config.evm.dataset.requirement;
this.evm.dataset.proof = config.evm.dataset.proof;
this.evm.dataset.challenge = config.evm.dataset.challenge;
this.evm.matching.metadata = config.evm.matching.metadata;
this.evm.matching.target = config.evm.matching.target;
this.evm.matching.bids = config.evm.matching.bids;
this.evm.storages = config.evm.storages;
this.evm.datacaps = config.evm.datacaps;
// this.evm.roles = config.evm.roles;
// this.evm.filplus = config.evm.filplus;
// this.evm.escrow = config.evm.escrow;
this.evm.datasetMetadata = config.evm.datasetMetadata;
// this.evm.dataset.requirement = config.evm.dataset.requirement;
// this.evm.dataset.proof = config.evm.dataset.proof;
// this.evm.dataset.challenge = config.evm.dataset.challenge;
// this.evm.matching.metadata = config.evm.matching.metadata;
// this.evm.matching.target = config.evm.matching.target;
// this.evm.matching.bids = config.evm.matching.bids;
// this.evm.storages = config.evm.storages;
// this.evm.datacaps = config.evm.datacaps;
}
}
102 changes: 51 additions & 51 deletions src/backgroundTask/decoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,59 +47,59 @@ export class Decoder implements IDecoder {
pendingChainInfo.messages.forEach((msg) => {
//TODO:To check address format ,add toEthaddress function
switch (msg.Msg.To) {
case this.context.evm.dataset.metadata.getContractAddress():
res.push(this.context.evm.dataset.metadata.decodeMessage(msg).data);
case this.context.evm.datasetMetadata.getContractAddress():
res.push(this.context.evm.datasetMetadata.decodeMessage(msg).data);
break;

case this.context.evm.dataset.requirement.getContractAddress():
res.push(
this.context.evm.dataset.requirement.decodeMessage(msg).data,
);
break;

case this.context.evm.dataset.proof.getContractAddress():
res.push(this.context.evm.dataset.proof.decodeMessage(msg).data);
break;

case this.context.evm.dataset.challenge.getContractAddress():
res.push(
this.context.evm.dataset.challenge.decodeMessage(msg).data,
);
break;

case this.context.evm.matching.target.getContractAddress():
res.push(this.context.evm.matching.target.decodeMessage(msg).data);
break;

case this.context.evm.matching.metadata.getContractAddress():
res.push(
this.context.evm.matching.metadata.decodeMessage(msg).data,
);
break;

case this.context.evm.matching.bids.getContractAddress():
res.push(this.context.evm.matching.bids.decodeMessage(msg).data);
break;

case this.context.evm.storages.getContractAddress():
res.push(this.context.evm.storages.decodeMessage(msg).data);
break;

case this.context.evm.datacaps.getContractAddress():
res.push(this.context.evm.datacaps.decodeMessage(msg).data);
break;

case this.context.evm.escrow.getContractAddress():
res.push(this.context.evm.escrow.decodeMessage(msg).data);
break;

case this.context.evm.filplus.getContractAddress():
res.push(this.context.evm.filplus.decodeMessage(msg).data);
break;

case this.context.evm.roles.getContractAddress():
res.push(this.context.evm.roles.decodeMessage(msg).data);
break;
// case this.context.evm.dataset.requirement.getContractAddress():
// res.push(
// this.context.evm.dataset.requirement.decodeMessage(msg).data,
// );
// break;

// case this.context.evm.dataset.proof.getContractAddress():
// res.push(this.context.evm.dataset.proof.decodeMessage(msg).data);
// break;

// case this.context.evm.dataset.challenge.getContractAddress():
// res.push(
// this.context.evm.dataset.challenge.decodeMessage(msg).data,
// );
// break;

// case this.context.evm.matching.target.getContractAddress():
// res.push(this.context.evm.matching.target.decodeMessage(msg).data);
// break;

// case this.context.evm.matching.metadata.getContractAddress():
// res.push(
// this.context.evm.matching.metadata.decodeMessage(msg).data,
// );
// break;

// case this.context.evm.matching.bids.getContractAddress():
// res.push(this.context.evm.matching.bids.decodeMessage(msg).data);
// break;

// case this.context.evm.storages.getContractAddress():
// res.push(this.context.evm.storages.decodeMessage(msg).data);
// break;

// case this.context.evm.datacaps.getContractAddress():
// res.push(this.context.evm.datacaps.decodeMessage(msg).data);
// break;

// case this.context.evm.escrow.getContractAddress():
// res.push(this.context.evm.escrow.decodeMessage(msg).data);
// break;

// case this.context.evm.filplus.getContractAddress():
// res.push(this.context.evm.filplus.decodeMessage(msg).data);
// break;

// case this.context.evm.roles.getContractAddress():
// res.push(this.context.evm.roles.decodeMessage(msg).data);
// break;

default:
break;
Expand Down
52 changes: 25 additions & 27 deletions src/backgroundTask/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ import {
} from '@unipackage/filecoin';
import {
DatasetMetadataEvm,
DatasetProofEvm,
DatasetRequirementEvm,
DatasetChallengeEvm,
MatchingBidsEvm,
MatchingMetadataEvm,
MatchingTargetEvm,
StoragesEvm,
DatacapsEvm,
EscrowEvm,
RolesEvm,
FilplusEvm,
// DatasetProofEvm,
// DatasetRequirementEvm,
// DatasetChallengeEvm,
// MatchingBidsEvm,
// MatchingMetadataEvm,
// MatchingTargetEvm,
// StoragesEvm,
// DatacapsEvm,
// EscrowEvm,
// RolesEvm,
// FilplusEvm,
DataswapMessage,
DataswapMessageMongoDatastore,
DatasetMetadataMongoDatastore,
Expand All @@ -58,22 +58,20 @@ export interface ChainContext {
* Configuration for Evm context.
*/
export interface EvmContext {
escrow: EscrowEvm;
filplus: FilplusEvm;
roles: RolesEvm;
dataset: {
metadata: DatasetMetadataEvm;
requirement: DatasetRequirementEvm;
proof: DatasetProofEvm;
challenge: DatasetChallengeEvm;
};
matching: {
target: MatchingTargetEvm;
metadata: MatchingMetadataEvm;
bids: MatchingBidsEvm;
};
storages: StoragesEvm;
datacaps: DatacapsEvm;
// escrow: EscrowEvm;
// filplus: FilplusEvm;
// roles: RolesEvm;
datasetMetadata: DatasetMetadataEvm;
// requirement: DatasetRequirementEvm;
// proof: DatasetProofEvm;
// challenge: DatasetChallengeEvm;
// matching: {
// target: MatchingTargetEvm;
// metadata: MatchingMetadataEvm;
// bids: MatchingBidsEvm;
// };
// storages: StoragesEvm;
// datacaps: DatacapsEvm;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/config/backgroundTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import { EvmContext } from '../backgroundTask/interface';
import { Syncer } from '../backgroundTask/syncer';
import { Decoder } from '../backgroundTask/decoder';
import { Storager } from '../backgroundTask/storager';
import { datasetMetadataEvm_Calibration } from './evm';
import * as dotenv from 'dotenv';
dotenv.config();

/**
* Calibration network configuration
Expand All @@ -33,7 +36,9 @@ export const calibrationConfig: Config = {
token: process.env.CALIBRATION_LOTUS_TOKEN as string,
mongoUrl: process.env.CALIBRATION_MONGO_URL as string,
startHeight: 1210900,
evm: {} as EvmContext,
evm: {
datasetMetadata: datasetMetadataEvm_Calibration,
},
};

/**
Expand Down
29 changes: 29 additions & 0 deletions src/config/evm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* (c) 2024 dataswap
*
* Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0
* (the "Apache License"). You may not use this file except in compliance with one of these
* licenses. You may obtain a copy of the MIT License at
*
* https://opensource.org/licenses/MIT
*
* Or the Apache License, Version 2.0 at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the MIT License or the Apache License for the specific language governing permissions and
* limitations under the respective licenses.
********************************************************************************/
import { DatasetMetadataEvm } from '@dataswapjs/dataswapjs';
import datasetMetaAbi from '@dataswapcore/contracts/abi/v0.8/Datasets.json';
import * as dotenv from 'dotenv';
dotenv.config();

export const datasetMetadataEvm_Calibration = new DatasetMetadataEvm(
datasetMetaAbi,
'0x023e4b966b943c830b7d4cae84fe761641b29003',
process.env.CALIBRATION_LOTUS_PROVIDER_URL,
);
17 changes: 17 additions & 0 deletions test/backgroundTask/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { calibrationBgTask } from '../../src/config/backgroundTask';

describe('BackgroundTask', () => {
beforeAll(() => {
calibrationBgTask.start();
});

afterAll(() => {
calibrationBgTask.stop();
});

it('should stop the background task', () => {
expect(calibrationBgTask.isRunning()).toBe(true);
calibrationBgTask.stop();
expect(calibrationBgTask.isRunning()).toBe(false);
});
});
23 changes: 14 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
"noFallthroughCasesInSwitch": false,
"outDir": "./dist-test",
"declaration": true,
"target": "ES2015",
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": false,
"experimentalDecorators": true,
"jsx": "react",
"skipLibCheck": true,
"incremental": false,
}
}

0 comments on commit d2c93f7

Please sign in to comment.