-
Notifications
You must be signed in to change notification settings - Fork 202
improve grpc converter tests #8208
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
Open
mts1715
wants to merge
4
commits into
feature/optimistic-sync
Choose a base branch
from
taras/8127-Improve-grpc-converter-tests
base: feature/optimistic-sync
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e4286a
test: achieve 100% test coverage for engine/common/rpc/convert package.
mts1715 85357e5
Merge branch 'feature/optimistic-sync' into taras/8127-Improve-grpc-c…
UlyanaAndrukhiv ae8c1d5
Test fixes after review; fix for TransactionID and CollectionID conve…
mts1715 c5e7c3e
Test fixes after review; fix for TransactionID and CollectionID conve…
mts1715 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| package convert_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/onflow/flow-go/engine/common/rpc/convert" | ||
| "github.com/onflow/flow-go/model/flow" | ||
| "github.com/onflow/flow-go/utils/unittest" | ||
| ) | ||
|
|
||
| // TestConvertIdentifier tests converting a flow.Identifier to and from a protobuf message. | ||
| func TestConvertIdentifier(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| id := unittest.IdentifierFixture() | ||
|
|
||
| msg := convert.IdentifierToMessage(id) | ||
| converted := convert.MessageToIdentifier(msg) | ||
|
|
||
| assert.Equal(t, id, converted) | ||
| } | ||
|
|
||
| // TestConvertIdentifiers tests converting a slice of flow.Identifiers to and from protobuf messages. | ||
| func TestConvertIdentifiers(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| ids := unittest.IdentifierListFixture(10) | ||
|
|
||
| msgs := convert.IdentifiersToMessages(ids) | ||
| converted := convert.MessagesToIdentifiers(msgs) | ||
|
|
||
| assert.Equal(t, ids, flow.IdentifierList(converted)) | ||
| } | ||
|
|
||
| // TestConvertSignature tests converting a crypto.Signature to and from a protobuf message. | ||
| func TestConvertSignature(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| sig := unittest.SignatureFixture() | ||
|
|
||
| msg := convert.SignatureToMessage(sig) | ||
| converted := convert.MessageToSignature(msg) | ||
|
|
||
| assert.Equal(t, sig, converted) | ||
| } | ||
|
|
||
| // TestConvertSignatures tests converting a slice of crypto.Signatures to and from protobuf messages. | ||
| func TestConvertSignatures(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| sigs := unittest.SignaturesFixture(5) | ||
|
|
||
| msgs := convert.SignaturesToMessages(sigs) | ||
| converted := convert.MessagesToSignatures(msgs) | ||
|
|
||
| assert.Equal(t, sigs, converted) | ||
| } | ||
|
|
||
| // TestConvertStateCommitment tests converting a flow.StateCommitment to and from a protobuf message. | ||
| func TestConvertStateCommitment(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| sc := unittest.StateCommitmentFixture() | ||
|
|
||
| msg := convert.StateCommitmentToMessage(sc) | ||
| converted, err := convert.MessageToStateCommitment(msg) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, sc, converted) | ||
| } | ||
|
|
||
| // TestConvertStateCommitmentInvalidLength tests that MessageToStateCommitment returns an error | ||
| // for invalid length byte slices. | ||
| func TestConvertStateCommitmentInvalidLength(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| invalidMsg := []byte{0x01, 0x02, 0x03} // Too short | ||
|
|
||
| _, err := convert.MessageToStateCommitment(invalidMsg) | ||
| assert.Error(t, err) | ||
mts1715 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.Contains(t, err.Error(), "invalid state commitment length") | ||
| } | ||
|
|
||
| // TestConvertAggregatedSignatures tests converting a slice of flow.AggregatedSignatures to and from | ||
| // protobuf messages. | ||
| func TestConvertAggregatedSignatures(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| aggSigs := unittest.Seal.AggregatedSignatureFixtures(2) | ||
|
|
||
| msgs := convert.AggregatedSignaturesToMessages(aggSigs) | ||
| converted := convert.MessagesToAggregatedSignatures(msgs) | ||
|
|
||
| assert.Equal(t, aggSigs, converted) | ||
| } | ||
|
|
||
| // TestConvertAggregatedSignaturesEmpty tests converting an empty slice of flow.AggregatedSignatures. | ||
| func TestConvertAggregatedSignaturesEmpty(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| aggSigs := []flow.AggregatedSignature{} | ||
|
|
||
| msgs := convert.AggregatedSignaturesToMessages(aggSigs) | ||
| converted := convert.MessagesToAggregatedSignatures(msgs) | ||
|
|
||
| assert.Empty(t, converted) | ||
| } | ||
|
|
||
| // TestConvertChainId tests converting a valid chainId string to flow.ChainID. | ||
| func TestConvertChainId(t *testing.T) { | ||
mts1715 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| t.Parallel() | ||
|
|
||
| t.Run("valid chain IDs", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| validChainIDs := []flow.ChainID{ | ||
| flow.Mainnet, | ||
| flow.Testnet, | ||
| flow.Emulator, | ||
| flow.Localnet, | ||
| flow.Sandboxnet, | ||
| flow.Previewnet, | ||
| flow.Benchnet, | ||
| flow.BftTestnet, | ||
| flow.MonotonicEmulator, | ||
| } | ||
|
|
||
| for _, chainID := range validChainIDs { | ||
| t.Run(chainID.String(), func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| result, err := convert.MessageToChainId(chainID.String()) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, result) | ||
| assert.Equal(t, chainID, *result) | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("invalid chain IDs", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| invalid := []string{"invalid-chain", ""} | ||
|
|
||
| for _, chainID := range invalid { | ||
| t.Run(fmt.Sprintf("invalid_%q", chainID), func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| result, err := convert.MessageToChainId(chainID) | ||
| assert.Error(t, err) | ||
| assert.Nil(t, result) | ||
| assert.Contains(t, err.Error(), "invalid chainId") | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.