Skip to content

Commit 1ad2da9

Browse files
committed
fix: update test scripts for horizon addresses
1 parent 86e0057 commit 1ad2da9

File tree

2 files changed

+108
-41
lines changed

2 files changed

+108
-41
lines changed

integration-tests/fund_escrow.sh

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,108 @@
11
#!/bin/bash
22
set -e
33

4-
# Constants taken from local-network/.env
5-
GRAPH_TOKEN="0x3Aa5ebB10DC797CAC828524e59A333d0A371443c"
6-
TAP_ESCROW="0x0355B7B8cb128fA5692729Ab3AAa199C1753f726"
7-
# Sender address is also known as ACCOUNT0_ADDRESS
8-
# in our services configuration along with local-network
9-
SENDER_ADDRESS="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
10-
# Sender key is the private key use to sign receipts
11-
# This is defined as ACCOUNT0_SECRET in local-network/.env
12-
SENDER_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
13-
AMOUNT="10000000000000000000"
14-
15-
echo "Funding escrow for sender: $SENDER_ADDRESS"
4+
# ==============================================================================
5+
# FUND ESCROW FOR HORIZON UPGRADE
6+
# ==============================================================================
7+
# This script funds the TAP escrow contract with GRT tokens for horizon upgrade.
8+
# It reads the correct contract addresses from the horizon file structure.
9+
# ==============================================================================
10+
11+
# Function to get contract address from JSON file
12+
get_contract_address() {
13+
local file="$1"
14+
local contract="$2"
15+
if [ ! -f "$file" ]; then
16+
echo "Error: File $file not found"
17+
exit 1
18+
fi
19+
local address=$(jq -r "."1337".$contract.address" "$file")
20+
if [ "$address" == "null" ] || [ -z "$address" ]; then
21+
echo "Error: Could not find $contract address in $file"
22+
exit 1
23+
fi
24+
echo "$address"
25+
}
26+
27+
# Load environment variables
28+
if [ -f ".env" ]; then
29+
source .env
30+
else
31+
echo "Error: .env file not found. Please run from local-network directory."
32+
exit 1
33+
fi
34+
35+
# Get contract addresses from horizon file structure
36+
GRAPH_TOKEN=$(get_contract_address "horizon.json" "L2GraphToken")
37+
TAP_ESCROW=$(get_contract_address "tap-contracts.json" "TAPEscrow")
38+
39+
# Use environment variables from .env
40+
SENDER_ADDRESS="$ACCOUNT0_ADDRESS"
41+
SENDER_KEY="$ACCOUNT0_SECRET"
42+
AMOUNT="10000000000000000000" # 10 GRT
43+
44+
echo "============ FUNDING ESCROW FOR HORIZON ============"
45+
echo "L2GraphToken address: $GRAPH_TOKEN"
46+
echo "TAPEscrow address: $TAP_ESCROW"
47+
echo "Sender address: $SENDER_ADDRESS"
48+
echo "Amount: $AMOUNT (10 GRT)"
49+
echo "=================================================="
50+
51+
# Check if contracts have code deployed
52+
echo "Verifying L2GraphToken contract..."
53+
code=$(docker exec chain cast code $GRAPH_TOKEN --rpc-url http://localhost:8545)
54+
if [ -z "$code" ] || [ "$code" == "0x" ]; then
55+
echo "Error: L2GraphToken contract has no code at $GRAPH_TOKEN"
56+
exit 1
57+
fi
58+
59+
echo "Verifying TAPEscrow contract..."
60+
code=$(docker exec chain cast code $TAP_ESCROW --rpc-url http://localhost:8545)
61+
if [ -z "$code" ] || [ "$code" == "0x" ]; then
62+
echo "Error: TAPEscrow contract has no code at $TAP_ESCROW"
63+
exit 1
64+
fi
65+
66+
# Check current escrow balance before funding
67+
echo "Checking current escrow balance..."
68+
CURRENT_BALANCE=$(docker exec chain cast call \
69+
--rpc-url http://localhost:8545 \
70+
$TAP_ESCROW "getEscrowAmount(address,address)(uint256)" $SENDER_ADDRESS $SENDER_ADDRESS)
71+
echo "Current escrow balance: $CURRENT_BALANCE"
1672

1773
# Approve GRT for escrow
18-
echo "Approving GRT..."
74+
echo "Approving GRT for escrow..."
1975
docker exec chain cast send \
2076
--rpc-url http://localhost:8545 \
2177
--private-key $SENDER_KEY \
78+
--confirmations 1 \
2279
$GRAPH_TOKEN "approve(address,uint256)" $TAP_ESCROW $AMOUNT
2380

2481
# Deposit to escrow
2582
echo "Depositing to escrow..."
2683
docker exec chain cast send \
2784
--rpc-url http://localhost:8545 \
2885
--private-key $SENDER_KEY \
86+
--confirmations 1 \
2987
$TAP_ESCROW "deposit(address,uint256)" $SENDER_ADDRESS $AMOUNT
3088

3189
# Verify deposit
3290
echo "Verifying deposit..."
3391
ESCROW_BALANCE=$(docker exec chain cast call \
3492
--rpc-url http://localhost:8545 \
3593
$TAP_ESCROW "getEscrowAmount(address,address)(uint256)" $SENDER_ADDRESS $SENDER_ADDRESS)
36-
echo "Escrow balance: $ESCROW_BALANCE"
37-
if [[ "$ESCROW_BALANCE" == "0" ]]; then
38-
echo "Error: Failed to fund escrow"
94+
echo "New escrow balance: $ESCROW_BALANCE"
95+
96+
# Calculate expected balance
97+
EXPECTED_BALANCE=$((CURRENT_BALANCE + AMOUNT))
98+
if [[ "$ESCROW_BALANCE" -ge "$EXPECTED_BALANCE" ]]; then
99+
echo "✅ Successfully funded escrow!"
100+
echo " Previous balance: $CURRENT_BALANCE"
101+
echo " Added amount: $AMOUNT"
102+
echo " New balance: $ESCROW_BALANCE"
103+
else
104+
echo "❌ Error: Escrow funding failed"
105+
echo " Expected at least: $EXPECTED_BALANCE"
106+
echo " Actual balance: $ESCROW_BALANCE"
39107
exit 1
40108
fi
41-
echo "Successfully funded escrow"

setup-test-network.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
set -e
33

44
# ==============================================================================
5-
# SETUP LOCAL GRAPH NETWORK FOR TESTING
5+
# SETUP LOCAL GRAPH NETWORK FOR TESTING (HORIZON VERSION)
66
# ==============================================================================
7-
# This script sets up a local Graph network for testing.
7+
# This script sets up a local Graph network for testing with horizon upgrade.
88
#
99
# NOTES:
1010
# - If you encounter container conflicts, run: docker compose down
@@ -34,13 +34,8 @@ container_running() {
3434
return $?
3535
}
3636

37-
# Function to fund the escrow smart contract
38-
# 1. first read .env variables from local-network/.env
39-
# 2. then read contract addresses from local-network/contracts.json
40-
# 3. finally, use the cast command to approve and deposit GRT to the escrow
41-
# this should be done just after deploying the gateway
42-
# otherwise it does not move forward in its setup process
43-
# causing false error during deployment of our local testnet
37+
# Function to fund the escrow smart contract for horizon
38+
# Uses L2GraphToken and TAPEscrow from the horizon structure
4439
fund_escrow() {
4540
echo "Funding escrow for sender..."
4641

@@ -51,11 +46,14 @@ fund_escrow() {
5146
return 1
5247
fi
5348

54-
GRAPH_TOKEN=$(jq -r '."1337".GraphToken.address' local-network/contracts.json)
55-
TAP_ESCROW=$(jq -r '."1337".TAPEscrow.address' local-network/contracts.json)
49+
# Use L2GraphToken from horizon.json for horizon upgrade
50+
GRAPH_TOKEN=$(jq -r '."1337".L2GraphToken.address' local-network/horizon.json)
51+
TAP_ESCROW=$(jq -r '."1337".TAPEscrow.address' local-network/tap-contracts.json)
5652

57-
if [ -z "$GRAPH_TOKEN" ] || [ -z "$TAP_ESCROW" ]; then
58-
echo "Error: Could not read contract addresses from contracts.json"
53+
if [ -z "$GRAPH_TOKEN" ] || [ -z "$TAP_ESCROW" ] || [ "$GRAPH_TOKEN" == "null" ] || [ "$TAP_ESCROW" == "null" ]; then
54+
echo "Error: Could not read contract addresses from horizon.json or tap-contracts.json"
55+
echo "GRAPH_TOKEN: $GRAPH_TOKEN"
56+
echo "TAP_ESCROW: $TAP_ESCROW"
5957
return 1
6058
fi
6159

@@ -64,7 +62,7 @@ fund_escrow() {
6462
SENDER_KEY="$ACCOUNT0_SECRET"
6563
AMOUNT="10000000000000000000"
6664

67-
echo "Using GraphToken at: $GRAPH_TOKEN"
65+
echo "Using L2GraphToken at: $GRAPH_TOKEN"
6866
echo "Using TapEscrow at: $TAP_ESCROW"
6967
echo "Using sender address: $SENDER_ADDRESS"
7068

@@ -116,7 +114,7 @@ pwd
116114
if [ ! -d "local-network" ]; then
117115
git clone https://github.com/semiotic-ai/local-network.git
118116
cd local-network
119-
# Checkout to a branch with no dipper
117+
# Checkout to the horizon branch
120118
git checkout suchapalaver/test/horizon
121119
cd ..
122120
fi
@@ -135,17 +133,17 @@ docker compose up -d graph-contracts
135133
# Wait for contracts to be deployed
136134
timeout 300 bash -c 'until docker ps -a | grep graph-contracts | grep -q "Exited (0)"; do sleep 5; done'
137135

138-
# Verify the contracts have code
139-
graph_token_address=$(jq -r '."1337".GraphToken.address' contracts.json)
140-
controller_address=$(jq -r '."1337".Controller.address' contracts.json)
136+
# Verify the contracts have code using horizon structure
137+
l2_graph_token_address=$(jq -r '."1337".L2GraphToken.address' horizon.json)
138+
controller_address=$(jq -r '."1337".Controller.address' horizon.json)
141139

142-
echo "Checking GraphToken contract at $graph_token_address"
143-
code=$(docker exec chain cast code $graph_token_address --rpc-url http://localhost:8545)
140+
echo "Checking L2GraphToken contract at $l2_graph_token_address"
141+
code=$(docker exec chain cast code $l2_graph_token_address --rpc-url http://localhost:8545)
144142
if [ -z "$code" ] || [ "$code" == "0x" ]; then
145-
echo "ERROR: GraphToken contract has no code!"
143+
echo "ERROR: L2GraphToken contract has no code!"
146144
exit 1
147145
fi
148-
echo "GraphToken contract verified."
146+
echo "L2GraphToken contract verified."
149147

150148
echo "Checking Controller contract at $controller_address"
151149
code=$(docker exec chain cast code $controller_address --rpc-url http://localhost:8545)
@@ -237,10 +235,12 @@ source local-network/.env
237235
docker build -t local-gateway:latest ./local-network/gateway
238236

239237
echo "Running gateway container..."
238+
# Updated to use the horizon file structure
240239
docker run -d --name gateway \
241240
--network local-network_default \
242241
-p 7700:7700 \
243-
-v "$(pwd)/local-network/contracts.json":/opt/contracts.json:ro \
242+
-v "$(pwd)/local-network/tap-contracts.json":/opt/tap-contracts.json:ro \
243+
-v "$(pwd)/local-network/subgraph-service.json":/opt/subgraph-service.json:ro \
244244
-e RUST_LOG=info,graph_gateway=trace \
245245
-e ACCOUNT0_SECRET="$ACCOUNT0_SECRET" \
246246
-e ACCOUNT0_ADDRESS="$ACCOUNT0_ADDRESS" \
@@ -275,7 +275,7 @@ END_CONTAINERS_SIZE=$(docker system df --format '{{.ContainersSize}}' 2>/dev/nul
275275
END_VOLUMES_SIZE=$(docker system df --format '{{.VolumesSize}}' 2>/dev/null || echo "N/A")
276276

277277
echo "All services are now running!"
278-
echo "You can enjoy your new local network setup for testing."
278+
echo "You can enjoy your new local network setup for testing with horizon upgrade."
279279

280280
echo "============ FINAL DISK USAGE ============"
281281
echo "Docker directory usage: $END_SPACE"

0 commit comments

Comments
 (0)