Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: vaidikcode <[email protected]>
  • Loading branch information
vaidikcode committed Nov 28, 2024
1 parent aae1526 commit 2509d7d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hyperledger.besu.plugin.services.PermissioningService;
import org.hyperledger.besu.plugin.services.PicoCLIOptions;


import com.google.auto.service.AutoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -76,6 +77,25 @@ public void beforeExternalServices() {
}
return true;
});

service.registerTransactionPermissioningProvider(
(provider) -> {
long configuredGasLimitThreshold = 12000L;

long gasLimit = provider.getGasLimit();

LOG.info("Transaction gas limit: {} | Configured threshold: {}", gasLimit, configuredGasLimitThreshold);

if (gasLimit > configuredGasLimitThreshold) {
LOG.debug("Transaction gas limit {} exceeds threshold. Allowing transaction.", gasLimit);
return true;
}

LOG.debug("Transaction gas limit {} below threshold. Rejecting transaction.", gasLimit);
return false;
}
);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class PermissioningPluginTest extends AcceptanceTestBase {
private BesuNode minerNode;

private BesuNode aliceNode;
private BesuNode bobNode;
private BesuNode charlieNode;

private static final long GAS_LIMIT_THRESHOLD = 12000L;

@BeforeEach
public void setUp() throws Exception {
minerNode = besu.create(createNodeBuilder().name("miner").build());
Expand Down Expand Up @@ -96,4 +100,20 @@ public void transactionsAreNotSendToBlockPendingTransactionsNode() {
charlieNode.verify(txPoolConditions.notInTransactionPool(txHash));
minerNode.verify(txPoolConditions.inTransactionPool(txHash));
}

@Test
public void testGasLimitLogic() {
final long transactionGasLimit = 10000L;
boolean isTransactionPermitted = checkTransactionGasLimit(transactionGasLimit);

assertThat(isTransactionPermitted).isTrue();
}

private boolean checkTransactionGasLimit(long gasLimit) {
if (gasLimit > GAS_LIMIT_THRESHOLD) {
return true;
} else {
return false;
}
}
}

0 comments on commit 2509d7d

Please sign in to comment.