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

Remove data generator #2387

Merged
merged 21 commits into from
Aug 18, 2021
Merged

Remove data generator #2387

merged 21 commits into from
Aug 18, 2021

Conversation

ijungmann
Copy link
Contributor

@ijungmann ijungmann commented Aug 10, 2021

Description:
Remove data generator module and add test cases for TransactionSuppliers

  • Remove the data generator module and all references to it.
  • Move TransactionSuppliers and anything else needed by the monitor into the monitor module
  • Add unit tests for the TransactionSuppliers

Related issue(s):

Fixes #2312

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Ian Jungmann added 5 commits August 9, 2021 09:40
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@ijungmann ijungmann self-assigned this Aug 10, 2021
@ijungmann ijungmann added monitor Area: Monitoring and dashboard P3 labels Aug 10, 2021
@ijungmann ijungmann added this to the Mirror 0.39.0 milestone Aug 10, 2021
class AccountCreateTransactionSupplierTest extends AbstractTransactionSupplierTest {

@Test
void createWithMinimumData() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should probably be Minimal, no Minimum

@codecov
Copy link

codecov bot commented Aug 10, 2021

Codecov Report

Merging #2387 (b5c7073) into main (922abc5) will increase coverage by 6.27%.
The diff coverage is 97.22%.

❗ Current head b5c7073 differs from pull request most recent head 91c311e. Consider uploading reports for the commit 91c311e to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##               main    #2387      +/-   ##
============================================
+ Coverage     84.42%   90.69%   +6.27%     
- Complexity     2335     2424      +89     
============================================
  Files           440      419      -21     
  Lines         12018    11578     -440     
  Branches       1024     1009      -15     
============================================
+ Hits          10146    10501     +355     
+ Misses         1554      745     -809     
- Partials        318      332      +14     
Impacted Files Coverage Δ
...or/monitor/expression/ExpressionConverterImpl.java 94.80% <ø> (ø)
...r/properties/ScenarioPropertiesAggregatorImpl.java 100.00% <ø> (ø)
.../hedera/mirror/monitor/publish/PublishMetrics.java 85.36% <ø> (ø)
...ror/monitor/publish/PublishScenarioProperties.java 94.11% <ø> (ø)
...sh/generator/ConfigurableTransactionGenerator.java 100.00% <ø> (ø)
...r/monitor/publish/transaction/TransactionType.java 100.00% <ø> (ø)
...tion/account/AccountCreateTransactionSupplier.java 68.18% <ø> (ø)
...tion/account/AccountDeleteTransactionSupplier.java 63.63% <ø> (ø)
...tion/account/AccountUpdateTransactionSupplier.java 77.27% <ø> (ø)
...ensus/ConsensusCreateTopicTransactionSupplier.java 78.94% <ø> (ø)
... and 46 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 922abc5...91c311e. Read the comment docs.

Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@ijungmann ijungmann requested a review from a team August 10, 2021 16:53
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@ijungmann
Copy link
Contributor Author

Will address code smells

Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@steven-sheehy
Copy link
Member

Merging #2387 (88d4072) into main (10cbbb0) will increase coverage by 7.44%.

92% coverage now. Nice!

@ijungmann
Copy link
Contributor Author

Merging #2387 (88d4072) into main (10cbbb0) will increase coverage by 7.44%.

92% coverage now. Nice!

Yeah! Much nicer number.

@steven-sheehy steven-sheehy added the enhancement Type: New feature label Aug 10, 2021
Copy link
Contributor

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Seems there were merge issue with copyrights details.

* ‌
* Hedera Mirror Node
* ​
* Copyright (C) 2019 - 2021 Hedera Hashgraph, LLC
* Copyright (C) 2019 - 2020 Hedera Hashgraph, LLC
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix year

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I've removed the setup I had to add this automatically as it had all sorts of issues so this doesn't crop up again.

* ‌
* Hedera Mirror Node
* ​
* Copyright (C) 2019 - 2020 Hedera Hashgraph, LLC
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy right repeated. Should also be 2021

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 46 to 58
AccountCreateTransaction expected = new AccountCreateTransaction()
.setAccountMemo(actual.getAccountMemo())
.setInitialBalance(ONE_TINYBAR)
.setKey(key)
.setMaxTransactionFee(ONE_TINYBAR)
.setReceiverSignatureRequired(true)
.setTransactionMemo(actual.getTransactionMemo());

assertAll(
() -> assertThat(actual.getTransactionMemo()).contains("Mirror node created test account"),
() -> assertThat(actual.getAccountMemo()).contains("Mirror node created test account"),
() -> assertThat(actual).usingRecursiveComparison().isEqualTo(expected)
);
Copy link
Member

Choose a reason for hiding this comment

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

I don't like creating a temporary object just do do equality on it. I'm also not a fan of assertAll. It would be simpler to do a single chaining assert to verify results:

assertThat(actual)
    .returns(key, AccountCreateTransaction::getKey)
    .returns(ONE_TINYBAR, AccountCreateTransaction::getMaxTransactionFee)
...

You can chain non-equality assertions like contains using satisfies(a -> assertThat(a.get...()) or using extracting() at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing I like about creating the temporary object and doing equality on it is it forces someone to set every field, it protects against future fields or some of the fields that aren't as explicit (like setting adminKey in a supplier also gets used for submitKey, freezeKey, etc.). The other thing I'm running into as I've tried to convert over, TokenNftTransfer is not a public class so I don't know of a great way to go field-by-field for that.

I do see the value in the chaining you mentioned, that can be done.

Copy link
Member

@steven-sheehy steven-sheehy Aug 11, 2021

Choose a reason for hiding this comment

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

That logic makes sense in general, but these SDK objects are quite complex and I'm not sure we want to rely on their internals being stable. They don't implement equals()/hashCode() to provide proper equality and they contain a lot of internal, non-settable fields like proto builders, node account IDs, signed transactions, signatures, etc. that should not be compared.

I don't think we're trying to validate quite to the level of every field. My intent with the ticket was just to test that the few fields we set are getting passed through. Validating everything might become brittle as the SDK changes things internally.

I've opened hashgraph/hedera-sdk-java#603 to address the TokenNftTransfer issue. If you see such minor issues with the SDK you can always just submit a PR to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fair, I did have a to do something different with ScheduleCreate for that reason, too many internal fields that I could not get a hold of to even set the expected and all of the extra fields you mentioned. I'll work on swapping things over to just checking fields and will keep an eye out for other bugs.

Copy link
Member

Choose a reason for hiding this comment

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

2.0.11 of sdk was released with my fix for public class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworked the tests to use the chaining suggested.

Ian Jungmann added 5 commits August 10, 2021 18:25
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
.satisfies(a -> assertThat(a.getAccountMemo()).contains("Mirror node created test account"))
.satisfies(a -> assertThat(a.getKey()).isNotNull())
.satisfies(a -> assertThat(a.getTransactionMemo()).contains("Mirror node created test account"))
.satisfies(a -> assertThat(a).usingRecursiveComparison().isEqualTo(expected));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.satisfies(a -> assertThat(a).usingRecursiveComparison().isEqualTo(expected));
.usingRecursiveComparison()
.isEqualTo(expected));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this line.

Ian Jungmann added 5 commits August 17, 2021 16:28
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Ian Jungmann added 2 commits August 18, 2021 10:38
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@sonarcloud
Copy link

sonarcloud bot commented Aug 18, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.8% 0.8% Duplication

Comment on lines +79 to +82
.extracting(TokenMintTransaction::getMetadata)
.returns(2, List::size)
.returns(14, metadataList -> metadataList.get(0).length)
.returns(14, metadataList -> metadataList.get(1).length);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haven't found a good chain to check this yet, if I cast it to a list in the extracting it won't let me use returns, which then I didn't see a great way to extract the length of each the byte array cleanly. Suggestions are welcome, this is the only test that hasn't been refactored.

Comment on lines -70 to -71
.setAutoRenewPeriod(autoRenewPeriod)
.setExpirationTime(expirationTime)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

expirationTime is coerced by the autoRenewPeriod, if setExpirationTime is called it also sets autoRenewPeriod to null, so setting both does nothing. I'll have a separate PR to address this in a couple other spots I saw in other modules.

Copy link
Member

@steven-sheehy steven-sheehy left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@xin-hedera xin-hedera left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

LGTM

@ijungmann ijungmann merged commit dc8570c into main Aug 18, 2021
@ijungmann ijungmann deleted the remove_data_generator branch August 18, 2021 20:21
steven-sheehy added a commit that referenced this pull request Aug 23, 2021
* Remove data generator (#2387)

* Remove the data generator module and all references to it.
* Move TransactionSuppliers and anything else needed by the monitor into the monitor module
* Add unit tests for the TransactionSuppliers

Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>

* Fix startDate logic on empty DB (#2421)

* Fix startDate logic on empty DB

The current MirrorDateRangePropertiesProcessor.newDateRangeFilter() currently doesn't honor the startDate set on an empty db

- Update newDateRangeFilter() logic to handle case when there's no lastFileInstant
- Add a test case to verify scenario

Signed-off-by: Nana-EC <nana.essilfie-conduah@hedera.com>

* Remove transactionMemo from TransactionSupplier and expirationTime from TokenClient (#2423)

* Remove setting transactionMemo in TransactionSuppliers
* Remove setting expirationTime in TokenClient

Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>

* Fix rest service startup crash (#2425)

- replace the one-time verifyDbConnection with on-demand transaction result & type loading

Signed-off-by: Xin Li <xin.li@hedera.com>

* Add missing token account association migration (#2424)

- add a db migration script to add the missing token account associations

Signed-off-by: Xin Li <xin.li@hedera.com>

Co-authored-by: Ian Jungmann <ian.jungmann@hedera.com>
Co-authored-by: Nana-EC <56320167+Nana-EC@users.noreply.github.com>
Co-authored-by: Xin Li <59580070+xin-hedera@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature monitor Area: Monitoring and dashboard P3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove data generator module
4 participants