From eeb5a2463417300b3c69cdf414fdb12c9b28e03d Mon Sep 17 00:00:00 2001 From: WYANG008 Date: Thu, 21 Feb 2019 14:48:40 +0800 Subject: [PATCH] update tests --- src/services/ContractService.test.ts | 80 ++++++++++++++++--- src/services/ContractService.ts | 12 +++ .../ContractService.test.ts.snap | 17 +++- 3 files changed, 99 insertions(+), 10 deletions(-) diff --git a/src/services/ContractService.test.ts b/src/services/ContractService.test.ts index 08d6366..6be0e59 100644 --- a/src/services/ContractService.test.ts +++ b/src/services/ContractService.test.ts @@ -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( @@ -167,6 +161,9 @@ test('fetchEvent', async () => { Mozart: { Perpetual: 'MZT-PPT', M19: 'MZT-M19' + }, + Vivaldi: { + tenor: 'VVD-tenor' } } as any) ); @@ -174,7 +171,13 @@ test('fetchEvent', async () => { 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', @@ -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 = { @@ -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 () => { @@ -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 () => { diff --git a/src/services/ContractService.ts b/src/services/ContractService.ts index 6a0a838..3058d0e 100644 --- a/src/services/ContractService.ts +++ b/src/services/ContractService.ts @@ -187,6 +187,18 @@ export default class ContractService { address: 'account', privateKey: '' } + }, + Mozart: { + operator: { + address: 'account', + privateKey: '' + } + }, + Vivaldi: { + operator: { + address: 'account', + privateKey: '' + } } }; try { diff --git a/src/services/__snapshots__/ContractService.test.ts.snap b/src/services/__snapshots__/ContractService.test.ts.snap index 3d659c4..3a9a034 100644 --- a/src/services/__snapshots__/ContractService.test.ts.snap +++ b/src/services/__snapshots__/ContractService.test.ts.snap @@ -918,6 +918,7 @@ Array [ Object { "contract": "EsplanadeWrapper", }, + "VVD-tenor", ], false, ], @@ -1013,7 +1014,7 @@ Array [ ] `; -exports[`startCustodian 1`] = ` +exports[`startCustodian, dualClass 1`] = ` Array [ Array [ "account", @@ -1024,6 +1025,20 @@ Array [ ] `; +exports[`startCustodian, vivaldi 1`] = ` +Array [ + Array [ + "account", + "0x2C4bD22588af822a95Fb9D7e972A1F1C4aE28F13", + "0x9f49bb024EB176d227d4b85A58730a5dDeEF529D", + "0x0d729B3C11b3E6Bf5792d36f640f3Be6f187Dd67", + 1, + true, + true, + ], +] +`; + exports[`trigger 1`] = ` Array [ Array [