Skip to content

Commit

Permalink
Extend e2e tests, minimize rounding errors per delegator
Browse files Browse the repository at this point in the history
  • Loading branch information
DrZoltanFazekas committed Mar 4, 2025
1 parent 5eed549 commit 2924a4d
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 199 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ To enable the tests to interact with the Zilliqa 2.0 deposit contract, the contr
@zilliqa/zq2/=/home/user/zq2/zilliqa/src/contracts/
```

To execute end-to-end tests on a local network, set `consensus.staker_withdrawal_period` to 5 and
`consensus.blocks_per_epoch` to 3 in `config_docker.toml` and run
To execute end-to-end tests on a local network, set the funds of the first item in `consensus.genesis_accounts` to `5000000000000000000000000`, `consensus.staker_withdrawal_period` to 5 and `consensus.blocks_per_epoch` to 3 in `config_docker.toml` and run
```bash
chmod +x e2e_liquid.sh && ./e2e_liquid.sh
chmod +x e2e_non-liquid.sh && ./e2e_non-liquid.sh
Expand Down
179 changes: 109 additions & 70 deletions e2e_liquid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ CONTROL_KEY_4=0xdb670cbff28f4b15297d03fafdab8f5303d68b7591bd59e31eaef215dd0f246a



staker() {
# $1 = 2-digit index
# $2 = STAKER_KEY or STAKER_ADDRESS
STAKER_KEY=${STAKER_KEY:0:64}$1
STAKER_ADDRESS=$(cast wallet address $STAKER_KEY)
local var=$2
echo ${!var}
}



unbond() {
# sleep two times as many seconds as many blocks the deposit withdrawal period
# consists of to wait long enough even if there is a 2 second average block time
Expand Down Expand Up @@ -204,25 +215,92 @@ join_all() {



stake_all() {
echo "############################### EARNING ##############################"
sleep 10s
stake_one() {
# $1 = 2-digit staker index
# $2 = amount
echo "############################### STAKING ##############################"
cast send --legacy --value 300ether --private-key 0x0000000000000000000000000000000000000000000000000000000000000002 $STAKER_ADDRESS 1>/dev/null
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $(staker $1 STAKER_ADDRESS)) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker $1 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
temp=$(forge script script/Stake.s.sol --broadcast --legacy --sig "run(address payable, uint256)" $CONTRACT_ADDRESS $2 --private-key $(staker $1 STAKER_KEY) 2>&1 1>/dev/null)
errors=$(echo $temp | grep -o -i -e "error" -e "fail" -e "revert" | wc -l)
if [ $errors -eq 0 ]; then
echo "🟒 Stake $1"
else
echo "πŸ”΄ Stake $1 $temp"
fi
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker $1 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $(staker $1 STAKER_ADDRESS)) ether
sleep 2s
}



unstake_one() {
# $1 = 2-digit staker index
# $2 = amount
echo "############################### UNSTAKING ##############################"
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker $1 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $(staker $1 STAKER_ADDRESS)) ether
temp=$(forge script script/Unstake.s.sol --broadcast --legacy --sig "run(address payable, uint256)" $CONTRACT_ADDRESS $2 --private-key $(staker $1 STAKER_KEY) 2>&1 1>/dev/null)
errors=$(echo $temp | grep -o -i -e "error" -e "fail" -e "revert" | wc -l)
if [ $errors -eq 0 ]; then
echo "🟒 Unstake $1"
else
echo "πŸ”΄ Unstake $1 $temp"
fi
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker $1 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $(staker $1 STAKER_ADDRESS)) ether
sleep 2s
}



claim_one() {
# $1 = 2-digit staker index
echo "############################### CLAIMING ##############################"
echo -n "🟒 claimable: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getClaimable()(uint256)" --from $(staker $1 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
temp=$(forge script script/Stake.s.sol --broadcast --legacy --sig "run(address payable, uint256)" $CONTRACT_ADDRESS 200000000000000000000 --private-key $STAKER_KEY 2>&1 1>/dev/null)
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker $1 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $(staker $1 STAKER_ADDRESS)) ether
temp=$(forge script script/Claim.s.sol --broadcast --legacy --sig "run(address payable)" $CONTRACT_ADDRESS --private-key $(staker $1 STAKER_KEY) 2>&1 1>/dev/null)
errors=$(echo $temp | grep -o -i -e "error" -e "fail" -e "revert" | wc -l)
if [ $errors -eq 0 ]; then
echo "🟒 Stake"
echo "🟒 Claim $1"
else
echo "πŸ”΄ Stake $temp"
echo "πŸ”΄ Claim $1 $temp"
fi
echo -n "🟒 claimable: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getClaimable()(uint256)" --from $(staker $1 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker $1 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 controller balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $(staker $1 STAKER_ADDRESS)) ether
sleep 2s
}



stake_all() {
echo "############################### EARNING ##############################"
sleep 10s

cast send --legacy --value 300ether --private-key 0x0000000000000000000000000000000000000000000000000000000000000002 $(staker 01 STAKER_ADDRESS) 1>/dev/null
stake_one 01 200000000000000000000

cast send --legacy --value 2100ether --private-key 0x0000000000000000000000000000000000000000000000000000000000000002 $(staker 02 STAKER_ADDRESS) 1>/dev/null
stake_one 02 2000000000000000000000

cast send --legacy --value 20100ether --private-key 0x0000000000000000000000000000000000000000000000000000000000000002 $(staker 03 STAKER_ADDRESS) 1>/dev/null
stake_one 03 20000000000000000000000

validators=$(cast call $CONTRACT_ADDRESS "validators()(bool[])" | grep -o "true" | wc -l)
if [ $validators -gt 0 ]; then
priv_key=$CONTROL_KEY_3
Expand All @@ -245,27 +323,19 @@ stake_all() {
echo "############################### EARNING ##############################"
sleep 10s

echo "############################### UNSTAKING ##############################"
temp=$(forge script script/Unstake.s.sol --broadcast --legacy --sig "run(address payable, uint256)" $CONTRACT_ADDRESS 100000000000000000000 --private-key $STAKER_KEY 2>&1 1>/dev/null)
errors=$(echo $temp | grep -o -i -e "error" -e "fail" -e "revert" | wc -l)
if [ $errors -eq 0 ]; then
echo "🟒 Unstake"
else
echo "πŸ”΄ Unstake $temp"
fi
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
unstake_one 01 100000000000000000000

unstake_one 02 1000000000000000000000

unstake_one 03 10000000000000000000000

echo "############################### UNBONDING ##############################"
unbond

echo "############################### STAKING REWARDS ##############################"
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker 01 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
temp=$(forge script script/StakeRewards.s.sol --broadcast --legacy --sig "run(address payable)" $CONTRACT_ADDRESS --private-key $OWNER_KEY 2>&1 1>/dev/null)
errors=$(echo $temp | grep -o -i -e "error" -e "fail" -e "revert" | wc -l)
if [ $errors -eq 0 ]; then
Expand All @@ -274,25 +344,14 @@ stake_all() {
echo "πŸ”΄ StakeRewards $temp"
fi
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker 01 STAKER_ADDRESS) | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether

echo "############################### CLAIMING ##############################"
echo -n "🟒 claimable: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getClaimable()(uint256)" --from $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
temp=$(forge script script/Claim.s.sol --broadcast --legacy --sig "run(address payable)" $CONTRACT_ADDRESS --private-key $STAKER_KEY 2>&1 1>/dev/null)
errors=$(echo $temp | grep -o -i -e "error" -e "fail" -e "revert" | wc -l)
if [ $errors -eq 0 ]; then
echo "🟒 Claim"
else
echo "πŸ”΄ Claim $temp"
fi
echo -n "🟒 claimable: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getClaimable()(uint256)" --from $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
claim_one 01

echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
claim_one 02

claim_one 03

echo "############################### EARNING ##############################"
sleep 10s
Expand Down Expand Up @@ -366,43 +425,23 @@ unstake_all() {
echo -n "🟒 total rewards: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getRewards()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether

echo "############################### UNSTAKING ##############################"
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
temp=$(forge script script/Unstake.s.sol --broadcast --legacy --sig "run(address payable, uint256)" $CONTRACT_ADDRESS $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS) --private-key $STAKER_KEY 2>&1 1>/dev/null)
errors=$(echo $temp | grep -o -i -e "error" -e "fail" -e "revert" | wc -l)
if [ $errors -eq 0 ]; then
echo "🟒 Unstake"
else
echo "πŸ”΄ Unstake $temp"
fi
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
unstake_one 01 $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker 01 STAKER_ADDRESS))

unstake_one 02 $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker 02 STAKER_ADDRESS))

unstake_one 03 $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $(staker 03 STAKER_ADDRESS))

echo "############################### UNBONDING ##############################"
unbond
echo -n "🟒 taxed rewards: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getTaxedRewards()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 total rewards: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getRewards()(uint256)" | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 lst price: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getPrice()(uint256)" | sed 's/\[[^]]*\]//g') ether

echo "############################### CLAIMING ##############################"
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
echo -n "🟒 claimable: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getClaimable()(uint256)" --from $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
temp=$(forge script script/Claim.s.sol --broadcast --legacy --sig "run(address payable)" $CONTRACT_ADDRESS --private-key $STAKER_KEY 2>&1 1>/dev/null)
errors=$(echo $temp | grep -o -i -e "error" -e "fail" -e "revert" | wc -l)
if [ $errors -eq 0 ]; then
echo "🟒 Claim"
else
echo "πŸ”΄ Claim $temp"
fi
echo -n "🟒 claimable: " && cast to-unit $(cast call $CONTRACT_ADDRESS "getClaimable()(uint256)" --from $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
echo -n "🟒 commission: " && cast to-unit $(cast balance $COMMISSION_ADDRESS) ether
echo -n "🟒 staker balance: " && cast to-unit $(cast balance $STAKER_ADDRESS) ether
echo -n "🟒 lst balance: " && cast to-unit $(cast call $(cast call $CONTRACT_ADDRESS "getLST()(address)") "balanceOf(address)(uint256)" $STAKER_ADDRESS | sed 's/\[[^]]*\]//g') ether
claim_one 01

claim_one 02

claim_one 03
}


Expand Down
Loading

0 comments on commit 2924a4d

Please sign in to comment.