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

sovereign chain block unit tests #6675

Open
wants to merge 6 commits into
base: feat/chain-go-sdk
Choose a base branch
from

Conversation

axenteoctavian
Copy link
Contributor

@axenteoctavian axenteoctavian commented Dec 13, 2024

Reasoning behind the pull request

Proposed changes

  • CreateNewHeader full
  • CreateBlock partial

Testing procedure

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@axenteoctavian axenteoctavian self-assigned this Dec 13, 2024
@axenteoctavian axenteoctavian marked this pull request as ready for review December 13, 2024 13:28
@mariusmihaic mariusmihaic self-requested a review December 16, 2024 10:49
Comment on lines +120 to +122
coreComponents, dataComponents, bootstrapComponents, statusComponents := createComponentHolderMocks()
arguments := createSovereignMockArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents)
sovArgs := createArgsSovereignChainBlockProcessor(arguments)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Please make a simple func that creates all args for sovereign, which doesn't require any input, like it was before.
  2. Compress these 3 lines into that function from abive and use it in these tests

return arguments
}

func createSovereignMockArguments(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func createSovereignMockArguments(
func createShardBlockProcesorArgsForSovereign(


headerHandler, err := scbp.CreateNewHeader(round, 1)
require.Nil(t, err)
require.NotNil(t, headerHandler)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we actually check the header with a full &block.Sovereign... ?


h, err := scbp.CreateNewHeader(round, nonce)
require.Nil(t, err)
require.IsType(t, &block.SovereignChainHeader{}, h)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same remark as above, better to check directly with a header

Comment on lines +458 to +461
coreComponents, dataComponents, bootstrapComponents, statusComponents := createComponentHolderMocks()
arguments := createSovereignMockArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents)
sovArgs := createArgsSovereignChainBlockProcessor(arguments)
scbp, err := blproc.NewSovereignChainBlockProcessor(sovArgs)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Same remark regarding only 1 func to create everything
  2. You can move scbp, err := blproc.NewSovereignChainBlockProcessor(sovArgs) outside these tests and reuse that instance

require.Equal(t, process.ErrAccountStateDirty, err)
require.Equal(t, expectedBusyIdleSequencePerCall, busyIdleCalled)
})
t.Run("create block started should error", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also mention why you make it fail (e.g. tx coordinator fails bcz...)

scbp, err := blproc.NewSovereignChainBlockProcessor(sovArgs)
require.Nil(t, err)

doesHaveTime := func() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

This func can be moved outside these funcs.

}

hdr, bodyHandler, err := scbp.CreateBlock(sovHeader, doesHaveTime)
require.False(t, check.IfNil(bodyHandler))
Copy link
Contributor

Choose a reason for hiding this comment

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

Check directly with miniblocks and skip using these False.Nil.
Applies also for expected header. If you require it to be equal to your expected object, there is no need to also check it is not nil

require.Equal(t, expectedErr, err)
require.Equal(t, expectedBusyIdleSequencePerCall, busyIdleCalled)
})
t.Run("should work with sovereign header and epoch start rewriting the epoch value", func(t *testing.T) {
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 this func name, we do not rewrite, I think you mean we change epoch

return true
}

hdr, bodyHandler, err := scbp.CreateBlock(expectedSovHeader, doesHaveTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same remarks as above

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.

2 participants