-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patheip7883.bats
More file actions
82 lines (69 loc) · 2.74 KB
/
eip7883.bats
File metadata and controls
82 lines (69 loc) · 2.74 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
#!/usr/bin/env bats
# bats file_tags=fusaka,eip-7883
# This file implements tests for EIP-7883
# https://eips.ethereum.org/EIPS/eip-7883
setup() {
true
}
setup_file() {
# shellcheck source=core/helpers/common.bash
source "$BATS_TEST_DIRNAME/../../core/helpers/common.bash"
_setup_vars
contract_bytecode=$(cat $PROJECT_ROOT/tests/fusaka/contracts/PreModExp.json | jq -r .bytecode.object)
if [ -z "$contract_bytecode" ]; then
echo "❌ Failed to read bytecode from $PROJECT_ROOT/tests/fusaka/contracts/PreModExp.json" >&3
exit 1
fi
export contract_bytecode
}
function deploy_contract() {
local rpc_url="$1"
local private_key="$2"
# Deploy the contract
run cast send --rpc-url $rpc_url --private-key $private_key --create $contract_bytecode --json
if [ "$status" -ne 0 ]; then
echo "❌ Failed to deploy contract: $output" >&3
exit 1
fi
contract_address=$(echo "$output" | jq -r '.contractAddress')
if [ -z "$contract_address" ]; then
echo "❌ Contract address not found in output" >&3
exit 1
fi
echo $contract_address
}
@test "Modexp gas costs" {
# L2
contract_address=$(deploy_contract $l2_rpc_url $l2_private_key)
if [ -z "$contract_address" ]; then
echo "❌ Failed to deploy contract" >&3
exit 1
fi
echo "ModExp helper contract deployed on L2 at: $contract_address" >&3
run cast send --rpc-url $l2_rpc_url --private-key $l2_private_key --gas-limit 1750000 $contract_address "modexp_test_0()(bytes32)" --json
if [ "$status" -ne 0 ]; then
echo "❌ Failed to call modexp precompile, output: $output" >&3
exit 1
fi
l1_gas_used=$(echo "$output" | jq -r '.gasUsed' | cast to-dec)
echo "✅ Successfully called modexp precompile on L2, gas used: $l1_gas_used" >&3
# L1
contract_address=$(deploy_contract $l1_rpc_url $l1_private_key)
if [ -z "$contract_address" ]; then
echo "❌ Failed to deploy contract" >&3
exit 1
fi
echo "ModExp helper contract deployed on L1 at: $contract_address" >&3
run cast send --rpc-url $l1_rpc_url --private-key $l1_private_key --gas-limit 1750000 $contract_address "modexp_test_0()(bytes32)" --json
if [ "$status" -ne 0 ]; then
echo "❌ Failed to call modexp precompile, output: $output" >&3
exit 1
fi
l2_gas_used=$(echo "$output" | jq -r '.gasUsed' | cast to-dec)
diff=$((l2_gas_used - l1_gas_used))
if [ "$diff" -ne 300 ]; then
echo "❌ Gas used on L2 is not 300 more than on L1, l1: $l1_gas_used, l2: $l2_gas_used, diff: $diff" >&3
exit 1
fi
echo "✅ Successfully called modexp precompile on L1, gas used: $l2_gas_used, l2 gas used is 300 more than l1 gas used" >&3
}