Skip to content

Commit 032ec71

Browse files
committed
internal/ethapi: add test for eth_config, fixup few remaining issues
1 parent 756304b commit 032ec71

File tree

5 files changed

+231
-8
lines changed

5 files changed

+231
-8
lines changed

internal/ethapi/api.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ type config struct {
11411141
BlobSchedule *params.BlobConfig `json:"blobSchedule"`
11421142
ChainId *hexutil.Big `json:"chainId"`
11431143
ForkId hexutil.Bytes `json:"forkId"`
1144-
Precompiles map[common.Address]string `json:"precompiles"`
1144+
Precompiles map[string]common.Address `json:"precompiles"`
11451145
SystemContracts map[string]common.Address `json:"systemContracts"`
11461146
}
11471147

@@ -1165,10 +1165,10 @@ func (api *BlockChainAPI) Config(ctx context.Context) (*configResponse, error) {
11651165

11661166
var (
11671167
rules = c.Rules(c.LondonBlock, true, t)
1168-
precompiles = make(map[common.Address]string)
1168+
precompiles = make(map[string]common.Address)
11691169
)
11701170
for addr, c := range vm.ActivePrecompiledContracts(rules) {
1171-
precompiles[addr] = c.Name()
1171+
precompiles[c.Name()] = addr
11721172
}
11731173
forkid := forkid.NewID(c, genesis, ^uint64(0), t).Hash
11741174
return &config{
@@ -1191,6 +1191,7 @@ func (api *BlockChainAPI) Config(ctx context.Context) (*configResponse, error) {
11911191
}
11921192
// Nil out last if no future-fork is configured.
11931193
if resp.Next == nil {
1194+
resp.Current.ActivationTime = 0
11941195
resp.Last = nil
11951196
}
11961197
return &resp, nil

internal/ethapi/api_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3726,3 +3726,88 @@ func TestCreateAccessListWithStateOverrides(t *testing.T) {
37263726
}}
37273727
require.Equal(t, expected, result.Accesslist)
37283728
}
3729+
3730+
func TestEIP7910Config(t *testing.T) {
3731+
var (
3732+
newUint64 = func(val uint64) *uint64 { return &val }
3733+
// Define a snapshot of the current Hoodi config (only Prague scheduled) so that future forks do not
3734+
// cause this test to fail.
3735+
config = &params.ChainConfig{
3736+
ChainID: big.NewInt(560048),
3737+
HomesteadBlock: big.NewInt(0),
3738+
DAOForkBlock: nil,
3739+
DAOForkSupport: true,
3740+
EIP150Block: big.NewInt(0),
3741+
EIP155Block: big.NewInt(0),
3742+
EIP158Block: big.NewInt(0),
3743+
ByzantiumBlock: big.NewInt(0),
3744+
ConstantinopleBlock: big.NewInt(0),
3745+
PetersburgBlock: big.NewInt(0),
3746+
IstanbulBlock: big.NewInt(0),
3747+
MuirGlacierBlock: big.NewInt(0),
3748+
BerlinBlock: big.NewInt(0),
3749+
LondonBlock: big.NewInt(0),
3750+
ArrowGlacierBlock: nil,
3751+
GrayGlacierBlock: nil,
3752+
TerminalTotalDifficulty: big.NewInt(0),
3753+
MergeNetsplitBlock: big.NewInt(0),
3754+
ShanghaiTime: newUint64(0),
3755+
CancunTime: newUint64(0),
3756+
PragueTime: newUint64(1742999832),
3757+
DepositContractAddress: common.HexToAddress("0x00000000219ab540356cBB839Cbe05303d7705Fa"),
3758+
Ethash: new(params.EthashConfig),
3759+
BlobScheduleConfig: &params.BlobScheduleConfig{
3760+
Cancun: params.DefaultCancunBlobConfig,
3761+
Prague: params.DefaultPragueBlobConfig,
3762+
},
3763+
}
3764+
)
3765+
gspec := core.DefaultHoodiGenesisBlock()
3766+
gspec.Config = config
3767+
3768+
var testSuite = []struct {
3769+
time uint64
3770+
file string
3771+
}{
3772+
{
3773+
time: 0,
3774+
file: "next-and-last",
3775+
},
3776+
{
3777+
time: *gspec.Config.PragueTime,
3778+
file: "current",
3779+
},
3780+
}
3781+
3782+
for i, tt := range testSuite {
3783+
backend := configTimeBackend{nil, gspec, tt.time}
3784+
api := NewBlockChainAPI(backend)
3785+
result, err := api.Config(context.Background())
3786+
if err != nil {
3787+
t.Errorf("test %d: want no error, have %v", i, err)
3788+
continue
3789+
}
3790+
testRPCResponseWithFile(t, i, result, "eth_config", tt.file)
3791+
}
3792+
}
3793+
3794+
type configTimeBackend struct {
3795+
*testBackend
3796+
genesis *core.Genesis
3797+
time uint64
3798+
}
3799+
3800+
func (b configTimeBackend) ChainConfig() *params.ChainConfig {
3801+
return b.genesis.Config
3802+
}
3803+
3804+
func (b configTimeBackend) BlockByNumber(_ context.Context, n rpc.BlockNumber) (*types.Block, error) {
3805+
if n == 0 {
3806+
return b.genesis.ToBlock(), nil
3807+
}
3808+
panic("not implemented")
3809+
}
3810+
3811+
func (b configTimeBackend) CurrentHeader() *types.Header {
3812+
return &types.Header{Time: b.time}
3813+
}

internal/ethapi/override/override_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ import (
3131

3232
type precompileContract struct{}
3333

34-
func (p *precompileContract) Name() string {
35-
panic("implement me")
36-
}
37-
3834
func (p *precompileContract) RequiredGas(input []byte) uint64 { return 0 }
3935

4036
func (p *precompileContract) Run(input []byte) ([]byte, error) { return nil, nil }
4137

42-
func (p *precompileContract) Name() string { return "" }
38+
func (p *precompileContract) Name() string {
39+
panic("implement me")
40+
}
4341

4442
func TestStateOverrideMovePrecompile(t *testing.T) {
4543
db := state.NewDatabase(triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil), nil)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"current": {
3+
"activationTime": 0,
4+
"blobSchedule": {
5+
"target": 6,
6+
"max": 9,
7+
"baseFeeUpdateFraction": 5007716
8+
},
9+
"chainId": "0x88bb0",
10+
"forkId": "0x0929e24e",
11+
"precompiles": {
12+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
13+
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
14+
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
15+
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
16+
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
17+
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
18+
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
19+
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
20+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
21+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
22+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
23+
"ECREC": "0x0000000000000000000000000000000000000001",
24+
"ID": "0x0000000000000000000000000000000000000004",
25+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
26+
"MODEXP": "0x0000000000000000000000000000000000000005",
27+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
28+
"SHA256": "0x0000000000000000000000000000000000000002"
29+
},
30+
"systemContracts": {
31+
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
32+
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": "0x0000bbddc7ce488642fb579f8b00f3a590007251",
33+
"DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa",
34+
"HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935",
35+
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
36+
}
37+
},
38+
"next": null,
39+
"last": null
40+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"current": {
3+
"activationTime": 0,
4+
"blobSchedule": {
5+
"baseFeeUpdateFraction": 3338477,
6+
"max": 6,
7+
"target": 3
8+
},
9+
"chainId": "0x88bb0",
10+
"forkId": "0xbef71d30",
11+
"precompiles": {
12+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
13+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
14+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
15+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
16+
"ECREC": "0x0000000000000000000000000000000000000001",
17+
"ID": "0x0000000000000000000000000000000000000004",
18+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
19+
"MODEXP": "0x0000000000000000000000000000000000000005",
20+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
21+
"SHA256": "0x0000000000000000000000000000000000000002"
22+
},
23+
"systemContracts": {
24+
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02"
25+
}
26+
},
27+
"next": {
28+
"activationTime": 1742999832,
29+
"blobSchedule": {
30+
"baseFeeUpdateFraction": 5007716,
31+
"max": 9,
32+
"target": 6
33+
},
34+
"chainId": "0x88bb0",
35+
"forkId": "0x0929e24e",
36+
"precompiles": {
37+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
38+
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
39+
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
40+
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
41+
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
42+
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
43+
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
44+
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
45+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
46+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
47+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
48+
"ECREC": "0x0000000000000000000000000000000000000001",
49+
"ID": "0x0000000000000000000000000000000000000004",
50+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
51+
"MODEXP": "0x0000000000000000000000000000000000000005",
52+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
53+
"SHA256": "0x0000000000000000000000000000000000000002"
54+
},
55+
"systemContracts": {
56+
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
57+
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": "0x0000bbddc7ce488642fb579f8b00f3a590007251",
58+
"DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa",
59+
"HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935",
60+
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
61+
}
62+
},
63+
"last": {
64+
"activationTime": 1742999832,
65+
"blobSchedule": {
66+
"baseFeeUpdateFraction": 5007716,
67+
"max": 9,
68+
"target": 6
69+
},
70+
"chainId": "0x88bb0",
71+
"forkId": "0x0929e24e",
72+
"precompiles": {
73+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
74+
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
75+
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
76+
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
77+
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
78+
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
79+
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
80+
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
81+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
82+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
83+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
84+
"ECREC": "0x0000000000000000000000000000000000000001",
85+
"ID": "0x0000000000000000000000000000000000000004",
86+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
87+
"MODEXP": "0x0000000000000000000000000000000000000005",
88+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
89+
"SHA256": "0x0000000000000000000000000000000000000002"
90+
},
91+
"systemContracts": {
92+
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
93+
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": "0x0000bbddc7ce488642fb579f8b00f3a590007251",
94+
"DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa",
95+
"HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935",
96+
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)