-
Notifications
You must be signed in to change notification settings - Fork 879
Expand file tree
/
Copy pathpath_test.go
More file actions
192 lines (149 loc) · 5.93 KB
/
path_test.go
File metadata and controls
192 lines (149 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package utils
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDirExists(t *testing.T) {
dir := t.TempDir()
assert.True(t, DirExists(dir))
assert.False(t, DirExists(filepath.Join(dir, "nonexistent")))
f := filepath.Join(dir, "file.txt")
require.NoError(t, os.WriteFile(f, []byte("hi"), 0644))
assert.False(t, DirExists(f), "regular file should not match DirExists")
}
func TestFileExists(t *testing.T) {
dir := t.TempDir()
assert.False(t, FileExists(dir), "directory should not match FileExists")
assert.False(t, FileExists(filepath.Join(dir, "nonexistent")))
f := filepath.Join(dir, "file.txt")
require.NoError(t, os.WriteFile(f, []byte("hi"), 0644))
assert.True(t, FileExists(f))
}
// --- GetCosmosSCStorePath ---
func TestGetCosmosSCStorePath_NewNode(t *testing.T) {
home := t.TempDir()
got := GetCosmosSCStorePath(home)
assert.Equal(t, filepath.Join(home, "data", "state_commit", "memiavl"), got)
}
func TestGetCosmosSCStorePath_LegacyExists(t *testing.T) {
home := t.TempDir()
legacy := filepath.Join(home, "data", "committer.db")
require.NoError(t, os.MkdirAll(legacy, 0755))
got := GetCosmosSCStorePath(home)
assert.Equal(t, legacy, got)
}
// --- GetFlatKVPath ---
func TestGetFlatKVPath_NewNode(t *testing.T) {
home := t.TempDir()
got := GetFlatKVPath(home)
assert.Equal(t, filepath.Join(home, "data", "state_commit", "flatkv"), got)
}
func TestGetFlatKVPath_LegacyExists(t *testing.T) {
home := t.TempDir()
legacy := filepath.Join(home, "data", "flatkv")
require.NoError(t, os.MkdirAll(legacy, 0755))
got := GetFlatKVPath(home)
assert.Equal(t, legacy, got)
}
// --- GetStateStorePath ---
func TestGetStateStorePath_NewNode_Pebble(t *testing.T) {
home := t.TempDir()
got := GetStateStorePath(home, "pebbledb")
assert.Equal(t, filepath.Join(home, "data", "state_store", "cosmos", "pebbledb"), got)
}
func TestGetStateStorePath_NewNode_RocksDB(t *testing.T) {
home := t.TempDir()
got := GetStateStorePath(home, "rocksdb")
assert.Equal(t, filepath.Join(home, "data", "state_store", "cosmos", "rocksdb"), got)
}
func TestGetStateStorePath_LegacyExists(t *testing.T) {
home := t.TempDir()
legacy := filepath.Join(home, "data", "pebbledb")
require.NoError(t, os.MkdirAll(legacy, 0755))
got := GetStateStorePath(home, "pebbledb")
assert.Equal(t, legacy, got)
}
func TestGetStateStorePath_LegacyForDifferentBackend(t *testing.T) {
home := t.TempDir()
// Legacy rocksdb dir exists but we ask for pebbledb — no legacy match
require.NoError(t, os.MkdirAll(filepath.Join(home, "data", "rocksdb"), 0755))
got := GetStateStorePath(home, "pebbledb")
assert.Equal(t, filepath.Join(home, "data", "state_store", "cosmos", "pebbledb"), got)
}
// --- GetEVMStateStorePath ---
func TestGetEVMStateStorePath_NewNode_Pebble(t *testing.T) {
home := t.TempDir()
got := GetEVMStateStorePath(home, "pebbledb")
assert.Equal(t, filepath.Join(home, "data", "state_store", "evm", "pebbledb"), got)
}
func TestGetEVMStateStorePath_NewNode_RocksDB(t *testing.T) {
home := t.TempDir()
got := GetEVMStateStorePath(home, "rocksdb")
assert.Equal(t, filepath.Join(home, "data", "state_store", "evm", "rocksdb"), got)
}
func TestGetEVMStateStorePath_LegacyExists(t *testing.T) {
home := t.TempDir()
legacy := filepath.Join(home, "data", "evm_ss")
require.NoError(t, os.MkdirAll(legacy, 0755))
got := GetEVMStateStorePath(home, "pebbledb")
assert.Equal(t, legacy, got)
}
// --- GetReceiptStorePath ---
func TestGetReceiptStorePath_NewNode_Pebble(t *testing.T) {
home := t.TempDir()
got := GetReceiptStorePath(home, "pebbledb")
assert.Equal(t, filepath.Join(home, "data", "ledger", "receipt", "pebbledb"), got)
}
func TestGetReceiptStorePath_NewNode_Parquet(t *testing.T) {
home := t.TempDir()
got := GetReceiptStorePath(home, "parquet")
assert.Equal(t, filepath.Join(home, "data", "ledger", "receipt", "parquet"), got)
}
func TestGetReceiptStorePath_LegacyExists(t *testing.T) {
home := t.TempDir()
legacy := filepath.Join(home, "data", "receipt.db")
require.NoError(t, os.MkdirAll(legacy, 0755))
got := GetReceiptStorePath(home, "pebbledb")
assert.Equal(t, legacy, got)
}
// --- GetChangelogPath (unchanged, but verify) ---
func TestGetChangelogPath(t *testing.T) {
assert.Equal(t, "/foo/bar/changelog", GetChangelogPath("/foo/bar"))
}
// --- Edge: new path already has data (second run of new node) ---
func TestGetCosmosSCStorePath_NewDataAlreadyExists(t *testing.T) {
home := t.TempDir()
newPath := filepath.Join(home, "data", "state_commit", "memiavl")
require.NoError(t, os.MkdirAll(newPath, 0755))
got := GetCosmosSCStorePath(home)
assert.Equal(t, newPath, got, "should use new path when legacy is absent even if new path already exists")
}
func TestGetStateStorePath_NewDataAlreadyExists(t *testing.T) {
home := t.TempDir()
newPath := filepath.Join(home, "data", "state_store", "cosmos", "pebbledb")
require.NoError(t, os.MkdirAll(newPath, 0755))
got := GetStateStorePath(home, "pebbledb")
assert.Equal(t, newPath, got, "should use new path when legacy is absent even if new path already exists")
}
// --- Edge: both legacy and new exist (legacy wins) ---
func TestGetCosmosSCStorePath_BothExist(t *testing.T) {
home := t.TempDir()
legacy := filepath.Join(home, "data", "committer.db")
require.NoError(t, os.MkdirAll(legacy, 0755))
newPath := filepath.Join(home, "data", "state_commit", "memiavl")
require.NoError(t, os.MkdirAll(newPath, 0755))
got := GetCosmosSCStorePath(home)
assert.Equal(t, legacy, got, "legacy should take precedence when both exist")
}
func TestGetReceiptStorePath_BothExist(t *testing.T) {
home := t.TempDir()
legacy := filepath.Join(home, "data", "receipt.db")
require.NoError(t, os.MkdirAll(legacy, 0755))
newPath := filepath.Join(home, "data", "ledger", "receipt", "pebbledb")
require.NoError(t, os.MkdirAll(newPath, 0755))
got := GetReceiptStorePath(home, "pebbledb")
assert.Equal(t, legacy, got, "legacy should take precedence when both exist")
}