-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_local.sh
More file actions
executable file
·93 lines (72 loc) · 2.54 KB
/
Copy pathtest_local.sh
File metadata and controls
executable file
·93 lines (72 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Local Testing Script for Token Sender
# This script helps you test the token sender locally using Anvil
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}🧪 Local Testing Script for Token Sender${NC}"
echo "=============================================="
# Check if addresses.csv exists
if [ ! -f "addresses.csv" ]; then
echo -e "${RED}❌ addresses.csv file not found!${NC}"
echo "Please create an addresses.csv file with the addresses you want to send ETH to."
exit 1
fi
echo -e "${GREEN}✅ Starting local Anvil instance...${NC}"
# Start Anvil in the background
anvil --port 8545 &
ANVIL_PID=$!
# Wait for Anvil to start
sleep 2
echo -e "${GREEN}✅ Anvil started on http://localhost:8545${NC}"
# Get the first account's private key from Anvil
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
echo "Using private key: $PRIVATE_KEY"
# Create .env file for local testing
cat > .env << EOF
PRIVATE_KEY=$PRIVATE_KEY
RPC_URL=http://localhost:8545
EOF
echo -e "${GREEN}✅ Created .env file for local testing${NC}"
# Count addresses in CSV
ADDRESS_COUNT=$(tail -n +2 addresses.csv | wc -l | tr -d ' ')
echo "Number of addresses: $ADDRESS_COUNT"
# Calculate total ETH needed
TOTAL_ETH=$(echo "scale=2; $ADDRESS_COUNT * 0.01" | bc)
echo "Total ETH needed: $TOTAL_ETH ETH"
echo ""
echo -e "${YELLOW}⚠️ Note: Anvil accounts come with 1000 ETH each, so you have plenty for testing!${NC}"
echo ""
# Ask for confirmation
read -p "Do you want to run the token sender script? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}Testing cancelled.${NC}"
kill $ANVIL_PID 2>/dev/null || true
exit 0
fi
echo ""
echo -e "${GREEN}🚀 Running Token Sender Script on local Anvil...${NC}"
echo "=================================================="
# Run the Foundry script
forge script script/TokenSender.s.sol:TokenSender \
--rpc-url http://localhost:8545 \
--broadcast
echo ""
echo -e "${GREEN}✅ Token sender script completed!${NC}"
echo "Check the output above for transaction details."
# Ask if user wants to stop Anvil
echo ""
read -p "Do you want to stop the Anvil instance? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${GREEN}Stopping Anvil...${NC}"
kill $ANVIL_PID 2>/dev/null || true
echo -e "${GREEN}✅ Anvil stopped${NC}"
else
echo -e "${YELLOW}Anvil is still running on http://localhost:8545${NC}"
echo "You can continue testing or manually stop it with: pkill anvil"
fi