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

Make testEnv implement Autoclosable Interface, replace occurrences #2023

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

steffenboe
Copy link
Contributor

@steffenboe steffenboe commented Oct 4, 2024

Description:
Makes IntegrationTestEnv implement Autoclosable and replaces occurrences in tests with try-with-resources-block.

Related issue(s):

Fixes #
#1975

Notes for reviewer:

Checklist

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

@steffenboe steffenboe requested a review from a team as a code owner October 4, 2024 06:41
@steffenboe steffenboe changed the title Make testEnv implement Autoclosable Interface, replace occurrences WIP: Make testEnv implement Autoclosable Interface, replace occurrences Oct 4, 2024
@steffenboe
Copy link
Contributor Author

need to take a look at the indentation changes yet, so i switched this PR to WIP

@steffenboe steffenboe changed the title WIP: Make testEnv implement Autoclosable Interface, replace occurrences Make testEnv implement Autoclosable Interface, replace occurrences Oct 4, 2024
@steffenboe
Copy link
Contributor Author

ready for review!

Copy link
Contributor

@0xivanov 0xivanov left a comment

Choose a reason for hiding this comment

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

Hey, nice work!
DCO check is failing because the commits are not signed off. Please check out https://github.com/hashgraph/.github/blob/main/CONTRIBUTING.md and see how to set up your GPG keys.
When you've setup the keys you can rebase your commits while signing them.
https://github.com/hashgraph/hedera-sdk-java/pull/2023/checks?check_run_id=31080572033

Signed-off-by: steffenboe <[email protected]>

check tab indentation fix

Signed-off-by: steffenboe <[email protected]>

check tab indentation fix, 2nd try

Signed-off-by: steffenboe <[email protected]>

check tab indentation fix, 3rd try

Signed-off-by: steffenboe <[email protected]>

check tab indentation fix, 4th try

Signed-off-by: steffenboe <[email protected]>

Fix intendation

Fix indentation
Copy link
Contributor

@0xivanov 0xivanov left a comment

Choose a reason for hiding this comment

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

Looks good, there are some usages missing thought, like in TokenGrantKycIntegrationTest and TransactionResponseTest

@steffenboe
Copy link
Contributor Author

you're correct, and these tests aren't the only ones where a replacement is not possible. this is because the close()-method gets called with parameters there. this is not conforming to the Autoclosable interface, and so these occurrences can't be replaced with a try-with-resources block.

@0xivanov
Copy link
Contributor

0xivanov commented Oct 9, 2024

@steffenboe You are right, I had forgotten about that! I was actually thinking a while back to rework the close method to not have overloads and remove the wiping logic wipeAccountHbars(newAccountId, newAccountKey); . This additional logic is making the github action slow and we don't need it since the operator we are using in the local-node has 10k HBARs which should be enough.

Would you like to rework the close method to look something like this? :

    public void close() throws Exception {
        if (!operatorId.equals(originalClient.getOperatorAccountId())) {
            var hbarsBalance = new AccountBalanceQuery()
                .setAccountId(operatorId)
                .execute(originalClient)
                .hbars;
            new TransferTransaction()
                .addHbarTransfer(operatorId, hbarsBalance.negated())
                .addHbarTransfer(Objects.requireNonNull(originalClient.getOperatorAccountId()), hbarsBalance)
                .freezeWith(originalClient)
                .signWithOperator(client)
                .execute(originalClient);
            client.close();
        }

        originalClient.close();
    }

And then you could finish the rest of the tests to use try-with-resources.

@steffenboe
Copy link
Contributor Author

Sounds good! Will work on that ;)

Copy link
Contributor

@0xivanov 0xivanov left a comment

Choose a reason for hiding this comment

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

LGTM, TY @steffenboe

@0xivanov 0xivanov merged commit edf21e0 into hashgraph:main Oct 10, 2024
7 checks passed
logickoder pushed a commit to logickoder/hedera-sdk-java that referenced this pull request Oct 10, 2024
…ashgraph#2023)

Signed-off-by: steffenboe <[email protected]>
Co-authored-by: Ivan Ivanov <[email protected]>
Signed-off-by: Jeffery Orazulike <[email protected]>
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.

2 participants