2020-10-19 16:17:27 +00:00
const { expect } = require ( "chai" ) ;
const hre = require ( "hardhat" ) ;
2020-11-04 17:09:34 +00:00
const { deployments , ethers } = hre ;
2020-10-19 16:17:27 +00:00
const ORACLE _MAKER _ETH _USD = "ETH/USD-Maker-v1" ;
const ORACLE _MAKER _ETH _USD _ADDR = "0x729D19f657BD0614b4985Cf1D82531c67569197B" ;
const PRICE _ORACLE _MAKER _PAYLOAD = "0x57de26a4" ; // IMakerOracle.read()
describe ( "PriceOracleResolver Unit Test" , function ( ) {
this . timeout ( 0 ) ;
if ( hre . network . name !== "hardhat" ) {
console . error ( "Test Suite is meant to be run on hardhat only" ) ;
process . exit ( 1 ) ;
}
let priceOracleResolver ;
2020-11-04 17:09:34 +00:00
beforeEach ( async function ( ) {
await deployments . fixture ( ) ;
priceOracleResolver = await ethers . getContract ( "PriceOracleResolver" ) ;
2020-10-19 16:17:27 +00:00
} ) ;
it ( "#1: addOracle should add a maker medianizer for a currencyPair" , async function ( ) {
await priceOracleResolver . addOracle (
ORACLE _MAKER _ETH _USD ,
ORACLE _MAKER _ETH _USD _ADDR ,
PRICE _ORACLE _MAKER _PAYLOAD
) ;
expect ( await priceOracleResolver . oracle ( ORACLE _MAKER _ETH _USD ) ) . to . be . equal (
ORACLE _MAKER _ETH _USD _ADDR
) ;
expect (
await priceOracleResolver . oraclePayload ( ORACLE _MAKER _ETH _USD )
) . to . be . equal ( PRICE _ORACLE _MAKER _PAYLOAD ) ;
} ) ;
it ( "#2: addOracle should revert when adding a maker medianizer and for this currency pair it was been already added" , async function ( ) {
2020-11-04 17:09:34 +00:00
await priceOracleResolver . addOracle (
ORACLE _MAKER _ETH _USD ,
ORACLE _MAKER _ETH _USD _ADDR ,
PRICE _ORACLE _MAKER _PAYLOAD
) ;
2020-10-19 16:17:27 +00:00
await expect (
priceOracleResolver . addOracle (
ORACLE _MAKER _ETH _USD ,
ethers . constants . AddressZero ,
PRICE _ORACLE _MAKER _PAYLOAD
)
) . to . be . revertedWith ( "PriceOracleResolver.addOracle: set" ) ;
} ) ;
it ( "#3: getPrice returns price" , async function ( ) {
2020-11-04 17:09:34 +00:00
await priceOracleResolver . addOracle (
ORACLE _MAKER _ETH _USD ,
ORACLE _MAKER _ETH _USD _ADDR ,
PRICE _ORACLE _MAKER _PAYLOAD
) ;
2020-10-19 16:17:27 +00:00
expect ( ( await priceOracleResolver . getPrice ( ORACLE _MAKER _ETH _USD ) ) . isZero ( ) )
. to . be . false ;
} ) ;
it ( "#4: getMakerTokenPrice should return PriceOracleResolver.getMakerTokenPrice: CurrencyPairNotSupported. when currencyPair are not supported / not been added" , async function ( ) {
await expect ( priceOracleResolver . getPrice ( "ETH/DAI" ) ) . to . be . revertedWith (
"PriceOracleResolver.getPrice: no oracle"
) ;
} ) ;
} ) ;