Skip to content

Commit

Permalink
Updated according to suggested comments
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyanaAndrukhiv committed Oct 30, 2024
1 parent 09a19ea commit 0380c35
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
1 change: 1 addition & 0 deletions admin/commands/storage/backfill_tx_error_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (b *BackfillTxErrorMessagesCommand) Handler(ctx context.Context, request *a
for _, txResult := range results {
if txResult.Failed {
fetchTxErrorMessages = true
break // Exit the loop as soon as a failed result is found
}
}

Expand Down
18 changes: 9 additions & 9 deletions admin/commands/storage/backfill_tx_error_messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ func (suite *BackfillTxErrorMessagesSuite) SetupTest() {
suite.params.On("SealedRoot").Return(suite.nodeRootBlock.Header, nil)
suite.state.On("Params").Return(suite.params, nil).Maybe()

suite.snapshot = createSnapshot(parent)
suite.snapshot = createSnapshot(suite.T(), parent)
suite.state.On("Sealed").Return(suite.snapshot)
suite.state.On("Final").Return(suite.snapshot)

suite.state.On("AtHeight", mock.Anything).Return(
func(height uint64) protocol.Snapshot {
if int(height) < len(suite.blockHeadersMap) {
header := suite.blockHeadersMap[height]
return createSnapshot(header)
return createSnapshot(suite.T(), header)
}
return invalid.NewSnapshot(fmt.Errorf("invalid height: %v", height))
},
Expand Down Expand Up @@ -169,7 +169,7 @@ func (suite *BackfillTxErrorMessagesSuite) TestValidateInvalidFormat() {
},
})
suite.Error(err)
suite.Equal(err, admin.NewInvalidAdminReqErrorf(
suite.ErrorIs(err, admin.NewInvalidAdminReqErrorf(
"invalid 'start-height' field: %w",
fmt.Errorf("invalid value for \"n\": %v", 0)))
})
Expand All @@ -182,7 +182,7 @@ func (suite *BackfillTxErrorMessagesSuite) TestValidateInvalidFormat() {
},
})
suite.Error(err)
suite.Equal(err, admin.NewInvalidAdminReqErrorf(
suite.ErrorIs(err, admin.NewInvalidAdminReqErrorf(
"invalid 'end-height' field: %w",
fmt.Errorf("invalid value for \"n\": %v", 0)))
})
Expand All @@ -197,7 +197,7 @@ func (suite *BackfillTxErrorMessagesSuite) TestValidateInvalidFormat() {
},
})
suite.Error(err)
suite.Equal(err, admin.NewInvalidAdminReqErrorf(
suite.ErrorIs(err, admin.NewInvalidAdminReqErrorf(
"start-height %v should not be smaller than end-height %v", startHeight, endHeight))
})

Expand All @@ -210,7 +210,7 @@ func (suite *BackfillTxErrorMessagesSuite) TestValidateInvalidFormat() {
},
})
suite.Error(err)
suite.Equal(err, admin.NewInvalidAdminReqParameterError(
suite.ErrorIs(err, admin.NewInvalidAdminReqParameterError(
"execution-node-ids", "must be a list of string", []int{1, 2, 3}))

// invalid type
Expand All @@ -220,7 +220,7 @@ func (suite *BackfillTxErrorMessagesSuite) TestValidateInvalidFormat() {
},
})
suite.Error(err)
suite.Equal(err, admin.NewInvalidAdminReqParameterError(
suite.ErrorIs(err, admin.NewInvalidAdminReqParameterError(
"execution-node-ids", "must be a list of string", "123"))

// invalid execution node id
Expand All @@ -233,7 +233,7 @@ func (suite *BackfillTxErrorMessagesSuite) TestValidateInvalidFormat() {
},
})
suite.Error(err)
suite.Equal(err, admin.NewInvalidAdminReqParameterError(
suite.ErrorIs(err, admin.NewInvalidAdminReqParameterError(
"execution-node-ids", "could not found execution nodes by provided ids", []string{invalidENID.String()}))
})
}
Expand Down Expand Up @@ -430,7 +430,7 @@ func (suite *BackfillTxErrorMessagesSuite) TestHandleBackfillTxErrorMessagesErro

_, err := suite.command.Handler(ctx, req)
suite.Require().Error(err)
suite.Equal(err, fmt.Errorf("failed to get result by block ID: %w", expectedErr))
suite.ErrorIs(err, fmt.Errorf("failed to get result by block ID: %w", expectedErr))
suite.assertAllExpectations()
})
}
Expand Down
14 changes: 7 additions & 7 deletions admin/commands/storage/read_blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ func TestReadBlocks(t *testing.T) {
suite.Run(t, new(ReadBlocksSuite))
}

func createSnapshot(head *flow.Header) *protocolmock.Snapshot {
snapshot := new(protocolmock.Snapshot)
func createSnapshot(t *testing.T, head *flow.Header) *protocolmock.Snapshot {
snapshot := protocolmock.NewSnapshot(t)
snapshot.On("Head").Return(
func() *flow.Header {
return head
},
nil,
)
).Maybe()
return snapshot
}

Expand All @@ -70,13 +70,13 @@ func (suite *ReadBlocksSuite) SetupTest() {
suite.sealed = sealed
suite.final = final

suite.state.On("Final").Return(createSnapshot(final.Header))
suite.state.On("Sealed").Return(createSnapshot(sealed.Header))
suite.state.On("Final").Return(createSnapshot(suite.T(), final.Header))
suite.state.On("Sealed").Return(createSnapshot(suite.T(), sealed.Header))
suite.state.On("AtBlockID", mock.Anything).Return(
func(blockID flow.Identifier) protocol.Snapshot {
for _, block := range blocks {
if block.ID() == blockID {
return createSnapshot(block.Header)
return createSnapshot(suite.T(), block.Header)
}
}
return invalid.NewSnapshot(fmt.Errorf("invalid block ID: %v", blockID))
Expand All @@ -86,7 +86,7 @@ func (suite *ReadBlocksSuite) SetupTest() {
func(height uint64) protocol.Snapshot {
if int(height) < len(blocks) {
block := blocks[height]
return createSnapshot(block.Header)
return createSnapshot(suite.T(), block.Header)
}
return invalid.NewSnapshot(fmt.Errorf("invalid height: %v", height))
},
Expand Down
8 changes: 4 additions & 4 deletions admin/commands/storage/read_results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func (suite *ReadResultsSuite) SetupTest() {
suite.finalResult = finalResult
suite.sealedResult = sealedResult

suite.state.On("Final").Return(createSnapshot(final.Header))
suite.state.On("Sealed").Return(createSnapshot(sealed.Header))
suite.state.On("Final").Return(createSnapshot(suite.T(), final.Header))
suite.state.On("Sealed").Return(createSnapshot(suite.T(), sealed.Header))
suite.state.On("AtBlockID", mock.Anything).Return(
func(blockID flow.Identifier) protocol.Snapshot {
for _, block := range blocks {
if block.ID() == blockID {
return createSnapshot(block.Header)
return createSnapshot(suite.T(), block.Header)
}
}
return invalid.NewSnapshot(fmt.Errorf("invalid block ID: %v", blockID))
Expand All @@ -109,7 +109,7 @@ func (suite *ReadResultsSuite) SetupTest() {
func(height uint64) protocol.Snapshot {
if int(height) < len(blocks) {
block := blocks[height]
return createSnapshot(block.Header)
return createSnapshot(suite.T(), block.Header)
}
return invalid.NewSnapshot(fmt.Errorf("invalid height: %v", height))
},
Expand Down
7 changes: 0 additions & 7 deletions cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1807,13 +1807,6 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
builder.Storage.Events = bstorage.NewEvents(node.Metrics.Cache, node.DB)
return nil
}).
Module("transaction result error messages storage", func(node *cmd.NodeConfig) error {
if builder.storeTxResultErrorMessages {
builder.Storage.TransactionResultErrorMessages = bstorage.NewTransactionResultErrorMessages(node.Metrics.Cache, node.DB, bstorage.DefaultCacheSize)
}

return nil
}).
Module("reporter", func(node *cmd.NodeConfig) error {
builder.Reporter = index.NewReporter()
return nil
Expand Down

0 comments on commit 0380c35

Please sign in to comment.