mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
Per @MariusVanDerWijden's review feedback, tighten the change to match geth's existing style: - Drop the MarkConsensusExpected/MarkConsensusContacted/ConsensusReady doc paragraphs on Ethereum; collapse the field comments to single trailing lines matching eth/handler.go's atomic.Bool style. - Rename the unexported accessors to MarkCLExpected/MarkCLContacted (catalyst can't reach the fields directly). - Drop the multi-line comments at the catalyst call sites — the method names are self-describing. - Trim the Backend.ConsensusReady() interface comment and EthAPIBackend wrapper comment. - Replace the verbose docstring on EthereumAPI.Syncing with a single reference to #33687. - Drop the long doc comments on the syncing_test.go cases; rename test functions to short forms (TestSyncingBeforeCLContact, etc.). No behavioural change. Run: `go test ./internal/ethapi/ -count=1`.
75 lines
2.4 KiB
Go
75 lines
2.4 KiB
Go
// Copyright 2026 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package ethapi
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum"
|
|
)
|
|
|
|
type syncingBackend struct {
|
|
Backend
|
|
progress ethereum.SyncProgress
|
|
ready bool
|
|
}
|
|
|
|
func (b *syncingBackend) SyncProgress(_ context.Context) ethereum.SyncProgress { return b.progress }
|
|
func (b *syncingBackend) ConsensusReady() bool { return b.ready }
|
|
|
|
// Issue #33687: a Done downloader but no CL handshake yet must report syncing.
|
|
func TestSyncingBeforeCLContact(t *testing.T) {
|
|
api := NewEthereumAPI(&syncingBackend{progress: ethereum.SyncProgress{}, ready: false})
|
|
res, err := api.Syncing(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("Syncing returned error: %v", err)
|
|
}
|
|
if v, ok := res.(bool); ok && !v {
|
|
t.Fatal("expected truthy syncing payload before CL handshake, got false")
|
|
}
|
|
}
|
|
|
|
func TestSyncingAfterCLContact(t *testing.T) {
|
|
api := NewEthereumAPI(&syncingBackend{progress: ethereum.SyncProgress{}, ready: true})
|
|
res, err := api.Syncing(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("Syncing returned error: %v", err)
|
|
}
|
|
if v, ok := res.(bool); !ok || v {
|
|
t.Fatalf("expected false after CL handshake when sync is done, got %v", res)
|
|
}
|
|
}
|
|
|
|
// Active sync stays truthy regardless of the CL gate.
|
|
func TestSyncingActiveSyncIgnoresCLGate(t *testing.T) {
|
|
api := NewEthereumAPI(&syncingBackend{
|
|
progress: ethereum.SyncProgress{
|
|
StartingBlock: 100,
|
|
CurrentBlock: 150,
|
|
HighestBlock: 200,
|
|
},
|
|
ready: false,
|
|
})
|
|
res, err := api.Syncing(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("Syncing returned error: %v", err)
|
|
}
|
|
if _, ok := res.(map[string]interface{}); !ok {
|
|
t.Fatalf("expected progress map during active sync, got %T", res)
|
|
}
|
|
}
|