mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
internal/ethapi: add test for eth_config, fixup few remaining issues
This commit is contained in:
parent
42c3141489
commit
2883e3a656
5 changed files with 231 additions and 8 deletions
|
|
@ -1159,7 +1159,7 @@ type config struct {
|
|||
BlobSchedule *params.BlobConfig `json:"blobSchedule"`
|
||||
ChainId *hexutil.Big `json:"chainId"`
|
||||
ForkId hexutil.Bytes `json:"forkId"`
|
||||
Precompiles map[common.Address]string `json:"precompiles"`
|
||||
Precompiles map[string]common.Address `json:"precompiles"`
|
||||
SystemContracts map[string]common.Address `json:"systemContracts"`
|
||||
}
|
||||
|
||||
|
|
@ -1183,10 +1183,10 @@ func (api *BlockChainAPI) Config(ctx context.Context) (*configResponse, error) {
|
|||
|
||||
var (
|
||||
rules = c.Rules(c.LondonBlock, true, t)
|
||||
precompiles = make(map[common.Address]string)
|
||||
precompiles = make(map[string]common.Address)
|
||||
)
|
||||
for addr, c := range vm.ActivePrecompiledContracts(rules) {
|
||||
precompiles[addr] = c.Name()
|
||||
precompiles[c.Name()] = addr
|
||||
}
|
||||
forkid := forkid.NewID(c, genesis, ^uint64(0), t).Hash
|
||||
return &config{
|
||||
|
|
@ -1209,6 +1209,7 @@ func (api *BlockChainAPI) Config(ctx context.Context) (*configResponse, error) {
|
|||
}
|
||||
// Nil out last if no future-fork is configured.
|
||||
if resp.Next == nil {
|
||||
resp.Current.ActivationTime = 0
|
||||
resp.Last = nil
|
||||
}
|
||||
return &resp, nil
|
||||
|
|
|
|||
|
|
@ -3767,3 +3767,88 @@ func TestEstimateGasWithMovePrecompile(t *testing.T) {
|
|||
t.Fatalf("mismatched gas: %d, want 21366", gas)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEIP7910Config(t *testing.T) {
|
||||
var (
|
||||
newUint64 = func(val uint64) *uint64 { return &val }
|
||||
// Define a snapshot of the current Hoodi config (only Prague scheduled) so that future forks do not
|
||||
// cause this test to fail.
|
||||
config = ¶ms.ChainConfig{
|
||||
ChainID: big.NewInt(560048),
|
||||
HomesteadBlock: big.NewInt(0),
|
||||
DAOForkBlock: nil,
|
||||
DAOForkSupport: true,
|
||||
EIP150Block: big.NewInt(0),
|
||||
EIP155Block: big.NewInt(0),
|
||||
EIP158Block: big.NewInt(0),
|
||||
ByzantiumBlock: big.NewInt(0),
|
||||
ConstantinopleBlock: big.NewInt(0),
|
||||
PetersburgBlock: big.NewInt(0),
|
||||
IstanbulBlock: big.NewInt(0),
|
||||
MuirGlacierBlock: big.NewInt(0),
|
||||
BerlinBlock: big.NewInt(0),
|
||||
LondonBlock: big.NewInt(0),
|
||||
ArrowGlacierBlock: nil,
|
||||
GrayGlacierBlock: nil,
|
||||
TerminalTotalDifficulty: big.NewInt(0),
|
||||
MergeNetsplitBlock: big.NewInt(0),
|
||||
ShanghaiTime: newUint64(0),
|
||||
CancunTime: newUint64(0),
|
||||
PragueTime: newUint64(1742999832),
|
||||
DepositContractAddress: common.HexToAddress("0x00000000219ab540356cBB839Cbe05303d7705Fa"),
|
||||
Ethash: new(params.EthashConfig),
|
||||
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
||||
Cancun: params.DefaultCancunBlobConfig,
|
||||
Prague: params.DefaultPragueBlobConfig,
|
||||
},
|
||||
}
|
||||
)
|
||||
gspec := core.DefaultHoodiGenesisBlock()
|
||||
gspec.Config = config
|
||||
|
||||
var testSuite = []struct {
|
||||
time uint64
|
||||
file string
|
||||
}{
|
||||
{
|
||||
time: 0,
|
||||
file: "next-and-last",
|
||||
},
|
||||
{
|
||||
time: *gspec.Config.PragueTime,
|
||||
file: "current",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range testSuite {
|
||||
backend := configTimeBackend{nil, gspec, tt.time}
|
||||
api := NewBlockChainAPI(backend)
|
||||
result, err := api.Config(context.Background())
|
||||
if err != nil {
|
||||
t.Errorf("test %d: want no error, have %v", i, err)
|
||||
continue
|
||||
}
|
||||
testRPCResponseWithFile(t, i, result, "eth_config", tt.file)
|
||||
}
|
||||
}
|
||||
|
||||
type configTimeBackend struct {
|
||||
*testBackend
|
||||
genesis *core.Genesis
|
||||
time uint64
|
||||
}
|
||||
|
||||
func (b configTimeBackend) ChainConfig() *params.ChainConfig {
|
||||
return b.genesis.Config
|
||||
}
|
||||
|
||||
func (b configTimeBackend) BlockByNumber(_ context.Context, n rpc.BlockNumber) (*types.Block, error) {
|
||||
if n == 0 {
|
||||
return b.genesis.ToBlock(), nil
|
||||
}
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (b configTimeBackend) CurrentHeader() *types.Header {
|
||||
return &types.Header{Time: b.time}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,15 +31,13 @@ import (
|
|||
|
||||
type precompileContract struct{}
|
||||
|
||||
func (p *precompileContract) Name() string {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (p *precompileContract) RequiredGas(input []byte) uint64 { return 0 }
|
||||
|
||||
func (p *precompileContract) Run(input []byte) ([]byte, error) { return nil, nil }
|
||||
|
||||
func (p *precompileContract) Name() string { return "" }
|
||||
func (p *precompileContract) Name() string {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func TestStateOverrideMovePrecompile(t *testing.T) {
|
||||
db := state.NewDatabase(triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil), nil)
|
||||
|
|
|
|||
40
internal/ethapi/testdata/eth_config-current.json
vendored
Normal file
40
internal/ethapi/testdata/eth_config-current.json
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"current": {
|
||||
"activationTime": 0,
|
||||
"blobSchedule": {
|
||||
"target": 6,
|
||||
"max": 9,
|
||||
"baseFeeUpdateFraction": 5007716
|
||||
},
|
||||
"chainId": "0x88bb0",
|
||||
"forkId": "0x0929e24e",
|
||||
"precompiles": {
|
||||
"BLAKE2F": "0x0000000000000000000000000000000000000009",
|
||||
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
|
||||
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
|
||||
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
|
||||
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
|
||||
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
|
||||
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
|
||||
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
|
||||
"BN254_ADD": "0x0000000000000000000000000000000000000006",
|
||||
"BN254_MUL": "0x0000000000000000000000000000000000000007",
|
||||
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
|
||||
"ECREC": "0x0000000000000000000000000000000000000001",
|
||||
"ID": "0x0000000000000000000000000000000000000004",
|
||||
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
|
||||
"MODEXP": "0x0000000000000000000000000000000000000005",
|
||||
"RIPEMD160": "0x0000000000000000000000000000000000000003",
|
||||
"SHA256": "0x0000000000000000000000000000000000000002"
|
||||
},
|
||||
"systemContracts": {
|
||||
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
|
||||
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": "0x0000bbddc7ce488642fb579f8b00f3a590007251",
|
||||
"DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa",
|
||||
"HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935",
|
||||
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
|
||||
}
|
||||
},
|
||||
"next": null,
|
||||
"last": null
|
||||
}
|
||||
99
internal/ethapi/testdata/eth_config-next-and-last.json
vendored
Normal file
99
internal/ethapi/testdata/eth_config-next-and-last.json
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"current": {
|
||||
"activationTime": 0,
|
||||
"blobSchedule": {
|
||||
"baseFeeUpdateFraction": 3338477,
|
||||
"max": 6,
|
||||
"target": 3
|
||||
},
|
||||
"chainId": "0x88bb0",
|
||||
"forkId": "0xbef71d30",
|
||||
"precompiles": {
|
||||
"BLAKE2F": "0x0000000000000000000000000000000000000009",
|
||||
"BN254_ADD": "0x0000000000000000000000000000000000000006",
|
||||
"BN254_MUL": "0x0000000000000000000000000000000000000007",
|
||||
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
|
||||
"ECREC": "0x0000000000000000000000000000000000000001",
|
||||
"ID": "0x0000000000000000000000000000000000000004",
|
||||
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
|
||||
"MODEXP": "0x0000000000000000000000000000000000000005",
|
||||
"RIPEMD160": "0x0000000000000000000000000000000000000003",
|
||||
"SHA256": "0x0000000000000000000000000000000000000002"
|
||||
},
|
||||
"systemContracts": {
|
||||
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02"
|
||||
}
|
||||
},
|
||||
"next": {
|
||||
"activationTime": 1742999832,
|
||||
"blobSchedule": {
|
||||
"baseFeeUpdateFraction": 5007716,
|
||||
"max": 9,
|
||||
"target": 6
|
||||
},
|
||||
"chainId": "0x88bb0",
|
||||
"forkId": "0x0929e24e",
|
||||
"precompiles": {
|
||||
"BLAKE2F": "0x0000000000000000000000000000000000000009",
|
||||
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
|
||||
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
|
||||
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
|
||||
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
|
||||
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
|
||||
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
|
||||
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
|
||||
"BN254_ADD": "0x0000000000000000000000000000000000000006",
|
||||
"BN254_MUL": "0x0000000000000000000000000000000000000007",
|
||||
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
|
||||
"ECREC": "0x0000000000000000000000000000000000000001",
|
||||
"ID": "0x0000000000000000000000000000000000000004",
|
||||
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
|
||||
"MODEXP": "0x0000000000000000000000000000000000000005",
|
||||
"RIPEMD160": "0x0000000000000000000000000000000000000003",
|
||||
"SHA256": "0x0000000000000000000000000000000000000002"
|
||||
},
|
||||
"systemContracts": {
|
||||
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
|
||||
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": "0x0000bbddc7ce488642fb579f8b00f3a590007251",
|
||||
"DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa",
|
||||
"HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935",
|
||||
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
|
||||
}
|
||||
},
|
||||
"last": {
|
||||
"activationTime": 1742999832,
|
||||
"blobSchedule": {
|
||||
"baseFeeUpdateFraction": 5007716,
|
||||
"max": 9,
|
||||
"target": 6
|
||||
},
|
||||
"chainId": "0x88bb0",
|
||||
"forkId": "0x0929e24e",
|
||||
"precompiles": {
|
||||
"BLAKE2F": "0x0000000000000000000000000000000000000009",
|
||||
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
|
||||
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
|
||||
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
|
||||
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
|
||||
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
|
||||
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
|
||||
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
|
||||
"BN254_ADD": "0x0000000000000000000000000000000000000006",
|
||||
"BN254_MUL": "0x0000000000000000000000000000000000000007",
|
||||
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
|
||||
"ECREC": "0x0000000000000000000000000000000000000001",
|
||||
"ID": "0x0000000000000000000000000000000000000004",
|
||||
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
|
||||
"MODEXP": "0x0000000000000000000000000000000000000005",
|
||||
"RIPEMD160": "0x0000000000000000000000000000000000000003",
|
||||
"SHA256": "0x0000000000000000000000000000000000000002"
|
||||
},
|
||||
"systemContracts": {
|
||||
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
|
||||
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": "0x0000bbddc7ce488642fb579f8b00f3a590007251",
|
||||
"DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa",
|
||||
"HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935",
|
||||
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue