-
Notifications
You must be signed in to change notification settings - Fork 144
testing (rpc/modules): migrate current tests to integration tests, write new unit tests #1957
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
Conversation
Codecov Report
@@ Coverage Diff @@
## development #1957 +/- ##
===============================================
+ Coverage 60.62% 61.23% +0.61%
===============================================
Files 202 203 +1
Lines 27286 27301 +15
===============================================
+ Hits 16541 16719 +178
+ Misses 8845 8706 -139
+ Partials 1900 1876 -24
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
535485d
to
4fa800d
Compare
29aa003
to
653753b
Compare
653753b
to
16ab592
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! so, are the integration tests only run when you add the --tags=integration
flag?
16ab592
to
95add11
Compare
yup yup! |
95add11
to
ebdc92e
Compare
@@ -27,7 +27,6 @@ run: | |||
skip-files: | |||
- .*mock_.*\.go | |||
- .*mocks\/.*\.go | |||
- author_integration_test\.go # TODO remove once fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
//go:build integration | ||
// +build integration | ||
|
||
// Copyright 2019 ChainSafe Systems (ON) Corp. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove and run make license
Hash: nil, | ||
} | ||
|
||
res := make([]string, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
res := make([]string, 0) | |
var res []string |
require.Contains(t, []string{ | ||
":child_first", ":child_second", ":another_child", | ||
}, string(b)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's risky since if b
is always one of them, that will pass.
Instead change that to a set map[string]struct{}{":child_first": {}, ...}
which you check with
key := string(b)
_, ok := set[key]
assert.True(t, ok)
delete(set, key)
var req GetChildStorageRequest | ||
var res uint64 | ||
|
||
req.Hash = test.hash | ||
req.EntryKey = test.entry | ||
req.KeyChild = test.keyChild |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var req GetChildStorageRequest | |
var res uint64 | |
req.Hash = test.hash | |
req.EntryKey = test.entry | |
req.KeyChild = test.keyChild | |
req := GetChildStorageRequest{ | |
Hash: test.hash, | |
EntryKey: test.entry, | |
KeyChild: test.keyChild, | |
} | |
var res uint64 | |
also why not have var req GetChildStorageRequest
directly as a field in your test cases?
var req GetStorageHash | ||
var res string | ||
|
||
req.Hash = test.hash | ||
req.EntryKey = test.entry | ||
req.KeyChild = test.keyChild | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here, you could have req
as a field in your test cases
|
||
func TestGetChildStorage(t *testing.T) { | ||
mod, blockHash := setupChildStateStorage(t) | ||
randomHash, err := common.HexToHash(RandomHash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's RandomHash
? Maybe have it inlined here as a constant? I don't think it's really random either, since it's a constant 🤔
require.Error(t, err) | ||
require.Equal(t, err.Error(), test.errMsg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.Error(t, err) | |
require.Equal(t, err.Error(), test.errMsg) | |
require.EqualError(t, err, test.errMsg) |
if test.expected != nil { | ||
// Convert human-readable result value to hex. | ||
expectedVal := "0x" + hex.EncodeToString(test.expected) | ||
require.Equal(t, StateStorageResponse(expectedVal), res) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check StateStorageResponse(expectedVal)
is also as expected when test.expected
is nil
?
@EclesioMeloJunior I'm not sure where you are in refactoring these tests, but maybe this feedback could be helpful in your refactor |
@jimjbrettj thanks! @qdm12 the RPC integration tests are being touched in another PR (I will rise a PR for each RPC module). |
025976c
to
14f996f
Compare
…#1995) * migrate rpc/module tests to integration tests TODO:write unit tests * fix TestAuthorModule_InsertKey_Valid * fix TestAuthorModule_InsertKey_Valid_Gran_Keytype * migrate rpc/module tests to integration tests TODO:write unit tests * use mockery to generate BlockProducerAPI * WIP/test for dev control function * 100% test coverage for rpc/module/dev unit tests * test cov for getKeys in childState * 100% cover for getStorage size * 100% cover for getStorage hash * 100% coverage for childstate unit tests * format childState * lint * tests for offchain get * full coverage for offchain unit tests * unit tests for payment * 100% for grandpa proveFinality * grandpa unit tests * GenSyncSpec coverage * sync state unit tests * GetBlock * getBlockHash tests * chain tests * Wip/system tests * AccountNextIndex test * syncState test * tes localListenAndAddresses * test localPeerId * system tests * state getPairs test * getKeysPages test * test GetMetadata * test GetReadProof * test GetRuntime Version * test GetStorage * test GetStorageHash * test GetStorageSize * test queryStorage * state tests * remove subscribe func tests * format * rebase * fix naming and remove unnecessary variable inits * remove log * push test data * remove AnythingOfType from chain test * remove AnythingOfType from childState test * remove AnythingOfType from Grandpa test * remove AnythingOfType from offchain test * remove AnythingOfType from payment test * remove mocking anything in state test * remove mocking anything in sync state test * WIP/Finish removing mock.AnythingOfType * WIP/author test * author test * add exp cases to chain test * WIP/figure out error assertion issue * WIP/fix errors still * fix chain test error handling * author module tests fix * childstate test CR feedback * dev tests * wip/grandpa tests * grandpa tests * offchain tests * payment tests * syc state test updates * state test CR feedback * system tests * fix inconsistent test to use reflect on maps * use zip file for test data * delete test data hex file * fix up tests * close to final changes * finish CR feedback * clean up error checking * CR feedback TODO/Fix integration test error * move response init into subtests * remove panic from code * WIP/clean up tests * change res variable to be non pointer * WIP/add expected response check for error case * add response check for error case * finish first round of CR feedback * hasSessionKey tests * remove old author module tests * rename err to expErr * use system module constructor instead of fields * rename getter for test metadata * wip/CR feedback * separate out system getter tests * fix naming * clean up imports * wip/cr feedback * remove wantErr from rpc/module tests * finalize feedback * rebase * CR feedback * remove apimocks alias * final CR feedback * finalize CR changes * fix failing http test * fix LocalPeerId naming
🎉 This PR is included in version 0.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
…ite new unit tests (ChainSafe#1957) * fix TestAuthorModule_InsertKey_Valid * fix TestAuthorModule_InsertKey_Valid_Gran_Keytype * fix rpc/module/author_integration_test * migrate rpc/module tests to integration tests TODO:write unit tests * remove skip author integration tests from golangci.yml * lint * rebase and fix errors * license * testing (rpc/modules): write new unit tests to increase code coverage (ChainSafe#1995) * migrate rpc/module tests to integration tests TODO:write unit tests * fix TestAuthorModule_InsertKey_Valid * fix TestAuthorModule_InsertKey_Valid_Gran_Keytype * migrate rpc/module tests to integration tests TODO:write unit tests * use mockery to generate BlockProducerAPI * WIP/test for dev control function * 100% test coverage for rpc/module/dev unit tests * test cov for getKeys in childState * 100% cover for getStorage size * 100% cover for getStorage hash * 100% coverage for childstate unit tests * format childState * lint * tests for offchain get * full coverage for offchain unit tests * unit tests for payment * 100% for grandpa proveFinality * grandpa unit tests * GenSyncSpec coverage * sync state unit tests * GetBlock * getBlockHash tests * chain tests * Wip/system tests * AccountNextIndex test * syncState test * tes localListenAndAddresses * test localPeerId * system tests * state getPairs test * getKeysPages test * test GetMetadata * test GetReadProof * test GetRuntime Version * test GetStorage * test GetStorageHash * test GetStorageSize * test queryStorage * state tests * remove subscribe func tests * format * rebase * fix naming and remove unnecessary variable inits * remove log * push test data * remove AnythingOfType from chain test * remove AnythingOfType from childState test * remove AnythingOfType from Grandpa test * remove AnythingOfType from offchain test * remove AnythingOfType from payment test * remove mocking anything in state test * remove mocking anything in sync state test * WIP/Finish removing mock.AnythingOfType * WIP/author test * author test * add exp cases to chain test * WIP/figure out error assertion issue * WIP/fix errors still * fix chain test error handling * author module tests fix * childstate test CR feedback * dev tests * wip/grandpa tests * grandpa tests * offchain tests * payment tests * syc state test updates * state test CR feedback * system tests * fix inconsistent test to use reflect on maps * use zip file for test data * delete test data hex file * fix up tests * close to final changes * finish CR feedback * clean up error checking * CR feedback TODO/Fix integration test error * move response init into subtests * remove panic from code * WIP/clean up tests * change res variable to be non pointer * WIP/add expected response check for error case * add response check for error case * finish first round of CR feedback * hasSessionKey tests * remove old author module tests * rename err to expErr * use system module constructor instead of fields * rename getter for test metadata * wip/CR feedback * separate out system getter tests * fix naming * clean up imports * wip/cr feedback * remove wantErr from rpc/module tests * finalize feedback * rebase * CR feedback * remove apimocks alias * final CR feedback * finalize CR changes * fix failing http test * fix LocalPeerId naming
Changes
Tests
Issues
Primary Reviewer