From 2509d7d0be6ebbf5313378aadb3b7673ba5073ee Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Thu, 28 Nov 2024 23:34:19 +0530 Subject: [PATCH] add tests Signed-off-by: vaidikcode --- .../plugins/TestPermissioningPlugin.java | 20 +++++++++++++++++++ .../plugins/PermissioningPluginTest.java | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java index b41bcbc4a5f..436dfedf051 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java @@ -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; @@ -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; + } + ); + } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java index c469802fc1e..03fbb64743f 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java @@ -27,6 +27,8 @@ 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; @@ -34,6 +36,8 @@ public class PermissioningPluginTest extends AcceptanceTestBase { 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()); @@ -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; + } + } }