Search in sources :

Example 1 with RepositoryConfig

use of org.aion.zero.impl.db.RepositoryConfig in project aion by aionnetwork.

the class TokenBridgeContractTest method before.

@Before
public void before() {
    RepositoryConfig repoConfig = new RepositoryConfig() {

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

        @Override
        public PruneConfig getPruneConfig() {
            return new CfgPrune(false);
        }

        @Override
        public Properties getDatabaseConfig(String db_name) {
            Properties props = new Properties();
            props.setProperty(DatabaseFactory.Props.DB_TYPE, DBVendor.MOCKDB.toValue());
            return props;
        }
    };
    this.repository = new AionRepositoryCache(AionRepositoryImpl.createForTesting(repoConfig));
    // override defaults
    this.contract = new TokenBridgeContract(dummyContext(), ExternalStateForTests.usingRepository(this.repository), OWNER_ADDR, CONTRACT_ADDR);
    this.connector = this.contract.getConnector();
}
Also used : RepositoryConfig(org.aion.zero.impl.db.RepositoryConfig) TokenBridgeContract(org.aion.precompiled.contracts.ATB.TokenBridgeContract) CfgPrune(org.aion.zero.impl.config.CfgPrune) Properties(java.util.Properties) AionRepositoryCache(org.aion.zero.impl.db.AionRepositoryCache) Before(org.junit.Before)

Example 2 with RepositoryConfig

use of org.aion.zero.impl.db.RepositoryConfig in project aion by aionnetwork.

the class ExternalStateForTests method usingDefaultRepository.

public static ExternalStateForTests usingDefaultRepository() {
    RepositoryConfig repoConfig = new RepositoryConfig() {

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

        @Override
        public PruneConfig getPruneConfig() {
            return new CfgPrune(false);
        }

        @Override
        public Properties getDatabaseConfig(String db_name) {
            Properties props = new Properties();
            props.setProperty(DatabaseFactory.Props.DB_TYPE, DBVendor.MOCKDB.toValue());
            return props;
        }
    };
    AionRepositoryCache repository = new AionRepositoryCache(AionRepositoryImpl.createForTesting(repoConfig));
    return new ExternalStateForTests(repository);
}
Also used : RepositoryConfig(org.aion.zero.impl.db.RepositoryConfig) CfgPrune(org.aion.zero.impl.config.CfgPrune) Properties(java.util.Properties) AionRepositoryCache(org.aion.zero.impl.db.AionRepositoryCache)

Example 3 with RepositoryConfig

use of org.aion.zero.impl.db.RepositoryConfig 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)

Aggregations

Properties (java.util.Properties)3 RepositoryConfig (org.aion.zero.impl.db.RepositoryConfig)3 CfgPrune (org.aion.zero.impl.config.CfgPrune)2 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TokenBridgeContract (org.aion.precompiled.contracts.ATB.TokenBridgeContract)1 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)1 BlockchainTestUtils.generateNewBlock (org.aion.zero.impl.blockchain.BlockchainTestUtils.generateNewBlock)1 BlockchainTestUtils.generateNextBlock (org.aion.zero.impl.blockchain.BlockchainTestUtils.generateNextBlock)1 StandaloneBlockchain (org.aion.zero.impl.blockchain.StandaloneBlockchain)1 PruneConfig (org.aion.zero.impl.config.PruneConfig)1 Block (org.aion.zero.impl.types.Block)1 Before (org.junit.Before)1 Test (org.junit.Test)1