Search in sources :

Example 16 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class MinerUtilsTest method invalidNonceTransactionTest.

@Test
public void invalidNonceTransactionTest() {
    Transaction tx = Tx.create(config, 0, 50000, 2, 0, 0, 0);
    List<Transaction> txs = new LinkedList<>();
    txs.add(tx);
    Map<RskAddress, BigInteger> accountNounces = new HashMap();
    accountNounces.put(tx.getSender(), BigInteger.valueOf(0));
    Repository repository = Mockito.mock(Repository.class);
    Coin minGasPrice = Coin.valueOf(1L);
    List<Transaction> txsToRemove = new LinkedList<>();
    List<Transaction> res = new MinerUtils().filterTransactions(txsToRemove, txs, accountNounces, repository, minGasPrice);
    Assert.assertEquals(0, res.size());
    Assert.assertEquals(0, txsToRemove.size());
}
Also used : Coin(co.rsk.core.Coin) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 17 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class TestProgramInvokeFactory method generalInvoke.

private ProgramInvoke generalInvoke(Transaction tx, int txindex, Repository repository, BlockStore blockStore) {
    /**
     *         ADDRESS op       **
     */
    // YP: Get address of currently executing account.
    RskAddress addr = tx.isContractCreation() ? tx.getContractAddress() : tx.getReceiveAddress();
    /**
     *         ORIGIN op       **
     */
    // YP: This is the sender of original transaction; it is never a contract.
    RskAddress origin = tx.getSender();
    /**
     *         CALLER op       **
     */
    // YP: This is the address of the account that is directly responsible for this execution.
    RskAddress caller = tx.getSender();
    /**
     *         BALANCE op       **
     */
    Coin balance = repository.getBalance(addr);
    /**
     *         GASPRICE op       **
     */
    Coin gasPrice = tx.getGasPrice();
    /**
     * GAS op **
     */
    byte[] gas = tx.getGasLimit();
    /**
     *        CALLVALUE op      **
     */
    Coin callValue = tx.getValue() == null ? Coin.ZERO : tx.getValue();
    /**
     *     CALLDATALOAD  op   **
     */
    /**
     *     CALLDATACOPY  op   **
     */
    /**
     *     CALLDATASIZE  op   **
     */
    byte[] data = tx.isContractCreation() ? ByteUtil.EMPTY_BYTE_ARRAY : (tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData());
    // byte[] data =  tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData() ;
    /**
     *    PREVHASH  op  **
     */
    byte[] lastHash = env.getPreviousHash();
    /**
     *   COINBASE  op **
     */
    byte[] coinbase = env.getCurrentCoinbase();
    /**
     * TIMESTAMP  op  **
     */
    long timestamp = ByteUtil.byteArrayToLong(env.getCurrentTimestamp());
    /**
     * NUMBER  op  **
     */
    long number = ByteUtil.byteArrayToLong(env.getCurrentNumber());
    /**
     * DIFFICULTY  op  **
     */
    byte[] difficulty = env.getCurrentDifficulty();
    /**
     * GASLIMIT op **
     */
    byte[] gaslimit = env.getCurrentGasLimit();
    return new ProgramInvokeImpl(addr.getBytes(), origin.getBytes(), caller.getBytes(), balance.getBytes(), gasPrice.getBytes(), gas, callValue.getBytes(), data, lastHash, coinbase, timestamp, number, txindex, difficulty, gaslimit, repository, blockStore);
}
Also used : Coin(co.rsk.core.Coin) RskAddress(co.rsk.core.RskAddress) ProgramInvokeImpl(org.ethereum.vm.program.invoke.ProgramInvokeImpl)

Example 18 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class TestRunner method loadRepository.

public Repository loadRepository(Repository track, Map<RskAddress, AccountState> pre) {
    /* 1. Store pre-exist accounts - Pre */
    for (RskAddress addr : pre.keySet()) {
        AccountState accountState = pre.get(addr);
        track.addBalance(addr, accountState.getBalance());
        ((RepositoryTrack) track).setNonce(addr, new BigInteger(1, accountState.getNonce()));
        track.saveCode(addr, accountState.getCode());
        for (DataWord storageKey : accountState.getStorage().keySet()) {
            track.addStorageRow(addr, storageKey, accountState.getStorage().get(storageKey));
        }
    }
    return track;
}
Also used : RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) DataWord(org.ethereum.vm.DataWord)

Example 19 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class AddressesTopicsFilterTest method matchAddress.

@Test
public void matchAddress() {
    Account account = new AccountBuilder().name("account").build();
    RskAddress address = account.getAddress();
    AddressesTopicsFilter filter = new AddressesTopicsFilter(new RskAddress[] { address }, null);
    Assert.assertTrue(filter.matchesContractAddress(address));
    Assert.assertFalse(filter.matchesContractAddress(RskAddress.nullAddress()));
}
Also used : Account(org.ethereum.core.Account) RskAddress(co.rsk.core.RskAddress) AccountBuilder(co.rsk.test.builders.AccountBuilder) Test(org.junit.Test)

Example 20 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class AddressesTopicsFilterTest method matchAllBloomWithFilterWithAccount.

@Test
public void matchAllBloomWithFilterWithAccount() {
    Account account = new AccountBuilder().name("account").build();
    RskAddress address = account.getAddress();
    AddressesTopicsFilter filter = new AddressesTopicsFilter(new RskAddress[] { address }, null);
    Assert.assertTrue(filter.matchBloom(getAllBloom()));
}
Also used : Account(org.ethereum.core.Account) RskAddress(co.rsk.core.RskAddress) AccountBuilder(co.rsk.test.builders.AccountBuilder) Test(org.junit.Test)

Aggregations

RskAddress (co.rsk.core.RskAddress)174 Test (org.junit.Test)102 Repository (org.ethereum.core.Repository)60 BigInteger (java.math.BigInteger)47 Coin (co.rsk.core.Coin)38 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 DataWord (org.ethereum.vm.DataWord)27 TrieImplHashTest (co.rsk.trie.TrieImplHashTest)24 RepositoryImpl (co.rsk.db.RepositoryImpl)16 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)15 Transaction (org.ethereum.core.Transaction)15 Program (org.ethereum.vm.program.Program)15 InvocationOnMock (org.mockito.invocation.InvocationOnMock)14 AccountState (org.ethereum.core.AccountState)12 HashMapDB (org.ethereum.datasource.HashMapDB)11 ArrayList (java.util.ArrayList)10 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)10 BridgeConstants (co.rsk.config.BridgeConstants)8 RskSystemProperties (co.rsk.config.RskSystemProperties)8 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)8