Skip to content

Conversation

@ricardopinto
Copy link
Contributor

Scope

What is changing with this PR?
Added lots of test the the admin handler and dman packages.

Why?

To ensure greater stability on AliceNet

@ricardopinto ricardopinto changed the base branch from main to candidate May 13, 2022 18:19
@ricardopinto ricardopinto marked this pull request as ready for review May 13, 2022 18:19
@ricardopinto ricardopinto requested a review from nelsonhp as a code owner May 13, 2022 18:19
func (db *Database) SetSafeToProceed(txn *badger.Txn, height uint32, isSafe bool) error {
if height%constants.EpochLength != 1 {
panic("The height must be mod 1 epoch length")
panic(fmt.Errorf("the height must be mod 1 epoch length. height: %v\n", height))
Copy link

Choose a reason for hiding this comment

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

nit: panic internally just converts the error to a string, which negates the need to do fmt.Errorf. You can just do a fmt.Sprintf if you want to convert to format a string. Also the trailing \n isn't needed as panic inserts one automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll improve this on the next commit

func (db *Database) SetSafeToProceed(txn *badger.Txn, height uint32, isSafe bool) error {
if height%constants.EpochLength != 1 {
panic("The height must be mod 1 epoch length")
panic(fmt.Errorf("the height must be mod 1 epoch length. height: %v\n", height))
Copy link

Choose a reason for hiding this comment

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

nit: panic internally just converts the error to a string, which negates the need to do fmt.Errorf. You can just do a fmt.Sprintf if you want to convert to format a string. Also the trailing \n isn't needed as panic inserts one automatically.

skipCallCheck bool
}

// assert struct `testingProxy` implements `reqBusView` , `txMarshaller`, `databaseView` and `typeProxyIface` interfaces
Copy link

Choose a reason for hiding this comment

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

question: Does it matter if testingProxy doesn't implement these interfaces if tests cover that functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some parts of the code require interfaces to be passed in as arguments and this ensures the testingProxy struct actually implements the required interfaces. Note that testingProxy mocks functionality to better test these components in isolation.

var _ databaseView = &testingProxy{}
var _ typeProxyIface = &testingProxy{}

func (trb *testingProxy) checkExpect() error {
Copy link

Choose a reason for hiding this comment

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

nit: Might be a good idea to convert these functions into test helpers (take a *t.Testing and call t.Helper() at the start) so that you can just t.Error and t.Fatal without having to worry about returning errors. Less handling on the calling test side and the test log will bubble up the checks to the failing parent test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an interesting idea and I see its potential in more functions like generateChain() or makeGoodBlock(). This particular test suite would require a great deal of rewriting to accommodate that, given its stateful nature. I'll investigate more about helper functions and learn how we can leverage them in our testing.

- Improved panic error messages
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 21 Code Smells

No Coverage information No Coverage information
16.3% 16.3% Duplication

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