Skip to content

Commit

Permalink
test: Increase code coverage in CryptoGetAccountRecordsHandler (#17411
Browse files Browse the repository at this point in the history
)

Signed-off-by: Petar Tonev <[email protected]>
  • Loading branch information
petreze authored Jan 28, 2025
1 parent 8739c66 commit 862ec2b
Showing 1 changed file with 34 additions and 1 deletion.
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

0 comments on commit 862ec2b

Please sign in to comment.