Search in sources :

Example 31 with AccountState

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));
}
Also used : Transaction(org.ethereum.core.Transaction) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

Example 32 with AccountState

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));
}
Also used : BridgeRegTestConstants(co.rsk.config.BridgeRegTestConstants) Transaction(org.ethereum.core.Transaction) ECKey(org.ethereum.crypto.ECKey) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

Example 33 with AccountState

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));
}
Also used : Transaction(org.ethereum.core.Transaction) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

Example 34 with AccountState

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));
}
Also used : Transaction(org.ethereum.core.Transaction) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

Example 35 with AccountState

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);
}
Also used : AccountState(org.ethereum.core.AccountState) ContractDetails(org.ethereum.db.ContractDetails)

Aggregations

AccountState (org.ethereum.core.AccountState)46 Test (org.junit.Test)20 RskAddress (co.rsk.core.RskAddress)12 BigInteger (java.math.BigInteger)11 Coin (co.rsk.core.Coin)10 Transaction (org.ethereum.core.Transaction)10 Repository (org.ethereum.core.Repository)7 ContractDetails (org.ethereum.db.ContractDetails)7 Program (org.ethereum.vm.program.Program)5 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)5 Ignore (org.junit.Ignore)5 RskSystemProperties (co.rsk.config.RskSystemProperties)3 TrieImplHashTest (co.rsk.trie.TrieImplHashTest)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ECKey (org.ethereum.crypto.ECKey)3 RepositoryImpl (co.rsk.db.RepositoryImpl)2 TxsPerAccount (co.rsk.net.handler.TxsPerAccount)2 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)2 HashMapDB (org.ethereum.datasource.HashMapDB)2