forked from GoodDollar/gooddollar-l2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validator_functionality.sh
More file actions
99 lines (82 loc) · 4.17 KB
/
test_validator_functionality.sh
File metadata and controls
99 lines (82 loc) · 4.17 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
94
95
96
97
98
99
#!/bin/bash
# ValidatorStaking functionality test
# Tests the validator staking workflow
set -e
echo "⚡ ValidatorStaking Functionality Test"
echo "====================================="
# Load environment
source .autobuilder/addresses.env
FOUNDRY_INSTALL_DIR="$HOME/.foundry"
PATH="$FOUNDRY_INSTALL_DIR/bin:$PATH"
WALLET=$(cast wallet address --private-key $TESTER_KEY)
echo "🏦 Wallet: $WALLET"
# Get initial balances and staking info
echo "📊 Initial status:"
GDT_BALANCE=$(cast call $GDT 'balanceOf(address)(uint256)' $WALLET --rpc-url $RPC)
TOTAL_STAKED=$(cast call $VS 'totalStaked()(uint256)' --rpc-url $RPC)
echo " GDT Balance: $GDT_BALANCE"
echo " Total Staked: $TOTAL_STAKED"
# Check minimum stake requirement
MIN_STAKE=$(cast call $VS 'MIN_STAKE()(uint256)' --rpc-url $RPC 2>/dev/null || echo "1000000000000000000000")
echo " Minimum Stake: $MIN_STAKE"
# Step 1: Approve staking contract
echo ""
echo "🔐 Step 1: Approving staking contract..."
APPROVAL_AMOUNT="10000000000000000000000" # 10,000 GDT
cast send $GDT 'approve(address,uint256)' $VS $APPROVAL_AMOUNT --rpc-url $RPC --private-key $TESTER_KEY --confirmations 1
echo " ✅ Approved $APPROVAL_AMOUNT for staking contract"
# Step 2: Test staking
echo ""
echo "⚡ Step 2: Testing validator staking..."
STAKE_AMOUNT="1000000000000000000000" # 1,000 GDT
VALIDATOR_NAME="TestValidator$(date +%s)"
VALIDATOR_URL="https://test-validator.gooddollar.org"
echo " Attempting to stake $STAKE_AMOUNT with validator '$VALIDATOR_NAME'..."
if cast send $VS 'stake(uint256,string,string)' $STAKE_AMOUNT "$VALIDATOR_NAME" "$VALIDATOR_URL" --rpc-url $RPC --private-key $TESTER_KEY --confirmations 1 2>/dev/null; then
echo " ✅ Validator staking successful!"
# Check updated totals
NEW_TOTAL_STAKED=$(cast call $VS 'totalStaked()(uint256)' --rpc-url $RPC)
NEW_GDT_BALANCE=$(cast call $GDT 'balanceOf(address)(uint256)' $WALLET --rpc-url $RPC)
echo " 📊 New total staked: $NEW_TOTAL_STAKED"
echo " 📊 New GDT balance: $NEW_GDT_BALANCE"
# Try to check validator info
echo " 🔍 Checking validator information..."
if cast call $VS 'validators(address)(string,string,uint256,bool)' $WALLET --rpc-url $RPC 2>/dev/null; then
VALIDATOR_INFO=$(cast call $VS 'validators(address)(string,string,uint256,bool)' $WALLET --rpc-url $RPC)
echo " 📋 Validator info: $VALIDATOR_INFO"
else
echo " ⚠️ Could not retrieve validator info (different interface)"
fi
# Step 3: Test unstaking (small amount)
echo ""
echo "💸 Step 3: Testing partial unstaking..."
UNSTAKE_AMOUNT="100000000000000000000" # 100 GDT
if cast send $VS 'unstake(uint256)' $UNSTAKE_AMOUNT --rpc-url $RPC --private-key $TESTER_KEY --confirmations 1 2>/dev/null; then
FINAL_TOTAL_STAKED=$(cast call $VS 'totalStaked()(uint256)' --rpc-url $RPC)
FINAL_GDT_BALANCE=$(cast call $GDT 'balanceOf(address)(uint256)' $WALLET --rpc-url $RPC)
echo " ✅ Partial unstaking successful!"
echo " 📊 Final total staked: $FINAL_TOTAL_STAKED"
echo " 📊 Final GDT balance: $FINAL_GDT_BALANCE"
else
echo " ⚠️ Unstaking failed (may have cooldown period or different interface)"
fi
else
echo " ⚠️ Validator staking failed"
# Check if it's a minimum stake issue
if [[ $(echo "$STAKE_AMOUNT < $MIN_STAKE" | bc 2>/dev/null || echo "0") == "1" ]]; then
echo " ℹ️ Stake amount ($STAKE_AMOUNT) is below minimum ($MIN_STAKE)"
# Try with minimum stake
echo " 🔄 Retrying with minimum stake amount..."
if cast send $VS 'stake(uint256,string,string)' $MIN_STAKE "$VALIDATOR_NAME" "$VALIDATOR_URL" --rpc-url $RPC --private-key $TESTER_KEY --confirmations 1 2>/dev/null; then
echo " ✅ Staking with minimum amount successful!"
else
echo " ❌ Staking still failed - may need additional requirements"
fi
else
echo " ❌ Staking failed - may need additional requirements or different interface"
fi
fi
echo ""
echo "🎉 ValidatorStaking test complete!"
echo "✅ Contract accessible and responsive"
echo "ℹ️ Full functionality depends on minimum stake and validator requirements"