Coverage Summary for Class: TxValidatorIntrinsicGasLimitValidator (co.rsk.net.handler.txvalidator)

Class Class, % Method, % Line, %
TxValidatorIntrinsicGasLimitValidator 100% (1/1) 100% (2/2) 85.7% (6/7)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * 5  * This program is free software: you can redistribute it and/or modify 6  * it under the terms of the GNU Lesser General Public License as published by 7  * the Free Software Foundation, either version 3 of the License, or 8  * (at your option) any later version. 9  * 10  * This program is distributed in the hope that it will be useful, 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  * GNU Lesser General Public License for more details. 14  * 15  * You should have received a copy of the GNU Lesser General Public License 16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 17  */ 18  19 package co.rsk.net.handler.txvalidator; 20  21 import co.rsk.core.Coin; 22 import co.rsk.net.TransactionValidationResult; 23 import org.ethereum.config.Constants; 24 import org.ethereum.config.blockchain.upgrades.ActivationConfig; 25 import org.ethereum.core.*; 26  27 import javax.annotation.Nullable; 28 import java.math.BigInteger; 29  30 /** 31  * Checks if a minimum gas limit estimated based on the data is lower than 32  * the gas limit of the transaction 33  */ 34 public class TxValidatorIntrinsicGasLimitValidator implements TxValidatorStep { 35  36  private final Constants constants; 37  private final ActivationConfig activationConfig; 38  39  public TxValidatorIntrinsicGasLimitValidator(Constants constants, ActivationConfig activationConfig) { 40  this.constants = constants; 41  this.activationConfig = activationConfig; 42  } 43  44  @Override 45  public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx) { 46  if (BigInteger.valueOf(tx.transactionCost(constants, activationConfig.forBlock(bestBlockNumber))).compareTo(tx.getGasLimitAsInteger()) <= 0) { 47  return TransactionValidationResult.ok(); 48  } 49  50  return TransactionValidationResult.withError("transaction's basic cost is above the gas limit"); 51  } 52  53 }