Search in sources :

Example 16 with TestSystemProperties

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);
}
Also used : RepositorySnapshot(co.rsk.db.RepositorySnapshot) Blockchain(org.ethereum.core.Blockchain) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) RskAddress(co.rsk.core.RskAddress) RskTestFactory(org.ethereum.util.RskTestFactory) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) TestSystemProperties(co.rsk.config.TestSystemProperties) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Example 17 with TestSystemProperties

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);
}
Also used : TestSystemProperties(co.rsk.config.TestSystemProperties) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with TestSystemProperties

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 };
}
Also used : TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 19 with TestSystemProperties

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);
}
Also used : TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 20 with TestSystemProperties

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());
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) BlockStore(org.ethereum.db.BlockStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Aggregations

TestSystemProperties (co.rsk.config.TestSystemProperties)158 Test (org.junit.Test)130 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)109 Blockchain (org.ethereum.core.Blockchain)78 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)75 SimplePeer (co.rsk.net.simples.SimplePeer)69 Block (org.ethereum.core.Block)69 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)56 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)23 EthereumListener (org.ethereum.listener.EthereumListener)23 BlockStore (org.ethereum.db.BlockStore)21 RskSystemProperties (co.rsk.config.RskSystemProperties)17 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)16 Keccak256 (co.rsk.crypto.Keccak256)13 RepositoryLocator (co.rsk.db.RepositoryLocator)10 World (co.rsk.test.World)10 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)9 Ignore (org.junit.Ignore)9 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)8 AsyncNodeBlockProcessorListener (co.rsk.net.utils.AsyncNodeBlockProcessorListener)8