Skip to content

Commit 39f9fde

Browse files
committed
wip
1 parent 85b87a2 commit 39f9fde

File tree

14 files changed

+282
-127
lines changed

14 files changed

+282
-127
lines changed

packages/horizon/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"lint": "yarn lint:ts && yarn lint:sol",
1717
"clean": "rm -rf build dist cache cache_forge typechain-types",
1818
"build": "BUILD_RUN=true hardhat compile",
19-
"test": "forge test && hardhat test:integration --deploy-type deploy"
19+
"test": "forge test && hardhat test:integration --deploy-type deploy",
20+
"test:e2e:deploy": "./scripts/e2e-deploy",
21+
"test:e2e:migrate": "./scripts/e2e-migrate"
2022
},
2123
"devDependencies": {
2224
"@graphprotocol/contracts": "workspace:^7.0.0",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
# Remove ignition deployment files if they exist
6+
echo "Removing ignition deployment files..."
7+
rm -rf ignition/deployments/chain-31337
8+
9+
# Export environment variable for all commands
10+
export SECURE_ACCOUNTS_DISABLE_PROVIDER=true
11+
12+
# Function to cleanup resources
13+
cleanup() {
14+
# Kill hardhat node
15+
if [ ! -z "$NODE_PID" ]; then
16+
echo "Cleaning up node process..."
17+
kill $NODE_PID 2>/dev/null || true
18+
fi
19+
20+
# Unset environment variable
21+
# echo "Cleaning up environment variables..."
22+
# unset SECURE_ACCOUNTS_DISABLE_PROVIDER
23+
}
24+
25+
# Set trap to call cleanup function on script exit (normal or error)
26+
trap cleanup EXIT
27+
28+
# Check if port 8545 is in use
29+
if lsof -i:8545 > /dev/null 2>&1; then
30+
echo "Error: Port 8545 is already in use"
31+
exit 1
32+
fi
33+
34+
# Start local hardhat node
35+
echo "Starting local hardhat node..."
36+
npx hardhat node > node.log 2>&1 &
37+
NODE_PID=$!
38+
39+
# Wait for node to start
40+
sleep 10
41+
42+
# Deploy protocol
43+
npx hardhat deploy:protocol --network localhost
44+
45+
# Run integration tests - After transition period
46+
echo "Running after-transition-period tests..."
47+
npx hardhat test:integration --phase after-transition --network localhost
48+
49+
# Enable delegation slashing
50+
npx hardhat transition:enable-delegation-slashing --network localhost --governor-index 1
51+
52+
# Run integration tests - After delegation slashing enabled
53+
echo "Running after-delegation-slashing tests..."
54+
npx hardhat test:integration --phase after-delegation-slashing --network localhost
55+
56+
echo "E2E tests completed successfully!"

packages/horizon/scripts/e2e renamed to packages/horizon/scripts/e2e-migrate

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
set -eo pipefail
44

5+
# Function to cleanup resources
6+
cleanup() {
7+
# Remove ignition deployment files
8+
echo "Removing ignition deployment files..."
9+
rm -rf ignition/deployments/horizon-localhost
10+
11+
# Kill hardhat node
12+
if [ ! -z "$NODE_PID" ]; then
13+
echo "Cleaning up node process..."
14+
kill $NODE_PID 2>/dev/null || true
15+
fi
16+
}
17+
18+
# Set trap to call cleanup function on script exit (normal or error)
19+
trap cleanup EXIT
20+
521
# Check required env variables
622
if [ -z "$ARBITRUM_SEPOLIA_RPC" ]; then
723
echo "ARBITRUM_SEPOLIA_RPC environment variable is required"
@@ -59,21 +75,18 @@ npx hardhat test:integration --phase during-transition --network localhost
5975

6076
# Clear thawing period
6177
echo "Clearing thawing period..."
62-
npx hardhat transition:clear-thawing
78+
npx hardhat transition:clear-thawing --network localhost --governor-index 0
6379

6480
# Run integration tests - After transition period
6581
echo "Running after-transition-period tests..."
6682
npx hardhat test:integration --phase after-transition --network localhost
6783

6884
# Enable delegation slashing
6985
echo "Enabling delegation slashing..."
70-
npx hardhat transition:enable-delegation-slashing
86+
npx hardhat transition:enable-delegation-slashing --network localhost --governor-index 0
7187

7288
# Run integration tests - After delegation slashing enabled
7389
echo "Running after-delegation-slashing tests..."
7490
npx hardhat test:integration --phase after-delegation-slashing --network localhost
7591

76-
# Cleanup
77-
kill $NODE_PID
78-
7992
echo "E2E tests completed successfully!"
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { task } from 'hardhat/config'
1+
import { task, types } from 'hardhat/config'
22

33
task('transition:clear-thawing', 'Clears the thawing period in HorizonStaking')
4-
.setAction(async (_, hre) => {
5-
const [governor] = await hre.ethers.getSigners()
4+
.addOptionalParam('governorIndex', 'Index of the governor account in getSigners array', 0, types.int)
5+
.setAction(async (taskArgs, hre) => {
6+
const signers = await hre.ethers.getSigners()
7+
const governor = signers[taskArgs.governorIndex]
68
const horizonStaking = hre.graph().horizon!.contracts.HorizonStaking
79

810
console.log('Clearing thawing period...')
@@ -12,12 +14,17 @@ task('transition:clear-thawing', 'Clears the thawing period in HorizonStaking')
1214
})
1315

1416
task('transition:enable-delegation-slashing', 'Enables delegation slashing in HorizonStaking')
15-
.setAction(async (_, hre) => {
16-
const [governor] = await hre.ethers.getSigners()
17+
.addOptionalParam('governorIndex', 'Index of the governor account in getSigners array', 0, types.int)
18+
.setAction(async (taskArgs, hre) => {
19+
const signers = await hre.ethers.getSigners()
20+
const governor = signers[taskArgs.governorIndex]
1721
const horizonStaking = hre.graph().horizon!.contracts.HorizonStaking
1822

1923
console.log('Enabling delegation slashing...')
2024
const tx = await horizonStaking.connect(governor).setDelegationSlashingEnabled()
2125
await tx.wait()
22-
console.log('Delegation slashing enabled')
26+
27+
// Log if the delegation slashing is enabled
28+
const delegationSlashingEnabled = await horizonStaking.isDelegationSlashingEnabled()
29+
console.log('Delegation slashing enabled:', delegationSlashingEnabled)
2330
})

packages/horizon/test/integration/after-delegation-slashing-enabled/add-to-delegation-pool.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import hre from 'hardhat'
22
import { ethers } from 'hardhat'
33
import { expect } from 'chai'
4-
import { HorizonStaking, IGraphToken } from '../../../typechain-types'
4+
import { IHorizonStaking, IGraphToken } from '../../../typechain-types'
55
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
66

77
import {
@@ -13,7 +13,7 @@ import {
1313
} from '../shared/staking'
1414

1515
describe('Add to delegation pool', () => {
16-
let horizonStaking: HorizonStaking
16+
let horizonStaking: IHorizonStaking
1717
let graphToken: IGraphToken
1818
let serviceProvider: SignerWithAddress
1919
let delegator: SignerWithAddress
@@ -28,7 +28,7 @@ describe('Add to delegation pool', () => {
2828
before(async () => {
2929
const graph = hre.graph()
3030

31-
horizonStaking = graph.horizon!.contracts.HorizonStaking
31+
horizonStaking = graph.horizon!.contracts.HorizonStaking as unknown as IHorizonStaking
3232
graphToken = graph.horizon!.contracts.L2GraphToken as unknown as IGraphToken
3333

3434
[serviceProvider, delegator, signer] = await ethers.getSigners()

packages/horizon/test/integration/after-delegation-slashing-enabled/slashing.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import hre from 'hardhat'
22
import { ethers } from 'hardhat'
33
import { expect } from 'chai'
44
import { HDNodeWallet } from 'ethers'
5-
import { HorizonStaking, IGraphToken } from '../../../typechain-types'
5+
import { IHorizonStaking, IGraphToken } from '../../../typechain-types'
66
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
77

88
import {
@@ -15,7 +15,7 @@ import {
1515
} from '../shared/staking'
1616

1717
describe('Slashing', () => {
18-
let horizonStaking: HorizonStaking
18+
let horizonStaking: IHorizonStaking
1919
let graphToken: IGraphToken
2020
let serviceProvider: SignerWithAddress
2121
let delegator: SignerWithAddress
@@ -30,11 +30,15 @@ describe('Slashing', () => {
3030
before(async () => {
3131
const graph = hre.graph()
3232

33-
horizonStaking = graph.horizon!.contracts.HorizonStaking
33+
horizonStaking = graph.horizon!.contracts.HorizonStaking as unknown as IHorizonStaking
3434
graphToken = graph.horizon!.contracts.L2GraphToken as unknown as IGraphToken
3535

3636
[serviceProvider, delegator] = await ethers.getSigners()
3737

38+
// Check that delegation slashing is enabled
39+
const delegationSlashingEnabled = await horizonStaking.isDelegationSlashingEnabled()
40+
expect(delegationSlashingEnabled).to.be.equal(true, 'Delegation slashing should be enabled')
41+
3842
// Send funds to delegator
3943
await graphToken.connect(serviceProvider).transfer(delegator.address, delegationTokens * 3n)
4044
})

packages/horizon/test/integration/after-transition-period/add-to-delegation-pool.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import hre from 'hardhat'
22
import { ethers } from 'hardhat'
33
import { expect } from 'chai'
4-
import { HorizonStaking, IGraphToken } from '../../../typechain-types'
4+
import { IHorizonStaking, IGraphToken } from '../../../typechain-types'
55
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
66

77
import {
@@ -12,7 +12,7 @@ import {
1212
} from '../shared/staking'
1313

1414
describe('Add to delegation pool', () => {
15-
let horizonStaking: HorizonStaking
15+
let horizonStaking: IHorizonStaking
1616
let graphToken: IGraphToken
1717
let serviceProvider: SignerWithAddress
1818
let delegator: SignerWithAddress
@@ -27,7 +27,7 @@ describe('Add to delegation pool', () => {
2727
before(async () => {
2828
const graph = hre.graph()
2929

30-
horizonStaking = graph.horizon!.contracts.HorizonStaking
30+
horizonStaking = graph.horizon!.contracts.HorizonStaking as unknown as IHorizonStaking
3131
graphToken = graph.horizon!.contracts.L2GraphToken as unknown as IGraphToken
3232

3333
[serviceProvider, delegator, signer] = await ethers.getSigners()

packages/horizon/test/integration/after-transition-period/delegator.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import hre from 'hardhat'
22
import { ethers } from 'hardhat'
33
import { expect } from 'chai'
4-
import { HorizonStaking, IGraphToken } from '../../../typechain-types'
4+
import { IHorizonStaking, IGraphToken } from '../../../typechain-types'
55
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
66

77
import {
@@ -14,7 +14,7 @@ import {
1414
} from '../shared/staking'
1515

1616
describe('Delegator', () => {
17-
let horizonStaking: HorizonStaking
17+
let horizonStaking: IHorizonStaking
1818
let graphToken: IGraphToken
1919
let delegator: SignerWithAddress
2020
let serviceProvider: SignerWithAddress
@@ -29,7 +29,7 @@ describe('Delegator', () => {
2929
before(async () => {
3030
const graph = hre.graph()
3131

32-
horizonStaking = graph.horizon!.contracts.HorizonStaking
32+
horizonStaking = graph.horizon!.contracts.HorizonStaking as unknown as IHorizonStaking
3333
graphToken = graph.horizon!.contracts.L2GraphToken as unknown as IGraphToken
3434

3535
[serviceProvider, delegator, newServiceProvider] = await ethers.getSigners()
@@ -50,7 +50,17 @@ describe('Delegator', () => {
5050
thawingPeriod,
5151
})
5252

53-
// Send funds to delegator and new service provider
53+
// Send eth to delegator and new service provider to cover gas fees
54+
await serviceProvider.sendTransaction({
55+
to: delegator.address,
56+
value: ethers.parseEther('0.04'),
57+
})
58+
await serviceProvider.sendTransaction({
59+
to: newServiceProvider.address,
60+
value: ethers.parseEther('0.04'),
61+
})
62+
63+
// Send GRT to delegator and new service provider to use for delegation and staking
5464
await graphToken.connect(serviceProvider).transfer(delegator.address, tokens)
5565
await graphToken.connect(serviceProvider).transfer(newServiceProvider.address, tokens)
5666
})

packages/horizon/test/integration/after-transition-period/operator.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import hre from 'hardhat'
22
import { expect } from 'chai'
33
import { ethers } from 'hardhat'
4-
import { HorizonStaking, IGraphToken } from '../../../typechain-types'
4+
import { IHorizonStaking, IGraphToken } from '../../../typechain-types'
55
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
66

77
import { createProvision, deprovision, reprovision, stakeTo, thaw, unstake } from '../shared/staking'
88
import { PaymentTypes } from '../utils/types'
99

1010
describe('Operator', () => {
11-
let horizonStaking: HorizonStaking
11+
let horizonStaking: IHorizonStaking
1212
let graphToken: IGraphToken
1313
let serviceProvider: SignerWithAddress
1414
let verifier: string
@@ -21,7 +21,7 @@ describe('Operator', () => {
2121
before(async () => {
2222
const graph = hre.graph()
2323

24-
horizonStaking = graph.horizon!.contracts.HorizonStaking
24+
horizonStaking = graph.horizon!.contracts.HorizonStaking as unknown as IHorizonStaking
2525
graphToken = graph.horizon!.contracts.L2GraphToken as unknown as IGraphToken
2626

2727
// Get signers

packages/horizon/test/integration/after-transition-period/service-provider.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import hre from 'hardhat'
22
import { ethers } from 'hardhat'
33
import { expect } from 'chai'
4-
import { HorizonStaking, IGraphToken } from '../../../typechain-types'
4+
import { IHorizonStaking, IGraphToken } from '../../../typechain-types'
55
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
66

77
import {
@@ -17,7 +17,7 @@ import {
1717
import { PaymentTypes } from '../utils/types'
1818

1919
describe('Service provider', () => {
20-
let horizonStaking: HorizonStaking
20+
let horizonStaking: IHorizonStaking
2121
let graphToken: IGraphToken
2222
let verifier: string
2323
let serviceProvider: SignerWithAddress
@@ -26,7 +26,7 @@ describe('Service provider', () => {
2626
before(async () => {
2727
const graph = hre.graph()
2828

29-
horizonStaking = graph.horizon!.contracts.HorizonStaking
29+
horizonStaking = graph.horizon!.contracts.HorizonStaking as unknown as IHorizonStaking
3030
graphToken = graph.horizon!.contracts.L2GraphToken as unknown as IGraphToken
3131

3232
verifier = await ethers.Wallet.createRandom().getAddress();

0 commit comments

Comments
 (0)