Search in sources :

Example 71 with ByteArrayWrapper

use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.

the class TaskImportBlocksTest method testFilterBatch_wPruningRestrictions.

@Test
public void testFilterBatch_wPruningRestrictions() {
    int current_count = 5, height = 10;
    StandaloneBlockchain.Bundle bundle = builder.withValidatorConfiguration("simple").withDefaultAccounts(accounts).withRepoConfig(new RepositoryConfig() {

        @Override
        public String getDbPath() {
            return "";
        }

        @Override
        public PruneConfig getPruneConfig() {
            // top pruning without archiving
            return new PruneConfig() {

                @Override
                public boolean isEnabled() {
                    return true;
                }

                @Override
                public boolean isArchived() {
                    return false;
                }

                @Override
                public int getCurrentCount() {
                    return current_count;
                }

                @Override
                public int getArchiveRate() {
                    return 0;
                }
            };
        }

        @Override
        public Properties getDatabaseConfig(String db_name) {
            Properties props = new Properties();
            props.setProperty(DatabaseFactory.Props.DB_TYPE, DBVendor.MOCKDB.toValue());
            return props;
        }
    }).build();
    StandaloneBlockchain chain = bundle.bc;
    // populate chain at random
    generateRandomChain(chain, height, 1, accounts, 10);
    // populate initial input lists
    List<Block> allBlocks = new ArrayList<>();
    Map<ByteArrayWrapper, Object> allHashes = new HashMap<>();
    List<Block> unrestrictedBlocks = new ArrayList<>();
    Map<ByteArrayWrapper, Object> unrestrictedHashes = new HashMap<>();
    for (long i = 0; i <= height; i++) {
        Block current = chain.getBlockByNumber(i);
        allBlocks.add(current);
        allHashes.put(ByteArrayWrapper.wrap(current.getHash()), true);
        if (i >= height - current_count + 1) {
            unrestrictedBlocks.add(current);
            unrestrictedHashes.put(ByteArrayWrapper.wrap(current.getHash()), true);
        }
    }
    // will filter out all blocks
    assertThat(filterBatch(allBlocks, chain, allHashes)).isEmpty();
    // will filter out all blocks
    assertThat(filterBatch(allBlocks, chain, unrestrictedHashes)).isEmpty();
    // will filter out the prune restricted blocks
    assertThat(filterBatch(allBlocks, chain, new HashMap<>())).isEqualTo(unrestrictedBlocks);
}
Also used : RepositoryConfig(org.aion.zero.impl.db.RepositoryConfig) PruneConfig(org.aion.zero.impl.config.PruneConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StandaloneBlockchain(org.aion.zero.impl.blockchain.StandaloneBlockchain) Properties(java.util.Properties) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) Block(org.aion.zero.impl.types.Block) BlockchainTestUtils.generateNewBlock(org.aion.zero.impl.blockchain.BlockchainTestUtils.generateNewBlock) BlockchainTestUtils.generateNextBlock(org.aion.zero.impl.blockchain.BlockchainTestUtils.generateNextBlock) Test(org.junit.Test)

Example 72 with ByteArrayWrapper

use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.

the class TaskImportBlocksTest method testFilterBatch_woPruningRestrictions.

@Test
public void testFilterBatch_woPruningRestrictions() {
    StandaloneBlockchain.Bundle bundle = builder.withValidatorConfiguration("simple").withDefaultAccounts(accounts).build();
    StandaloneBlockchain chain = bundle.bc;
    // populate chain at random
    generateRandomChain(chain, 3, 1, accounts, 10);
    // populate initial input lists
    List<Block> batch = new ArrayList<>();
    Map<ByteArrayWrapper, Object> imported = new HashMap<>();
    Block current = chain.getBestBlock();
    while (current.getNumber() > 0) {
        batch.add(current);
        imported.put(ByteArrayWrapper.wrap(current.getHash()), true);
        current = chain.getBlockByHash(current.getParentHash());
    }
    batch.add(current);
    imported.put(ByteArrayWrapper.wrap(current.getHash()), true);
    // will filter out all blocks
    assertThat(filterBatch(batch, chain, imported)).isEmpty();
    // will filter out none of the blocks
    assertThat(filterBatch(batch, chain, new HashMap<>())).isEqualTo(batch);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Block(org.aion.zero.impl.types.Block) BlockchainTestUtils.generateNewBlock(org.aion.zero.impl.blockchain.BlockchainTestUtils.generateNewBlock) BlockchainTestUtils.generateNextBlock(org.aion.zero.impl.blockchain.BlockchainTestUtils.generateNextBlock) StandaloneBlockchain(org.aion.zero.impl.blockchain.StandaloneBlockchain) Test(org.junit.Test)

Example 73 with ByteArrayWrapper

use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.

the class ExternalStateForAvm method putStorage.

@Override
public void putStorage(AionAddress address, byte[] key, byte[] value) {
    ByteArrayWrapper storageKey = ByteArrayWrapper.wrap(key);
    ByteArrayWrapper storageValue = ByteArrayWrapper.wrap(value);
    this.repositoryCache.addStorageRow(address, storageKey, storageValue);
    setVmType(address);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper)

Example 74 with ByteArrayWrapper

use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.

the class ExternalStateForAvm method removeStorage.

@Override
public void removeStorage(AionAddress address, byte[] key) {
    ByteArrayWrapper storageKey = ByteArrayWrapper.wrap(key);
    this.repositoryCache.removeStorageRow(address, storageKey);
    setVmType(address);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper)

Example 75 with ByteArrayWrapper

use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.

the class ExternalStateForAvm method getStorage.

@Override
public byte[] getStorage(AionAddress address, byte[] key) {
    ByteArrayWrapper storageKey = ByteArrayWrapper.wrap(key);
    ByteArrayWrapper value = this.repositoryCache.getStorageValue(address, storageKey);
    return (value == null) ? null : value.toBytes();
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper)

Aggregations

ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)130 Test (org.junit.Test)51 HashMap (java.util.HashMap)39 ArrayList (java.util.ArrayList)33 AionAddress (org.aion.types.AionAddress)26 Block (org.aion.zero.impl.types.Block)24 Map (java.util.Map)20 BigInteger (java.math.BigInteger)14 MiningBlock (org.aion.zero.impl.types.MiningBlock)14 IOException (java.io.IOException)13 MockDB (org.aion.db.impl.mockdb.MockDB)13 DataWord (org.aion.util.types.DataWord)13 PooledTransaction (org.aion.base.PooledTransaction)11 List (java.util.List)10 AionTransaction (org.aion.base.AionTransaction)10 Properties (java.util.Properties)8 HashSet (java.util.HashSet)5 Optional (java.util.Optional)5 ECKey (org.aion.crypto.ECKey)5 RLPElement (org.aion.rlp.RLPElement)5