Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cliff0412 committed Feb 21, 2019
1 parent ecd582c commit eeb5a24
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 10 deletions.
80 changes: 71 additions & 9 deletions src/services/ContractService.test.ts
Expand Up @@ -149,12 +149,6 @@ test('fetchPrice', async () => {
expect((priceUtil.fetchPrice as jest.Mock).mock.calls).toMatchSnapshot();
});

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

test('fetchEvent', async () => {
eventUtil.fetch = jest.fn();
contractService.createDuoWrappers = jest.fn(
Expand All @@ -167,14 +161,23 @@ test('fetchEvent', async () => {
Mozart: {
Perpetual: 'MZT-PPT',
M19: 'MZT-M19'
},
Vivaldi: {
tenor: 'VVD-tenor'
}
} as any)
);
await contractService.fetchEvent();
expect((eventUtil.fetch as jest.Mock).mock.calls).toMatchSnapshot();
});

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

test('startCustodian, dualClass', async () => {
const contractService1 = new ContractService('tool', {
live: false,
provider: 'provider',
Expand Down Expand Up @@ -204,6 +207,67 @@ test('startCustodian', async () => {
expect((startCustodian as jest.Mock).mock.calls).toMatchSnapshot();
});

test('startCustodian, wrong type', async () => {
const contractService1 = new ContractService('tool', {
live: false,
provider: 'provider',
event: 'event',
gasPrice: 1000000000,
gasLimit: 10000,
pair: 'quote|base',
contractType: 'type',
tenor: 'Perpetual'
} as any);
const startCustodian = jest.fn();

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

test('startCustodian, vivaldi', async () => {
const option1 = ({
live: false,
provider: 'provider',
event: 'event',
gasPrice: 1000000000,
gasLimit: 10000,
pair: 'quote|base',
contractType: 'Vivaldi',
tenor: '100C-3H'
} as any) as any;
const contractService2 = new ContractService('tool', option1);
const startCustodian = jest.fn();

contractService2.createDuoWrappers = jest.fn(
() =>
({
Vivaldi: {
'100C-3H': {
startCustodian: startCustodian,
web3Wrapper: {
contractAddresses: kovan
}
}
}
} as any)
);
await contractService2.startCustodian(option1);
expect((startCustodian as jest.Mock).mock.calls).toMatchSnapshot();
});

test('checkRound, just started, startRound', async () => {
util.getUTCNowTimestamp = jest.fn(() => 1200000000);
const contractWrapper = {
Expand All @@ -230,7 +294,6 @@ test('checkRound, just started, startRound', async () => {

await contractService.checkRound(contractWrapper, magiWrapper);
expect((contractWrapper.startRound as jest.Mock).mock.calls).toMatchSnapshot();

});

test('checkRound, skiped round', async () => {
Expand Down Expand Up @@ -378,7 +441,6 @@ test('checkRound, startRound, priceFetchCoolDown > 0', async () => {

await contractService.checkRound(contractWrapper, magiWrapper);
expect(contractWrapper.startRound as jest.Mock).not.toBeCalled();

});

test('checkRound, endRound', async () => {
Expand Down
12 changes: 12 additions & 0 deletions src/services/ContractService.ts
Expand Up @@ -187,6 +187,18 @@ export default class ContractService {
address: 'account',
privateKey: ''
}
},
Mozart: {
operator: {
address: 'account',
privateKey: ''
}
},
Vivaldi: {
operator: {
address: 'account',
privateKey: ''
}
}
};
try {
Expand Down
17 changes: 16 additions & 1 deletion src/services/__snapshots__/ContractService.test.ts.snap
Expand Up @@ -918,6 +918,7 @@ Array [
Object {
"contract": "EsplanadeWrapper",
},
"VVD-tenor",
],
false,
],
Expand Down Expand Up @@ -1013,7 +1014,7 @@ Array [
]
`;

exports[`startCustodian 1`] = `
exports[`startCustodian, dualClass 1`] = `
Array [
Array [
"account",
Expand All @@ -1024,6 +1025,20 @@ Array [
]
`;

exports[`startCustodian, vivaldi 1`] = `
Array [
Array [
"account",
"0x2C4bD22588af822a95Fb9D7e972A1F1C4aE28F13",
"0x9f49bb024EB176d227d4b85A58730a5dDeEF529D",
"0x0d729B3C11b3E6Bf5792d36f640f3Be6f187Dd67",
1,
true,
true,
],
]
`;

exports[`trigger 1`] = `
Array [
Array [
Expand Down

0 comments on commit eeb5a24

Please sign in to comment.