1
1
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs" ;
2
2
import { expect } from "chai" ;
3
3
import { deployments , ethers , getNamedAccounts , network } from "hardhat" ;
4
- import { BigNumber } from "ethers" ;
4
+ import { toBigInt , BytesLike } from "ethers" ;
5
5
import {
6
6
PNK ,
7
7
KlerosCore ,
@@ -19,10 +19,11 @@ import {
19
19
/* eslint-disable no-unused-expressions */ // https://github.com/standard/standard/issues/690#issuecomment-278533482
20
20
21
21
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 ( ) ;
26
27
27
28
const enum Period {
28
29
evidence , // Evidence can be submitted. This is also when drawing has to take place.
@@ -39,7 +40,16 @@ describe("Integration tests", async () => {
39
40
}
40
41
41
42
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 ;
43
53
44
54
beforeEach ( "Setup" , async ( ) => {
45
55
( { deployer } = await getNamedAccounts ( ) ) ;
@@ -60,10 +70,10 @@ describe("Integration tests", async () => {
60
70
} ) ;
61
71
62
72
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 ) ;
64
74
const [ , , relayer ] = await ethers . getSigners ( ) ;
65
75
66
- await pnk . approve ( core . address , ONE_THOUSAND_PNK . mul ( 100 ) ) ;
76
+ await pnk . approve ( core . target , ONE_THOUSAND_PNK * toBigInt ( 100 ) ) ;
67
77
68
78
await core . setStake ( 1 , ONE_THOUSAND_PNK ) ;
69
79
await sortitionModule . getJurorBalance ( deployer , 1 ) . then ( ( result ) => {
@@ -72,9 +82,9 @@ describe("Integration tests", async () => {
72
82
logJurorBalance ( result ) ;
73
83
} ) ;
74
84
75
- await core . setStake ( 1 , ONE_HUNDRED_PNK . mul ( 5 ) ) ;
85
+ await core . setStake ( 1 , ONE_HUNDRED_PNK * toBigInt ( 5 ) ) ;
76
86
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 ) ) ;
78
88
expect ( result . totalLocked ) . to . equal ( 0 ) ;
79
89
logJurorBalance ( result ) ;
80
90
} ) ;
@@ -86,48 +96,48 @@ describe("Integration tests", async () => {
86
96
logJurorBalance ( result ) ;
87
97
} ) ;
88
98
89
- await core . setStake ( 1 , ONE_THOUSAND_PNK . mul ( 4 ) ) ;
99
+ await core . setStake ( 1 , ONE_THOUSAND_PNK * toBigInt ( 4 ) ) ;
90
100
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 ) ) ;
92
102
expect ( result . totalLocked ) . to . equal ( 0 ) ;
93
103
logJurorBalance ( result ) ;
94
104
} ) ;
95
- const tx = await arbitrable . functions [ "createDispute(string)" ] ( "future of france" , {
105
+ const tx = await arbitrable [ "createDispute(string)" ] ( "future of france" , {
96
106
value : arbitrationCost ,
97
107
} ) ;
98
108
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()
100
110
console . log ( "Dispute Created with disputeId: %d" , disputeId ) ;
101
111
await expect ( tx )
102
112
. to . emit ( foreignGateway , "CrossChainDisputeOutgoing" )
103
- . withArgs ( anyValue , arbitrable . address , 1 , 2 , "0x00" ) ;
113
+ . withArgs ( anyValue , arbitrable . target , 1 , 2 , "0x00" ) ;
104
114
await expect ( tx )
105
115
. to . emit ( arbitrable , "DisputeRequest" )
106
116
. withArgs (
107
- foreignGateway . address ,
117
+ foreignGateway . target ,
108
118
1 ,
109
- BigNumber . from ( "46619385602526556702049273755915206310773794210139929511467397410441395547901" ) ,
119
+ toBigInt ( "46619385602526556702049273755915206310773794210139929511467397410441395547901" ) ,
110
120
0 ,
111
121
""
112
122
) ;
113
123
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 (
116
126
[ "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" ]
118
128
) ;
119
129
console . log ( "dispute hash: " , disputeHash ) ;
120
130
121
131
// Relayer tx
122
132
const tx2 = await homeGateway
123
133
. 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))" ] (
125
135
{
126
- foreignBlockHash : lastBlock . hash ,
136
+ foreignBlockHash : lastBlock ? .hash as BytesLike ,
127
137
foreignChainID : 31337 ,
128
- foreignArbitrable : arbitrable . address ,
138
+ foreignArbitrable : arbitrable . target ,
129
139
foreignDisputeID : disputeId ,
130
- externalDisputeID : ethers . utils . keccak256 ( ethers . utils . toUtf8Bytes ( "future of france" ) ) ,
140
+ externalDisputeID : ethers . keccak256 ( ethers . toUtf8Bytes ( "future of france" ) ) ,
131
141
templateId : 0 ,
132
142
templateUri : "" ,
133
143
choices : 2 ,
@@ -136,7 +146,7 @@ describe("Integration tests", async () => {
136
146
{ value : arbitrationCost }
137
147
) ;
138
148
expect ( tx2 ) . to . emit ( homeGateway , "Dispute" ) ;
139
- const events2 = ( await tx2 . wait ( ) ) . events ;
149
+ await tx2 . wait ( ) ;
140
150
141
151
await network . provider . send ( "evm_increaseTime" , [ 2000 ] ) ; // Wait for minStakingTime
142
152
await network . provider . send ( "evm_mine" ) ;
@@ -146,23 +156,23 @@ describe("Integration tests", async () => {
146
156
console . log ( "KC phase: %d" , await sortitionModule . phase ( ) ) ;
147
157
148
158
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
150
160
expect ( await sortitionModule . phase ( ) ) . to . equal ( Phase . generating ) ;
151
161
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 ) ) ;
153
163
await sortitionModule . passPhase ( ) ; // Generating -> Drawing
154
164
expect ( await sortitionModule . phase ( ) ) . to . equal ( Phase . drawing ) ;
155
165
console . log ( "KC phase: %d" , await sortitionModule . phase ( ) ) ;
156
166
157
167
const tx3 = await core . draw ( 0 , 1000 ) ;
158
168
console . log ( "draw successful" ) ;
159
- const events3 = ( await tx3 . wait ( ) ) . events ;
169
+ await tx3 . wait ( ) ;
160
170
161
171
const roundInfo = await core . getRoundInfo ( 0 , 0 ) ;
162
172
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 ) ) ;
164
174
expect ( roundInfo . totalFeesForJurors ) . to . equal ( arbitrationCost ) ;
165
- expect ( roundInfo . feeToken ) . to . equal ( ethers . constants . AddressZero ) ;
175
+ expect ( roundInfo . feeToken ) . to . equal ( ethers . ZeroAddress ) ;
166
176
167
177
expect ( ( await core . disputes ( 0 ) ) . period ) . to . equal ( Period . evidence ) ;
168
178
@@ -180,8 +190,8 @@ describe("Integration tests", async () => {
180
190
181
191
const tx4 = await core . executeRuling ( 0 , { gasLimit : 10000000 , gasPrice : 5000000000 } ) ;
182
192
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.
185
195
} ) ;
186
196
187
197
const mineBlocks = async ( n : number ) => {
@@ -192,9 +202,5 @@ describe("Integration tests", async () => {
192
202
} ) ;
193
203
194
204
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 ) ) ;
200
206
} ;
0 commit comments