Skip to content

Commit c8555b8

Browse files
committed
Update with testing fixes and code rabbit suggestions
1 parent a9ba888 commit c8555b8

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

script/pioneer/PioneerQA.sol

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ contract PioneerQA is Script {
1313
bytes32 transactionId;
1414
address sendingAssetId;
1515
address receiver;
16-
uint256 inputAmount;
1716
uint256 minAmount;
1817
uint256 destinationChainId;
1918
}
@@ -47,15 +46,15 @@ contract PioneerQA is Script {
4746

4847
if (LibAsset.isNativeAsset(param.sendingAssetId)) {
4948
PioneerFacet(diamond).startBridgeTokensViaPioneer{
50-
value: param.inputAmount
49+
value: param.minAmount
5150
}(_bridgeData, _pioneerData);
5251
} else {
5352
// Set allowance
5453
LibAsset.approveERC20(
5554
IERC20(param.sendingAssetId),
5655
diamond,
57-
param.inputAmount,
58-
param.inputAmount
56+
param.minAmount,
57+
param.minAmount
5958
);
6059

6160
PioneerFacet(diamond).startBridgeTokensViaPioneer(

script/pioneer/pioneer-qa-full.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1+
#!/usr/bin/env bash
2+
13
## Load env
24
source .env
35

46
# This script is created to assist with throughput testing of Pioneer through the LI.FI diamond.
57

6-
# Get from network.
7-
NETWORK=$1 # ["optimism", "arbitrum", "polygon"]
8-
# Get to networks
9-
TO_NETWORKS=$2 # ["optimism", "arbitrum", "polygon"]
10-
# Get the token
11-
TOKEN=$3 # 0x...
12-
NUM_TRANSACTIONS=$4 # 10
13-
NUM_RUNS=5 # 5
8+
# Get from networks (JSON-like list or comma-separated)
9+
SRC_NETWORKS=${1:?Usage: $0 SRC_NETWORKS TO_NETWORKS TOKEN NUM_TRANSACTIONS NUM_RUNS}
10+
11+
# Get to networks "[optimism, arbitrum, polygon]"
12+
TO_NETWORKS=${2:?missing TO_NETWORKS}
13+
14+
TOKEN=${3:?missing TOKEN}
15+
NUM_TRANSACTIONS=${4:?missing NUM_TRANSACTIONS}
16+
NUM_RUNS=${5:-5}
1417

1518

1619
# For each network provided, run the qa script in parallel and then wait for all to finish.
1720
for RUN in $(seq 1 $NUM_RUNS);
1821
do
1922
echo "Starting run $RUN of $NUM_RUNS"
20-
for NETWORK in $(echo $NETWORK | tr -d '[]"' | tr ',' '\n');
23+
for NET in $(echo $SRC_NETWORKS | tr -d '[]"' | tr ',' '\n');
2124
do
22-
echo "Starting QA for network: $NETWORK"
23-
bash script/pioneer/pioneer-qa.sh "$NETWORK" "$TO_NETWORKS" "$TOKEN" "$NUM_TRANSACTIONS" &
25+
echo "Starting QA for network: $NET"
26+
bash script/pioneer/pioneer-qa.sh "$NET" "$TO_NETWORKS" "$TOKEN" "$NUM_TRANSACTIONS" &
2427
done
2528
# Wait for all background processes to finish
2629
wait

script/pioneer/pioneer-qa.sh

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env bash
2+
13
## Load env
24
source .env
35

@@ -16,23 +18,32 @@ NETWORK=$(echo $NETWORK | tr '[:upper:]' '[:lower:]')
1618
UPPER_NETWORK=$(echo $NETWORK | tr '[:lower:]' '[:upper:]')
1719

1820
# Get the diamond address for the network (stored at ./deployments/<network>.json)
19-
DIAMOND=$(jq -r '.LiFiDiamond' ./deployments/$NETWORK.staging.json)
21+
DEPLOY_FILE="./deployments/${NETWORK}.staging.json"
22+
test -f "$DEPLOY_FILE" || { echo "Missing $DEPLOY_FILE"; exit 1; }
23+
DIAMOND=$(jq -r '.LiFiDiamond' "$DEPLOY_FILE")
2024
echo "Using LiFi Diamond at $DIAMOND"
2125

2226
# Get the RPC_URL for the network ($ETH_NODE_URI_<NETWORK>)
23-
RPC_URL=$(eval echo \$ETH_NODE_URI_$UPPER_NETWORK)
27+
RPC_ENV="ETH_NODE_URI_${UPPER_NETWORK}"
28+
RPC_URL=$(eval "echo \${$RPC_ENV:-}")
29+
[ -n "$RPC_URL" ] || { echo "Missing $RPC_ENV"; exit 1; }
2430

2531
# Get from network id.
26-
FROM_NETWORK_ID=$(cast chain-id --rpc-url $RPC_URL)
32+
FROM_NETWORK_ID=$(cast chain-id --rpc-url "$RPC_URL")
2733

2834
# Convert to_networks to array of ids.
2935
TO_NETWORKS_IDS=()
3036
for NET in $(echo $TO_NETWORKS | tr -d '[]"' | tr ',' '\n');
3137
do
32-
NET_ID=$(cast chain-id --rpc-url $(eval echo \$ETH_NODE_URI_$(echo $NET | tr '[:lower:]' '[:upper:]')))
33-
TO_NETWORKS_IDS+=($NET_ID)
38+
UPPER_NET=$(echo "$NET" | tr '[:lower:]' '[:upper:]')
39+
NET_RPC_ENV="ETH_NODE_URI_${UPPER_NET}"
40+
NET_RPC=$(eval "echo \${$NET_RPC_ENV:-}")
41+
[ -n "$NET_RPC" ] || { echo "Missing $NET_RPC_ENV"; exit 1; }
42+
NET_ID=$(cast chain-id --rpc-url "$NET_RPC")
43+
TO_NETWORKS_IDS+=("$NET_ID")
3444
done
3545

46+
[[ -n "${PRIVATE_KEY:-}" ]] || { echo "Missing PRIVATE_KEY in env" >&2; exit 1; }
3647
# Compute the user's address
3748
USER_ADDRESS=$(cast wallet address $PRIVATE_KEY)
3849

@@ -49,11 +60,12 @@ USER_BALANCE=$(cast balance $USER_ADDRESS --rpc-url $RPC_URL)
4960
USER_BALANCE=$((USER_BALANCE / 10))
5061

5162
# Compute the amount we want to use, 10000000000000000 or user balance / 10 whatever is smallest.
52-
OP_AMOUNT=10000000000000000
63+
OP_AMOUNT=100000000000000000
5364
if [ "$USER_BALANCE" -lt "$OP_AMOUNT" ]; then
5465
OP_AMOUNT=$USER_BALANCE
5566
fi
5667
echo "Operating Amount: $OP_AMOUNT"
68+
[ "$OP_AMOUNT" -gt 0 ] || { echo "OP_AMOUNT computed as 0"; exit 1; }
5769

5870
# Collect quotes from Pioneer
5971
# Initialize an empty array to hold responses
@@ -73,6 +85,7 @@ do
7385
TO_ADDRESS="$USER_ADDRESS"
7486
# Divide the OP_AMOUNT by number of operations
7587
FROM_AMOUNT=$(($OP_AMOUNT / $NUM_TRANSACTIONS))
88+
[ "$FROM_AMOUNT" -gt 0 ] || { echo "Per-tx FROM_AMOUNT computed as 0" >&2; exit 1; }
7689
SLIPPAGE="0"
7790
EXTERNAL_ID="$TRANSACTION_ID"
7891

@@ -90,6 +103,9 @@ do
90103
# Fetch quote from Pioneer
91104
RESPONSE=$(curl -s -G "$PIONEER_ENDPOINT/quote?$QUERY_STRING" -H "Content-Type: application/json")
92105

106+
echo "$PIONEER_ENDPOINT/quote?$QUERY_STRING"
107+
echo "Response: $RESPONSE"
108+
93109
# # Check if the response is valid
94110
if [ -z "$RESPONSE" ] || echo "$RESPONSE" | grep -q '"error"'; then
95111
echo "Quote request failed: $RESPONSE"
@@ -98,9 +114,8 @@ do
98114

99115
# Extract necessary fields from the response
100116
TO_CHAIN_ID=$(echo "$RESPONSE" | jq -r '.toChainId')
101-
TO_AMOUNT_MIN=$(echo "$RESPONSE" | jq -r '.toAmountMin')
102117

103-
RESPONSES+=("$(echo "$TRANSACTION_ID, $TOKEN, $USER_ADDRESS, $OP_AMOUNT, $TO_AMOUNT_MIN, $TO_CHAIN_ID")")
118+
RESPONSES+=("$(echo "$TRANSACTION_ID, $TOKEN, $USER_ADDRESS, $FROM_AMOUNT, $TO_CHAIN_ID")")
104119
done
105120

106121
echo "All quote responses collected."
@@ -111,4 +126,4 @@ FLATTENED_RESPONSES=$(printf "(%s)," "${RESPONSES[@]}")
111126
FLATTENED_RESPONSES="[${FLATTENED_RESPONSES%,}]"
112127

113128
# Execute transactions:
114-
forge script PioneerQA --sig "run(address,address,(bytes32,address,address,uint256,uint256,uint256)[])" "$DIAMOND" "$USER_ADDRESS" "$FLATTENED_RESPONSES" --private-key $PRIVATE_KEY --rpc-url $RPC_URL --broadcast -vvvv
129+
forge script PioneerQA --sig "run(address,address,(bytes32,address,address,uint256,uint256)[])" "$DIAMOND" "$USER_ADDRESS" "$FLATTENED_RESPONSES" --private-key "$PRIVATE_KEY" --rpc-url "$RPC_URL" --broadcast -vvvv

0 commit comments

Comments
 (0)