@@ -751,6 +751,102 @@ run_upload_tests() {
751751 await_events 1 " ReadOnchain(address,uint256)"
752752}
753753
754+ # ##################################################
755+ # ############ INSUFFICIENT FEES TESTS #############
756+ # ##################################################
757+ # Function to fetch the requestCount from a transaction hash
758+ parse_request_count_from_tx_hash () {
759+ receipt=$( cast receipt " $LAST_TX_HASH " --rpc-url " $EVMX_RPC " --json)
760+
761+ # Extract matching log's data field
762+ # cast keccak "RequestSubmitted(address,uint40,(bytes32,address,address,address,address,bytes32,bytes32,uint256,uint256,uint256,uint256,bytes,address)[])"
763+ request_submitted_keccak=" 0xb856562fcff2119ba754f0486f47c06087ebc1842bff464faf1b2a1f8d273b1d"
764+ data_hex=$( echo " $receipt " | jq -r --arg topic0 " $request_submitted_keccak " '
765+ .logs[]
766+ | select(.topics[0] == $topic0)
767+ | .data
768+ ' )
769+
770+ data_hex=$( echo " $data_hex " | sed ' s/^0x//' | tr ' A-F' ' a-f' )
771+ uint40_hex=${data_hex: 64: 64}
772+ uint40=$( echo " ibase=16; $( echo " $uint40_hex " | tr ' a-f' ' A-F' ) " | bc)
773+ echo " Payload requestCount (decimal): $uint40 "
774+ export REQUEST_COUNT=$uint40
775+ }
776+
777+ # Function to run insufficient fees to EVMx tests
778+ run_insufficient_fees_tests () {
779+ local contractname=$1
780+ local chainid=$2
781+ echo -e " ${CYAN} Testing fees for '$contractname ' on chain $chainid ${NC} "
782+ local contractid
783+ contractid=$( cast call " $APP_GATEWAY " " $contractname ()(bytes32)" --rpc-url " $EVMX_RPC " || {
784+ echo -e " ${RED} Error:${NC} Failed to get contract ID"
785+ exit 1
786+ })
787+
788+ # Wait for valid forwarder address with progress bar
789+ local attempts=0
790+ local max_attempts=15
791+ local width=50
792+ local forwarder
793+ local bar
794+ while [ $attempts -lt $max_attempts ]; do
795+ forwarder=$( cast call " $APP_GATEWAY " \
796+ " forwarderAddresses(bytes32,uint32)(address)" \
797+ " $contractid " " $chainid " --rpc-url " $EVMX_RPC " || echo " error" )
798+
799+ if [ " $forwarder " != " error" ] && [ " $forwarder " != " 0x0000000000000000000000000000000000000000" ]; then
800+ [ $attempts -ne 0 ] && printf " \n"
801+ echo " $forwarder "
802+ return 0
803+ fi
804+
805+ local progress=$(( (attempts * width) / max_attempts ))
806+ local percent=$(( (attempts * 100 ) / max_attempts ))
807+ bar=$( printf " #%.0s" $( seq 1 $progress ) )
808+ printf " \r${YELLOW} Waiting for forwarder:${NC} [%-${width} s] %d%%" " $bar " " $percent "
809+ sleep 1
810+ attempts=$(( attempts + 1 ))
811+ done
812+ printf " \n"
813+ echo " No valid forwarder after $max_attempts seconds"
814+ parse_request_count_from_tx_hash
815+
816+ # Set fees
817+ send_transaction " $APP_GATEWAY " " increaseFees(uint40,uint256)" " $EVMX_RPC " " evmx.cloud" \
818+ " $REQUEST_COUNT " " $DEPLOY_FEES_AMOUNT " || {
819+ echo -e " ${RED} Error:${NC} Failed to set fees"
820+ return 1
821+ }
822+
823+ # Verify forwarder after fees
824+ attempts=0
825+ bar=" "
826+ while [ $attempts -lt $max_attempts ]; do
827+ forwarder=$( cast call " $APP_GATEWAY " \
828+ " forwarderAddresses(bytes32,uint32)(address)" \
829+ " $contractid " " $chainid " --rpc-url " $EVMX_RPC " || echo " error" )
830+
831+ if [ " $forwarder " != " error" ] && [ " $forwarder " != " 0x0000000000000000000000000000000000000000" ]; then
832+ [ $attempts -ne 0 ] && printf " \n"
833+ echo -e " ${GREEN} Chain $chainid ${NC} "
834+ echo -e " Forwarder: $forwarder "
835+ return 0
836+ fi
837+
838+ local progress=$(( (attempts * width) / max_attempts ))
839+ local percent=$(( (attempts * 100 ) / max_attempts ))
840+ bar=$( printf " #%.0s" $( seq 1 $progress ) )
841+ printf " \r${YELLOW} Waiting for forwarder:${NC} [%-${width} s] %d%%" " $bar " " $percent "
842+ sleep 5
843+ attempts=$(( attempts + 1 ))
844+ done
845+ printf " \n"
846+ echo -e " ${RED} Error:${NC} No valid forwarder after $(( max_attempts * 5 )) seconds"
847+ exit 1
848+ }
849+
754850# ##################################################
755851# ############### SCHEDULER TESTS ##################
756852# ##################################################
@@ -991,6 +1087,15 @@ main() {
9911087 withdraw_funds
9921088 }
9931089
1090+ # Insufficient Fees Tests function
1091+ run_insufficient_fees_tests_func () {
1092+ deploy_appgateway read ReadAppGateway 0 # Zero Max fees to force no transmitter biding
1093+ deposit_funds
1094+ deploy_onchain $OP_SEP_CHAIN_ID
1095+ run_insufficient_fees_tests ' multichain' $OP_SEP_CHAIN_ID
1096+ withdraw_funds
1097+ }
1098+
9941099 # Scheduler Tests function
9951100 run_scheduler_tests_func () {
9961101 deploy_appgateway schedule ScheduleAppGateway
@@ -1023,19 +1128,21 @@ main() {
10231128 RUN_READ=false
10241129 RUN_TRIGGER=false
10251130 RUN_UPLOAD=false
1131+ RUN_FEES=false
10261132 RUN_SCHEDULER=false
10271133 RUN_REVERT=false
10281134 RUN_ALL=false
10291135
10301136 # Parse command line options
10311137 # To extend: Add new single-letter flags to "wrthua" string
10321138 # and corresponding case in the switch statement
1033- while getopts " wrtusva ?" opt; do
1139+ while getopts " wrtuisva ?" opt; do
10341140 case $opt in
10351141 w) RUN_WRITE=true;;
10361142 r) RUN_READ=true;;
10371143 t) RUN_TRIGGER=true;;
10381144 u) RUN_UPLOAD=true;;
1145+ i) RUN_FEES=true;;
10391146 s) RUN_SCHEDULER=true;;
10401147 v) RUN_REVERT=true;;
10411148 a) RUN_ALL=true;;
@@ -1055,6 +1162,7 @@ main() {
10551162 RUN_READ=true
10561163 RUN_TRIGGER=true
10571164 RUN_UPLOAD=true
1165+ RUN_FEES=true
10581166 RUN_SCHEDULER=true
10591167 RUN_REVERT=true
10601168 fi
@@ -1065,6 +1173,7 @@ main() {
10651173 $RUN_READ && run_read_tests_func
10661174 $RUN_TRIGGER && run_trigger_tests_func
10671175 $RUN_UPLOAD && run_upload_tests_func
1176+ $RUN_FEES && run_insufficient_fees_tests_func
10681177 $RUN_SCHEDULER && run_scheduler_tests_func
10691178 $RUN_REVERT && run_revert_tests_func
10701179}
0 commit comments