use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class TxValidatorAccountBalanceValidatorTest method validAccountBalance.
@Test
public void validAccountBalance() {
Transaction tx1 = Mockito.mock(Transaction.class);
Transaction tx2 = Mockito.mock(Transaction.class);
Transaction tx3 = 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(1));
Mockito.when(tx3.getGasLimitAsInteger()).thenReturn(BigInteger.valueOf(2));
Mockito.when(tx1.getGasPrice()).thenReturn(Coin.valueOf(1));
Mockito.when(tx2.getGasPrice()).thenReturn(Coin.valueOf(10000));
Mockito.when(tx3.getGasPrice()).thenReturn(Coin.valueOf(5000));
Mockito.when(as.getBalance()).thenReturn(Coin.valueOf(10000));
TxValidatorAccountBalanceValidator tvabv = new TxValidatorAccountBalanceValidator();
Assert.assertTrue(tvabv.validate(tx1, as, null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvabv.validate(tx2, as, null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvabv.validate(tx3, as, null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class TxValidatorAccountStateValidatorTest method validAccountState.
@Test
public void validAccountState() {
AccountState state = Mockito.mock(AccountState.class);
Mockito.when(state.isDeleted()).thenReturn(false);
TxValidatorAccountStateValidator tvasv = new TxValidatorAccountStateValidator();
Assert.assertTrue(tvasv.validate(null, state, null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class TxValidatorAccountStateValidatorTest method invalidAccountState.
@Test
public void invalidAccountState() {
AccountState state = Mockito.mock(AccountState.class);
Mockito.when(state.isDeleted()).thenReturn(true);
TxValidatorAccountStateValidator tvasv = new TxValidatorAccountStateValidator();
Assert.assertFalse(tvasv.validate(null, state, null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class TxValidatorIntrinsicGasLimitValidatorTest method invalidIntrinsicGasPrice.
@Test
public void invalidIntrinsicGasPrice() {
Transaction tx1 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(21071).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), config.getBlockchainConfig().getCommonConstants().getChainId());
tx1.sign(new ECKey().getPrivKeyBytes());
Transaction tx2 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(20999).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), null, config.getBlockchainConfig().getCommonConstants().getChainId());
tx2.sign(new ECKey().getPrivKeyBytes());
Transaction tx3 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.ZERO.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(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), null, config.getBlockchainConfig().getCommonConstants().getChainId());
tx4.sign(new ECKey().getPrivKeyBytes());
TxValidatorIntrinsicGasLimitValidator tvigpv = new TxValidatorIntrinsicGasLimitValidator(config);
Assert.assertFalse(tvigpv.validate(tx1, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertFalse(tvigpv.validate(tx2, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertFalse(tvigpv.validate(tx3, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertFalse(tvigpv.validate(tx4, new AccountState(), null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class VMComplexTest method test8.
// sha3_memSizeQuadraticCost31
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test8() {
int expectedGas = 354;
DataWord key1 = new DataWord(999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
String code = "60016103c020600055";
RskAddress contractAddrB = new RskAddress(contractAddr);
RskAddress callerAddrB = new RskAddress(callerAddr);
byte[] codeB = Hex.decode(code);
byte[] codeKey = HashUtil.keccak256(codeB);
AccountState accountState = new AccountState();
accountState.setCodeHash(codeKey);
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractAddrB);
Repository repository = pi.getRepository();
repository.createAccount(callerAddrB);
final BigInteger value = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935");
repository.addBalance(callerAddrB, new Coin(value));
repository.createAccount(contractAddrB);
repository.saveCode(contractAddrB, codeB);
repository.addStorageRow(contractAddrB, key1, value1);
// Play the program
VM vm = getSubject();
Program program = getProgram(codeB, pi);
try {
while (!program.isStopped()) vm.step(program);
} catch (RuntimeException e) {
program.setRuntimeFailure(e);
}
System.out.println();
System.out.println("============ Results ============");
Coin balance = repository.getBalance(callerAddrB);
System.out.println("*** Used gas: " + program.getResult().getGasUsed());
System.out.println("*** Contract Balance: " + balance);
// todo: assert caller balance after contract exec
repository.close();
assertEquals(expectedGas, program.getResult().getGasUsed());
}
Aggregations