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

Fix sonar issues #9979

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
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
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 @@ -71,6 +71,7 @@ void setup() throws Exception {

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

@SuppressWarnings("unused") // 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 All @@ -28,6 +29,7 @@
import java.time.Duration;
import java.util.Properties;
import java.util.concurrent.ForkJoinPool;
import lombok.SneakyThrows;
import org.gaul.s3proxy.S3Proxy;
import org.gaul.shaded.org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.jclouds.ContextBuilder;
Expand All @@ -46,7 +48,7 @@ class S3StreamFileProviderTest extends AbstractStreamFileProviderTest {

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

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

@BeforeEach
@Override
void setup() throws Exception {
super.setup();
var s3AsyncClient = S3AsyncClient.builder()
Expand All @@ -75,7 +78,8 @@ protected FileCopier createFileCopier(Path dataPath) {
.to(properties.getBucketName(), StreamType.RECORD.getPath());
}

private void startS3Proxy() throws Exception {
@SneakyThrows
private void startS3Proxy() {
Properties properties = new Properties();
properties.setProperty(
"jclouds.filesystem.basedir", dataPath.toAbsolutePath().toString());
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,7 @@ void migrate() {
assertThat(findHistory("token", PostMigrationToken.class)).containsExactlyInAnyOrderElementsOf(expectedHistory);
}

@SuppressWarnings("java:S1854") // timestamp is needed in order to avoid repetition
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
1 change: 0 additions & 1 deletion hedera-mirror-web3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ plugins {
// We need to use this version in order to be able to decode hex data when using the hedera.app
// dependency
val headlongVersion = "6.1.1"
val javaxInjectVersion = "1"

dependencies {
implementation(platform("org.springframework.cloud:spring-cloud-dependencies"))
Expand Down
2 changes: 2 additions & 0 deletions hedera-mirror-web3/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Exclude a package and its child packages
sonar.exclusions=src/main/java/com/hedera/services/**
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