use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class BlockchainLoaderTest method testLoadBlockchainEmptyBlockchain.
@Test
public void testLoadBlockchainEmptyBlockchain() {
RskTestFactory objects = new RskTestFactory() {
@Override
protected GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "blockchain_loader_genesis.json", BigInteger.ZERO, true, true, true);
}
};
// calls loadBlockchain
Blockchain blockchain = objects.getBlockchain();
RepositorySnapshot repository = objects.getRepositoryLocator().snapshotAt(blockchain.getBestBlock().getHeader());
TestSystemProperties testSystemProperties = new TestSystemProperties();
ActivationConfig.ForBlock activations = testSystemProperties.getActivationConfig().forBlock(0);
int enabledPCCs = PrecompiledContracts.GENESIS_ADDRESSES.size();
for (ConsensusRule consensusRule : PrecompiledContracts.CONSENSUS_ENABLED_ADDRESSES.values()) {
if (activations.isActive(consensusRule)) {
enabledPCCs++;
}
}
int testAccountsSize = 3;
// PCCs + test accounts in blockchain_loader_genesis.json
int genesisAccountKeysSize = enabledPCCs + testAccountsSize;
Assert.assertEquals(genesisAccountKeysSize, repository.getAccountsKeys().size());
RskAddress daba01 = new RskAddress("dabadabadabadabadabadabadabadabadaba0001");
Assert.assertEquals(Coin.valueOf(2000), repository.getBalance(daba01));
Assert.assertEquals(BigInteger.valueOf(24), repository.getNonce(daba01));
RskAddress daba02 = new RskAddress("dabadabadabadabadabadabadabadabadaba0002");
Assert.assertEquals(Coin.valueOf(1000), repository.getBalance(daba02));
Assert.assertEquals(BigInteger.ZERO, repository.getNonce(daba02));
RskAddress address = new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051");
Assert.assertEquals(Coin.valueOf(10), repository.getBalance(address));
Assert.assertEquals(BigInteger.valueOf(25), repository.getNonce(address));
Assert.assertEquals(DataWord.ONE, repository.getStorageValue(address, DataWord.ZERO));
Assert.assertEquals(DataWord.valueOf(3), repository.getStorageValue(address, DataWord.ONE));
Assert.assertEquals(274, Objects.requireNonNull(repository.getCode(address)).length);
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class GitHubBlockTest method runBCValidBlockTest.
@Ignore
@Test
public void runBCValidBlockTest() throws ParseException, IOException {
TestSystemProperties config = new TestSystemProperties();
config.setGenesisInfo("frontier.json");
run("bcValidBlockTest", true, true);
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class ParameterizedNetworkUpgradeTest method data.
@Parameterized.Parameters(name = "Network version: {0}")
public static Object[] data() {
TestSystemProperties bambooConfig = new TestSystemProperties() {
@Override
public ActivationConfig getActivationConfig() {
return ActivationConfigsForTest.genesis();
}
@Override
public String toString() {
return "Bamboo";
}
@Override
public String projectVersionModifier() {
return "Bamboo";
}
};
TestSystemProperties orchidConfig = new TestSystemProperties() {
@Override
public ActivationConfig getActivationConfig() {
return ActivationConfigsForTest.orchid();
}
@Override
public String toString() {
return "Orchid";
}
@Override
public String projectVersionModifier() {
return "Orchid";
}
};
return new Object[] { bambooConfig, orchidConfig };
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorUnclesTest method createAsyncNodeBlockProcessor.
private static AsyncNodeBlockProcessor createAsyncNodeBlockProcessor(BlockChainImpl blockChain, AsyncNodeBlockProcessorListener listener) {
NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockChain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
return new AsyncNodeBlockProcessor(store, blockChain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class SyncProcessorTest method doesntProcessUnexpectedBodyResponse.
@Test
public void doesntProcessUnexpectedBodyResponse() {
final NetBlockStore store = new NetBlockStore();
Blockchain blockchain = new BlockChainBuilder().ofSize(10);
SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Block block = new BlockGenerator().createChildBlock(blockchain.getBlockByNumber(10));
Blockchain extended = BlockChainBuilder.copy(blockchain);
extended.tryToConnect(block);
Assert.assertEquals(11, block.getNumber());
Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
BlockNodeInformation nodeInformation = new BlockNodeInformation();
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(getChannelManager(), SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
List<Transaction> transactions = blockchain.getBestBlock().getTransactionsList();
List<BlockHeader> uncles = blockchain.getBestBlock().getUncleList();
long lastRequestId = new Random().nextLong();
BodyResponseMessage response = new BodyResponseMessage(lastRequestId, transactions, uncles);
processor.registerExpectedMessage(response);
Deque<BlockHeader> headerStack = new ArrayDeque<>();
headerStack.add(block.getHeader());
List<Deque<BlockHeader>> headers = new ArrayList<>();
headers.add(headerStack);
int connectionPoint = 10;
int step = 192;
int linkCount = 1;
processor.startDownloadingBodies(headers, Collections.singletonMap(sender, buildSkeleton(extended, connectionPoint, step, linkCount)), sender);
processor.processBodyResponse(sender, response);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertNotEquals(block.getNumber(), blockchain.getBestBlock().getNumber());
// if an invalid body arrives then stops syncing
Assert.assertFalse(processor.isSyncing());
}
Aggregations