Skip to content

Commit 3d7e811

Browse files
authored
test: incorporate funding into setup script
This fixes an issue with the gateway not being fully deploy
1 parent ddda0c3 commit 3d7e811

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

setup-test-network.sh

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,73 @@ echo "Containers size: $START_CONTAINERS_SIZE"
2929
echo "Volumes size: $START_VOLUMES_SIZE"
3030
echo "=============================================="
3131

32-
# Your existing script starts here
3332
container_running() {
3433
docker ps --format '{{.Names}}' | grep -q "^$1$"
3534
return $?
3635
}
3736

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
44+
fund_escrow() {
45+
echo "Funding escrow for sender..."
46+
47+
if [ -f "local-network/.env" ]; then
48+
source local-network/.env
49+
else
50+
echo "Error: local-network/.env file not found"
51+
return 1
52+
fi
53+
54+
GRAPH_TOKEN=$(jq -r '."1337".GraphToken.address' local-network/contracts.json)
55+
TAP_ESCROW=$(jq -r '."1337".TAPEscrow.address' local-network/contracts.json)
56+
57+
if [ -z "$GRAPH_TOKEN" ] || [ -z "$TAP_ESCROW" ]; then
58+
echo "Error: Could not read contract addresses from contracts.json"
59+
return 1
60+
fi
61+
62+
# Use constants from .env
63+
SENDER_ADDRESS="$ACCOUNT0_ADDRESS"
64+
SENDER_KEY="$ACCOUNT0_SECRET"
65+
AMOUNT="10000000000000000000"
66+
67+
echo "Using GraphToken at: $GRAPH_TOKEN"
68+
echo "Using TapEscrow at: $TAP_ESCROW"
69+
echo "Using sender address: $SENDER_ADDRESS"
70+
71+
# Approve GRT for escrow
72+
echo "Approving GRT..."
73+
docker exec chain cast send \
74+
--rpc-url http://localhost:8545 \
75+
--private-key $SENDER_KEY \
76+
$GRAPH_TOKEN "approve(address,uint256)" $TAP_ESCROW $AMOUNT
77+
78+
# Deposit to escrow
79+
echo "Depositing to escrow..."
80+
docker exec chain cast send \
81+
--rpc-url http://localhost:8545 \
82+
--private-key $SENDER_KEY \
83+
$TAP_ESCROW "deposit(address,uint256)" $SENDER_ADDRESS $AMOUNT
84+
85+
# Verify deposit
86+
echo "Verifying deposit..."
87+
ESCROW_BALANCE=$(docker exec chain cast call \
88+
--rpc-url http://localhost:8545 \
89+
$TAP_ESCROW "getEscrowAmount(address,address)(uint256)" $SENDER_ADDRESS $SENDER_ADDRESS)
90+
echo "Escrow balance: $ESCROW_BALANCE"
91+
if [[ "$ESCROW_BALANCE" == "0" ]]; then
92+
echo "Error: Failed to fund escrow"
93+
return 1
94+
fi
95+
echo "Successfully funded escrow"
96+
return 0
97+
}
98+
3899
if container_running "indexer-service" && container_running "tap-agent" && container_running "gateway"; then
39100
echo "====================================================================================="
40101
echo "All services are already running. To test changes to your indexer code, you can use:"
@@ -171,10 +232,6 @@ rm docker-compose.override.yml
171232
timeout 30 bash -c 'until docker ps | grep indexer | grep -q healthy; do sleep 5; done'
172233
timeout 30 bash -c 'until docker ps | grep tap-agent | grep -q healthy; do sleep 5; done'
173234

174-
# Mine some blocks
175-
# This is important for the gateway
176-
(./local-network/scripts/mine-block.sh 10) 2>/dev/null || true
177-
178235
echo "Building gateway image..."
179236
docker build -t local-gateway:latest ./local-network/gateway
180237

@@ -190,6 +247,18 @@ docker run -d --name gateway \
190247

191248
echo "Waiting for gateway to be available..."
192249

250+
# Try to fund escrow up to 3 times
251+
for i in {1..3}; do
252+
echo "Attempt $i to fund escrow..."
253+
if fund_escrow; then
254+
break
255+
fi
256+
if [ $i -lt 3 ]; then
257+
echo "Waiting before retry..."
258+
sleep 10
259+
fi
260+
done
261+
193262
# Ensure gateway is ready before testing
194263
timeout 100 bash -c 'until curl -f http://localhost:7700/ > /dev/null 2>&1; do echo "Waiting for gateway service..."; sleep 5; done'
195264

0 commit comments

Comments
 (0)