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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations