From ee12f9d0c1387c84e64b07deeb3db259b91f5a19 Mon Sep 17 00:00:00 2001 From: Petar Tonev Date: Thu, 16 Jan 2025 16:08:43 +0200 Subject: [PATCH] increase codecoverage in CryptoGetAccountRecordsHandlerTest.java Signed-off-by: Petar Tonev --- .../CryptoGetAccountRecordsHandlerTest.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/CryptoGetAccountRecordsHandlerTest.java b/hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/CryptoGetAccountRecordsHandlerTest.java index 37e9adf3aabb..1c50414449e9 100644 --- a/hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/CryptoGetAccountRecordsHandlerTest.java +++ b/hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/CryptoGetAccountRecordsHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Hedera Hashgraph, LLC + * Copyright (C) 2023-2025 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,12 @@ import static com.hedera.hapi.node.base.ResponseType.ANSWER_STATE_PROOF; import static com.hedera.hapi.node.base.ResponseType.COST_ANSWER; import static com.hedera.node.app.spi.fixtures.workflows.ExceptionConditions.responseCode; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mock.Strictness.LENIENT; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.base.QueryHeader; @@ -43,6 +46,9 @@ import com.hedera.node.app.service.token.impl.handlers.BaseCryptoHandler; import com.hedera.node.app.service.token.impl.handlers.CryptoGetAccountRecordsHandler; import com.hedera.node.app.service.token.impl.test.handlers.util.CryptoHandlerTestBase; +import com.hedera.node.app.spi.fees.FeeCalculator; +import com.hedera.node.app.spi.fees.Fees; +import com.hedera.node.app.spi.fixtures.fees.FakeFeeCalculator; import com.hedera.node.app.spi.records.RecordCache; import com.hedera.node.app.spi.workflows.PreCheckException; import com.hedera.node.app.spi.workflows.QueryContext; @@ -55,6 +61,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -263,6 +270,32 @@ void findResponseForCostOnly() { Assertions.assertThat(result.cryptoGetAccountRecords().records()).isEmpty(); } + @Test + void verifyFeeComputation() { + mockQueryContext(id, QueryHeader.newBuilder().responseType(COST_ANSWER).build()); + // setup the readable store + given(context.createStore(ReadableAccountStore.class)).willReturn(readableStore); + final ResponseHeader.Builder testHeaderBuilder = ResponseHeader.newBuilder(); + testHeaderBuilder.nodeTransactionPrecheckCode(ResponseCodeEnum.OK); + testHeaderBuilder.responseType(ResponseType.COST_ANSWER); + + final FeeCalculator feeSpy = Mockito.spy(new FakeFeeCalculator()); + given(context.feeCalculator()).willReturn(feeSpy); + + // validate a schedule that is present in state + given(context.query()) + .willReturn(Query.newBuilder() + .cryptoGetProxyStakers(CryptoGetStakersQuery.DEFAULT) + .cryptoGetAccountRecords(newAcctRecordsQuery(id).build()) + .build()); + Fees actual = subject.computeFees(context); + assertThat(actual.networkFee()).isEqualTo(0L); + assertThat(actual.nodeFee()).isEqualTo(0L); + assertThat(actual.serviceFee()).isEqualTo(0L); + assertThat(actual.totalFee()).isEqualTo(0L); + verify(feeSpy).legacyCalculate(any()); + } + @CsvSource({"ANSWER_ONLY", "COST_ANSWER_STATE_PROOF", "ANSWER_STATE_PROOF"}) @ParameterizedTest() void findResponseWithNonCostResponseTypes(String responseType) {