Search in sources :

Example 6 with RskTestFactory

use of org.ethereum.util.RskTestFactory 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 7 with RskTestFactory

use of org.ethereum.util.RskTestFactory in project rskj by rsksmart.

the class BlockResultDTOTest method buildBlockWithTransactions.

private Block buildBlockWithTransactions(List<Transaction> transactions) {
    RskTestFactory objects = new RskTestFactory() {

        @Override
        protected GenesisLoader buildGenesisLoader() {
            return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true);
        }
    };
    Blockchain blockChain = objects.getBlockchain();
    // Build block with remasc and normal txs
    BlockBuilder builder = new BlockBuilder(null, null, null).parent(blockChain.getBestBlock());
    return builder.transactions(transactions).build();
}
Also used : Blockchain(org.ethereum.core.Blockchain) RskTestFactory(org.ethereum.util.RskTestFactory) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Example 8 with RskTestFactory

use of org.ethereum.util.RskTestFactory in project rskj by rsksmart.

the class Web3ImplLogsTest method setUp.

// 20965255 getValue()
// 371303c0 inc()
@Before
public void setUp() {
    RskTestFactory factory = new RskTestFactory();
    blockChain = factory.getBlockchain();
    blockStore = factory.getBlockStore();
    trieStore = factory.getTrieStore();
    mainchainView = factory.getMiningMainchainView();
    repositoryLocator = factory.getRepositoryLocator();
    transactionPool = factory.getTransactionPool();
    eth = factory.getRsk();
    receiptStore = factory.getReceiptStore();
    web3 = createWeb3();
}
Also used : RskTestFactory(org.ethereum.util.RskTestFactory) Before(org.junit.Before)

Example 9 with RskTestFactory

use of org.ethereum.util.RskTestFactory in project rskj by rsksmart.

the class BlockExecutorTest method setUp.

@Before
public void setUp() {
    RskTestFactory objects = new RskTestFactory(CONFIG);
    blockchain = objects.getBlockchain();
    executor = objects.getBlockExecutor();
    trieStore = objects.getTrieStore();
    repository = objects.getRepositoryLocator().snapshotAt(blockchain.getBestBlock().getHeader());
}
Also used : RskTestFactory(org.ethereum.util.RskTestFactory) Before(org.junit.Before)

Example 10 with RskTestFactory

use of org.ethereum.util.RskTestFactory in project rskj by rsksmart.

the class MinerManagerTest method setup.

@Before
public void setup() {
    RskTestFactory factory = new RskTestFactory(config);
    blockchain = factory.getBlockchain();
    miningMainchainView = factory.getMiningMainchainView();
    transactionPool = factory.getTransactionPool();
    repositoryLocator = factory.getRepositoryLocator();
    blockStore = factory.getBlockStore();
    blockFactory = factory.getBlockFactory();
    blockExecutor = factory.getBlockExecutor();
}
Also used : RskTestFactory(org.ethereum.util.RskTestFactory) Before(org.junit.Before)

Aggregations

RskTestFactory (org.ethereum.util.RskTestFactory)13 Before (org.junit.Before)7 TestGenesisLoader (co.rsk.core.genesis.TestGenesisLoader)5 Blockchain (org.ethereum.core.Blockchain)5 Test (org.junit.Test)5 RepositoryLocator (co.rsk.db.RepositoryLocator)4 Block (org.ethereum.core.Block)3 BlockStore (org.ethereum.db.BlockStore)3 TestSystemProperties (co.rsk.config.TestSystemProperties)2 BlockDifficulty (co.rsk.core.BlockDifficulty)1 RskAddress (co.rsk.core.RskAddress)1 RepositorySnapshot (co.rsk.db.RepositorySnapshot)1 BlockBuilder (co.rsk.test.builders.BlockBuilder)1 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)1 ConsensusRule (org.ethereum.config.blockchain.upgrades.ConsensusRule)1 Genesis (org.ethereum.core.Genesis)1 GenesisLoader (org.ethereum.core.genesis.GenesisLoader)1 CompositeEthereumListener (org.ethereum.listener.CompositeEthereumListener)1