Skip to content

Commit

Permalink
Fix sonar issues
Browse files Browse the repository at this point in the history
Signed-off-by: sdimitrov9 <[email protected]>
  • Loading branch information
sdimitrov9 committed Dec 18, 2024
1 parent 26878b7 commit a0c5411
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ByteArrayToHexSerializer extends JsonSerializer<byte[]> {
public static final ByteArrayToHexSerializer INSTANCE = new ByteArrayToHexSerializer();
static final String PREFIX = "\\x";

private ByteArrayToHexSerializer() {}

@Override
public void serialize(byte[] value, JsonGenerator jsonGenerator, SerializerProvider serializers)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package com.hedera.mirror.importer.domain;

import static com.hedera.mirror.importer.reader.signature.ProtoSignatureFileReader.VERSION;

import com.hedera.mirror.common.domain.StreamType;
import com.hedera.mirror.common.util.DomainUtils;
import com.hedera.mirror.importer.addressbook.ConsensusNode;
import com.hedera.mirror.importer.reader.signature.ProtoSignatureFileReader;
import java.util.Comparator;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -87,7 +88,7 @@ public String getMetadataHashAsHex() {
}

private boolean hasCompressedDataFile() {
return version >= ProtoSignatureFileReader.VERSION || filename.isCompressed();
return version >= VERSION || filename.isCompressed();
}

public enum SignatureStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Collection of fields that can be used by Transaction Filter to filter on.
*/
@Value
@SuppressWarnings("java:S6548") // Class is not a singleton
public class TransactionFilterFields {
public static final TransactionFilterFields EMPTY = new TransactionFilterFields(Set.of(), null);
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ abstract class AbstractStreamFileProviderTest {
protected StreamFileProvider streamFileProvider;

@BeforeEach
@SuppressWarnings("java:S1130") // Exception is thrown in the child classes setup method
void setup() throws Exception {
var mirrorProperties = new ImporterProperties();
mirrorProperties.setDataPath(dataPath);
Expand All @@ -71,6 +72,7 @@ void setup() throws Exception {

protected abstract String resolveProviderRelativePath(ConsensusNode node, String fileName);

@SuppressWarnings("java:S1172") // node is used in the child classes implementations
protected FileCopier getFileCopier(ConsensusNode node) {
return fileCopier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hedera.mirror.importer.downloader.provider;

import static com.hedera.mirror.importer.downloader.provider.S3StreamFileProvider.SEPARATOR;
import static org.awaitility.Awaitility.await;
import static software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR;

Expand Down Expand Up @@ -46,7 +47,7 @@ class S3StreamFileProviderTest extends AbstractStreamFileProviderTest {

@Override
protected String getProviderPathSeparator() {
return S3StreamFileProvider.SEPARATOR;
return SEPARATOR;
}

@Override
Expand All @@ -55,6 +56,7 @@ protected String resolveProviderRelativePath(ConsensusNode node, String fileName
}

@BeforeEach
@Override
void setup() throws Exception {
super.setup();
var s3AsyncClient = S3AsyncClient.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,22 +394,25 @@ private void setEntityTablesPreV_1_36() {
jdbcOperations.execute("drop table if exists entity cascade;");

// add t_entities if not present
jdbcOperations.execute("create table if not exists t_entities" + "(\n"
+ " entity_num bigint not null,\n"
+ " entity_realm bigint not null,\n"
+ " entity_shard bigint not null,\n"
+ " fk_entity_type_id integer not null,\n"
+ " auto_renew_period bigint,\n"
+ " key bytea,\n"
+ " deleted boolean default false,\n"
+ " exp_time_ns bigint,\n"
+ " ed25519_public_key_hex character varying,\n"
+ " submit_key bytea,\n"
+ " memo text,\n"
+ " auto_renew_account_id bigint,\n"
+ " id bigint not null,\n"
+ " proxy_account_id bigint"
+ ");");
jdbcOperations.execute(
"""
create table if not exists t_entities (
entity_num bigint not null,
entity_realm bigint not null,
entity_shard bigint not null,
fk_entity_type_id integer not null,
auto_renew_period bigint,
key bytea,
deleted boolean default false,
exp_time_ns bigint,
ed25519_public_key_hex character varying,
submit_key bytea,
memo text,
auto_renew_account_id bigint,
id bigint not null,
proxy_account_id bigint
);
""");
}

private int getTEntitiesCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,18 @@ private void runMigration() {
jdbcTemplate.update(FileUtils.readFileToString(migrationSql, "UTF-8"));
}

@SuppressWarnings("java:S1854") // No useless assignments in the method, since they help avoiding code repetition
private MigrationTokenAccount update(
MigrationTokenAccount current, Consumer<MigrationTokenAccount.MigrationTokenAccountBuilder> customizer) {
var nextBuilder = current.toBuilder();
customizer.accept(nextBuilder);
var next = nextBuilder.build();
next.setModifiedTimestamp(current.getModifiedTimestamp() + 100);
if (next.getCreatedTimestamp() == -1) {
var accountBuilder = current.toBuilder();
customizer.accept(accountBuilder);
MigrationTokenAccount account = accountBuilder.build();
account.setModifiedTimestamp(current.getModifiedTimestamp() + 100);
if (account.getCreatedTimestamp() == -1) {
// start a new token account relationship
next.setCreatedTimestamp(next.getModifiedTimestamp());
account.setCreatedTimestamp(account.getModifiedTimestamp());
}
return next;
return account;
}

@Builder(toBuilder = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ void migrate() {
assertThat(findHistory("token", PostMigrationToken.class)).containsExactlyInAnyOrderElementsOf(expectedHistory);
}

@SuppressWarnings(
"java:S1854") // timestamp variable is necessary in order to avoid repetition and to make code easier to
// read
private MigrationToken.MigrationTokenBuilder getMigrationToken() {
long timestamp = domainBuilder.timestamp();
return MigrationToken.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ void fileUpdateExpiryToExisting() {
Entity actualFile = getTransactionEntity(txnRecord.getConsensusTimestamp());

assertAll(
// TODO: Review row count of fileDataRepository with issue #294, probably should be 1
this::assertRowCountOnTwoFileTransactions,
() -> assertTransactionAndRecord(transactionBody, txnRecord),
// Additional entity checks
Expand Down Expand Up @@ -534,7 +533,6 @@ void fileUpdateExpiryToNew() {
Entity actualFile = getTransactionEntity(txnRecord.getConsensusTimestamp());

assertAll(
// TODO: Review row count in fileDataRepository with issue #294, probably should be 0
() -> assertRowCountOnSuccess(FILE_ID),
() -> assertTransactionAndRecord(transactionBody, txnRecord),
// Additional entity checks
Expand Down Expand Up @@ -574,7 +572,6 @@ void fileUpdateKeysToExisting() {
Entity dbFileEntity = getTransactionEntity(txnRecord.getConsensusTimestamp());

assertAll(
// TODO: Review row count of fileDataRepository with issue #294, probably should be 1
this::assertRowCountOnTwoFileTransactions,
() -> assertTransactionAndRecord(transactionBody, txnRecord),
// Additional entity checks
Expand All @@ -600,7 +597,6 @@ void fileUpdateKeysToNew() {
Entity dbFileEntity = getTransactionEntity(txnRecord.getConsensusTimestamp());

assertAll(
// TODO: Review row count in fileDataRepository with issue #294, probably should be 0
() -> assertRowCountOnSuccess(FILE_ID),
() -> assertTransactionAndRecord(transactionBody, txnRecord),
// Additional entity checks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public void verifyMirrorAPIAccountResponses(int status) {
verifyMirrorTransactionsResponse(mirrorClient, status);
}

@Then("the mirror node REST API should verify the deployed contract entity")
public void verifyDeployedContractMirror() {
@Then("the mirror node REST API should verify the contract")
public void verifyContract() {
verifyContractFromMirror(false);
verifyContractExecutionResultsById();
verifyContractExecutionResultsByTransactionId();
Expand All @@ -144,13 +144,6 @@ public void verifyUpdatedContractMirror() {
verifyContractFromMirror(false);
}

@Then("the mirror node REST API should verify the called contract function")
public void verifyContractFunctionCallMirror() {
verifyContractFromMirror(false);
verifyContractExecutionResultsById();
verifyContractExecutionResultsByTransactionId();
}

@Then("I call the contract via the mirror node REST API")
public void restContractCall() {
if (!web3Properties.isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Contract Base Coverage Feature

Given I successfully create a contract from the parent contract bytes with 10000000 balance
Then the mirror node REST API should return status <httpStatusCode> for the contract transaction
And the mirror node REST API should verify the deployed contract entity
And the mirror node REST API should verify the contract
When I successfully update the contract
Then the mirror node REST API should return status <httpStatusCode> for the contract transaction
And the mirror node REST API should verify the updated contract entity
Expand Down
2 changes: 0 additions & 2 deletions hedera-mirror-web3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ plugins {
id("spring-conventions")
}

val javaxInjectVersion = "1"

dependencies {
implementation(platform("org.springframework.cloud:spring-cloud-dependencies"))
implementation(project(":common"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/**
* Exact copy from hedera-services
*/
@SuppressWarnings("squid:S6548") // enum soon to be deleted with the introduction of reusable services
public enum TokenEntitySizes {
TOKEN_ENTITY_SIZES;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,39 +181,6 @@ void considersPayerAsOwnerIfNotMentioned() {
assertEquals(1, updatedAccount.getApproveForAllNfts().size());
}

@Test
void wipesSerialsWhenApprovedForAll() {
givenValidTxnCtx();

given(store.getAccount(payerAccount.getAccountAddress(), OnMissing.THROW))
.willReturn(payerAccount);
given(store.loadAccountOrFailWith(ownerAccount.getAccountAddress(), INVALID_ALLOWANCE_OWNER_ID))
.willReturn(ownerAccount);
given(store.getUniqueToken(
new NftId(TOKEN_ID_2.shard(), TOKEN_ID_2.realm(), TOKEN_ID_2.num(), SERIAL_1), OnMissing.THROW))
.willReturn(nft1);
given(store.getUniqueToken(
new NftId(TOKEN_ID_2.shard(), TOKEN_ID_2.realm(), TOKEN_ID_2.num(), SERIAL_2), OnMissing.THROW))
.willReturn(nft2);

final var accountsChanged = new TreeMap<Long, Account>();
subject.approveAllowance(
store,
accountsChanged,
new TreeMap<>(),
op.getCryptoAllowancesList(),
op.getTokenAllowancesList(),
op.getNftAllowancesList(),
fromGrpcAccount(PAYER_ID).asGrpcAccount());

final var updatedAccount = accountsChanged.get(ownerAccount.getId().num());
assertEquals(1, updatedAccount.getCryptoAllowances().size());
assertEquals(1, updatedAccount.getFungibleTokenAllowances().size());
assertEquals(1, updatedAccount.getApproveForAllNfts().size());

verify(store).updateAccount(updatedAccount);
}

@Test
void emptyAllowancesInStateTransitionWorks() {
cryptoApproveAllowanceTxn = TransactionBody.newBuilder()
Expand Down

0 comments on commit a0c5411

Please sign in to comment.