Search in sources :

Example 1 with CfgPrune

use of org.aion.zero.impl.config.CfgPrune in project aion by aionnetwork.

the class AionRepositoryCacheTest method setup.

@Before
public void setup() {
    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;
        }
    };
    repository = AionRepositoryImpl.createForTesting(repoConfig);
    cache = new AionRepositoryCache(repository);
}
Also used : CfgPrune(org.aion.zero.impl.config.CfgPrune) Properties(java.util.Properties) Before(org.junit.Before)

Example 2 with CfgPrune

use of org.aion.zero.impl.config.CfgPrune 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 3 with CfgPrune

use of org.aion.zero.impl.config.CfgPrune 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 4 with CfgPrune

use of org.aion.zero.impl.config.CfgPrune in project aion by aionnetwork.

the class BlockchainImplementationTest method testIsPruneRestricted_wSpreadState.

/**
 * In SPREAD mode the top K blocks and the blocks that are multiples of the archive rate have a
 * stored state. There are no restrictions due to pruning.
 */
@Test
public void testIsPruneRestricted_wSpreadState() {
    // number of blocks stored by the blockchain
    int stored = 150;
    // the maximum height considered by this test
    int height = 1200;
    // the interval at which blocks are indexed
    int index = 1000;
    StandaloneBlockchain.Bundle bundle = new StandaloneBlockchain.Builder().withValidatorConfiguration("simple").withRepoConfig(new MockRepositoryConfig(new CfgPrune(stored, index))).withDefaultAccounts(accounts).build();
    StandaloneBlockchain chain = bundle.bc;
    AionRepositoryImpl repo = chain.getRepository();
    BlockContext context;
    List<AionTransaction> txs;
    // creating (height) blocks
    long time = System.currentTimeMillis();
    for (int i = 0; i < height; i++) {
        txs = BlockchainTestUtils.generateTransactions(MAX_TX_PER_BLOCK, accounts, repo);
        context = chain.createNewMiningBlockInternal(chain.getBestBlock(), txs, true, time / 100000L);
        assertThat(chain.tryToConnect(context.block)).isEqualTo(ImportResult.IMPORTED_BEST);
    }
    // testing restriction for unrestricted blocks
    for (int i = height; i >= 0; i--) {
        assertThat(chain.isPruneRestricted(i)).isFalse();
        if (i % index == 0 || i >= height - stored) {
            // ensure the state exists
            assertThat(repo.isValidRoot(chain.getBlockByNumber(i).getStateRoot())).isTrue();
        } else {
            // ensure the state is missing
            assertThat(repo.isValidRoot(chain.getBlockByNumber(i).getStateRoot())).isFalse();
        }
    }
}
Also used : MockRepositoryConfig(org.aion.zero.impl.db.MockRepositoryConfig) BlockContext(org.aion.zero.impl.types.BlockContext) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionTransaction(org.aion.base.AionTransaction) CfgPrune(org.aion.zero.impl.config.CfgPrune) Test(org.junit.Test)

Example 5 with CfgPrune

use of org.aion.zero.impl.config.CfgPrune in project aion by aionnetwork.

the class BlockchainImplementationTest method testIsPruneRestricted_wFullState.

/**
 * In FULL mode the state is stored for all blocks. There are no restrictions due to pruning.
 */
@Test
public void testIsPruneRestricted_wFullState() {
    // the maximum height considered by this test
    int height = 200;
    StandaloneBlockchain.Bundle bundle = new StandaloneBlockchain.Builder().withValidatorConfiguration("simple").withRepoConfig(new MockRepositoryConfig(new CfgPrune(false))).withDefaultAccounts(accounts).build();
    StandaloneBlockchain chain = bundle.bc;
    AionRepositoryImpl repo = chain.getRepository();
    BlockContext context;
    List<AionTransaction> txs;
    // creating (height) blocks
    long time = System.currentTimeMillis();
    for (int i = 0; i < height; i++) {
        txs = BlockchainTestUtils.generateTransactions(MAX_TX_PER_BLOCK, accounts, repo);
        context = chain.createNewMiningBlockInternal(chain.getBestBlock(), txs, true, time / 10000L);
        assertThat(chain.tryToConnect(context.block)).isEqualTo(ImportResult.IMPORTED_BEST);
    }
    // testing restriction for unrestricted blocks
    for (int i = height; i >= 0; i--) {
        assertThat(chain.isPruneRestricted(i)).isFalse();
        // ensure the state exists
        assertThat(repo.isValidRoot(chain.getBlockByNumber(i).getStateRoot())).isTrue();
    }
}
Also used : MockRepositoryConfig(org.aion.zero.impl.db.MockRepositoryConfig) BlockContext(org.aion.zero.impl.types.BlockContext) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionTransaction(org.aion.base.AionTransaction) CfgPrune(org.aion.zero.impl.config.CfgPrune) Test(org.junit.Test)

Aggregations

CfgPrune (org.aion.zero.impl.config.CfgPrune)6 Properties (java.util.Properties)3 AionTransaction (org.aion.base.AionTransaction)3 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)3 MockRepositoryConfig (org.aion.zero.impl.db.MockRepositoryConfig)3 Test (org.junit.Test)3 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)2 RepositoryConfig (org.aion.zero.impl.db.RepositoryConfig)2 BlockContext (org.aion.zero.impl.types.BlockContext)2 Before (org.junit.Before)2 TokenBridgeContract (org.aion.precompiled.contracts.ATB.TokenBridgeContract)1 Block (org.aion.zero.impl.types.Block)1 MiningBlock (org.aion.zero.impl.types.MiningBlock)1