-
Notifications
You must be signed in to change notification settings - Fork 42
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
Refactor with repository pattern #2540
Merged
Merged
Conversation
This file contains 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
moreal
force-pushed
the
introduce-repository
branch
from
August 22, 2024 01:50
1128716
to
cc53ab7
Compare
moreal
force-pushed
the
introduce-repository
branch
9 times, most recently
from
September 6, 2024 03:32
a5ba925
to
030603c
Compare
moreal
force-pushed
the
introduce-repository
branch
4 times, most recently
from
September 11, 2024 10:04
116012b
to
688f8f1
Compare
DevEx 테스트가 실패하는데 괜찮은건가요? |
@ipdae 테스트 관련해서 깨지는 것이 아닌 Roslyn 컴파일러 쪽에서 발생하고 있습니다. 최근 계속 발생하고 있는데 원인을 파악하지 못 해 재시도(rerun) 하는 것으로 넘어가고 있습니다 |
#2582 이슈로 만들어 놓았습니다 |
- Introduce `IBlockChainRepository`. - Introduce `IWorldStateRepository`. - Introduce `ITransactionRepository`. - Introduce `IStateTrieRepository`. - Replace the usage of `StandaloneContext.BlockChain` with repositories. - Separate `NodeStatusType` GraphQL type and `NodeStatus` record type.
moreal
force-pushed
the
introduce-repository
branch
from
September 20, 2024 05:21
688f8f1
to
02a1406
Compare
ipdae
approved these changes
Sep 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
This pull request adds the repository pattern. Specifically, it will abstract and incrementally improve the behavior of BlockChain so that BlockChain, TxPool, etc. can be accessed through a repository instead of directly.
This is because we found a problem while working on something else: right now we're using BlockChain directly, so it's hard to test "under what conditions" we want the headless to behave that way. This is because the only way to manipulate the state of BlockChain is to do transactions, create blocks, and expect them to change the state. That's well tested in the Libplanet project, but testing headless implies that as well. This will not only make writing tests difficult, but it will also make the tests take longer to run.
That's why we want to gradually refactor to the repository pattern. I'd appreciate your feedback.
Overview
Repositories
I introduce several new repositories in this pull request. The purpose of the repositories is to separate
BlockChain
logic (in general HTTP server,Database
) andGraphQL
representation (in general HTTP serverController
). This makes testing easier because the GraphQL layer only depends on repositories in some parts.Below are the new repository names and descriptions:
IBlockChainRepository
: A repository about blocks (BlockChain.Tip
,Block
)IWorldStateRepository
: A repository about states (IWorldState
)IStateTrieRepository
: A repository about state-trie (MerkleTrie
)ITransactionRepository
: A repository about transactions, transaction results, nonces.Testing with mocking
Since this pull request, you don't have to setup any
NineChroniclesNodeService
and anyBlockChain
to setup states that you want. You can just mockIWorldStateRepository
.You can manually mock like the below example code:
But if your test don't care any block data and care only states on tip, you can use
GraphQLTestBase.SetupStatesOnTip
: