-
Notifications
You must be signed in to change notification settings - Fork 116
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 web3 tests code #10293
base: main
Are you sure you want to change the base?
Refactor web3 tests code #10293
Conversation
Signed-off-by: filev94 <todor.filev@limechain.tech>
Signed-off-by: filev94 <todor.filev@limechain.tech>
# Conflicts: # hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java # hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/OpcodeServiceTest.java
Signed-off-by: filev94 <todor.filev@limechain.tech>
Signed-off-by: filev94 <todor.filev@limechain.tech>
.customize(e -> e.evmAddress(null)) | ||
.persist() | ||
.toEntityId(); | ||
return accountEntityPersistCustomizable(e -> e.evmAddress(null)).toEntityId(); |
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.
This test is an example why we needed this refactoring. Usually we want both alias and evmAddress to be null or non-null or with the reusable services integration this will probably fail. We can use directly accountEntityPersist
method from the parent.
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.
Changed from customizable method to accountEntityPersist
...a-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java
Show resolved
Hide resolved
@@ -84,7 +84,7 @@ class ContractCallNestedCallsTest extends AbstractContractCallServiceOpcodeTrace | |||
void updateTokenKeysAndGetUpdatedTokenKeyForFungibleToken(final KeyValueType keyValueType, final KeyType keyType) | |||
throws Exception { | |||
// Given | |||
final var tokenEntityId = fungibleTokenPersist(); | |||
final var tokenEntityId = fungibleTokenPersistWithTreasuryAccount(domainBuilder.entity().persist()); |
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.
If the treasury account is generated, can't we use the base method where we don't pass any treasury account?
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.
Yes, you are correct. Fixing it
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10293 +/- ##
=========================================
Coverage 92.17% 92.17%
Complexity 7966 7966
=========================================
Files 975 975
Lines 33278 33278
Branches 4201 4201
=========================================
+ Hits 30673 30674 +1
Misses 1606 1606
+ Partials 999 998 -1 ☔ View full report in Codecov by Sentry. |
Signed-off-by: filev94 <todor.filev@limechain.tech>
Signed-off-by: filev94 <todor.filev@limechain.tech>
* @param treasuryEntity - the treasuryEntity that has to be set in the token | ||
* @return Token object that is persisted in db | ||
*/ | ||
protected Token fungibleTokenPersistWithTreasuryAccount(final Entity treasuryEntity) { |
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.
Do we really need both fungibleTokenPersistWithTreasuryAccount(final Entity treasuryEntity)
and fungibleTokenPersistWithTreasuryAccount(final EntityId treasuryEntityId)
? Can't we change the code to use only 1 of them?
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.
Yes, we can change the code. My idea was to use the Entity as a parameter for the method so that you can extend the functionality in the future, if needed. However, there are tests that use the EntityId and to refactor it back to Entity would be a big change, so that's why i left it with both for now. In the end, i can remove the Entity parameter and just leave the EntityId, that way i should only refactor tests in one class (TokenModificationFunctionsTest)
e.type(EntityType.ACCOUNT).evmAddress(null).alias(null).balance(100_000_000_000_000_000L)) | ||
.persist(); | ||
return accountEntityPersistCustomizable( | ||
e -> e.type(EntityType.ACCOUNT).evmAddress(null).alias(null).balance(100_000_000_000_000_000L)); |
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.
Is there a reason the balance in this method and in the other one (accountEntityWithEvmAddressPersist()
) to differ? If not, we can choose one of the values and extract it into a constant.
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.
Good catch. I tried using one balance for both, the smaller value - the tests passed so I will extract it in a constant.
final var treasury = accountPersistWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY); | ||
final var token = fungibleTokenPersist(treasury); | ||
final var token = fungibleTokenPersistWithTreasuryAccount(treasury); |
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.
Do we really need to create and set a specific treasury account everywhere? If we don't use it in the test later, we can just leave it to the generated one.
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.
You are correct. When i removed the treasuryAccount and used the fungibleTokenPersist(), the tests passed. And thus the need for the fungibleTokenPersistWithTreasuryAccount(Entity ...) method was removed. Two birds with one stone i guess.
@@ -887,7 +870,7 @@ private Token nftPersist(final Entity treasuryEntity) { | |||
} | |||
|
|||
private Entity accountPersist() { | |||
return domainBuilder.entity().customize(a -> a.evmAddress(null)).persist(); | |||
return accountEntityPersistCustomizable(e -> e.evmAddress(null)); |
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.
The same is valid as in #10293 (comment)
Description:
Removed similar code from several tests and put it in parent class so that if a change is needed it should be done in one place only. This is the first PR, more might be needed if i find more code that needs to be extracted in a similar way.
Related issue(s):
Fixes #10255
Notes for reviewer:
Checklist