Skip to content

Commit 6d486ce

Browse files
committed
chore: proxy and integration test update
1 parent b558f6e commit 6d486ce

File tree

2 files changed

+50
-44
lines changed

2 files changed

+50
-44
lines changed

contracts/test/integration/index.ts

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
22
import { expect } from "chai";
33
import { deployments, ethers, getNamedAccounts, network } from "hardhat";
4-
import { BigNumber } from "ethers";
4+
import { toBigInt, BytesLike } from "ethers";
55
import {
66
PNK,
77
KlerosCore,
@@ -19,10 +19,11 @@ import {
1919
/* eslint-disable no-unused-expressions */ // https://github.com/standard/standard/issues/690#issuecomment-278533482
2020

2121
describe("Integration tests", async () => {
22-
const ONE_TENTH_ETH = BigNumber.from(10).pow(17);
23-
const ONE_ETH = BigNumber.from(10).pow(18);
24-
const ONE_HUNDRED_PNK = BigNumber.from(10).pow(20);
25-
const ONE_THOUSAND_PNK = BigNumber.from(10).pow(21);
22+
const ONE_TENTH_ETH = toBigInt(10) ** toBigInt(17);
23+
const ONE_ETH = toBigInt(10) ** toBigInt(18);
24+
const ONE_HUNDRED_PNK = toBigInt(10) ** toBigInt(20);
25+
const ONE_THOUSAND_PNK = toBigInt(10) ** toBigInt(21);
26+
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
2627

2728
const enum Period {
2829
evidence, // Evidence can be submitted. This is also when drawing has to take place.
@@ -39,7 +40,16 @@ describe("Integration tests", async () => {
3940
}
4041

4142
let deployer;
42-
let rng, randomizer, disputeKit, pnk, core, vea, foreignGateway, arbitrable, homeGateway, sortitionModule;
43+
let rng: RandomizerRNG,
44+
randomizer: RandomizerMock,
45+
disputeKit: DisputeKitClassic,
46+
pnk: PNK,
47+
core: KlerosCore,
48+
vea: VeaMock,
49+
foreignGateway: ForeignGateway,
50+
arbitrable: ArbitrableExample,
51+
homeGateway: HomeGateway,
52+
sortitionModule: SortitionModule;
4353

4454
beforeEach("Setup", async () => {
4555
({ deployer } = await getNamedAccounts());
@@ -60,10 +70,10 @@ describe("Integration tests", async () => {
6070
});
6171

6272
it("Resolves a dispute on the home chain with no appeal", async () => {
63-
const arbitrationCost = ONE_TENTH_ETH.mul(3);
73+
const arbitrationCost = ONE_TENTH_ETH * toBigInt(3);
6474
const [, , relayer] = await ethers.getSigners();
6575

66-
await pnk.approve(core.address, ONE_THOUSAND_PNK.mul(100));
76+
await pnk.approve(core.target, ONE_THOUSAND_PNK * toBigInt(100));
6777

6878
await core.setStake(1, ONE_THOUSAND_PNK);
6979
await sortitionModule.getJurorBalance(deployer, 1).then((result) => {
@@ -72,9 +82,9 @@ describe("Integration tests", async () => {
7282
logJurorBalance(result);
7383
});
7484

75-
await core.setStake(1, ONE_HUNDRED_PNK.mul(5));
85+
await core.setStake(1, ONE_HUNDRED_PNK * toBigInt(5));
7686
await sortitionModule.getJurorBalance(deployer, 1).then((result) => {
77-
expect(result.totalStaked).to.equal(ONE_HUNDRED_PNK.mul(5));
87+
expect(result.totalStaked).to.equal(ONE_HUNDRED_PNK * toBigInt(5));
7888
expect(result.totalLocked).to.equal(0);
7989
logJurorBalance(result);
8090
});
@@ -86,48 +96,48 @@ describe("Integration tests", async () => {
8696
logJurorBalance(result);
8797
});
8898

89-
await core.setStake(1, ONE_THOUSAND_PNK.mul(4));
99+
await core.setStake(1, ONE_THOUSAND_PNK * toBigInt(4));
90100
await sortitionModule.getJurorBalance(deployer, 1).then((result) => {
91-
expect(result.totalStaked).to.equal(ONE_THOUSAND_PNK.mul(4));
101+
expect(result.totalStaked).to.equal(ONE_THOUSAND_PNK * toBigInt(4));
92102
expect(result.totalLocked).to.equal(0);
93103
logJurorBalance(result);
94104
});
95-
const tx = await arbitrable.functions["createDispute(string)"]("future of france", {
105+
const tx = await arbitrable["createDispute(string)"]("future of france", {
96106
value: arbitrationCost,
97107
});
98108
const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);
99-
const [disputeId] = ethers.utils.defaultAbiCoder.decode(["uint"], `0x${trace.returnValue}`); // get returned value from createDispute()
109+
const [disputeId] = abiCoder.decode(["uint"], `0x${trace.returnValue}`); // get returned value from createDispute()
100110
console.log("Dispute Created with disputeId: %d", disputeId);
101111
await expect(tx)
102112
.to.emit(foreignGateway, "CrossChainDisputeOutgoing")
103-
.withArgs(anyValue, arbitrable.address, 1, 2, "0x00");
113+
.withArgs(anyValue, arbitrable.target, 1, 2, "0x00");
104114
await expect(tx)
105115
.to.emit(arbitrable, "DisputeRequest")
106116
.withArgs(
107-
foreignGateway.address,
117+
foreignGateway.target,
108118
1,
109-
BigNumber.from("46619385602526556702049273755915206310773794210139929511467397410441395547901"),
119+
toBigInt("46619385602526556702049273755915206310773794210139929511467397410441395547901"),
110120
0,
111121
""
112122
);
113123

114-
const lastBlock = await ethers.provider.getBlock(tx.blockNumber - 1);
115-
const disputeHash = ethers.utils.solidityKeccak256(
124+
const lastBlock = await ethers.provider.getBlock(tx.blockNumber ?? 0 - 1);
125+
const disputeHash = ethers.solidityPackedKeccak256(
116126
["bytes", "bytes32", "uint256", "address", "uint256", "uint256", "bytes"],
117-
[ethers.utils.toUtf8Bytes("createDispute"), lastBlock.hash, 31337, arbitrable.address, disputeId, 2, "0x00"]
127+
[ethers.toUtf8Bytes("createDispute"), lastBlock?.hash, 31337, arbitrable.target, disputeId, 2, "0x00"]
118128
);
119129
console.log("dispute hash: ", disputeHash);
120130

121131
// Relayer tx
122132
const tx2 = await homeGateway
123133
.connect(relayer)
124-
.functions["relayCreateDispute((bytes32,uint256,address,uint256,uint256,uint256,string,uint256,bytes))"](
134+
["relayCreateDispute((bytes32,uint256,address,uint256,uint256,uint256,string,uint256,bytes))"](
125135
{
126-
foreignBlockHash: lastBlock.hash,
136+
foreignBlockHash: lastBlock?.hash as BytesLike,
127137
foreignChainID: 31337,
128-
foreignArbitrable: arbitrable.address,
138+
foreignArbitrable: arbitrable.target,
129139
foreignDisputeID: disputeId,
130-
externalDisputeID: ethers.utils.keccak256(ethers.utils.toUtf8Bytes("future of france")),
140+
externalDisputeID: ethers.keccak256(ethers.toUtf8Bytes("future of france")),
131141
templateId: 0,
132142
templateUri: "",
133143
choices: 2,
@@ -136,7 +146,7 @@ describe("Integration tests", async () => {
136146
{ value: arbitrationCost }
137147
);
138148
expect(tx2).to.emit(homeGateway, "Dispute");
139-
const events2 = (await tx2.wait()).events;
149+
await tx2.wait();
140150

141151
await network.provider.send("evm_increaseTime", [2000]); // Wait for minStakingTime
142152
await network.provider.send("evm_mine");
@@ -146,23 +156,23 @@ describe("Integration tests", async () => {
146156
console.log("KC phase: %d", await sortitionModule.phase());
147157

148158
await sortitionModule.passPhase(); // Staking -> Generating
149-
await mineBlocks(await sortitionModule.rngLookahead()); // Wait for finality
159+
await mineBlocks(ethers.getNumber(await sortitionModule.rngLookahead())); // Wait for finality
150160
expect(await sortitionModule.phase()).to.equal(Phase.generating);
151161
console.log("KC phase: %d", await sortitionModule.phase());
152-
await randomizer.relay(rng.address, 0, ethers.utils.randomBytes(32));
162+
await randomizer.relay(rng.target, 0, ethers.randomBytes(32));
153163
await sortitionModule.passPhase(); // Generating -> Drawing
154164
expect(await sortitionModule.phase()).to.equal(Phase.drawing);
155165
console.log("KC phase: %d", await sortitionModule.phase());
156166

157167
const tx3 = await core.draw(0, 1000);
158168
console.log("draw successful");
159-
const events3 = (await tx3.wait()).events;
169+
await tx3.wait();
160170

161171
const roundInfo = await core.getRoundInfo(0, 0);
162172
expect(roundInfo.drawnJurors).deep.equal([deployer, deployer, deployer]);
163-
expect(roundInfo.pnkAtStakePerJuror).to.equal(ONE_HUNDRED_PNK.mul(2));
173+
expect(roundInfo.pnkAtStakePerJuror).to.equal(ONE_HUNDRED_PNK * toBigInt(2));
164174
expect(roundInfo.totalFeesForJurors).to.equal(arbitrationCost);
165-
expect(roundInfo.feeToken).to.equal(ethers.constants.AddressZero);
175+
expect(roundInfo.feeToken).to.equal(ethers.ZeroAddress);
166176

167177
expect((await core.disputes(0)).period).to.equal(Period.evidence);
168178

@@ -180,8 +190,8 @@ describe("Integration tests", async () => {
180190

181191
const tx4 = await core.executeRuling(0, { gasLimit: 10000000, gasPrice: 5000000000 });
182192
console.log("Ruling executed on KlerosCore");
183-
expect(tx4).to.emit(core, "Ruling").withArgs(homeGateway.address, 0, 0);
184-
expect(tx4).to.emit(arbitrable, "Ruling").withArgs(foreignGateway.address, 1, 0); // The ForeignGateway starts counting disputeID from 1.
193+
expect(tx4).to.emit(core, "Ruling").withArgs(homeGateway.target, 0, 0);
194+
expect(tx4).to.emit(arbitrable, "Ruling").withArgs(foreignGateway.target, 1, 0); // The ForeignGateway starts counting disputeID from 1.
185195
});
186196

187197
const mineBlocks = async (n: number) => {
@@ -192,9 +202,5 @@ describe("Integration tests", async () => {
192202
});
193203

194204
const logJurorBalance = async (result) => {
195-
console.log(
196-
"staked=%s, locked=%s",
197-
ethers.utils.formatUnits(result.totalStaked),
198-
ethers.utils.formatUnits(result.totalLocked)
199-
);
205+
console.log("staked=%s, locked=%s", ethers.formatUnits(result.totalLocked), ethers.formatUnits(result.totalStaked));
200206
};

contracts/test/proxy/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ describe("Upgradability", async () => {
6868
const UUPSUnsupportedProxiableUUIDFactory = await ethers.getContractFactory("UUPSUnsupportedProxiableUUID");
6969
const uupsUnsupportedUUID = await UUPSUnsupportedProxiableUUIDFactory.deploy();
7070
await expect(
71-
proxy.connect(deployer).upgradeToAndCall(uupsUnsupportedUUID.address, "0x")
71+
proxy.connect(deployer).upgradeToAndCall(uupsUnsupportedUUID.target, "0x")
7272
).to.be.revertedWithCustomError(proxy, "UUPSUnsupportedProxiableUUID");
7373
});
7474
it("Should revert on upgrades to non UUPS-compliant implementation", async () => {
7575
const NonUpgradeableMockFactory = await ethers.getContractFactory("NonUpgradeableMock");
7676
const nonUpgradeableMock = await NonUpgradeableMockFactory.deploy();
77-
await expect(proxy.upgradeToAndCall(nonUpgradeableMock.address, "0x"))
77+
await expect(proxy.upgradeToAndCall(nonUpgradeableMock.target, "0x"))
7878
.to.be.revertedWithCustomError(proxy, "InvalidImplementation")
79-
.withArgs(nonUpgradeableMock.address);
79+
.withArgs(nonUpgradeableMock.target);
8080
});
8181
it("Should revert if upgrade is performed directly through the implementation", async () => {
8282
// In the implementation, the `governor` storage slot is not initialized so `governor === address(0)`, which fails _authorizeUpgrade()
8383
const UUPSUpgradeableMockV2Factory = await ethers.getContractFactory("UUPSUpgradeableMockV2");
8484
const newImplementation = await UUPSUpgradeableMockV2Factory.connect(deployer).deploy();
8585
await expect(
86-
implementation.connect(deployer).upgradeToAndCall(newImplementation.address, "0x")
86+
implementation.connect(deployer).upgradeToAndCall(newImplementation.target, "0x")
8787
).to.be.revertedWith("No privilege to upgrade");
8888
});
8989
});
@@ -93,15 +93,15 @@ describe("Upgradability", async () => {
9393
// Unauthorized user try to upgrade the implementation
9494
const UUPSUpgradeableMockV2Factory = await ethers.getContractFactory("UUPSUpgradeableMockV2");
9595
let upgradable = await UUPSUpgradeableMockV2Factory.connect(user1).deploy();
96-
await expect(proxy.connect(user1).upgradeToAndCall(upgradable.address, "0x")).to.be.revertedWith(
96+
await expect(proxy.connect(user1).upgradeToAndCall(upgradable.target, "0x")).to.be.revertedWith(
9797
"No privilege to upgrade"
9898
);
9999

100100
// Governor updates the implementation
101101
upgradable = await UUPSUpgradeableMockV2Factory.connect(deployer).deploy();
102-
await expect(proxy.connect(deployer).upgradeToAndCall(upgradable.address, "0x"))
102+
await expect(proxy.connect(deployer).upgradeToAndCall(upgradable.target, "0x"))
103103
.to.emit(proxy, "Upgraded")
104-
.withArgs(upgradable.address);
104+
.withArgs(upgradable.target);
105105
});
106106
});
107107
});

0 commit comments

Comments
 (0)