|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/json" |
5 | 4 | "os" |
6 | 5 | "strconv" |
7 | 6 | "testing" |
8 | 7 |
|
9 | | - "github.com/google/go-cmp/cmp" |
| 8 | + "github.com/BurntSushi/toml" |
10 | 9 | "github.com/stretchr/testify/require" |
11 | | - "gopkg.in/yaml.v3" |
12 | 10 | ) |
13 | 11 |
|
14 | 12 | const ( |
15 | 13 | addressDir = "../superchain/extra/addresses/sepolia/" |
16 | | - ymlConfigDir = "../superchain/configs/sepolia/" |
| 14 | + configDir = "../superchain/configs/sepolia/" |
17 | 15 | genesisSystemConfigDir = "../superchain/extra/genesis-system-configs/sepolia/" |
18 | 16 | ) |
19 | 17 |
|
@@ -90,9 +88,7 @@ func TestAddChain_Main(t *testing.T) { |
90 | 88 | err = runApp(args) |
91 | 89 | require.NoError(t, err, "add-chain app failed") |
92 | 90 |
|
93 | | - checkConfigYaml(t, tt.name, tt.chainShortName) |
94 | | - compareJsonFiles(t, "superchain/extra/addresses/sepolia/", tt.name, tt.chainShortName) |
95 | | - compareJsonFiles(t, "superchain/extra/genesis-system-configs/sepolia/", tt.name, tt.chainShortName) |
| 91 | + checkConfigTOML(t, tt.name, tt.chainShortName) |
96 | 92 | }) |
97 | 93 | } |
98 | 94 |
|
@@ -151,44 +147,25 @@ func TestAddChain_CheckGenesis(t *testing.T) { |
151 | 147 | }) |
152 | 148 | } |
153 | 149 |
|
154 | | -func compareJsonFiles(t *testing.T, dirPath, testName, chainShortName string) { |
155 | | - expectedBytes, err := os.ReadFile("./testdata/" + dirPath + "expected_" + testName + ".json") |
156 | | - require.NoError(t, err, "failed to read expected.json file from "+dirPath) |
| 150 | +func checkConfigTOML(t *testing.T, testName, chainShortName string) { |
| 151 | + expectedBytes, err := os.ReadFile("./testdata/superchain/configs/sepolia/expected_" + testName + ".toml") |
| 152 | + require.NoError(t, err, "failed to read expected.toml config file: %w", err) |
157 | 153 |
|
158 | | - var expectJSON map[string]interface{} |
159 | | - err = json.Unmarshal(expectedBytes, &expectJSON) |
160 | | - require.NoError(t, err, "failed to unmarshal expected.json file from "+dirPath) |
| 154 | + var expectedTOML map[string]interface{} |
| 155 | + err = toml.Unmarshal(expectedBytes, &expectedTOML) |
| 156 | + require.NoError(t, err, "failed to unmarshal expected.toml config file: %w", err) |
161 | 157 |
|
162 | | - testBytes, err := os.ReadFile("../" + dirPath + chainShortName + ".json") |
163 | | - require.NoError(t, err, "failed to read test generated json file from "+dirPath) |
| 158 | + testBytes, err := os.ReadFile(configDir + chainShortName + ".toml") |
| 159 | + require.NoError(t, err, "failed to read testchain.toml config file: %w", err) |
164 | 160 |
|
165 | | - var testJSON map[string]interface{} |
166 | | - err = json.Unmarshal(testBytes, &testJSON) |
167 | | - require.NoError(t, err, "failed to read test generated json file from "+dirPath) |
168 | | - |
169 | | - diff := cmp.Diff(expectJSON, testJSON) |
170 | | - require.Equal(t, diff, "", "expected json (-) does not match test json (+): %s", diff) |
171 | | -} |
172 | | - |
173 | | -func checkConfigYaml(t *testing.T, testName, chainShortName string) { |
174 | | - expectedBytes, err := os.ReadFile("./testdata/superchain/configs/sepolia/expected_" + testName + ".yaml") |
175 | | - require.NoError(t, err, "failed to read expected.yaml config file: %w", err) |
176 | | - |
177 | | - var expectedYaml map[string]interface{} |
178 | | - err = yaml.Unmarshal(expectedBytes, &expectedYaml) |
179 | | - require.NoError(t, err, "failed to unmarshal expected.yaml config file: %w", err) |
180 | | - |
181 | | - testBytes, err := os.ReadFile(ymlConfigDir + chainShortName + ".yaml") |
182 | | - require.NoError(t, err, "failed to read testchain.yaml config file: %w", err) |
183 | | - |
184 | | - require.Equal(t, string(expectedBytes), string(testBytes), "test .yaml contents do not meet expectation") |
| 161 | + require.Equal(t, string(expectedBytes), string(testBytes), "test .toml contents do not meet expectation") |
185 | 162 | } |
186 | 163 |
|
187 | 164 | func cleanupTestFiles(t *testing.T, chainShortName string) { |
188 | 165 | paths := []string{ |
189 | 166 | addressDir + chainShortName + ".json", |
190 | 167 | genesisSystemConfigDir + chainShortName + ".json", |
191 | | - ymlConfigDir + chainShortName + ".yaml", |
| 168 | + configDir + chainShortName + ".toml", |
192 | 169 | } |
193 | 170 |
|
194 | 171 | for _, path := range paths { |
|
0 commit comments