Search in sources :

Example 1 with Bloom

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

the class BlockStoreTest method saveHeader.

@Test
public void saveHeader() {
    BlockStore store = new BlockStore();
    BlockHeader blockHeader = new BlockHeader(new byte[] {}, new byte[] {}, RskAddress.nullAddress().getBytes(), new Bloom().getData(), new byte[] {}, 1, new byte[] {}, 0, 0, new byte[] {}, new byte[] {}, new byte[] {}, new byte[] {}, new byte[] {}, 0);
    store.saveHeader(blockHeader);
    Assert.assertTrue(store.hasHeader(blockHeader.getHash()));
}
Also used : Bloom(org.ethereum.core.Bloom) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 2 with Bloom

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

the class AddressesTopicsFilterTest method noMatchEmptyBloomWithFilterWithAccount.

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

Example 3 with Bloom

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

the class BlockEncodingTest method testBadBlockEncoding1.

@Test(expected = ArithmeticException.class)
public void testBadBlockEncoding1() {
    List<Transaction> txs = new ArrayList<>();
    Transaction tx = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ONE.toByteArray(), BigInteger.valueOf(21000).toByteArray(), new ECKey().getAddress(), BigInteger.valueOf(1000).toByteArray(), null);
    txs.add(tx);
    byte[] bigBadByteArray = new byte[10000];
    Arrays.fill(bigBadByteArray, (byte) -1);
    FreeBlock fblock = new FreeBlock(// parent hash
    PegTestUtils.createHash3().getBytes(), // uncle hash
    EMPTY_LIST_HASH, // coinbase
    TestUtils.randomAddress().getBytes(), // logs bloom
    new Bloom().getData(), // difficulty
    BigInteger.ONE.toByteArray(), bigBadByteArray, // gasLimit
    bigBadByteArray, // gasUsed
    bigBadByteArray, // timestamp
    bigBadByteArray, // extraData
    new byte[0], // mixHash
    new byte[0], // provisory nonce
    new byte[] { 0 }, // receipts root
    HashUtil.EMPTY_TRIE_HASH, // transaction root
    BlockChainImpl.calcTxTrie(txs), // EMPTY_TRIE_HASH,   // state root
    HashUtil.EMPTY_TRIE_HASH, // transaction list
    txs, // uncle list
    null, BigInteger.TEN.toByteArray(), new byte[0]);
    // Now decode, and re-encode
    Block parsedBlock = new Block(fblock.getEncoded());
    // must throw java.lang.ArithmeticException
    // forced parse
    parsedBlock.getGasLimit();
}
Also used : Transaction(org.ethereum.core.Transaction) Bloom(org.ethereum.core.Bloom) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 4 with Bloom

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

the class BlockStoreTest method removeHeader.

@Test
public void removeHeader() {
    BlockStore store = new BlockStore();
    BlockHeader blockHeader = new BlockHeader(new byte[] {}, new byte[] {}, RskAddress.nullAddress().getBytes(), new Bloom().getData(), new byte[] {}, 1, new byte[] {}, 0, 0, new byte[] {}, new byte[] {}, new byte[] {}, new byte[] {}, new byte[] {}, 0);
    store.saveHeader(blockHeader);
    store.removeHeader(blockHeader);
    Assert.assertFalse(store.hasHeader(blockHeader.getHash()));
}
Also used : Bloom(org.ethereum.core.Bloom) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 5 with Bloom

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

the class AddressesTopicsFilter method initBlooms.

private void initBlooms() {
    if (filterBlooms != null) {
        return;
    }
    List<byte[][]> addrAndTopics = new ArrayList<>(2);
    for (Topic[] toplist : topics) {
        byte[][] tops = new byte[toplist.length][];
        for (int k = 0; k < tops.length; k++) {
            tops[k] = toplist[k].getBytes();
        }
        addrAndTopics.add(tops);
    }
    byte[][] addrs = new byte[addresses.length][];
    for (int k = 0; k < addresses.length; k++) {
        addrs[k] = addresses[k].getBytes();
    }
    addrAndTopics.add(addrs);
    filterBlooms = new Bloom[addrAndTopics.size()][];
    for (int i = 0; i < addrAndTopics.size(); i++) {
        byte[][] orTopics = addrAndTopics.get(i);
        if (orTopics == null || orTopics.length == 0) {
            // always matches
            filterBlooms[i] = new Bloom[] { new Bloom() };
        } else {
            filterBlooms[i] = new Bloom[orTopics.length];
            for (int j = 0; j < orTopics.length; j++) {
                filterBlooms[i][j] = Bloom.create(Keccak256Helper.keccak256(orTopics[j]));
            }
        }
    }
}
Also used : Bloom(org.ethereum.core.Bloom) ArrayList(java.util.ArrayList)

Aggregations

Bloom (org.ethereum.core.Bloom)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 BlockHeader (org.ethereum.core.BlockHeader)2 RskAddress (co.rsk.core.RskAddress)1 AccountBuilder (co.rsk.test.builders.AccountBuilder)1 Account (org.ethereum.core.Account)1 Block (org.ethereum.core.Block)1 Transaction (org.ethereum.core.Transaction)1 ECKey (org.ethereum.crypto.ECKey)1