Skip to content

Commit

Permalink
Resolve sonar issues on master (#2685)
Browse files Browse the repository at this point in the history
* resolve few sonar issues

* fix more sonar issues

* fix more sonar issues

* resolve more sonar issues

* resolve more sonar issues

* resolve more sonar issues

* fix code smell

* resolve sonar

* address review comments

* optimize imports

* address review comments

* address review comments

* address review comments

* address review comments

* resolve sonar issues
  • Loading branch information
Neeharika-Sompalli authored Jan 24, 2022
1 parent 0820daa commit da7cdb9
Show file tree
Hide file tree
Showing 160 changed files with 2,157 additions and 2,007 deletions.
12 changes: 10 additions & 2 deletions hapi-fees/src/main/java/com/hedera/services/usage/TxnUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

public abstract class TxnUsage {
protected static final int AMOUNT_REPR_BYTES = 8;

public static EstimatorFactory estimatorFactory = TxnUsageEstimator::new;
protected static EstimatorFactory estimatorFactory = TxnUsageEstimator::new;
protected static final UsageProperties usageProperties = USAGE_PROPERTIES;

protected final TransactionBody op;
Expand Down Expand Up @@ -63,4 +62,13 @@ protected void addNetworkRecordRb(long rb) {
protected void addRecordRb(long rb) {
usageEstimator.addRbs(rb * usageProperties.legacyReceiptStorageSecs());
}

/* Used only for unit tests */
public static EstimatorFactory getEstimatorFactory() {
return estimatorFactory;
}

public static void setEstimatorFactory(final EstimatorFactory estimatorFactory) {
TxnUsage.estimatorFactory = estimatorFactory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -31,7 +31,13 @@ public class TxnUsageEstimator {
private final TransactionBody txn;
private final EstimatorUtils utils;

private long bpt, vpt, rbs, sbs, gas, tv, networkRbs;
private long bpt;
private long vpt;
private long rbs;
private long sbs;
private long gas;
private long tv;
private long networkRbs;

public TxnUsageEstimator(SigUsage sigUsage, TransactionBody txn, EstimatorUtils utils) {
this.txn = txn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class CryptoOpsUsage {

@Inject
public CryptoOpsUsage() {
// Default constructor
}

public void cryptoTransferUsage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static int bytesInBaseRepr() {

@Inject
public FileOpsUsage() {
// Default constructor
}

public void fileAppendUsage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ScheduleOpsUsage {

@Inject
public ScheduleOpsUsage() {
// Default constructor
}

public FeeData scheduleInfoUsage(Query scheduleInfo, ExtantScheduleContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,23 @@ void buildsAsExpected() {

@Test
void requiresAllFieldsSet() {
final var numSigners = builderWith(EnumSet.complementOf(EnumSet.of(NUM_SIGNERS)));
final var adminAndNoAdmin = builderWith(EnumSet.complementOf(
EnumSet.of(SettableField.ADMIN_KEY, NO_ADMIN_KEY)));
final var memo = builderWith(EnumSet.of(SettableField.MEMO));
final var scheduleTxn = builderWith(EnumSet.complementOf(EnumSet.of(SettableField.SCHEDULED_TXN)));
final var isResolved = builderWith(EnumSet.complementOf(EnumSet.of(SettableField.IS_RESOLVED)));
// expect:
Assertions.assertThrows(IllegalStateException.class,
() -> builderWith(EnumSet.complementOf(EnumSet.of(NUM_SIGNERS))).build());
() -> numSigners.build());
Assertions.assertThrows(IllegalStateException.class,
() -> builderWith(EnumSet.complementOf(
EnumSet.of(SettableField.ADMIN_KEY, NO_ADMIN_KEY))).build());
() -> adminAndNoAdmin.build());
Assertions.assertThrows(IllegalStateException.class,
() -> builderWith(EnumSet.of(SettableField.MEMO)).build());
() -> memo.build());
Assertions.assertThrows(IllegalStateException.class,
() -> builderWith(EnumSet.complementOf(EnumSet.of(SettableField.SCHEDULED_TXN))).build());
() -> scheduleTxn.build());
Assertions.assertThrows(IllegalStateException.class,
() -> builderWith(EnumSet.complementOf(EnumSet.of(SettableField.IS_RESOLVED))).build());
() -> isResolved.build());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void setup() {
factory = mock(EstimatorFactory.class);
given(factory.get(any(), any(), any())).willReturn(base);

TxnUsage.estimatorFactory = factory;
TxnUsage.setEstimatorFactory(factory);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void setUp() throws Exception {
factory = mock(EstimatorFactory.class);
given(factory.get(any(), any(), any())).willReturn(base);

TxnUsage.estimatorFactory = factory;
TxnUsage.setEstimatorFactory(factory);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void setUp() throws Exception {
factory = mock(EstimatorFactory.class);
given(factory.get(any(), any(), any())).willReturn(base);

TxnUsage.estimatorFactory = factory;
TxnUsage.setEstimatorFactory(factory);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void setup() {
factory = mock(EstimatorFactory.class);
given(factory.get(any(), any(), any())).willReturn(base);

TxnUsage.estimatorFactory = factory;
TxnUsage.setEstimatorFactory(factory);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void setUp() throws Exception {
factory = mock(EstimatorFactory.class);
given(factory.get(any(), any(), any())).willReturn(base);

TxnUsage.estimatorFactory = factory;
TxnUsage.setEstimatorFactory(factory);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void setUp() throws Exception {
factory = mock(EstimatorFactory.class);
given(factory.get(any(), any(), any())).willReturn(base);

TxnUsage.estimatorFactory = factory;
TxnUsage.setEstimatorFactory(factory);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ void setUp() throws Exception {
factory = mock(EstimatorFactory.class);
given(factory.get(any(), any(), any())).willReturn(base);

TxnUsage.estimatorFactory = factory;
TxnUsage.setEstimatorFactory(factory);
}

@Test
void gettersWork() {
assertEquals(TxnUsage.getEstimatorFactory(), factory);
}

@Test
Expand Down
Loading

0 comments on commit da7cdb9

Please sign in to comment.