Skip to content

Commit 86692dc

Browse files
committed
added bpo config + function to retrieve from it + unit test for that function
1 parent 9b30723 commit 86692dc

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"blobSchedule": {
3+
"cancun": {
4+
"target": 3,
5+
"max": 6,
6+
"baseFeeUpdateFraction": 3338477
7+
},
8+
"prague": {
9+
"target": 6,
10+
"max": 9,
11+
"baseFeeUpdateFraction": 5007716
12+
},
13+
"osaka": {
14+
"target": 6,
15+
"max": 9,
16+
"maxBlobsPerTx": 6,
17+
"baseFeeUpdateFraction": 5007716
18+
},
19+
"bpo1": {
20+
"target": 12,
21+
"max": 16,
22+
"maxBlobsPerTx": 12,
23+
"baseFeeUpdateFraction": 5007716
24+
},
25+
"bpo2": {
26+
"target": 16,
27+
"max": 24,
28+
"maxBlobsPerTx": 12,
29+
"baseFeeUpdateFraction": 5007716
30+
}
31+
},
32+
"cancunTime": 0,
33+
"pragueTime": 0,
34+
"osakaTime": 1747387400,
35+
"bpo1Time": 1757387400,
36+
"bpo2Time": 1767387784
37+
}

src/ethereum_test_types/blob_types.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Blob-related types for Ethereum tests."""
22

3+
import json
34
import random
45
from enum import Enum
56
from hashlib import sha256
@@ -22,6 +23,49 @@
2223
logger = get_logger(__name__)
2324

2425

26+
class BPO_Parameters(Enum):
27+
TARGET = "target"
28+
MAX = "max"
29+
BASE_FEE_UPDATE_FRACTION = "baseFeeUpdateFraction"
30+
TIME = "Time" # actually it is: <fork>Time
31+
32+
33+
def bpo_get_value(bpo_fork: str, bpo_parameter: BPO_Parameters) -> int:
34+
"""
35+
Retrieve BPO values from the JSON config.
36+
37+
Arguments:
38+
- bpo_fork: Any fork (e.g. cancun) or bpo forks (e.g. bpo1 or bpo2)
39+
- bpo_parameter: Enum value that specifies what you want to access in the bpo config
40+
41+
Returns the retrieved int.
42+
43+
"""
44+
# ensure the bpo config exists and can be read
45+
bpo_config_path = Path("src") / "ethereum_test_types" / "blob_bpo_config.json"
46+
if not bpo_config_path.exists():
47+
raise FileNotFoundError(f"Failed to find BPO config json: {bpo_config_path}")
48+
with open(bpo_config_path, "r") as file:
49+
bpo_config = json.load(file)
50+
51+
# force-lowercase the provided fork
52+
bpo_fork = bpo_fork.lower()
53+
54+
# retrieve requested value
55+
if bpo_parameter == BPO_Parameters.TARGET:
56+
return bpo_config["blobSchedule"][bpo_fork][BPO_Parameters.TARGET.value]
57+
elif bpo_parameter == BPO_Parameters.MAX:
58+
return bpo_config["blobSchedule"][bpo_fork][BPO_Parameters.MAX.value]
59+
elif bpo_parameter == BPO_Parameters.BASE_FEE_UPDATE_FRACTION:
60+
return bpo_config["blobSchedule"][bpo_fork][BPO_Parameters.BASE_FEE_UPDATE_FRACTION.value]
61+
elif bpo_parameter == BPO_Parameters.TIME:
62+
return bpo_config[bpo_fork + BPO_Parameters.TIME.value]
63+
64+
raise NotImplementedError(
65+
f"This function has not yet been updated to handle BPO Parameter: {bpo_parameter}"
66+
)
67+
68+
2569
def clear_blob_cache(cached_blobs_folder_path: Path):
2670
"""Delete all cached blobs."""
2771
if not cached_blobs_folder_path.is_dir():

src/ethereum_test_types/tests/test_blob_types.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
ShanghaiToCancunAtTime15k,
1616
)
1717

18-
from ..blob_types import CACHED_BLOBS_DIRECTORY, Blob, clear_blob_cache
18+
from ..blob_types import (
19+
CACHED_BLOBS_DIRECTORY,
20+
Blob,
21+
BPO_Parameters,
22+
bpo_get_value,
23+
clear_blob_cache,
24+
)
1925

2026

2127
@pytest.mark.parametrize("seed", [0, 10, 100])
@@ -109,3 +115,24 @@ def test_transition_fork_blobs(
109115
f"Transition fork failure! Fork {fork.name()} at timestamp: {timestamp} should have "
110116
f"transitioned to {post_transition_fork_at_15k.name()} but is still at {b.fork.name()}"
111117
)
118+
119+
120+
@pytest.mark.parametrize("bpo_fork", ["cancun", "prague", "osaka", "bpo1", "bpo2"])
121+
@pytest.mark.parametrize(
122+
"bpo_parameter",
123+
[
124+
BPO_Parameters.TARGET,
125+
BPO_Parameters.MAX,
126+
BPO_Parameters.BASE_FEE_UPDATE_FRACTION,
127+
BPO_Parameters.TIME,
128+
],
129+
)
130+
def test_bpo_parameter_lookup(bpo_fork, bpo_parameter):
131+
"""Tries looking up different values from the BPO configuration json."""
132+
result = bpo_get_value(bpo_fork=bpo_fork, bpo_parameter=bpo_parameter)
133+
print(
134+
f"\nbpo_fork: {bpo_fork}\n"
135+
f"bpo_parameter: {bpo_parameter}\n"
136+
f"retrieved value from config: {result}\n"
137+
)
138+
# TODO: when one day actual bpo_config is known assert correction of retrieved values

0 commit comments

Comments
 (0)