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

test: Increase code coverage in CryptoGetAccountRecordsHandler #17411

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down