Search in sources :

Example 1 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class AccountBuilder method build.

public static StateWrap build(AccountTck account) {
    ContractDetailsImpl details = new ContractDetailsImpl(new RskSystemProperties());
    details.setCode(parseData(account.getCode()));
    details.setStorage(convertStorage(account.getStorage()));
    AccountState state = new AccountState();
    state.addToBalance(new Coin(unifiedNumericToBigInteger(account.getBalance())));
    state.setNonce(unifiedNumericToBigInteger(account.getNonce()));
    state.setStateRoot(details.getStorageHash());
    state.setCodeHash(HashUtil.keccak256(details.getCode()));
    return new StateWrap(state, details);
}
Also used : Coin(co.rsk.core.Coin) ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) AccountState(org.ethereum.core.AccountState) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 2 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class RepositoryImplForTesting method addStorageBytes.

@Override
public synchronized void addStorageBytes(RskAddress addr, DataWord key, byte[] value) {
    super.addStorageBytes(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)

Example 3 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class RepositoryImplTest method updateAccountState.

@Test
public void updateAccountState() {
    RskAddress accAddress = randomAccountAddress();
    RepositoryImpl repository = new RepositoryImpl(config);
    AccountState accState = repository.createAccount(accAddress);
    accState.incrementNonce();
    accState.addToBalance(Coin.valueOf(1L));
    repository.updateAccountState(accAddress, accState);
    AccountState newAccState = repository.getAccountState(accAddress);
    Assert.assertNotNull(newAccState);
    Assert.assertEquals(BigInteger.ONE, newAccState.getNonce());
    Assert.assertEquals(BigInteger.ONE, newAccState.getBalance().asBigInteger());
}
Also used : RskAddress(co.rsk.core.RskAddress) AccountState(org.ethereum.core.AccountState) TrieImplHashTest(co.rsk.trie.TrieImplHashTest) Test(org.junit.Test)

Example 4 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class RepositoryImplTest method hibernateAccount.

@Test
public void hibernateAccount() {
    RskAddress accAddress = randomAccountAddress();
    RepositoryImpl repository = new RepositoryImpl(config);
    repository.createAccount(accAddress);
    repository.hibernate(accAddress);
    AccountState accState = repository.getAccountState(accAddress);
    Assert.assertNotNull(accState);
    Assert.assertTrue(accState.isHibernated());
}
Also used : RskAddress(co.rsk.core.RskAddress) AccountState(org.ethereum.core.AccountState) TrieImplHashTest(co.rsk.trie.TrieImplHashTest) Test(org.junit.Test)

Example 5 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class TxFilterAccumCostFilterTest method secondTxInvalidAccumGasPrice.

@Test
public void secondTxInvalidAccumGasPrice() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    AccountState as1 = Mockito.mock(AccountState.class);
    AccountState as2 = Mockito.mock(AccountState.class);
    AccountState as3 = Mockito.mock(AccountState.class);
    TxsPerAccount tpa1 = new TxsPerAccount();
    TxsPerAccount tpa2 = new TxsPerAccount();
    Mockito.when(tx1.getGasLimit()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(tx2.getGasLimit()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(tx1.getGasPrice()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx2.getGasPrice()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx1.getValue()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx2.getValue()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx1.getNonce()).thenReturn(BigInteger.valueOf(0).toByteArray());
    Mockito.when(tx2.getNonce()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(as1.getBalance()).thenReturn(Coin.valueOf(0));
    Mockito.when(as2.getBalance()).thenReturn(Coin.valueOf(1));
    Mockito.when(as3.getBalance()).thenReturn(Coin.valueOf(2));
    Mockito.when(as1.getNonce()).thenReturn(BigInteger.valueOf(0));
    Mockito.when(as2.getNonce()).thenReturn(BigInteger.valueOf(0));
    Mockito.when(as3.getNonce()).thenReturn(BigInteger.valueOf(0));
    TxFilterAccumCostFilter tfacf = new TxFilterAccumCostFilter(config);
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(0, tfacf.filter(as1, tpa1, null).size());
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(1, tfacf.filter(as2, tpa1, null).size());
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(1, tfacf.filter(as3, tpa1, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(0, tfacf.filter(as1, tpa2, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(1, tfacf.filter(as2, tpa2, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(1, tfacf.filter(as3, tpa2, null).size());
}
Also used : Transaction(org.ethereum.core.Transaction) TxsPerAccount(co.rsk.net.handler.TxsPerAccount) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

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