Skip to content

Commit c3c7e24

Browse files
committed
Fixes types in tests
1 parent bef414e commit c3c7e24

File tree

4 files changed

+46
-39
lines changed

4 files changed

+46
-39
lines changed

test/InverseApi3ReaderProxyV1.sol.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
21
import * as helpers from '@nomicfoundation/hardhat-network-helpers';
32
import { expect } from 'chai';
3+
import type { Signer } from 'ethers';
44
import { ethers } from 'hardhat';
5+
import type { InverseApi3ReaderProxyV1, NormalizedApi3ReaderProxyV1 } from 'typechain-types';
56

67
describe('InverseApi3ReaderProxyV1', function () {
78
async function deploy() {
89
const roleNames = ['deployer', 'manager', 'airnode', 'auctioneer', 'searcher'];
910
const accounts = await ethers.getSigners();
10-
const roles: Record<string, HardhatEthersSigner> = roleNames.reduce((acc, roleName, index) => {
11-
return { ...acc, [roleName]: accounts[index] };
11+
const roles: Record<typeof roleNames[number], Signer> = roleNames.reduce((acc, roleName, index) => {
12+
return { ...acc, [roleName]: accounts[index] as unknown as Signer };
1213
}, {});
1314

1415
const decimals = 20;
@@ -22,10 +23,10 @@ describe('InverseApi3ReaderProxyV1', function () {
2223
'NormalizedApi3ReaderProxyV1',
2324
roles.deployer
2425
);
25-
const proxy = await normalizedApi3ReaderProxyV1Factory.deploy(await feed.getAddress());
26+
const proxy = await normalizedApi3ReaderProxyV1Factory.deploy(await feed.getAddress()) as unknown as NormalizedApi3ReaderProxyV1;
2627

2728
const inverseApi3ReaderProxyV1Factory = await ethers.getContractFactory('InverseApi3ReaderProxyV1', roles.deployer);
28-
const inverseApi3ReaderProxyV1 = await inverseApi3ReaderProxyV1Factory.deploy(await proxy.getAddress());
29+
const inverseApi3ReaderProxyV1 = await inverseApi3ReaderProxyV1Factory.deploy(await proxy.getAddress()) as unknown as InverseApi3ReaderProxyV1;
2930

3031
return {
3132
proxy,

test/NormalizedApi3ReaderProxyV1.sol.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
21
import * as helpers from '@nomicfoundation/hardhat-network-helpers';
32
import { expect } from 'chai';
3+
import type { Signer } from 'ethers';
44
import { ethers } from 'hardhat';
5+
import type { MockAggregatorV2V3, NormalizedApi3ReaderProxyV1 } from 'typechain-types';
56

67
describe('NormalizedApi3ReaderProxyV1', function () {
78
async function deploy() {
89
const roleNames = ['deployer', 'manager', 'airnode', 'auctioneer', 'searcher'];
910
const accounts = await ethers.getSigners();
10-
const roles: Record<string, HardhatEthersSigner> = roleNames.reduce((acc, roleName, index) => {
11-
return { ...acc, [roleName]: accounts[index] };
11+
const roles: Record<(typeof roleNames)[number], Signer> = roleNames.reduce((acc, roleName, index) => {
12+
return { ...acc, [roleName]: accounts[index] as unknown as Signer };
1213
}, {});
1314

1415
const decimals = 8;
1516
const answer = ethers.parseUnits('0.25', decimals);
1617
const timestamp = await helpers.time.latest();
1718

1819
const mockAggregatorV2V3Factory = await ethers.getContractFactory('MockAggregatorV2V3', roles.deployer);
19-
const feed = await mockAggregatorV2V3Factory.deploy(decimals, answer, timestamp);
20+
const feed = (await mockAggregatorV2V3Factory.deploy(decimals, answer, timestamp)) as unknown as MockAggregatorV2V3;
2021

2122
const normalizedApi3ReaderProxyV1Factory = await ethers.getContractFactory(
2223
'NormalizedApi3ReaderProxyV1',
2324
roles.deployer
2425
);
25-
const normalizedApi3ReaderProxyV1 = await normalizedApi3ReaderProxyV1Factory.deploy(await feed.getAddress());
26+
const normalizedApi3ReaderProxyV1 = (await normalizedApi3ReaderProxyV1Factory.deploy(
27+
await feed.getAddress()
28+
)) as unknown as NormalizedApi3ReaderProxyV1;
2629

2730
return {
2831
feed,
@@ -96,9 +99,9 @@ describe('NormalizedApi3ReaderProxyV1', function () {
9699
'NormalizedApi3ReaderProxyV1',
97100
roles.deployer
98101
);
99-
const newNormalizedApi3ReaderProxyV1 = await normalizedApi3ReaderProxyV1Factory.deploy(
102+
const newNormalizedApi3ReaderProxyV1 = (await normalizedApi3ReaderProxyV1Factory.deploy(
100103
await newFeed.getAddress()
101-
);
104+
)) as unknown as NormalizedApi3ReaderProxyV1;
102105
const newDataFeed = await newNormalizedApi3ReaderProxyV1.read();
103106
expect(newDataFeed.value).to.equal(normalize(answer, 8));
104107
expect(newDataFeed.timestamp).to.equal(updatedAt);

test/ProductApi3ReaderProxyV1.sol.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
1+
import type { Api3ServerV1 } from '@api3/contracts';
22
import * as helpers from '@nomicfoundation/hardhat-network-helpers';
33
import { expect } from 'chai';
4+
import type { Signer } from 'ethers';
45
import { ethers } from 'hardhat';
6+
import type { Api3ReaderProxyV1, ProductApi3ReaderProxyV1 } from 'typechain-types';
57

68
import * as testUtils from './test-utils';
79

810
describe('ProductApi3ReaderProxyV1', function () {
911
async function deploy() {
1012
const roleNames = ['deployer', 'manager', 'airnode', 'auctioneer', 'searcher'];
1113
const accounts = await ethers.getSigners();
12-
const roles: Record<string, HardhatEthersSigner> = roleNames.reduce((acc, roleName, index) => {
13-
return { ...acc, [roleName]: accounts[index] };
14+
const roles: Record<typeof roleNames[number], Signer> = roleNames.reduce((acc, roleName, index) => {
15+
return { ...acc, [roleName]: accounts[index] as unknown as Signer };
1416
}, {});
1517

1618
const accessControlRegistryFactory = await ethers.getContractFactory('AccessControlRegistry', roles.deployer);
@@ -20,15 +22,15 @@ describe('ProductApi3ReaderProxyV1', function () {
2022
const api3ServerV1 = await api3ServerV1Factory.deploy(
2123
accessControlRegistry.getAddress(),
2224
'Api3ServerV1 admin',
23-
roles.manager!.address
24-
);
25+
roles.manager!.getAddress()
26+
) as unknown as Api3ServerV1;
2527

2628
const api3ServerV1OevExtensionAdminRoleDescription = 'Api3ServerV1OevExtension admin';
2729
const api3ServerV1OevExtensionFactory = await ethers.getContractFactory('Api3ServerV1OevExtension', roles.deployer);
2830
const api3ServerV1OevExtension = await api3ServerV1OevExtensionFactory.deploy(
2931
accessControlRegistry.getAddress(),
3032
api3ServerV1OevExtensionAdminRoleDescription,
31-
roles.manager!.address,
33+
roles.manager!.getAddress(),
3234
api3ServerV1.getAddress()
3335
);
3436

@@ -40,35 +42,35 @@ describe('ProductApi3ReaderProxyV1', function () {
4042
api3ServerV1OevExtension.getAddress(),
4143
dapiNameEthUsd,
4244
dappId
43-
);
45+
) as unknown as Api3ReaderProxyV1;
4446
const dapiNameSolEth = ethers.encodeBytes32String('SOL/ETH');
4547
const api3ReaderProxyV1SolEth = await api3ReaderProxyV1Factory.deploy(
4648
api3ServerV1OevExtension.getAddress(),
4749
dapiNameSolEth,
4850
dappId
49-
);
51+
) as unknown as Api3ReaderProxyV1;
5052

5153
const productApi3ReaderProxyV1Factory = await ethers.getContractFactory('ProductApi3ReaderProxyV1', roles.deployer);
5254

5355
const productApi3ReaderProxyV1SolUsd = await productApi3ReaderProxyV1Factory.deploy(
5456
api3ReaderProxyV1EthUsd.getAddress(),
5557
api3ReaderProxyV1SolEth.getAddress()
56-
);
58+
) as unknown as ProductApi3ReaderProxyV1;
5759

5860
const productApi3ReaderProxyV1EthSol = await productApi3ReaderProxyV1Factory.deploy(
5961
api3ReaderProxyV1EthUsd.getAddress(),
6062
productApi3ReaderProxyV1SolUsd.getAddress()
61-
);
63+
) as unknown as ProductApi3ReaderProxyV1;
6264

6365
const endpointIdEthUsd = testUtils.generateRandomBytes32();
6466
const templateParametersEthUsd = testUtils.generateRandomBytes();
6567
const templateIdEthUsd = ethers.keccak256(
6668
ethers.solidityPacked(['bytes32', 'bytes'], [endpointIdEthUsd, templateParametersEthUsd])
6769
);
6870
const beaconIdEthUsd = ethers.keccak256(
69-
ethers.solidityPacked(['address', 'bytes32'], [roles.airnode!.address, templateIdEthUsd])
71+
ethers.solidityPacked(['address', 'bytes32'], [await roles.airnode!.getAddress(), templateIdEthUsd])
7072
);
71-
await api3ServerV1.connect(roles.manager).setDapiName(dapiNameEthUsd, beaconIdEthUsd);
73+
await api3ServerV1.connect(roles.manager!).setDapiName(dapiNameEthUsd, beaconIdEthUsd);
7274

7375
const baseBeaconValueEthUsd = ethers.parseEther('1824.97');
7476
const baseBeaconTimestampEthUsd = await helpers.time.latest();
@@ -80,7 +82,7 @@ describe('ProductApi3ReaderProxyV1', function () {
8082
dataEthUsd
8183
);
8284
await api3ServerV1.updateBeaconWithSignedData(
83-
roles.airnode!.address,
85+
await roles.airnode!.getAddress(),
8486
templateIdEthUsd,
8587
baseBeaconTimestampEthUsd,
8688
dataEthUsd,
@@ -93,9 +95,9 @@ describe('ProductApi3ReaderProxyV1', function () {
9395
ethers.solidityPacked(['bytes32', 'bytes'], [endpointIdSolEth, templateParametersSolEth])
9496
);
9597
const beaconIdSolEth = ethers.keccak256(
96-
ethers.solidityPacked(['address', 'bytes32'], [roles.airnode!.address, templateIdSolEth])
98+
ethers.solidityPacked(['address', 'bytes32'], [await roles.airnode!.getAddress(), templateIdSolEth])
9799
);
98-
await api3ServerV1.connect(roles.manager).setDapiName(dapiNameSolEth, beaconIdSolEth);
100+
await api3ServerV1.connect(roles.manager!).setDapiName(dapiNameSolEth, beaconIdSolEth);
99101

100102
const baseBeaconValueSolEth = ethers.parseEther('0.08202');
101103
const baseBeaconTimestampSolEth = await helpers.time.latest();
@@ -107,7 +109,7 @@ describe('ProductApi3ReaderProxyV1', function () {
107109
dataSolEth
108110
);
109111
await api3ServerV1.updateBeaconWithSignedData(
110-
roles.airnode!.address,
112+
await roles.airnode!.getAddress(),
111113
templateIdSolEth,
112114
baseBeaconTimestampSolEth,
113115
dataSolEth,

test/adapters/ScaledApi3FeedProxyV1.sol.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import type { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
21
import * as helpers from '@nomicfoundation/hardhat-network-helpers';
32
import { expect } from 'chai';
3+
import type { Signer } from 'ethers';
44
import { ethers } from 'hardhat';
5+
import type { Api3ReaderProxyV1, Api3ServerV1, ScaledApi3FeedProxyV1 } from 'typechain-types';
56

67
import * as testUtils from '../test-utils';
78

89
describe('ScaledApi3FeedProxyV1', function () {
910
async function deploy() {
1011
const roleNames = ['deployer', 'manager', 'airnode', 'auctioneer', 'searcher'];
1112
const accounts = await ethers.getSigners();
12-
const roles: Record<string, HardhatEthersSigner> = roleNames.reduce((acc, roleName, index) => {
13-
return { ...acc, [roleName]: accounts[index] };
13+
const roles: Record<typeof roleNames[number], Signer> = roleNames.reduce((acc, roleName, index) => {
14+
return { ...acc, [roleName]: accounts[index] as unknown as Signer };
1415
}, {});
1516

1617
const accessControlRegistryFactory = await ethers.getContractFactory('AccessControlRegistry', roles.deployer);
@@ -20,15 +21,15 @@ describe('ScaledApi3FeedProxyV1', function () {
2021
const api3ServerV1 = await api3ServerV1Factory.deploy(
2122
accessControlRegistry.getAddress(),
2223
'Api3ServerV1 admin',
23-
roles.manager!.address
24-
);
24+
roles.manager!.getAddress()
25+
) as unknown as Api3ServerV1;
2526

2627
const api3ServerV1OevExtensionAdminRoleDescription = 'Api3ServerV1OevExtension admin';
2728
const api3ServerV1OevExtensionFactory = await ethers.getContractFactory('Api3ServerV1OevExtension', roles.deployer);
2829
const api3ServerV1OevExtension = await api3ServerV1OevExtensionFactory.deploy(
2930
accessControlRegistry.getAddress(),
3031
api3ServerV1OevExtensionAdminRoleDescription,
31-
roles.manager!.address,
32+
roles.manager!.getAddress(),
3233
api3ServerV1.getAddress()
3334
);
3435

@@ -40,22 +41,22 @@ describe('ScaledApi3FeedProxyV1', function () {
4041
api3ServerV1OevExtension.getAddress(),
4142
dapiName,
4243
dappId
43-
);
44+
) as unknown as Api3ReaderProxyV1;
4445

4546
const endpointId = testUtils.generateRandomBytes32();
4647
const templateParameters = testUtils.generateRandomBytes();
4748
const templateId = ethers.keccak256(ethers.solidityPacked(['bytes32', 'bytes'], [endpointId, templateParameters]));
4849
const beaconId = ethers.keccak256(
49-
ethers.solidityPacked(['address', 'bytes32'], [roles.airnode!.address, templateId])
50+
ethers.solidityPacked(['address', 'bytes32'], [await roles.airnode!.getAddress(), templateId])
5051
);
51-
await api3ServerV1.connect(roles.manager).setDapiName(dapiName, beaconId);
52+
await api3ServerV1.connect(roles.manager!).setDapiName(dapiName, beaconId);
5253

5354
const baseBeaconValue = ethers.parseEther('1824.97');
5455
const baseBeaconTimestamp = await helpers.time.latest();
5556
const data = ethers.AbiCoder.defaultAbiCoder().encode(['int256'], [baseBeaconValue]);
5657
const signature = await testUtils.signData(roles.airnode! as any, templateId, baseBeaconTimestamp, data);
5758
await api3ServerV1.updateBeaconWithSignedData(
58-
roles.airnode!.address,
59+
await roles.airnode!.getAddress(),
5960
templateId,
6061
baseBeaconTimestamp,
6162
data,
@@ -67,7 +68,7 @@ describe('ScaledApi3FeedProxyV1', function () {
6768
const scaledApi3FeedProxyV1 = await scaledApi3FeedProxyV1Factory.deploy(
6869
await api3ReaderProxyV1.getAddress(),
6970
decimals
70-
);
71+
) as unknown as ScaledApi3FeedProxyV1;
7172

7273
return {
7374
decimals,

0 commit comments

Comments
 (0)