// Copyright 2024 The Erigon Authors
// This file is part of Erigon.
//
// Erigon 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.
//
// Erigon 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 Erigon. If not, see <http://www.gnu.org/licenses/>.

package app

import (
	"os"
	"path/filepath"
	"testing"

	dir2 "github.com/erigontech/erigon/common/dir"
	"github.com/erigontech/erigon/db/datadir"
	"github.com/stretchr/testify/require"
)

func createMockFile(t *testing.T, dir string, name string) {
	t.Helper()
	require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte("DUMMY-CONTENT"), 0644))
}

func setupWorkingStateMockDatadir(t *testing.T) datadir.Dirs {
	t.Helper()
	dirs := datadir.New(t.TempDir())

	// snapshots/ root — config files
	createMockFile(t, dirs.Snap, "erigondb.toml")
	createMockFile(t, dirs.Snap, "erigondb.toml.torrent")
	createMockFile(t, dirs.Snap, "preverified.toml")
	createMockFile(t, dirs.Snap, "salt-blocks.txt")
	createMockFile(t, dirs.Snap, "salt-blocks.txt.torrent")
	createMockFile(t, dirs.Snap, "salt-state.txt")
	createMockFile(t, dirs.Snap, "salt-state.txt.torrent")

	// snapshots/ root — block segments (.seg)
	createMockFile(t, dirs.Snap, "v1.1-000000-000100-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000000-000100-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000100-000200-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000100-000200-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000200-000300-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000200-000300-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000300-000400-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000300-000400-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000400-000500-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000400-000500-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000500-000510-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000500-000510-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000510-000520-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000510-000520-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000520-000521-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000520-000521-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000521-000522-bodies.seg")
	createMockFile(t, dirs.Snap, "v1.1-000521-000522-bodies.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000000-000100-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000000-000100-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000100-000200-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000100-000200-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000200-000300-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000200-000300-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000300-000400-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000300-000400-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000400-000500-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000400-000500-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000500-000510-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000500-000510-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000510-000520-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000510-000520-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000520-000521-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000520-000521-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000521-000522-headers.seg")
	createMockFile(t, dirs.Snap, "v1.1-000521-000522-headers.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000000-000100-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000000-000100-transactions.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000100-000200-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000100-000200-transactions.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000200-000300-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000200-000300-transactions.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000300-000400-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000300-000400-transactions.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000400-000500-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000400-000500-transactions.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000500-000510-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000500-000510-transactions.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000510-000520-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000510-000520-transactions.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000520-000521-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000520-000521-transactions.seg.torrent")
	createMockFile(t, dirs.Snap, "v1.1-000521-000522-transactions.seg")
	createMockFile(t, dirs.Snap, "v1.1-000521-000522-transactions.seg.torrent")

	// snapshots/ root — block indexes (.idx)
	createMockFile(t, dirs.Snap, "v2.0-000000-000100-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000000-000100-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000100-000200-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000100-000200-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000200-000300-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000200-000300-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000300-000400-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000300-000400-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000400-000500-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000400-000500-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000500-000510-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000500-000510-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000510-000520-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000510-000520-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000520-000521-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000520-000521-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000521-000522-bodies.idx")
	createMockFile(t, dirs.Snap, "v2.0-000521-000522-bodies.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000000-000100-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000000-000100-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000100-000200-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000100-000200-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000200-000300-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000200-000300-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000300-000400-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000300-000400-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000400-000500-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000400-000500-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000500-000510-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000500-000510-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000510-000520-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000510-000520-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000520-000521-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000520-000521-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000521-000522-headers.idx")
	createMockFile(t, dirs.Snap, "v2.0-000521-000522-headers.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000000-000100-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000000-000100-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000100-000200-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000100-000200-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000200-000300-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000200-000300-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000300-000400-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000300-000400-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000400-000500-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000400-000500-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000500-000510-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000500-000510-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000510-000520-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000510-000520-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000520-000521-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000520-000521-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000521-000522-transactions.idx")
	createMockFile(t, dirs.Snap, "v2.0-000521-000522-transactions.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000000-000100-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000000-000100-transactions-to-block.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000100-000200-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000100-000200-transactions-to-block.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000200-000300-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000200-000300-transactions-to-block.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000300-000400-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000300-000400-transactions-to-block.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000400-000500-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000400-000500-transactions-to-block.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000500-000510-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000500-000510-transactions-to-block.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000510-000520-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000510-000520-transactions-to-block.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000520-000521-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000520-000521-transactions-to-block.idx.torrent")
	createMockFile(t, dirs.Snap, "v2.0-000521-000522-transactions-to-block.idx")
	createMockFile(t, dirs.Snap, "v2.0-000521-000522-transactions-to-block.idx.torrent")

	// snapshots/domain/
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-128.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-128.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-128.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-128.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-128.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-128.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.192-200.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.192-200.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.192-200.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.192-200.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.192-200.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.192-200.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.200-202.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.200-202.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.200-202.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.200-202.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.200-202.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.200-202.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.0-128.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.0-128.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.0-128.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.0-128.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.0-128.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.0-128.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.128-192.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.128-192.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.128-192.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.128-192.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.128-192.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.128-192.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.192-200.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.192-200.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.192-200.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.192-200.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.192-200.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.192-200.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.200-202.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.200-202.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.200-202.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.200-202.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.200-202.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-code.200-202.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.0-128.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.0-128.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.0-128.kvi")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.0-128.kvi.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.128-192.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.128-192.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.128-192.kvi")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.128-192.kvi.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.192-200.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.192-200.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.192-200.kvi")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.192-200.kvi.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.200-202.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.200-202.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.200-202.kvi")
	createMockFile(t, dirs.SnapDomain, "v1.1-commitment.200-202.kvi.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.0-128.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.0-128.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.0-128.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.0-128.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.0-128.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.0-128.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.128-192.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.128-192.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.128-192.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.128-192.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.128-192.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.128-192.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.192-200.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.192-200.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.192-200.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.192-200.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.192-200.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.192-200.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.200-202.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.200-202.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.200-202.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.200-202.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.200-202.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-receipt.200-202.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.0-128.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.0-128.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.0-128.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.0-128.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.0-128.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.0-128.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.128-192.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.128-192.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.128-192.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.128-192.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.128-192.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.128-192.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.192-200.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.192-200.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.192-200.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.192-200.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.192-200.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.192-200.kvei.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.200-202.bt")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.200-202.bt.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.200-202.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.200-202.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.200-202.kvei")
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.200-202.kvei.torrent")

	// snapshots/idx/
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.200-202.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-code.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-code.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-code.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-code.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-code.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-code.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-code.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-code.200-202.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-logaddrs.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-logaddrs.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-logaddrs.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-logaddrs.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-logaddrs.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-logaddrs.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-logaddrs.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-logaddrs.200-202.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-logtopics.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-logtopics.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-logtopics.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-logtopics.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-logtopics.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-logtopics.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-logtopics.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-logtopics.200-202.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-receipt.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-receipt.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-receipt.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-receipt.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-receipt.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-receipt.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-receipt.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-receipt.200-202.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-storage.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-storage.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-storage.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-storage.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-storage.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-storage.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-storage.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-storage.200-202.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesfrom.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesfrom.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesfrom.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesfrom.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesfrom.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesfrom.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesfrom.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesfrom.200-202.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesto.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesto.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesto.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesto.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesto.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesto.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesto.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-tracesto.200-202.ef.torrent")

	// snapshots/history/
	createMockFile(t, dirs.SnapHistory, "v1.1-accounts.0-128.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-accounts.0-128.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-accounts.128-192.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-accounts.128-192.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-accounts.192-200.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-accounts.192-200.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-accounts.200-202.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-accounts.200-202.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-code.0-128.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-code.0-128.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-code.128-192.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-code.128-192.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-code.192-200.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-code.192-200.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-code.200-202.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-code.200-202.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-receipt.0-128.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-receipt.0-128.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-receipt.128-192.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-receipt.128-192.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-receipt.192-200.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-receipt.192-200.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-receipt.200-202.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-receipt.200-202.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-storage.0-128.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-storage.0-128.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-storage.128-192.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-storage.128-192.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-storage.192-200.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-storage.192-200.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-storage.200-202.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-storage.200-202.v.torrent")

	// snapshots/accessor/
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.0-128.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.0-128.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.128-192.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.128-192.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.192-200.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.192-200.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.200-202.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-accounts.200-202.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.0-128.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.0-128.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.128-192.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.128-192.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.192-200.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.192-200.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.200-202.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-code.200-202.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logaddrs.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logaddrs.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logaddrs.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logaddrs.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logaddrs.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logaddrs.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logaddrs.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logaddrs.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logtopics.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logtopics.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logtopics.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logtopics.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logtopics.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logtopics.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logtopics.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-logtopics.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.0-128.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.0-128.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.128-192.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.128-192.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.192-200.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.192-200.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.200-202.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-receipt.200-202.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.0-128.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.0-128.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.128-192.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.128-192.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.192-200.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.192-200.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.200-202.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-storage.200-202.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesfrom.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesfrom.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesfrom.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesfrom.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesfrom.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesfrom.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesfrom.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesfrom.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesto.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesto.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesto.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesto.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesto.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesto.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesto.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-tracesto.200-202.efi.torrent")

	return dirs
}

func removeMockFile(t *testing.T, dir string, name string) {
	t.Helper()
	require.NoError(t, dir2.RemoveFile(filepath.Join(dir, name)))
}

func Test_CheckStateSnapshotFiles_SuccessCase(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	err := checkStateSnapshotFiles(dirs, false, false)
	require.NoError(t, err)
}

func Test_CheckStateSnapshotFiles_WithPersistReceiptCache(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	// Add rcache domain files (.kv + .kvi for each range)
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.0-128.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.0-128.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.0-128.kvi")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.0-128.kvi.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.128-192.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.128-192.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.128-192.kvi")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.128-192.kvi.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.192-200.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.192-200.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.192-200.kvi")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.192-200.kvi.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.200-202.kv")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.200-202.kv.torrent")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.200-202.kvi")
	createMockFile(t, dirs.SnapDomain, "v1.1-rcache.200-202.kvi.torrent")
	// Add rcache idx files (.ef)
	createMockFile(t, dirs.SnapIdx, "v2.0-rcache.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-rcache.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-rcache.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-rcache.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-rcache.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-rcache.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-rcache.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-rcache.200-202.ef.torrent")
	// Add rcache accessor files (.efi + .vi)
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.0-128.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.0-128.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.128-192.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.128-192.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.192-200.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.192-200.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.200-202.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-rcache.200-202.vi.torrent")
	// Add rcache history files (.v)
	createMockFile(t, dirs.SnapHistory, "v1.1-rcache.0-128.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-rcache.0-128.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-rcache.128-192.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-rcache.128-192.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-rcache.192-200.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-rcache.192-200.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-rcache.200-202.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-rcache.200-202.v.torrent")
	err := checkStateSnapshotFiles(dirs, true, false)
	require.NoError(t, err)
}

func Test_CheckStateSnapshotFiles_WithCommitmentHistory(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	// Add commitment idx files (.ef)
	createMockFile(t, dirs.SnapIdx, "v2.0-commitment.0-128.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-commitment.0-128.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-commitment.128-192.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-commitment.128-192.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-commitment.192-200.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-commitment.192-200.ef.torrent")
	createMockFile(t, dirs.SnapIdx, "v2.0-commitment.200-202.ef")
	createMockFile(t, dirs.SnapIdx, "v2.0-commitment.200-202.ef.torrent")
	// Add commitment accessor files (.efi + .vi)
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.0-128.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.0-128.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.0-128.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.0-128.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.128-192.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.128-192.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.128-192.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.128-192.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.192-200.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.192-200.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.192-200.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.192-200.vi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.200-202.efi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.200-202.efi.torrent")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.200-202.vi")
	createMockFile(t, dirs.SnapAccessors, "v1.1-commitment.200-202.vi.torrent")
	// Add commitment history files (.v)
	createMockFile(t, dirs.SnapHistory, "v1.1-commitment.0-128.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-commitment.0-128.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-commitment.128-192.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-commitment.128-192.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-commitment.192-200.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-commitment.192-200.v.torrent")
	createMockFile(t, dirs.SnapHistory, "v1.1-commitment.200-202.v")
	createMockFile(t, dirs.SnapHistory, "v1.1-commitment.200-202.v.torrent")
	err := checkStateSnapshotFiles(dirs, false, true)
	require.NoError(t, err)
}

// --- Domain checks ---

// A file in the domain directory that doesn't match the snapshot naming convention should be rejected.
func Test_CheckStateSnapshotFiles_DomainUnparseableFile(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	createMockFile(t, dirs.SnapDomain, "garbage.txt")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapParseFilename)
}

// When all account .kv files are missing, the check should report that no account snapshots were found.
func Test_CheckStateSnapshotFiles_DomainNoAccountKV(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-128.kv")
	removeMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.kv")
	removeMockFile(t, dirs.SnapDomain, "v1.1-accounts.192-200.kv")
	removeMockFile(t, dirs.SnapDomain, "v1.1-accounts.200-202.kv")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapNoAccountFiles)
}

// If the first account .kv range doesn't start at step 0, a gap-at-start error is expected.
func Test_CheckStateSnapshotFiles_DomainGapAtStart(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-128.kv")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapGapAtStart)
}

// Two account .kv files sharing the same From value should be flagged as a possible overlap.
func Test_CheckStateSnapshotFiles_DomainOverlapSameFrom(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.0-64.kv")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapOverlap)
}

// An account .kv file whose range overlaps with an existing range should be detected.
func Test_CheckStateSnapshotFiles_DomainOverlap(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	createMockFile(t, dirs.SnapDomain, "v1.1-accounts.64-200.kv")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapOverlap)
}

// Removing a middle account .kv file creates a gap between consecutive ranges.
func Test_CheckStateSnapshotFiles_DomainGap(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.kv")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapGap)
}

// Each account range must have a corresponding .kv file for every domain type; removing one triggers a missing-file error.
func Test_CheckStateSnapshotFiles_MissingDomainKV(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapDomain, "v1.1-storage.128-192.kv")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMissingFile)
}

// Domains with AccessorBTree (accounts, storage, code, receipt) require a .bt file for each range.
func Test_CheckStateSnapshotFiles_MissingDomainBT(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.bt")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMissingFile)
}

// Domains with AccessorExistence (accounts, storage, code, receipt) require a .kvei file for each range.
func Test_CheckStateSnapshotFiles_MissingDomainKVEI(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapDomain, "v1.1-accounts.128-192.kvei")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMissingFile)
}

// The commitment domain uses AccessorHashMap and requires a .kvi file for each range.
func Test_CheckStateSnapshotFiles_MissingDomainKVI(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapDomain, "v1.1-commitment.128-192.kvi")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMissingFile)
}

// If a non-account domain file extends beyond the account range, the maxStep check detects the mismatch.
func Test_CheckStateSnapshotFiles_DomainMaxStepMismatch(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	createMockFile(t, dirs.SnapDomain, "v1.1-storage.202-210.kv")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMaxStepMismatch)
}

// --- Idx checks ---

// A file in the idx directory that doesn't match the snapshot naming convention should be rejected.
func Test_CheckStateSnapshotFiles_IdxUnparseableFile(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	createMockFile(t, dirs.SnapIdx, "garbage.txt")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapParseFilename)
}

// When all account .ef files are missing, the check should report that no inverted index files were found.
func Test_CheckStateSnapshotFiles_IdxNoAccountEF(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapIdx, "v2.0-accounts.0-128.ef")
	removeMockFile(t, dirs.SnapIdx, "v2.0-accounts.128-192.ef")
	removeMockFile(t, dirs.SnapIdx, "v2.0-accounts.192-200.ef")
	removeMockFile(t, dirs.SnapIdx, "v2.0-accounts.200-202.ef")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapNoAccountFiles)
}

// If the first account .ef range doesn't start at step 0, a gap-at-start error is expected.
func Test_CheckStateSnapshotFiles_IdxGapAtStart(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapIdx, "v2.0-accounts.0-128.ef")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapGapAtStart)
}

// Two account .ef files sharing the same From value should be flagged as a possible overlap.
func Test_CheckStateSnapshotFiles_IdxOverlapSameFrom(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.0-64.ef")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapOverlap)
}

// An account .ef file whose range overlaps with an existing range should be detected.
func Test_CheckStateSnapshotFiles_IdxOverlap(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	createMockFile(t, dirs.SnapIdx, "v2.0-accounts.64-200.ef")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapOverlap)
}

// Removing a middle account .ef file creates a gap between consecutive ranges.
func Test_CheckStateSnapshotFiles_IdxGap(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapIdx, "v2.0-accounts.128-192.ef")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapGap)
}

// Each account range must have a corresponding .ef file for every II type; removing one triggers a missing-file error.
func Test_CheckStateSnapshotFiles_MissingIdxEF(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapIdx, "v2.0-logtopics.128-192.ef")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMissingFile)
}

// Every II type requires a corresponding .efi accessor file for each range.
func Test_CheckStateSnapshotFiles_MissingAccessorEFI(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapAccessors, "v1.1-accounts.128-192.efi")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMissingFile)
}

// Value-index types (accounts, storage, code, receipt) require a .vi accessor file for each range.
func Test_CheckStateSnapshotFiles_MissingAccessorVI(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapAccessors, "v1.1-accounts.128-192.vi")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMissingFile)
}

// Value-index types require a .v history file for each range.
func Test_CheckStateSnapshotFiles_MissingHistoryV(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapHistory, "v1.1-accounts.128-192.v")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMissingFile)
}

// If the account idx range is shorter than the domain maxStep, the cross-directory maxStep check fails.
func Test_CheckStateSnapshotFiles_IdxDomainMaxStepMismatch(t *testing.T) {
	t.Parallel()
	dirs := setupWorkingStateMockDatadir(t)
	removeMockFile(t, dirs.SnapIdx, "v2.0-accounts.200-202.ef")
	err := checkStateSnapshotFiles(dirs, false, false)
	require.ErrorIs(t, err, ErrSnapMaxStepMismatch)
}
