Skip to content

Commit 5b64095

Browse files
committed
Fixes tests
1 parent c274716 commit 5b64095

File tree

7 files changed

+97
-364
lines changed

7 files changed

+97
-364
lines changed

contracts/test/MockApi3ReaderProxyV1.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ import {
99
/// @dev This mock implements the minimal functions required for testing the
1010
/// data-feed-proxy-combinators contracts. Other functions will revert.
1111
contract MockApi3ReaderProxyV1 is IApi3ReaderProxyV1 {
12-
/// @notice The dApp ID of the mock proxy.
13-
uint256 public immutable override dappId;
1412
/// @notice The mock value to be returned by read().
1513
int224 private _value;
1614
/// @notice The mock timestamp to be returned by read().
1715
uint32 private _timestamp;
1816

19-
constructor(uint256 dappId_, int224 value_, uint32 timestamp_) {
20-
dappId = dappId_;
17+
constructor(int224 value_, uint32 timestamp_) {
2118
_value = value_;
2219
_timestamp = timestamp_;
2320
}
@@ -53,4 +50,8 @@ contract MockApi3ReaderProxyV1 is IApi3ReaderProxyV1 {
5350
function dapiName() external pure override returns (bytes32) {
5451
revert("Mock: Not implemented");
5552
}
53+
54+
function dappId() external pure override returns (uint256) {
55+
revert("Mock: Not implemented");
56+
}
5657
}

test/InverseApi3ReaderProxyV1.sol.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
22
import * as helpers from '@nomicfoundation/hardhat-network-helpers';
33
import { expect } from 'chai';
4-
import { ethers } from 'hardhat';
5-
6-
import * as testUtils from './test-utils';
4+
import hre from 'hardhat';
75

86
describe('InverseApi3ReaderProxyV1', 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 = 20;
18-
const answer = ethers.parseUnits('1824.97', decimals);
15+
const answer = hre.ethers.parseUnits('1824.97', 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 proxy = await normalizedApi3ReaderProxyV1Factory.deploy(await feed.getAddress(), dappId);
25+
const proxy = await normalizedApi3ReaderProxyV1Factory.deploy(await feed.getAddress());
2926

30-
const inverseApi3ReaderProxyV1Factory = await ethers.getContractFactory('InverseApi3ReaderProxyV1', roles.deployer);
27+
const inverseApi3ReaderProxyV1Factory = await hre.ethers.getContractFactory(
28+
'InverseApi3ReaderProxyV1',
29+
roles.deployer
30+
);
3131
const inverseApi3ReaderProxyV1 = await inverseApi3ReaderProxyV1Factory.deploy(await proxy.getAddress());
3232

3333
return {
3434
proxy,
35-
dappId,
3635
inverseApi3ReaderProxyV1,
3736
roles,
3837
};
@@ -43,14 +42,16 @@ describe('InverseApi3ReaderProxyV1', function () {
4342
it('constructs', async function () {
4443
const { proxy, inverseApi3ReaderProxyV1 } = await helpers.loadFixture(deploy);
4544
expect(await inverseApi3ReaderProxyV1.proxy()).to.equal(await proxy.getAddress());
46-
expect(await inverseApi3ReaderProxyV1.dappId()).to.equal(await proxy.dappId());
4745
});
4846
});
4947
context('proxy is zero address', function () {
5048
it('reverts', async function () {
5149
const { roles } = await helpers.loadFixture(deploy);
52-
const inverseApi3ReaderProxyV1 = await ethers.getContractFactory('InverseApi3ReaderProxyV1', roles.deployer);
53-
await expect(inverseApi3ReaderProxyV1.deploy(ethers.ZeroAddress))
50+
const inverseApi3ReaderProxyV1 = await hre.ethers.getContractFactory(
51+
'InverseApi3ReaderProxyV1',
52+
roles.deployer
53+
);
54+
await expect(inverseApi3ReaderProxyV1.deploy(hre.ethers.ZeroAddress))
5455
.to.be.revertedWithCustomError(inverseApi3ReaderProxyV1, 'ZeroProxyAddress')
5556
.withArgs();
5657
});
@@ -96,7 +97,7 @@ describe('InverseApi3ReaderProxyV1', function () {
9697
describe('getAnswer', function () {
9798
it('reverts', async function () {
9899
const { inverseApi3ReaderProxyV1 } = await helpers.loadFixture(deploy);
99-
const blockNumber = await ethers.provider.getBlockNumber();
100+
const blockNumber = await hre.ethers.provider.getBlockNumber();
100101
await expect(inverseApi3ReaderProxyV1.getAnswer(blockNumber))
101102
.to.be.revertedWithCustomError(inverseApi3ReaderProxyV1, 'FunctionIsNotSupported')
102103
.withArgs();
@@ -106,7 +107,7 @@ describe('InverseApi3ReaderProxyV1', function () {
106107
describe('getTimestamp', function () {
107108
it('reverts', async function () {
108109
const { inverseApi3ReaderProxyV1 } = await helpers.loadFixture(deploy);
109-
const blockNumber = await ethers.provider.getBlockNumber();
110+
const blockNumber = await hre.ethers.provider.getBlockNumber();
110111
await expect(inverseApi3ReaderProxyV1.getTimestamp(blockNumber))
111112
.to.be.revertedWithCustomError(inverseApi3ReaderProxyV1, 'FunctionIsNotSupported')
112113
.withArgs();
@@ -137,7 +138,7 @@ describe('InverseApi3ReaderProxyV1', function () {
137138
describe('getRoundData', function () {
138139
it('reverts', async function () {
139140
const { inverseApi3ReaderProxyV1 } = await helpers.loadFixture(deploy);
140-
const blockNumber = await ethers.provider.getBlockNumber();
141+
const blockNumber = await hre.ethers.provider.getBlockNumber();
141142
await expect(inverseApi3ReaderProxyV1.getRoundData(blockNumber))
142143
.to.be.revertedWithCustomError(inverseApi3ReaderProxyV1, 'FunctionIsNotSupported')
143144
.withArgs();

test/NormalizedApi3ReaderProxyV1.sol.ts

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
22
import * as helpers from '@nomicfoundation/hardhat-network-helpers';
33
import { expect } from 'chai';
4-
import { ethers } from 'hardhat';
5-
6-
import * as testUtils from './test-utils';
4+
import hre from 'hardhat';
75

86
describe('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

Comments
 (0)