11import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers' ;
22import * as helpers from '@nomicfoundation/hardhat-network-helpers' ;
33import { expect } from 'chai' ;
4- import { ethers } from 'hardhat' ;
5-
6- import * as testUtils from './test-utils' ;
4+ import hre from 'hardhat' ;
75
86describe ( 'NormalizedApi3ReaderProxyV1' , function ( ) {
97 async function deploy ( ) {
108 const roleNames = [ 'deployer' ] ;
11- const accounts = await ethers . getSigners ( ) ;
9+ const accounts = await hre . ethers . getSigners ( ) ;
1210 const roles : Record < string , HardhatEthersSigner > = roleNames . reduce ( ( acc , roleName , index ) => {
1311 return { ...acc , [ roleName ] : accounts [ index ] } ;
1412 } , { } ) ;
1513
16- const dappId = testUtils . generateRandomBytes32 ( ) ;
1714 const decimals = 8 ;
18- const answer = ethers . parseUnits ( '0.25' , decimals ) ;
15+ const answer = hre . ethers . parseUnits ( '0.25' , decimals ) ;
1916 const timestamp = await helpers . time . latest ( ) ;
2017
21- const mockAggregatorV2V3Factory = await ethers . getContractFactory ( 'MockAggregatorV2V3' , roles . deployer ) ;
18+ const mockAggregatorV2V3Factory = await hre . ethers . getContractFactory ( 'MockAggregatorV2V3' , roles . deployer ) ;
2219 const feed = await mockAggregatorV2V3Factory . deploy ( decimals , answer , timestamp ) ;
2320
24- const normalizedApi3ReaderProxyV1Factory = await ethers . getContractFactory (
21+ const normalizedApi3ReaderProxyV1Factory = await hre . ethers . getContractFactory (
2522 'NormalizedApi3ReaderProxyV1' ,
2623 roles . deployer
2724 ) ;
28- const normalizedApi3ReaderProxyV1 = await normalizedApi3ReaderProxyV1Factory . deploy (
29- await feed . getAddress ( ) ,
30- dappId
31- ) ;
25+ const normalizedApi3ReaderProxyV1 = await normalizedApi3ReaderProxyV1Factory . deploy ( await feed . getAddress ( ) ) ;
3226
3327 return {
3428 feed,
35- dappId,
3629 mockAggregatorV2V3Factory,
3730 normalizedApi3ReaderProxyV1,
3831 roles,
@@ -51,35 +44,38 @@ describe('NormalizedApi3ReaderProxyV1', function () {
5144 context ( 'feed is not zero address' , function ( ) {
5245 context ( 'feed does not have 18 decimals' , function ( ) {
5346 it ( 'constructs' , async function ( ) {
54- const { feed, dappId , normalizedApi3ReaderProxyV1 } = await helpers . loadFixture ( deploy ) ;
47+ const { feed, normalizedApi3ReaderProxyV1 } = await helpers . loadFixture ( deploy ) ;
5548 expect ( await normalizedApi3ReaderProxyV1 . feed ( ) ) . to . equal ( await feed . getAddress ( ) ) ;
56- expect ( await normalizedApi3ReaderProxyV1 . dappId ( ) ) . to . equal ( dappId ) ;
5749 expect ( await normalizedApi3ReaderProxyV1 . isUpscaling ( ) ) . to . equal ( true ) ; // 8 < 18 is true
5850 expect ( await normalizedApi3ReaderProxyV1 . scalingFactor ( ) ) . to . equal ( 10_000_000_000n ) ; // 10**(18-8)
5951 } ) ;
6052 } ) ;
6153 context ( 'feed has 18 decimals' , function ( ) {
6254 it ( 'reverts' , async function ( ) {
63- const { dappId, roles, mockAggregatorV2V3Factory } = await helpers . loadFixture ( deploy ) ;
64- const feed = await mockAggregatorV2V3Factory . deploy ( 18 , ethers . parseEther ( '1' ) , await helpers . time . latest ( ) ) ;
65- const normalizedApi3ReaderProxyV1Factory = await ethers . getContractFactory (
55+ const { roles, mockAggregatorV2V3Factory } = await helpers . loadFixture ( deploy ) ;
56+ const feed = await mockAggregatorV2V3Factory . deploy (
57+ 18 ,
58+ hre . ethers . parseEther ( '1' ) ,
59+ await helpers . time . latest ( )
60+ ) ;
61+ const normalizedApi3ReaderProxyV1Factory = await hre . ethers . getContractFactory (
6662 'NormalizedApi3ReaderProxyV1' ,
6763 roles . deployer
6864 ) ;
69- await expect ( normalizedApi3ReaderProxyV1Factory . deploy ( feed , dappId ) )
65+ await expect ( normalizedApi3ReaderProxyV1Factory . deploy ( feed ) )
7066 . to . be . revertedWithCustomError ( normalizedApi3ReaderProxyV1Factory , 'NoNormalizationNeeded' )
7167 . withArgs ( ) ;
7268 } ) ;
7369 } ) ;
7470 } ) ;
7571 context ( 'feed is zero address' , function ( ) {
7672 it ( 'reverts' , async function ( ) {
77- const { dappId , roles } = await helpers . loadFixture ( deploy ) ;
78- const normalizedApi3ReaderProxyV1Factory = await ethers . getContractFactory (
73+ const { roles } = await helpers . loadFixture ( deploy ) ;
74+ const normalizedApi3ReaderProxyV1Factory = await hre . ethers . getContractFactory (
7975 'NormalizedApi3ReaderProxyV1' ,
8076 roles . deployer
8177 ) ;
82- await expect ( normalizedApi3ReaderProxyV1Factory . deploy ( ethers . ZeroAddress , dappId ) )
78+ await expect ( normalizedApi3ReaderProxyV1Factory . deploy ( hre . ethers . ZeroAddress ) )
8379 . to . be . revertedWithCustomError ( normalizedApi3ReaderProxyV1Factory , 'ZeroProxyAddress' )
8480 . withArgs ( ) ;
8581 } ) ;
@@ -88,8 +84,7 @@ describe('NormalizedApi3ReaderProxyV1', function () {
8884
8985 describe ( 'read' , function ( ) {
9086 it ( 'reads the normalized to 18 decimals rate' , async function ( ) {
91- const { feed, dappId, mockAggregatorV2V3Factory, normalizedApi3ReaderProxyV1, roles } =
92- await helpers . loadFixture ( deploy ) ;
87+ const { feed, mockAggregatorV2V3Factory, normalizedApi3ReaderProxyV1, roles } = await helpers . loadFixture ( deploy ) ;
9388
9489 const decimals = await feed . decimals ( ) ;
9590 const [ , answer , , updatedAt ] = await feed . latestRoundData ( ) ;
@@ -101,13 +96,12 @@ describe('NormalizedApi3ReaderProxyV1', function () {
10196
10297 // Normalizes down
10398 const newFeed = await mockAggregatorV2V3Factory . deploy ( 8 , answer , updatedAt ) ;
104- const normalizedApi3ReaderProxyV1Factory = await ethers . getContractFactory (
99+ const normalizedApi3ReaderProxyV1Factory = await hre . ethers . getContractFactory (
105100 'NormalizedApi3ReaderProxyV1' ,
106101 roles . deployer
107102 ) ;
108103 const newNormalizedApi3ReaderProxyV1 = await normalizedApi3ReaderProxyV1Factory . deploy (
109- await newFeed . getAddress ( ) ,
110- dappId
104+ await newFeed . getAddress ( )
111105 ) ;
112106 const newDataFeed = await newNormalizedApi3ReaderProxyV1 . read ( ) ;
113107 expect ( newDataFeed . value ) . to . equal ( normalize ( answer , 8 ) ) ;
@@ -143,7 +137,7 @@ describe('NormalizedApi3ReaderProxyV1', function () {
143137 describe ( 'getAnswer' , function ( ) {
144138 it ( 'reverts' , async function ( ) {
145139 const { normalizedApi3ReaderProxyV1 } = await helpers . loadFixture ( deploy ) ;
146- const blockNumber = await ethers . provider . getBlockNumber ( ) ;
140+ const blockNumber = await hre . ethers . provider . getBlockNumber ( ) ;
147141 await expect ( normalizedApi3ReaderProxyV1 . getAnswer ( blockNumber ) )
148142 . to . be . revertedWithCustomError ( normalizedApi3ReaderProxyV1 , 'FunctionIsNotSupported' )
149143 . withArgs ( ) ;
@@ -153,7 +147,7 @@ describe('NormalizedApi3ReaderProxyV1', function () {
153147 describe ( 'getTimestamp' , function ( ) {
154148 it ( 'reverts' , async function ( ) {
155149 const { normalizedApi3ReaderProxyV1 } = await helpers . loadFixture ( deploy ) ;
156- const blockNumber = await ethers . provider . getBlockNumber ( ) ;
150+ const blockNumber = await hre . ethers . provider . getBlockNumber ( ) ;
157151 await expect ( normalizedApi3ReaderProxyV1 . getTimestamp ( blockNumber ) )
158152 . to . be . revertedWithCustomError ( normalizedApi3ReaderProxyV1 , 'FunctionIsNotSupported' )
159153 . withArgs ( ) ;
@@ -184,7 +178,7 @@ describe('NormalizedApi3ReaderProxyV1', function () {
184178 describe ( 'getRoundData' , function ( ) {
185179 it ( 'reverts' , async function ( ) {
186180 const { normalizedApi3ReaderProxyV1 } = await helpers . loadFixture ( deploy ) ;
187- const blockNumber = await ethers . provider . getBlockNumber ( ) ;
181+ const blockNumber = await hre . ethers . provider . getBlockNumber ( ) ;
188182 await expect ( normalizedApi3ReaderProxyV1 . getRoundData ( blockNumber ) )
189183 . to . be . revertedWithCustomError ( normalizedApi3ReaderProxyV1 , 'FunctionIsNotSupported' )
190184 . withArgs ( ) ;
0 commit comments