eth/catalyst: polish test

This commit is contained in:
Gary Rong 2025-09-24 22:27:17 +08:00
parent 4fcd663a89
commit e58a3ae086
2 changed files with 10 additions and 35 deletions

View file

@ -492,12 +492,12 @@ func (api *ConsensusAPI) getPayload(payloadID engine.PayloadID, full bool) (*eng
// Client software MAY return an array of all null entries if syncing or otherwise // Client software MAY return an array of all null entries if syncing or otherwise
// unable to serve blob pool data. // unable to serve blob pool data.
func (api *ConsensusAPI) GetBlobsV1(hashes []common.Hash) ([]*engine.BlobAndProofV1, error) { func (api *ConsensusAPI) GetBlobsV1(hashes []common.Hash) ([]*engine.BlobAndProofV1, error) {
// Check if Osaka fork is active // Reject the request if Osaka has been activated.
// follow https://github.com/ethereum/execution-apis/blob/main/src/engine/osaka.md#cancun-api // follow https://github.com/ethereum/execution-apis/blob/main/src/engine/osaka.md#cancun-api
if header := api.eth.BlockChain().CurrentHeader(); api.config().IsOsaka(header.Number, header.Time) { header := api.eth.BlockChain().CurrentHeader()
if api.config().IsOsaka(header.Number, header.Time) {
return nil, unsupportedForkErr("engine_getBlobsV1 is not supported after Osaka fork") return nil, unsupportedForkErr("engine_getBlobsV1 is not supported after Osaka fork")
} }
if len(hashes) > 128 { if len(hashes) > 128 {
return nil, engine.TooLargeRequest.With(fmt.Errorf("requested blob count too large: %v", len(hashes))) return nil, engine.TooLargeRequest.With(fmt.Errorf("requested blob count too large: %v", len(hashes)))
} }

View file

@ -1991,53 +1991,28 @@ func TestGetBlobsV1(t *testing.T) {
} }
} }
func TestGetBlobsV1OsakaFork(t *testing.T) { func TestGetBlobsV1AfterOsakaFork(t *testing.T) {
config := *params.AllEthashProtocolChanges
time := new(uint64)
config.ShanghaiTime = time
config.CancunTime = time
config.PragueTime = time
config.OsakaTime = time
// Add blob schedule configuration
config.BlobScheduleConfig = &params.BlobScheduleConfig{
Cancun: params.DefaultCancunBlobConfig,
Prague: params.DefaultPragueBlobConfig,
Osaka: params.DefaultOsakaBlobConfig,
}
genesis := &core.Genesis{ genesis := &core.Genesis{
Config: &config, Config: params.MergedTestChainConfig,
Alloc: types.GenesisAlloc{testAddr: {Balance: testBalance}}, Alloc: types.GenesisAlloc{testAddr: {Balance: testBalance}},
Difficulty: common.Big0, Difficulty: common.Big0,
Timestamp: 1, // Timestamp > 0 to ensure Osaka fork is active Timestamp: 1, // Timestamp > 0 to ensure Osaka fork is active
} }
n, ethServ := startEthService(t, genesis, nil) n, ethServ := startEthService(t, genesis, nil)
defer n.Close() defer n.Close()
var engineErr *engine.EngineAPIError
api := newConsensusAPIWithoutHeartbeat(ethServ) api := newConsensusAPIWithoutHeartbeat(ethServ)
_, err := api.GetBlobsV1([]common.Hash{testrand.Hash()})
vhashes := []common.Hash{testrand.Hash(), testrand.Hash()} if !errors.As(err, &engineErr) {
result, err := api.GetBlobsV1(vhashes) t.Fatalf("Unexpected error: %T", err)
} else {
if err == nil {
t.Fatal("Expected UnsupportedFork error when Osaka fork is active")
}
if engineErr, ok := err.(*engine.EngineAPIError); ok {
if engineErr.ErrorCode() != -38005 { if engineErr.ErrorCode() != -38005 {
t.Fatalf("Expected error code -38005, got %d", engineErr.ErrorCode()) t.Fatalf("Expected error code -38005, got %d", engineErr.ErrorCode())
} }
if engineErr.Error() != "Unsupported fork" { if engineErr.Error() != "Unsupported fork" {
t.Fatalf("Expected error message 'Unsupported fork', got '%s'", engineErr.Error()) t.Fatalf("Expected error message 'Unsupported fork', got '%s'", engineErr.Error())
} }
} else {
t.Fatalf("Expected EngineAPIError, got %T", err)
}
if result != nil {
t.Fatal("Expected nil result when Osaka fork is active")
} }
} }