Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal block api unit testing #3695

Merged
merged 16 commits into from
Feb 4, 2022

Conversation

ssd04
Copy link
Contributor

@ssd04 ssd04 commented Jan 12, 2022

Unit testing on several parts regarding internal block headers exposure:

  • api
  • facade
  • status handler ratings metrics
  • node internal blocks

@ssd04 ssd04 self-assigned this Jan 12, 2022
@ssd04 ssd04 marked this pull request as ready for review January 20, 2022 09:37
api/groups/internalGroup_test.go Outdated Show resolved Hide resolved
expectedOutput := bytes.Repeat([]byte("1"), 10)

facade := mock.FacadeStub{
GetInternalMetaBlockByHashCalled: func(_ common.OutportFormat, _ string) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename OutportFormat to OutputFormat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

storerMock := mock.NewStorerMock()
uint64Converter := mock.NewNonceHashConverterMock()

internalBlockProcessor := createMockInternalBlockProcessor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might rename internalBlockProcessor to ibp as it has the same name as the struct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -154,7 +154,7 @@ func InitRatingsMetrics(statusHandlerUtils StatusHandlersUtils, ratingsConfig co
appStatusHandler.SetStringValue(common.MetricRatingsMetaChainConsecutiveMissedBlocksPenalty, fmt.Sprintf("%f", ratingsConfig.MetaChain.ConsecutiveMissedBlocksPenalty))

appStatusHandler.SetStringValue(common.MetricRatingsPeerHonestyDecayCoefficient, fmt.Sprintf("%f", ratingsConfig.PeerHonesty.DecayCoefficient))
appStatusHandler.SetUInt64Value(common.MetricRatingsPeerHonestyDecayCoefficient, uint64(ratingsConfig.PeerHonesty.DecayUpdateIntervalInSeconds))
appStatusHandler.SetUInt64Value(common.MetricRatingsPeerHonestyDecayUpdateIntervalInSeconds, uint64(ratingsConfig.PeerHonesty.DecayUpdateIntervalInSeconds))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

node/node.go Outdated
@@ -1404,7 +1404,8 @@ func (n *Node) getKeyBytes(key string) ([]byte, error) {
return hex.DecodeString(key)
}

func (n *Node) createInternalBlockProcessor() error {
// CreateInternalBlockProcessor creates the block processor for handling internal block header
func (n *Node) CreateInternalBlockProcessor() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you export it? if only for testing, then you'd better create an export_test.go file where you export this function ONLY for testing purposes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, exported function in export_test.go

err := n.CreateInternalBlockProcessor()
require.Nil(t, err)

blk, err := n.GetInternalShardBlockByHash(common.Internal, "wronghashformat")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might rename Internal from common to ApiOutputFormatInternal
also rename Proto from internal to ApiOutputFormatProto
also rename OutportFormat to ApiOutputFormat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

@@ -255,7 +255,7 @@ func (sm *statusMetrics) RatingsMetrics() map[string]interface{} {
ratingsMetrics[common.MetricRatingsGeneralSignedBlocksThreshold] = sm.loadStringMetric(common.MetricRatingsGeneralSignedBlocksThreshold)

numSelectionChances := sm.loadUint64Metric(common.MetricRatingsGeneralSelectionChances + "_count")
selectionChances := make([]interface{}, 0)
selectionChances := make([]map[string]interface{}, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the items within the map seem only to be uint64. therefore, we could change the map from map[string]interface{} to map[string]uint64

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right 👍


for i, selectionChance := range selectionChances {
maxThresholdStr := fmt.Sprintf("%s%d%s", common.MetricRatingsGeneralSelectionChances, i, common.SelectionChancesMaxThresholdSuffix)
sm.SetUInt64Value(maxThresholdStr, uint64(selectionChance["MaxThreshold"]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant type conversion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

maxThresholdStr := fmt.Sprintf("%s%d%s", common.MetricRatingsGeneralSelectionChances, i, common.SelectionChancesMaxThresholdSuffix)
sm.SetUInt64Value(maxThresholdStr, uint64(selectionChance["MaxThreshold"]))
chancePercentStr := fmt.Sprintf("%s%d%s", common.MetricRatingsGeneralSelectionChances, i, common.SelectionChancesChancePercentSuffix)
sm.SetUInt64Value(chancePercentStr, uint64(selectionChance["ChancePercent"]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant type conversion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

- renaming
- use valid hash in tests
- rename OutportFormat type and vars
- status handler - ratings metrics improvements
…twork/elrond-go into internal-block-api-unit-testing
@ssd04 ssd04 force-pushed the internal-block-api-unit-testing branch from 3bd095f to 3938e57 Compare January 31, 2022 15:57
bogdan-rosianu
bogdan-rosianu previously approved these changes Feb 2, 2022
api/groups/internalGroup_test.go Outdated Show resolved Hide resolved
node/nodeMiniBlocks_test.go Outdated Show resolved Hide resolved
node/nodeMiniBlocks_test.go Show resolved Hide resolved
node/nodeMiniBlocks_test.go Outdated Show resolved Hide resolved
node/nodeInternalBlocks_test.go Outdated Show resolved Hide resolved
- handler errors properly
- improve coverage
AdoAdoAdo
AdoAdoAdo previously approved these changes Feb 4, 2022
- remove duplicate error
- handler error cases properly
- reduce duplicate code
node/blockAPI/error.go Outdated Show resolved Hide resolved
node/nodeInternalBlocks_test.go Outdated Show resolved Hide resolved
@ssd04 ssd04 merged commit 4759c46 into feat/api-routes-internal-data Feb 4, 2022
@ssd04 ssd04 deleted the internal-block-api-unit-testing branch February 4, 2022 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants