diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/TransactionValidationParams.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/TransactionValidationParams.java index a550b4a308..3459a95f1a 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/TransactionValidationParams.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/TransactionValidationParams.java @@ -14,6 +14,16 @@ public class TransactionValidationParams { + private static final TransactionValidationParams processingBlockParams = + new TransactionValidationParams(false, true, false); + private static final TransactionValidationParams transactionPoolParams = + new TransactionValidationParams(true, false, true); + private static final TransactionValidationParams miningParams = + new TransactionValidationParams(false, true, true); + private static final TransactionValidationParams blockReplayParams = + new TransactionValidationParams(false, false, false); + private static final TransactionValidationParams transactionSimulatorParams = + new TransactionValidationParams(false, false, false); private final boolean allowFutureNonce; private final boolean checkOnchainPermissions; private final boolean checkLocalPermissions; @@ -40,43 +50,23 @@ public boolean checkLocalPermissions() { } public static TransactionValidationParams transactionSimulator() { - return new Builder() - .checkLocalPermissions(false) - .checkOnchainPermissions(false) - .allowFutureNonce(false) - .build(); + return transactionSimulatorParams; } public static TransactionValidationParams processingBlock() { - return new Builder() - .checkLocalPermissions(false) - .checkOnchainPermissions(true) - .allowFutureNonce(false) - .build(); + return processingBlockParams; } public static TransactionValidationParams transactionPool() { - return new Builder() - .checkLocalPermissions(true) - .checkOnchainPermissions(false) - .allowFutureNonce(true) - .build(); + return transactionPoolParams; } public static TransactionValidationParams mining() { - return new Builder() - .checkLocalPermissions(true) - .checkOnchainPermissions(true) - .allowFutureNonce(false) - .build(); + return miningParams; } public static TransactionValidationParams blockReplay() { - return new Builder() - .checkLocalPermissions(false) - .checkOnchainPermissions(false) - .allowFutureNonce(false) - .build(); + return blockReplayParams; } static class Builder { diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/TransactionValidationParamsTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/TransactionValidationParamsTest.java new file mode 100644 index 0000000000..49a49f6419 --- /dev/null +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/TransactionValidationParamsTest.java @@ -0,0 +1,108 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * 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. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.ethereum.mainnet; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class TransactionValidationParamsTest { + + @Test + public void isAllowFutureNonce() { + assertThat( + new TransactionValidationParams.Builder() + .allowFutureNonce(true) + .build() + .isAllowFutureNonce()) + .isTrue(); + assertThat( + new TransactionValidationParams.Builder() + .allowFutureNonce(false) + .build() + .isAllowFutureNonce()) + .isFalse(); + } + + @Test + public void checkOnchainPermissions() { + assertThat( + new TransactionValidationParams.Builder() + .checkOnchainPermissions(true) + .build() + .checkOnchainPermissions()) + .isTrue(); + assertThat( + new TransactionValidationParams.Builder() + .checkOnchainPermissions(false) + .build() + .checkOnchainPermissions()) + .isFalse(); + } + + @Test + public void checkLocalPermissions() { + assertThat( + new TransactionValidationParams.Builder() + .checkLocalPermissions(true) + .build() + .checkLocalPermissions()) + .isTrue(); + assertThat( + new TransactionValidationParams.Builder() + .checkLocalPermissions(false) + .build() + .checkLocalPermissions()) + .isFalse(); + } + + @Test + public void transactionSimulator() { + final TransactionValidationParams params = TransactionValidationParams.transactionSimulator(); + assertThat(params.isAllowFutureNonce()).isFalse(); + assertThat(params.checkOnchainPermissions()).isFalse(); + assertThat(params.checkLocalPermissions()).isFalse(); + } + + @Test + public void processingBlock() { + final TransactionValidationParams params = TransactionValidationParams.processingBlock(); + assertThat(params.isAllowFutureNonce()).isFalse(); + assertThat(params.checkOnchainPermissions()).isTrue(); + assertThat(params.checkLocalPermissions()).isFalse(); + } + + @Test + public void transactionPool() { + final TransactionValidationParams params = TransactionValidationParams.transactionPool(); + assertThat(params.isAllowFutureNonce()).isTrue(); + assertThat(params.checkOnchainPermissions()).isFalse(); + assertThat(params.checkLocalPermissions()).isTrue(); + } + + @Test + public void mining() { + final TransactionValidationParams params = TransactionValidationParams.mining(); + assertThat(params.isAllowFutureNonce()).isFalse(); + assertThat(params.checkOnchainPermissions()).isTrue(); + assertThat(params.checkLocalPermissions()).isTrue(); + } + + @Test + public void blockReplay() { + final TransactionValidationParams params = TransactionValidationParams.blockReplay(); + assertThat(params.isAllowFutureNonce()).isFalse(); + assertThat(params.checkOnchainPermissions()).isFalse(); + assertThat(params.checkLocalPermissions()).isFalse(); + } +}