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

testing (dot/core): rewrite message.go unit tests #2197

Merged
merged 23 commits into from
Jan 21, 2022

Conversation

jimjbrettj
Copy link
Contributor

Changes

  • Rewrite dot/core message.go unit tests to increase speed and code coverage

Tests

 go test ./dot/core/ -v -coverprofile coverage.out
 go tool cover -func coverage.out // To view file code coverage

Issues

Primary Reviewer

@codecov
Copy link

codecov bot commented Jan 14, 2022

Codecov Report

❗ No coverage uploaded for pull request base (jimmy/coreIntegrationTests@55fd785). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@                      Coverage Diff                      @@
##             jimmy/coreIntegrationTests    #2197   +/-   ##
=============================================================
  Coverage                              ?   59.73%           
=============================================================
  Files                                 ?      210           
  Lines                                 ?    27371           
  Branches                              ?        0           
=============================================================
  Hits                                  ?    16349           
  Misses                                ?     9320           
  Partials                              ?     1702           
Flag Coverage Δ
unit-tests 59.73% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55fd785...d53eb01. Read the comment docs.

Copy link
Contributor

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

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

That test.log though 😄

Looks good, just a few comments here and there

dot/core/interface.go Outdated Show resolved Hide resolved
dot/core/messages.go Outdated Show resolved Hide resolved
dot/core/messages_test.go Outdated Show resolved Hide resolved
dot/core/messages_test.go Outdated Show resolved Hide resolved
dot/core/messages_test.go Outdated Show resolved Hide resolved
dot/core/messages_test.go Show resolved Hide resolved
txs := make([]*transaction.ValidTransaction, 2)

mockTxnStateEmpty.EXPECT().PendingInPool().Return([]*transaction.ValidTransaction{})
mockTxnState.EXPECT().PendingInPool().Return(txs)
Copy link
Contributor

Choose a reason for hiding this comment

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

wait why is the transaction state returning a slice with nil transactions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cuz I'm only testing the length function, so i thought it would be good to have a test case testing empty input. Can remove that case if that's preferred

Copy link
Contributor

@noot noot left a comment

Choose a reason for hiding this comment

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

can you pull development into here? that should remove the test.log file completely

@jimjbrettj jimjbrettj force-pushed the jimmy/coreIntegrationTests branch from 4b18eab to 55fd785 Compare January 18, 2022 17:51
EclesioMeloJunior and others added 10 commits January 18, 2022 10:51
…lue (#2143)

* fix: return error if result already has an assigned value

* chore: include unit test

* chore: fix typo `ErrResultAlreadySet`

* chore: remove unneeded `require.Error`

* chore: fix undeclared name

* chore: remove packaged scope var to avoid problems with result type

* chore: fix result.Set error at offchain test
@jimjbrettj jimjbrettj force-pushed the jimmy/coreMessageUnitTests branch from e70b2ee to ec7b7ff Compare January 18, 2022 17:58
@jimjbrettj jimjbrettj requested a review from noot January 18, 2022 18:18
dot/core/messages.go Outdated Show resolved Hide resolved
dot/core/messages.go Outdated Show resolved Hide resolved
dot/core/messages.go Outdated Show resolved Hide resolved
dot/core/messages.go Outdated Show resolved Hide resolved
dot/core/messages.go Outdated Show resolved Hide resolved
dot/core/messages.go Outdated Show resolved Hide resolved
dot/core/messages_test.go Show resolved Hide resolved
dot/core/service_integration_test.go Show resolved Hide resolved
dot/core/messages.go Outdated Show resolved Hide resolved
dot/core/messages.go Outdated Show resolved Hide resolved
@jimjbrettj jimjbrettj requested a review from qdm12 January 20, 2022 21:52
dot/core/messages.go Outdated Show resolved Hide resolved
@jimjbrettj jimjbrettj requested a review from qdm12 January 20, 2022 22:29
@@ -41,56 +78,29 @@ func (s *Service) HandleTransactionMessage(peerID peer.ID, msg *network.Transact
return false, err
}

isValid := true
Copy link
Contributor

Choose a reason for hiding this comment

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

nit perhaps rename to allTxsAreValid? 🤔

Value: peerset.BadTransactionValue,
Reason: peerset.BadTransactionReason,
},
id: peer.ID("jimbo"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving the author's mark 😄

@jimjbrettj jimjbrettj merged commit d800e07 into jimmy/coreIntegrationTests Jan 21, 2022
@jimjbrettj jimjbrettj deleted the jimmy/coreMessageUnitTests branch January 21, 2022 18:25
jimjbrettj added a commit that referenced this pull request Jan 21, 2022
…ssage.go` unit tests (#2224)

* chore(pkg/scale): return error if `Result` already has an assigned value  (#2143)

* fix: return error if result already has an assigned value

* chore: include unit test

* chore: fix typo `ErrResultAlreadySet`

* chore: remove unneeded `require.Error`

* chore: fix undeclared name

* chore: remove packaged scope var to avoid problems with result type

* chore: fix result.Set error at offchain test

* migrate core tests to integration tests

* remove test.log

* upgrade integration tests to match dev

* testing (dot/core): rewrite message.go unit tests (#2197)

* chore(pkg/scale): return error if `Result` already has an assigned value  (#2143)

* fix: return error if result already has an assigned value

* chore: include unit test

* chore: fix typo `ErrResultAlreadySet`

* chore: remove unneeded `require.Error`

* chore: fix undeclared name

* chore: remove packaged scope var to avoid problems with result type

* chore: fix result.Set error at offchain test

* test txt count and generate mocks with mockgen

* WIP/hanldeTxnMsgTest

* WIP/core message tests

* wip/finish core message tests

* wip/message test

* fix reporting issue

* test core messages

* remove comments and lint

* remove unused file

* wip/cr feedback

* use dummy error for tests

* wip/finish cr feedback

* wip/move message validation to a separate function

* move txn validity check to new func

* lint

* fix variable naming to make less confusing

* remove pointer from validateTxn helper params

* refactor tests to define mocks in subtest

* CR feedback

* finish feedback for core tests

* define runtime mocks in subtest

* remane validTxn var

Co-authored-by: Eclésio Junior <[email protected]>

* CR feedback

* finish feedback

* CR feedback

Co-authored-by: Eclésio Junior <[email protected]>
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.

5 participants