Skip to content

Conversation

jimjbrettj
Copy link
Contributor

Changes

  • Move current tests to be integration tests (another PR will be created to merge new unit tests into this branch)
  • Fix bugs in the author integration tests

Tests

go test ./dot/rpc/modules/ -short -v
go test ./dot/rpc/modules/ -short -v --tags=integration

Issues

Primary Reviewer

@codecov
Copy link

codecov bot commented Nov 1, 2021

Codecov Report

Merging #1957 (4f10fc1) into development (2f9f80c) will increase coverage by 0.61%.
The diff coverage is 73.91%.

Impacted file tree graph

@@               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     
Flag Coverage Δ
unit-tests 61.23% <73.91%> (+0.61%) ⬆️

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

Impacted Files Coverage Δ
dot/rpc/modules/author.go 78.88% <0.00%> (+10.00%) ⬆️
dot/rpc/modules/grandpa.go 89.15% <ø> (+12.04%) ⬆️
dot/rpc/modules/sync_state.go 86.04% <ø> (+63.31%) ⬆️
dot/rpc/modules/system.go 90.25% <ø> (+11.68%) ⬆️
dot/rpc/modules/state.go 95.39% <66.66%> (+16.24%) ⬆️
dot/rpc/modules/api_mocks.go 89.28% <100.00%> (+0.39%) ⬆️
dot/rpc/modules/chain.go 90.22% <100.00%> (+21.05%) ⬆️
dot/rpc/modules/childstate.go 100.00% <100.00%> (+9.78%) ⬆️
lib/blocktree/node.go 63.50% <0.00%> (-7.30%) ⬇️
lib/grandpa/types.go 67.18% <0.00%> (-6.25%) ⬇️
... and 23 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 2f9f80c...4f10fc1. Read the comment docs.

@jimjbrettj jimjbrettj force-pushed the jimmy/rpcModulesIntegrationTests branch from 535485d to 4fa800d Compare November 5, 2021 16:51
@jimjbrettj jimjbrettj marked this pull request as ready for review November 10, 2021 20:23
@jimjbrettj jimjbrettj force-pushed the jimmy/rpcModulesIntegrationTests branch from 29aa003 to 653753b Compare November 10, 2021 20:27
@jimjbrettj jimjbrettj force-pushed the jimmy/rpcModulesIntegrationTests branch from 653753b to 16ab592 Compare November 15, 2021 15:39
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.

looks good! so, are the integration tests only run when you add the --tags=integration flag?

@jimjbrettj jimjbrettj force-pushed the jimmy/rpcModulesIntegrationTests branch from 16ab592 to 95add11 Compare November 19, 2021 23:32
@jimjbrettj
Copy link
Contributor Author

looks good! so, are the integration tests only run when you add the --tags=integration flag?

yup yup!

@jimjbrettj jimjbrettj force-pushed the jimmy/rpcModulesIntegrationTests branch from 95add11 to ebdc92e Compare November 30, 2021 16:17
@jimjbrettj jimjbrettj requested a review from qdm12 as a code owner November 30, 2021 17:20
@@ -27,7 +27,6 @@ run:
skip-files:
- .*mock_.*\.go
- .*mocks\/.*\.go
- author_integration_test\.go # TODO remove once fixed
Copy link
Contributor

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.
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
res := make([]string, 0)
var res []string

Comment on lines +51 to +53
require.Contains(t, []string{
":child_first", ":child_second", ":another_child",
}, string(b))
Copy link
Contributor

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)

Comment on lines +120 to +125
var req GetChildStorageRequest
var res uint64

req.Hash = test.hash
req.EntryKey = test.entry
req.KeyChild = test.keyChild
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
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?

Comment on lines +178 to +184
var req GetStorageHash
var res string

req.Hash = test.hash
req.EntryKey = test.entry
req.KeyChild = test.keyChild

Copy link
Contributor

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)
Copy link
Contributor

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 🤔

Comment on lines +238 to +239
require.Error(t, err)
require.Equal(t, err.Error(), test.errMsg)
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
require.Error(t, err)
require.Equal(t, err.Error(), test.errMsg)
require.EqualError(t, err, test.errMsg)

Comment on lines +245 to +249
if test.expected != nil {
// Convert human-readable result value to hex.
expectedVal := "0x" + hex.EncodeToString(test.expected)
require.Equal(t, StateStorageResponse(expectedVal), res)
}
Copy link
Contributor

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?

@jimjbrettj
Copy link
Contributor Author

@EclesioMeloJunior I'm not sure where you are in refactoring these tests, but maybe this feedback could be helpful in your refactor

@EclesioMeloJunior
Copy link
Member

@jimjbrettj thanks! @qdm12 the RPC integration tests are being touched in another PR (I will rise a PR for each RPC module).

@timwu20 timwu20 force-pushed the jimmy/rpcModulesIntegrationTests branch from 025976c to 14f996f Compare December 2, 2021 02:06
…#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
@timwu20 timwu20 changed the title testing (rpc/modules): migrate current tests to integration tests testing (rpc/modules): migrate current tests to integration tests, write new unit tests Dec 2, 2021
@jimjbrettj jimjbrettj merged commit fe1dade into development Dec 2, 2021
@jimjbrettj jimjbrettj deleted the jimmy/rpcModulesIntegrationTests branch December 2, 2021 22:26
@github-actions
Copy link

github-actions bot commented Dec 3, 2021

🎉 This PR is included in version 0.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

timwu20 pushed a commit to timwu20/gossamer that referenced this pull request Dec 6, 2021
…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
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