-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbasic-e2e.bats
More file actions
211 lines (179 loc) · 9.21 KB
/
basic-e2e.bats
File metadata and controls
211 lines (179 loc) · 9.21 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bats
# bats file_tags=cdk
setup() {
load '../../core/helpers/agglayer-cdk-common-setup'
_agglayer_cdk_common_setup
}
# bats test_tags=transaction-eoa
@test "Send EOA transaction" {
local initial_nonce
# shellcheck disable=SC2154
initial_nonce=$(cast nonce "$sender_addr" --rpc-url "$L2_RPC_URL") || {
echo "Failed to retrieve nonce for sender: $sender_addr using RPC URL: $L2_RPC_URL"
return 1
}
local value="10ether"
# case 1: Transaction successful sender has sufficient balance
# shellcheck disable=SC2154
run send_tx "$L2_RPC_URL" "$sender_private_key" "$receiver" "$value"
assert_success
assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)"
# case 2: Transaction rejected as sender attempts to transfer more than it has in its wallet.
# Transaction will fail pre-validation check on the node and will be dropped subsequently from the pool
# without recording it on the chain and hence nonce will not change
local sender_balance
sender_balance=$(cast balance "$sender_addr" --ether --rpc-url "$L2_RPC_URL") || {
echo "Failed to retrieve balance for sender: $sender_addr using RPC URL: $L2_RPC_URL"
return 1
}
local excessive_value
excessive_value=$(echo "$sender_balance + 1" | bc)"ether"
run send_tx "$L2_RPC_URL" "$sender_private_key" "$receiver" "$excessive_value"
assert_failure
# Check whether the sender's nonce was updated correctly
local final_nonce
final_nonce=$(cast nonce "$sender_addr" --rpc-url "$L2_RPC_URL") || {
echo "Failed to retrieve nonce for sender: $sender_addr using RPC URL: $L2_RPC_URL"
return 1
}
assert_equal "$final_nonce" "$(echo "$initial_nonce + 1" | bc)"
}
# bats test_tags=transaction-erc20
@test "Test ERC20Mock contract" {
wallet_A_output=$(cast wallet new)
address_A=$(echo "$wallet_A_output" | grep "Address" | awk '{print $2}')
address_A_private_key=$(echo "$wallet_A_output" | grep "Private key" | awk '{print $3}')
address_B=$(cast wallet new | grep "Address" | awk '{print $2}')
# Deploy ERC20Mock
# shellcheck disable=SC2154
run deploy_contract "$L2_RPC_URL" "$sender_private_key" "$erc20_artifact_path"
assert_success
contract_addr=$(echo "$output" | tail -n 1)
# Mint ERC20 tokens
local amount="5"
run send_tx "$L2_RPC_URL" "$sender_private_key" "$contract_addr" "$MINT_FN_SIG" "$address_A" "$amount"
assert_success
assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)"
## Case 2: Insufficient gas scenario => Transactions fails
# nonce would not increase since transaction fails at the node's pre-validation check
# Get bytecode from the contract artifact
local bytecode
bytecode=$(jq -r .bytecode "$erc20_artifact_path")
if [[ -z "$bytecode" || "$bytecode" == "null" ]]; then
echo "Error: Failed to read bytecode from $erc20_artifact_path"
return 1
fi
# Estimate gas, gas price and gas cost
local gas_units
gas_units=$(cast estimate --rpc-url "$L2_RPC_URL" --create "$bytecode")
gas_units=$(echo "scale=0; $gas_units / 2" | bc)
local gas_price
gas_price=$(cast gas-price --rpc-url "$L2_RPC_URL")
local value
value=$(echo "$gas_units * $gas_price" | bc)
local value_ether
value_ether=$(cast to-unit "$value" ether)"ether"
# Transfer only half amount of tokens needed for contract deployment fees
cast_output=$(cast send --rpc-url "$L2_RPC_URL" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1)
if [[ $? -ne 0 ]]; then
echo "Error: Failed to send transaction. Output:"
echo "$cast_output"
return 1
fi
# Fetch initial nonce for address_A
local address_A_initial_nonce
address_A_initial_nonce=$(cast nonce "$address_A" --rpc-url "$L2_RPC_URL") || return 1
# Attempt to deploy contract with insufficient gas
run deploy_contract "$L2_RPC_URL" "$address_A_private_key" "$erc20_artifact_path"
assert_failure
## Case 3: Transaction should fail as address_A tries to transfer more tokens than it has
# nonce would not increase
# Transfer funds for gas fees to address_A
value_ether="4ether"
cast_output=$(cast send --rpc-url "$L2_RPC_URL" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1)
if [[ $? -ne 0 ]]; then
echo "Error: Failed to send transaction. Output:"
echo "$cast_output"
return 1
fi
# Fetch balance of address_A to simulate excessive transfer
run query_contract "$L2_RPC_URL" "$contract_addr" "$BALANCE_OF_FN_SIG" "$address_A"
assert_success
local address_A_Balance
address_A_Balance=$(echo "$output" | tail -n 1)
address_A_Balance=$(echo "$address_A_Balance" | xargs)
# Set excessive amount for transfer
local excessive_amount
excessive_amount=$(echo "$address_A_Balance + 1" | bc)
# Attempt transfer of excessive amount from address_A to address_B
local tranferFnSig="transfer(address,uint256)"
run send_tx "$L2_RPC_URL" "$address_A_private_key" "$contract_addr" "$tranferFnSig" "$address_B" "$excessive_amount"
assert_failure
# Verify balance of address_A after failed transaction
run query_contract "$L2_RPC_URL" "$contract_addr" "$BALANCE_OF_FN_SIG" "$address_A"
assert_success
address_A_BalanceAfterFailedTx=$(echo "$output" | tail -n 1)
address_A_BalanceAfterFailedTx=$(echo "$address_A_BalanceAfterFailedTx" | xargs)
# Ensure balance is unchanged
assert_equal "$address_A_BalanceAfterFailedTx" "$address_A_Balance"
# Verify balance of address_B is still zero
run query_contract "$L2_RPC_URL" "$contract_addr" "$BALANCE_OF_FN_SIG" "$address_B"
assert_success
local address_B_Balance
address_B_Balance=$(echo "$output" | tail -n 1)
address_B_Balance=$(echo "$address_B_Balance" | xargs)
assert_equal "$address_B_Balance" "0"
# Nonce should not increase
local address_A_final_nonce
address_A_final_nonce=$(cast nonce "$address_A" --rpc-url "$L2_RPC_URL") || {
echo "Failed to retrieve nonce for sender: $address_A using RPC URL: $L2_RPC_URL"
return 1
}
assert_equal "$address_A_final_nonce" "$address_A_initial_nonce"
}
# bats test_tags=transaction-uniswap
@test "Deploy and test UniswapV3 contract" {
# Generate new key pair
wallet_A_output=$(cast wallet new)
address_A=$(echo "$wallet_A_output" | grep "Address" | awk '{print $2}')
address_A_private_key=$(echo "$wallet_A_output" | grep "Private key" | awk '{print $3}')
# Transfer funds for gas
local value_ether="50ether"
cast_output=$(cast send --rpc-url "$L2_RPC_URL" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1)
if [[ $? -ne 0 ]]; then
echo "Error: Failed to send transaction. Output:"
echo "$cast_output"
return 1
fi
run polycli loadtest uniswapv3 --legacy -v 600 --rpc-url "$L2_RPC_URL" --private-key "$address_A_private_key"
assert_success
# Remove ANSI escape codes from the output
output=$(echo "$output" | sed -r "s/\x1B\[[0-9;]*[mGKH]//g")
# Check if all required Uniswap contracts were deployed
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=WETH9"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapV3Factory"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapInterfaceMulticall"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=ProxyAdmin"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=TickLens"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NFTDescriptor"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NonfungibleTokenPositionDescriptor"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=TransparentUpgradeableProxy"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NonfungiblePositionManager"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=V3Migrator"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapV3Staker"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=QuoterV2"
assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=SwapRouter02"
# Check if ERC20 tokens were minted
assert_output --regexp "Minted tokens amount=[0-9]+ recipient=0x[a-fA-F0-9]{40} token=SwapperA"
assert_output --regexp "Minted tokens amount=[0-9]+ recipient=0x[a-fA-F0-9]{40} token=SwapperB"
# Check if liquidity pool was created and initialized
assert_output --regexp "Pool created and initialized fees=[0-9]+"
# Check if liquidity was provided to the pool
assert_output --regexp "Liquidity provided to the pool liquidity=[0-9]+"
# Check if transaction got executed successfully
assert_output --regexp "Starting main load test loop"
assert_output --regexp "Finished main load test loop"
assert_output --regexp "Got final block number"
assert_output --regexp "Num errors numErrors=0"
assert_output --regexp "Finished"
}