Skip to content

Commit 219ac8c

Browse files
committed
Add validation tests
1 parent d314d2e commit 219ac8c

File tree

1 file changed

+65
-18
lines changed

1 file changed

+65
-18
lines changed

pkg/capabilities/consensus/ocr3/datafeeds/securemint_aggregator_test.go

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -286,56 +286,103 @@ func solConfig(t *testing.T, chainSelector string, meta solana.AccountMetaSlice)
286286

287287
func TestSecureMintAggregatorConfig_Validation(t *testing.T) {
288288
tests := []struct {
289-
name string
290-
chainSelector string
291-
expected chainSelector
292-
expectError bool
293-
errorMsg string
289+
name string
290+
chainSelector string
291+
dataID string
292+
expectedChainSelector chainSelector
293+
expectedDataID [16]byte
294+
expectError bool
295+
errorMsg string
294296
}{
295297
{
296-
name: "valid chain selector",
297-
chainSelector: "1",
298-
expected: 1,
299-
expectError: false,
298+
299+
name: "valid chain selector and dataID",
300+
chainSelector: "1",
301+
dataID: "0x01c508f42b0201320000000000000000",
302+
expectedChainSelector: 1,
303+
expectedDataID: [16]byte{0x01, 0xc5, 0x08, 0xf4, 0x2b, 0x02, 0x01, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
304+
expectError: false,
305+
},
306+
{
307+
name: "large chain selector",
308+
chainSelector: "16015286601757825753", // ethereum-testnet-sepolia
309+
dataID: "0x01c508f42b0201320000000000000000",
310+
expectedChainSelector: 16015286601757825753,
311+
expectedDataID: [16]byte{0x01, 0xc5, 0x08, 0xf4, 0x2b, 0x02, 0x01, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
312+
expectError: false,
300313
},
314+
{
315+
name: "dataID without 0x prefix",
316+
chainSelector: "1",
317+
dataID: "01c508f42b0201320000000000000000",
318+
expectedChainSelector: 1,
319+
expectedDataID: [16]byte{0x01, 0xc5, 0x08, 0xf4, 0x2b, 0x02, 0x01, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
320+
expectError: false},
301321
{
302322
name: "invalid chain selector",
303323
chainSelector: "invalid",
304324
expectError: true,
305325
errorMsg: "invalid chain selector",
306326
},
307-
{
308-
name: "large chain selector",
309-
chainSelector: "16015286601757825753", // ethereum-testnet-sepolia
310-
expected: 16015286601757825753,
311-
expectError: false,
312-
},
313327
{
314328
name: "negative chain selector",
315329
chainSelector: "-1",
330+
dataID: "0x01c508f42b0201320000000000000000",
316331
expectError: true,
317332
errorMsg: "invalid chain selector",
318333
},
334+
{
335+
name: "invalid dataID",
336+
chainSelector: "1",
337+
dataID: "invalid_data_id",
338+
expectError: true,
339+
errorMsg: "invalid dataID",
340+
},
341+
{
342+
name: "dataID too short",
343+
chainSelector: "1",
344+
dataID: "0x0000",
345+
expectError: true,
346+
errorMsg: "dataID must be 16 bytes",
347+
},
348+
{
349+
name: "dataID with odd length",
350+
chainSelector: "1",
351+
dataID: "0x0",
352+
expectError: true,
353+
errorMsg: "odd length hex string",
354+
},
355+
{
356+
name: "dataID too long",
357+
chainSelector: "1",
358+
dataID: "0x01111111111111111111111111111111111111111111",
359+
expectError: true,
360+
errorMsg: "dataID must be 16 bytes",
361+
},
319362
}
320363

364+
// TODO(gg): add tests for solana config?
365+
321366
for _, tt := range tests {
322367
t.Run(tt.name, func(t *testing.T) {
323368
configMap, err := values.WrapMap(map[string]any{
324369
"targetChainSelector": tt.chainSelector,
370+
"dataID": tt.dataID,
325371
})
326372
require.NoError(t, err)
327373

328374
aggregator, err := NewSecureMintAggregator(*configMap)
329375
if tt.expectError {
330-
require.Error(t, err)
376+
assert.Error(t, err)
331377
if tt.errorMsg != "" {
332-
require.Contains(t, err.Error(), tt.errorMsg)
378+
assert.Contains(t, err.Error(), tt.errorMsg)
333379
}
334380
return
335381
}
336382

337383
require.NoError(t, err)
338-
assert.Equal(t, tt.expected, aggregator.(*SecureMintAggregator).config.TargetChainSelector)
384+
assert.Equal(t, tt.expectedChainSelector, aggregator.(*SecureMintAggregator).config.TargetChainSelector)
385+
assert.Equal(t, tt.expectedDataID, aggregator.(*SecureMintAggregator).config.DataID)
339386
})
340387
}
341388
}

0 commit comments

Comments
 (0)