Skip to content

Commit

Permalink
FIN-1063 #comment update with vivaldi
Browse files Browse the repository at this point in the history
  • Loading branch information
cliff0412 committed Feb 20, 2019
1 parent c4ae39a commit 0146bcf
Show file tree
Hide file tree
Showing 8 changed files with 477 additions and 60 deletions.
7 changes: 3 additions & 4 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"cleanDB": "ts-node ./src/index cleanDB",
"fetchPrice": "ts-node ./src/index fetchPrice",
"fetchEvents": "ts-node ./src/index fetchEvents",
"startCustodian": "ts-node ./src/index startCustodian"
"startCustodian": "ts-node ./src/index startCustodian",
"startRound": "ts-node ./src/index startRound",
"endRound": "ts-node ./src/index endRound"
},
"jest": {
"roots": [
Expand Down Expand Up @@ -49,7 +51,7 @@
},
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@finbook/duo-contract-wrapper": "^1.1.2",
"@finbook/duo-contract-wrapper": "^1.2.0",
"@finbook/duo-market-data": "^1.0.1",
"@google-cloud/storage": "^2.4.1",
"aws-cli-js": "^2.0.4",
Expand Down
2 changes: 2 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const CLEAN_DB = 'cleanDB';
export const FETCH_PRICE = 'fetchPrice';
export const START_CUSTODIAN = 'startCustodian';
export const FETCH_EVENTS = 'fetchEvents';
export const START_ROUND = 'startRound';
export const END_ROUND = 'endRound';

// db setting
export const DB_SQL_SCHEMA_PRICEFEED = 'priceFeedDB';
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dbUtil.init(tool, option).then(() => {
new MarketDataService().cleanDb();
break;
case CST.START_CUSTODIAN:
new ContractService(tool, option).startCustodian();
new ContractService(tool, option).startCustodian(option);
break;
case CST.TRIGGER:
new ContractService(tool, option).trigger();
Expand All @@ -55,6 +55,12 @@ dbUtil.init(tool, option).then(() => {
case CST.FETCH_PRICE:
new ContractService(tool, option).fetchPrice();
break;
case CST.START_ROUND:
new ContractService(tool, option).startRound(option);
break;
case CST.END_ROUND:
new ContractService(tool, option).endRound(option);
break;
default:
util.logInfo('no such tool ' + tool);
break;
Expand Down
73 changes: 52 additions & 21 deletions src/services/ContractService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ import keyUtil from '../utils/keyUtil';
import priceUtil from '../utils/priceUtil';
import ContractService from './ContractService';

const option = {
forceREST: false,
live: false,
dbLive: false,
server: false,
dynamo: false,
aws: false,
gcp: false,
azure: false,
force: false,
pair: 'pair',
contractType: 'Beethoven',
tenor: '100C-3H',
assets: [''],
sources: [''],
exSources: [''],
source: '',
event: '',
provider: '',
period: 1
};

jest.mock('@finbook/duo-contract-wrapper', () => ({
Constants: Constants,
Web3Wrapper: jest.fn(() => ({
Expand All @@ -21,6 +43,9 @@ jest.mock('@finbook/duo-contract-wrapper', () => ({
DualClassWrapper: jest.fn(() => ({
contract: 'dualClassWrapper'
})),
VivaldiWrapper: jest.fn(() => ({
contract: 'VivaldiWrapper'
})),
EsplanadeWrapper: jest.fn(() => ({
contract: 'EsplanadeWrapper'
})),
Expand Down Expand Up @@ -125,22 +150,25 @@ test('fetchPrice', async () => {

test('startCustodian, worng type', async () => {
contractService.createDuoWrappers = jest.fn();
await contractService.startCustodian();
await contractService.startCustodian(option);
expect(contractService.createDuoWrappers as jest.Mock).not.toBeCalled();
});

test('fetchEvent', async () => {
eventUtil.fetch = jest.fn();
contractService.createDuoWrappers = jest.fn(() => ({
Beethoven: {
Perpetual: 'BTV-PPT',
M19: 'BTV-M19'
},
Mozart: {
Perpetual: 'MZT-PPT',
M19: 'MZT-M19'
}
} as any));
contractService.createDuoWrappers = jest.fn(
() =>
({
Beethoven: {
Perpetual: 'BTV-PPT',
M19: 'BTV-M19'
},
Mozart: {
Perpetual: 'MZT-PPT',
M19: 'MZT-M19'
}
} as any)
);
await contractService.fetchEvent();
expect((eventUtil.fetch as jest.Mock).mock.calls).toMatchSnapshot();
});
Expand All @@ -158,16 +186,19 @@ test('startCustodian', async () => {
} as any);
const startCustodian = jest.fn();

contractService1.createDuoWrappers = jest.fn(() => ({
Beethoven: {
Perpetual: {
startCustodian: startCustodian,
web3Wrapper: {
contractAddresses: kovan
contractService1.createDuoWrappers = jest.fn(
() =>
({
Beethoven: {
Perpetual: {
startCustodian: startCustodian,
web3Wrapper: {
contractAddresses: kovan
}
}
}
}
}
} as any));
await contractService1.startCustodian();
} as any)
);
await contractService1.startCustodian(option);
expect((startCustodian as jest.Mock).mock.calls).toMatchSnapshot();
});

0 comments on commit 0146bcf

Please sign in to comment.