Skip to content

Commit 6f1060b

Browse files
committed
Make test a bit simpler
1 parent 80ebc40 commit 6f1060b

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

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

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,14 @@ func TestSecureMintAggregator_Aggregate(t *testing.T) {
4242
expectedShouldReport bool
4343
expectError bool
4444
errorContains string
45-
shouldReportAssertFn func(t *testing.T, tc tcase, outcome *types.AggregationOutcome)
45+
shouldReportAssertFn func(t *testing.T, tc tcase, topLevelMap map[string]any)
4646
}
4747
acc1 := [32]byte{4, 5, 6}
4848
acc2 := [32]byte{3, 2, 1}
4949

50-
ethReportAssertFn := func(t *testing.T, tc tcase, outcome *types.AggregationOutcome) {
51-
// Verify the output structure matches the feeds aggregator format
52-
val, err := values.FromMapValueProto(outcome.EncodableOutcome)
53-
require.NoError(t, err)
54-
// TODO(gg): share some stuff?
55-
56-
topLevelMap, err := val.Unwrap()
57-
require.NoError(t, err)
58-
mm, ok := topLevelMap.(map[string]any)
59-
require.True(t, ok)
60-
50+
ethReportAssertFn := func(t *testing.T, tc tcase, topLevelMap map[string]any) {
6151
// Check that we have the expected reports
62-
reportsList, ok := mm[TopLevelListOutputFieldName].([]any)
52+
reportsList, ok := topLevelMap[TopLevelListOutputFieldName].([]any)
6353
require.True(t, ok)
6454
assert.Len(t, reportsList, 1)
6555

@@ -82,28 +72,18 @@ func TestSecureMintAggregator_Aggregate(t *testing.T) {
8272
assert.Equal(t, int64(1000), timestamp)
8373
}
8474

85-
solReportAssertFn := func(t *testing.T, tc tcase, outcome *types.AggregationOutcome) {
86-
// Verify the output structure matches the feeds aggregator format
87-
val, err := values.FromMapValueProto(outcome.EncodableOutcome)
88-
require.NoError(t, err)
89-
90-
topLevelMap, err := val.Unwrap()
91-
require.NoError(t, err)
92-
mm, ok := topLevelMap.(map[string]any)
93-
require.True(t, ok)
94-
75+
solReportAssertFn := func(t *testing.T, tc tcase, topLevelMap map[string]any) {
9576
// Check that we have the expected reports
96-
reportsList, ok := mm[TopLevelPayloadListFieldName].([]any)
77+
reportsList, ok := topLevelMap[TopLevelPayloadListFieldName].([]any)
9778
assert.True(t, ok)
9879
assert.Len(t, reportsList, 1)
9980

10081
// Check that we have expected account hash
101-
var accHash [32]byte
102-
err = val.Underlying[TopLevelAccountCtxHashFieldName].UnwrapTo(&accHash)
103-
require.NoError(t, err)
82+
accHash, ok := topLevelMap[TopLevelAccountCtxHashFieldName].([]byte)
83+
require.True(t, ok, "expected account hash to be []byte but got %T", topLevelMap[TopLevelAccountCtxHashFieldName])
84+
require.Len(t, accHash, 32)
10485
expHash := sha256.Sum256(append(acc1[:], acc2[:]...))
105-
106-
assert.Equal(t, expHash, accHash)
86+
assert.Equal(t, expHash, ([32]byte)(accHash))
10787

10888
// Check the first (and only) report
10989
report, ok := reportsList[0].(map[string]any)
@@ -258,7 +238,16 @@ func TestSecureMintAggregator_Aggregate(t *testing.T) {
258238
assert.Equal(t, tc.expectedShouldReport, outcome.ShouldReport)
259239

260240
if outcome.ShouldReport {
261-
tc.shouldReportAssertFn(t, tc, outcome)
241+
// Verify the output structure matches the feeds aggregator format
242+
val, err := values.FromMapValueProto(outcome.EncodableOutcome)
243+
require.NoError(t, err)
244+
245+
topLevelMap, err := val.Unwrap()
246+
require.NoError(t, err)
247+
mm, ok := topLevelMap.(map[string]any)
248+
require.True(t, ok)
249+
250+
tc.shouldReportAssertFn(t, tc, mm)
262251
}
263252
})
264253
}

0 commit comments

Comments
 (0)