file_layout_test.go 844 Bytes
Newer Older
1 2 3 4 5 6 7 8
package backend

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

9
	"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types"
10 11 12 13 14 15
	"github.com/stretchr/testify/require"
)

func TestLogDBPath(t *testing.T) {
	base := t.TempDir()
	chainIDStr := "42984928492928428424243444"
16
	chainIDBig, ok := new(big.Int).SetString(chainIDStr, 10)
17
	require.True(t, ok)
18
	chainID := types.ChainIDFromBig(chainIDBig)
19 20 21 22 23 24 25 26 27 28 29 30
	expected := filepath.Join(base, "subdir", chainIDStr, "log.db")
	path, err := prepLogDBPath(chainID, filepath.Join(base, "subdir"))
	require.NoError(t, err)
	require.Equal(t, expected, path)

	// Check it still works when directories exist
	require.NoError(t, os.WriteFile(path, []byte("test"), 0o644))

	path, err = prepLogDBPath(chainID, filepath.Join(base, "subdir"))
	require.NoError(t, err)
	require.Equal(t, expected, path)
}