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);
}
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();
}
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);
}
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();
}
}
}
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();
}
}
Aggregations