use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class TxValidatorAccountBalanceValidatorTest method invalidAccountBalance.
@Test
public void invalidAccountBalance() {
Transaction tx1 = Mockito.mock(Transaction.class);
Transaction tx2 = Mockito.mock(Transaction.class);
AccountState as = Mockito.mock(AccountState.class);
Mockito.when(tx1.getGasLimitAsInteger()).thenReturn(BigInteger.valueOf(1));
Mockito.when(tx2.getGasLimitAsInteger()).thenReturn(BigInteger.valueOf(2));
Mockito.when(tx1.getGasPrice()).thenReturn(Coin.valueOf(20));
Mockito.when(tx2.getGasPrice()).thenReturn(Coin.valueOf(10));
Mockito.when(as.getBalance()).thenReturn(Coin.valueOf(19));
TxValidatorAccountBalanceValidator tvabv = new TxValidatorAccountBalanceValidator();
Assert.assertFalse(tvabv.validate(tx1, as, null, null, Long.MAX_VALUE, false));
Assert.assertFalse(tvabv.validate(tx2, as, null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class TxValidatorIntrinsicGasLimitValidatorTest method validIntrinsicGasPrice.
@Test
public void validIntrinsicGasPrice() {
Transaction tx1 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(21000).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), null, config.getBlockchainConfig().getCommonConstants().getChainId());
tx1.sign(new ECKey().getPrivKeyBytes());
Transaction tx2 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(30000).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), config.getBlockchainConfig().getCommonConstants().getChainId());
tx2.sign(new ECKey().getPrivKeyBytes());
Transaction tx3 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(21072).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), config.getBlockchainConfig().getCommonConstants().getChainId());
tx3.sign(new ECKey().getPrivKeyBytes());
Transaction tx4 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), PrecompiledContracts.BRIDGE_ADDR.getBytes(), BigInteger.ZERO.toByteArray(), null, config.getBlockchainConfig().getCommonConstants().getChainId());
BridgeRegTestConstants bridgeRegTestConstants = BridgeRegTestConstants.getInstance();
tx4.sign(bridgeRegTestConstants.getFederatorPrivateKeys().get(0).getPrivKeyBytes());
TxValidatorIntrinsicGasLimitValidator tvigpv = new TxValidatorIntrinsicGasLimitValidator(config);
Assert.assertTrue(tvigpv.validate(tx1, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvigpv.validate(tx2, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvigpv.validate(tx3, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvigpv.validate(tx4, new AccountState(), null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class TxValidatorNonceRangeValidatorTest method nonceOutOfRange.
@Test
public void nonceOutOfRange() {
Transaction tx1 = Mockito.mock(Transaction.class);
Transaction tx2 = Mockito.mock(Transaction.class);
AccountState as = Mockito.mock(AccountState.class);
Mockito.when(tx1.getNonceAsInteger()).thenReturn(BigInteger.valueOf(0));
Mockito.when(tx2.getNonceAsInteger()).thenReturn(BigInteger.valueOf(6));
Mockito.when(as.getNonce()).thenReturn(BigInteger.valueOf(1));
TxValidatorNonceRangeValidator tvnrv = new TxValidatorNonceRangeValidator();
Assert.assertFalse(tvnrv.validate(tx1, as, null, null, Long.MAX_VALUE, false));
Assert.assertFalse(tvnrv.validate(tx2, as, null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class TxValidatorNonceRangeValidatorTest method nonceInRange.
@Test
public void nonceInRange() {
Transaction tx1 = Mockito.mock(Transaction.class);
Transaction tx2 = Mockito.mock(Transaction.class);
AccountState as = Mockito.mock(AccountState.class);
Mockito.when(tx1.getNonceAsInteger()).thenReturn(BigInteger.valueOf(0));
Mockito.when(tx2.getNonceAsInteger()).thenReturn(BigInteger.valueOf(3));
Mockito.when(as.getNonce()).thenReturn(BigInteger.valueOf(0));
TxValidatorNonceRangeValidator tvnrv = new TxValidatorNonceRangeValidator();
Assert.assertTrue(tvnrv.validate(tx1, as, null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvnrv.validate(tx2, as, null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryImplForTesting method addStorageRow.
@Override
public synchronized void addStorageRow(RskAddress addr, DataWord key, DataWord value) {
super.addStorageRow(addr, key, value);
AccountState accountState = getAccountState(addr);
ContractDetails details = getDetailsDataStore().get(addr);
accountState.setStateRoot(details.getStorageHash());
updateAccountState(addr, accountState);
}
Aggregations