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 dot/core service tests (part 2) #2308

Merged
merged 75 commits into from
Mar 23, 2022

Conversation

jimjbrettj
Copy link
Contributor

Changes

  • Finished writing unit tests for dot/core.Service.go
  • Should wait to review till P1 is merged to reduce diff (at time of opening its awaiting 1 review)

Tests

go test ./dot/core -v -coverprofile coverage.out
go tool cover -func coverage.out

Issues

Primary Reviewer

@jimjbrettj jimjbrettj requested review from qdm12 and noot March 2, 2022 19:27
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service.go Outdated Show resolved Hide resolved
dot/core/service.go Outdated Show resolved Hide resolved
dot/core/service.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
s := NewTestService(t, cfg)
s.transactionState = ts

provides := common.MustHexToBytes("0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00000000")
Copy link
Contributor

Choose a reason for hiding this comment

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

so you are expecting this Provides tags to be added via the runtime? I would put a comment about it. It would be nice to have a link to the runtime code that appends these tags, and what these tags are.

dot/core/service_test.go Outdated Show resolved Hide resolved
dot/core/service_test.go Show resolved Hide resolved
dot/core/helpers_test.go Outdated Show resolved Hide resolved
dot/core/helpers_test.go Outdated Show resolved Hide resolved
dot/core/messages_integration_test.go Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
Comment on lines 613 to 618
net.EXPECT().GossipMessage(gomock.AssignableToTypeOf(new(network.TransactionMessage))).AnyTimes()
net.EXPECT().IsSynced().Return(true).AnyTimes()
net.EXPECT().ReportPeer(
gomock.AssignableToTypeOf(peerset.ReputationChange{}),
gomock.AssignableToTypeOf(peer.ID("")),
).AnyTimes()
Copy link
Contributor

Choose a reason for hiding this comment

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

have these more restrictive if it's not a helper test function

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.

A bunch of nits, but looks good otherwise 💯

dot/core/service.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_integration_test.go Outdated Show resolved Hide resolved
dot/core/service_test.go Outdated Show resolved Hide resolved
dot/core/service_test.go Show resolved Hide resolved
transactionState: mockTxnStateOk,
}
execTest(t, service, testPrevHash, testCurrentHash, nil)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit this is fine, although it might a bit cleaner with mock configuration functions as test case fields (example)

dot/core/service_test.go Outdated Show resolved Hide resolved
dot/core/service_test.go Outdated Show resolved Hide resolved
@@ -901,7 +912,7 @@ func TestServiceHasKey(t *testing.T) {
},
args: args{
pubKeyStr: aliceKeypair.Public().Hex(),
keystoreType: "jimbo",
keystoreType: "test",
Copy link
Contributor

Choose a reason for hiding this comment

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

You could had left jimbo 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i got scared haha

@@ -21,3 +21,11 @@ type AccountInfo struct {
FreeFrozen *scale.Uint128
}
}

// AccountData represents account data of an account. Currently is used in core tests
type AccountData struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use this type instead of the anonymous struct in the Account struct in the types package as well?
And then update the comment as well for this struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup good call!

dot/core/service_test.go Outdated Show resolved Hide resolved
@@ -187,6 +187,11 @@ func (in *Instance) GetCodeHash() common.Hash {
return in.codeHash
}

// GetContext returns the context of the instance
func (in *Instance) GetContext() *runtime.Context {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems odd that we need to modify the context only in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I needed it to create valid extristics based on the current/correct runtime context. I think its modified elsewhere in the package, it just is not exported

@jimjbrettj jimjbrettj merged commit dd80d0d into development Mar 23, 2022
@jimjbrettj jimjbrettj deleted the jimmy/coreServiceTestsP2 branch March 23, 2022 00:13
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