@@ -23,34 +23,36 @@ jest.unmock('set-protocol-contracts');
23
23
jest . setTimeout ( 30000 ) ;
24
24
25
25
import * as _ from 'lodash' ;
26
- import * as ABIDecoder from 'abi-decoder' ;
27
26
import * as chai from 'chai' ;
28
27
import Web3 from 'web3' ;
29
28
import { Address , Web3Utils } from 'set-protocol-utils' ;
30
29
import * as setProtocolUtils from 'set-protocol-utils' ;
31
30
import {
31
+ ConstantPriceOracleContract ,
32
32
HistoricalPriceFeedContract ,
33
33
MedianContract ,
34
- MovingAverageOracleContract
34
+ MovingAverageOracleContract ,
35
35
} from 'set-protocol-oracles' ;
36
36
37
+ import { ProtocolViewerContract } from 'set-protocol-viewers' ;
38
+
37
39
import ChaiSetup from '@test/helpers/chaiSetup' ;
38
40
import { OracleAPI } from '@src/api' ;
39
- import { BigNumber } from '@src/util' ;
41
+ import { BigNumber , ether } from '@src/util' ;
42
+ import { SetProtocolConfig } from '@src/types/common' ;
40
43
import { DEFAULT_ACCOUNT } from '@src/constants/accounts' ;
41
- import { TX_DEFAULTS } from '@src/constants' ;
44
+ import { NULL_ADDRESS } from '@src/constants' ;
42
45
import {
43
46
addPriceFeedOwnerToMedianizer ,
47
+ deployConstantPriceOracleAsync ,
44
48
deployHistoricalPriceFeedAsync ,
45
49
deployMedianizerAsync ,
46
50
deployMovingAverageOracleAsync ,
51
+ deployProtocolViewerAsync ,
47
52
updateMedianizerPriceAsync ,
48
53
} from '@test/helpers' ;
49
54
50
- const Core = require ( 'set-protocol-contracts/dist/artifacts/ts/Core' ) . Core ;
51
-
52
55
ChaiSetup . configure ( ) ;
53
- const contract = require ( 'truffle-contract' ) ;
54
56
const web3 = new Web3 ( 'http://localhost:8545' ) ;
55
57
const web3Utils = new Web3Utils ( web3 ) ;
56
58
const { expect } = chai ;
@@ -59,13 +61,10 @@ let currentSnapshotId: number;
59
61
60
62
const { SetProtocolTestUtils : SetTestUtils } = setProtocolUtils ;
61
63
62
- const coreContract = contract ( Core ) ;
63
- coreContract . setProvider ( web3 . currentProvider ) ;
64
- coreContract . defaults ( TX_DEFAULTS ) ;
65
-
66
64
67
65
describe ( 'OracleAPI' , ( ) => {
68
66
let oracleAPI : OracleAPI ;
67
+ let protocolViewer : ProtocolViewerContract ;
69
68
70
69
const priceFeedUpdateFrequency : BigNumber = new BigNumber ( 10 ) ;
71
70
const initialMedianizerEthPrice : BigNumber = new BigNumber ( 1000000 ) ;
@@ -78,18 +77,27 @@ describe('OracleAPI', () => {
78
77
new BigNumber ( 5000000 ) ,
79
78
] ;
80
79
81
- beforeAll ( ( ) => {
82
- ABIDecoder . addABI ( coreContract . abi ) ;
83
- } ) ;
84
-
85
- afterAll ( ( ) => {
86
- ABIDecoder . removeABI ( coreContract . abi ) ;
87
- } ) ;
88
-
89
80
beforeEach ( async ( ) => {
90
81
currentSnapshotId = await web3Utils . saveTestSnapshot ( ) ;
91
82
92
- oracleAPI = new OracleAPI ( web3 ) ;
83
+ protocolViewer = await deployProtocolViewerAsync ( web3 ) ;
84
+ const setProtocolConfig : SetProtocolConfig = {
85
+ coreAddress : NULL_ADDRESS ,
86
+ transferProxyAddress : NULL_ADDRESS ,
87
+ vaultAddress : NULL_ADDRESS ,
88
+ setTokenFactoryAddress : NULL_ADDRESS ,
89
+ rebalancingSetTokenFactoryAddress : NULL_ADDRESS ,
90
+ kyberNetworkWrapperAddress : NULL_ADDRESS ,
91
+ rebalanceAuctionModuleAddress : NULL_ADDRESS ,
92
+ exchangeIssuanceModuleAddress : NULL_ADDRESS ,
93
+ rebalancingSetIssuanceModule : NULL_ADDRESS ,
94
+ rebalancingSetEthBidderAddress : NULL_ADDRESS ,
95
+ rebalancingSetExchangeIssuanceModule : NULL_ADDRESS ,
96
+ wrappedEtherAddress : NULL_ADDRESS ,
97
+ protocolViewerAddress : protocolViewer . address ,
98
+ } ;
99
+
100
+ oracleAPI = new OracleAPI ( web3 , setProtocolConfig ) ;
93
101
} ) ;
94
102
95
103
afterEach ( async ( ) => {
@@ -176,4 +184,40 @@ describe('OracleAPI', () => {
176
184
expect ( price ) . to . bignumber . equal ( btcPrice ) ;
177
185
} ) ;
178
186
} ) ;
187
+
188
+ describe ( '#batchFetchOraclePrices' , async ( ) => {
189
+ let component1Price : BigNumber ;
190
+ let component2Price : BigNumber ;
191
+
192
+ let component1Oracle : ConstantPriceOracleContract ;
193
+ let component2Oracle : ConstantPriceOracleContract ;
194
+
195
+ let subjectOracleAddresses : Address [ ] ;
196
+
197
+ beforeEach ( async ( ) => {
198
+ component1Price = ether ( 1 ) ;
199
+ component2Price = ether ( 2 ) ;
200
+
201
+ component1Oracle = await deployConstantPriceOracleAsync ( web3 , component1Price ) ;
202
+ component2Oracle = await deployConstantPriceOracleAsync ( web3 , component2Price ) ;
203
+
204
+ subjectOracleAddresses = [
205
+ component1Oracle . address ,
206
+ component2Oracle . address ,
207
+ ] ;
208
+ } ) ;
209
+
210
+ async function subject ( ) : Promise < BigNumber [ ] > {
211
+ return oracleAPI . getOraclePricesAsync (
212
+ subjectOracleAddresses ,
213
+ ) ;
214
+ }
215
+
216
+ it ( 'fetches oracle prices' , async ( ) => {
217
+ const oraclePrices = await subject ( ) ;
218
+
219
+ const expectedOraclePrices = [ component1Price , component2Price ] ;
220
+ expect ( JSON . stringify ( oraclePrices ) ) . to . equal ( JSON . stringify ( expectedOraclePrices ) ) ;
221
+ } ) ;
222
+ } ) ;
179
223
} ) ;
0 commit comments