Search in sources :

Example 1 with TestGenesisLoader

use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.

the class BlockChainImplInvalidTest method setup.

@Before
public void setup() {
    objects = new RskTestContext(new String[0]) {

        @Override
        protected synchronized RskSystemProperties buildRskSystemProperties() {
            RskSystemProperties rskSystemProperties = super.buildRskSystemProperties();
            ActivationConfig activationConfigSpy = spy(rskSystemProperties.getActivationConfig());
            RskSystemProperties rskSystemPropertiesSpy = spy(rskSystemProperties);
            doReturn(true).when(activationConfigSpy).isActive(eq(ConsensusRule.RSKIP126), anyLong());
            doReturn(activationConfigSpy).when(rskSystemPropertiesSpy).getActivationConfig();
            return rskSystemPropertiesSpy;
        }

        @Override
        protected GenesisLoader buildGenesisLoader() {
            return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true);
        }

        @Override
        public BlockValidator buildBlockValidator() {
            return new BlockValidatorImpl(getBlockStore(), getBlockParentDependantValidationRule(), getBlockValidationRule());
        }
    };
    blockChain = objects.getBlockchain();
}
Also used : GenesisLoader(org.ethereum.core.genesis.GenesisLoader) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) RskTestContext(org.ethereum.util.RskTestContext) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) RskSystemProperties(co.rsk.config.RskSystemProperties) BlockValidator(co.rsk.validators.BlockValidator) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Before(org.junit.Before)

Example 2 with TestGenesisLoader

use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.

the class BlockChainImplTest method setup.

@Before
public void setup() {
    objects = new RskTestFactory() {

        @Override
        protected GenesisLoader buildGenesisLoader() {
            return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true);
        }

        @Override
        protected CompositeEthereumListener buildCompositeEthereumListener() {
            return new BlockExecutorTest.SimpleEthereumListener();
        }
    };
    config = objects.getRskSystemProperties();
    blockChain = objects.getBlockchain();
    blockStore = objects.getBlockStore();
    blockExecutor = objects.getBlockExecutor();
    listener = (BlockExecutorTest.SimpleEthereumListener) objects.getCompositeEthereumListener();
}
Also used : GenesisLoader(org.ethereum.core.genesis.GenesisLoader) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) RskTestFactory(org.ethereum.util.RskTestFactory) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) Before(org.junit.Before)

Example 3 with TestGenesisLoader

use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.

the class MainNetMinerTest method setup.

@Before
public void setup() {
    config = spy(new TestSystemProperties());
    when(config.getNetworkConstants()).thenReturn(Constants.mainnet());
    when(config.getActivationConfig()).thenReturn(ActivationConfigsForTest.all());
    RskTestFactory factory = new RskTestFactory(config) {

        @Override
        public GenesisLoader buildGenesisLoader() {
            return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true) {

                @Override
                public Genesis load() {
                    Genesis genesis = super.load();
                    genesis.getHeader().setDifficulty(new BlockDifficulty(BigInteger.valueOf(300000)));
                    return genesis;
                }
            };
        }
    };
    mainchainView = factory.getMiningMainchainView();
    transactionPool = factory.getTransactionPool();
    blockStore = factory.getBlockStore();
    blockProcessor = factory.getNodeBlockProcessor();
    repositoryLocator = factory.getRepositoryLocator();
    blockFactory = factory.getBlockFactory();
    blockExecutor = factory.getBlockExecutor();
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) Genesis(org.ethereum.core.Genesis) RskTestFactory(org.ethereum.util.RskTestFactory) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) TestSystemProperties(co.rsk.config.TestSystemProperties) Before(org.junit.Before)

Example 4 with TestGenesisLoader

use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.

the class TransactionTest method multiSuicideTest.

@Test
public void multiSuicideTest() throws IOException, InterruptedException {
    /*
        Original contract

        pragma solidity ^0.4.3;

        contract PsychoKiller {
            function () payable {}

            function homicide() {
                suicide(msg.sender);
            }

            function multipleHomicide() {
                PsychoKiller k  = this;
                k.homicide();
                k.homicide();
                k.homicide();
                k.homicide();
            }
        }

         */
    BigInteger nonce = config.getNetworkConstants().getInitialNonce();
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    MutableRepository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
    IndexedBlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
    Blockchain blockchain = ImportLightTest.createBlockchain(new TestGenesisLoader(trieStore, getClass().getResourceAsStream("/genesis/genesis-light.json"), nonce, false, true, true).load(), config, repository, blockStore, trieStore);
    ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
    System.out.println("address: " + ByteUtil.toHexString(sender.getAddress()));
    String code = "6060604052341561000c57fe5b5b6102938061001c6000396000f3006060604052361561004a576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806309e587a514610053578063de990da914610065575b6100515b5b565b005b341561005b57fe5b610063610077565b005b341561006d57fe5b610075610092565b005b3373ffffffffffffffffffffffffffffffffffffffff16ff5b565b60003090508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b15156100fa57fe5b60325a03f1151561010757fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b151561016d57fe5b60325a03f1151561017a57fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b15156101e057fe5b60325a03f115156101ed57fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b151561025357fe5b60325a03f1151561026057fe5b5050505b505600a165627a7a72305820084e74021c556522723b6725354378df2fb4b6732f82dd33f5daa29e2820b37c0029";
    String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"homicide\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"multipleHomicide\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"payable\":true,\"type\":\"fallback\"}]";
    Transaction tx = createTx(sender, new byte[0], Hex.decode(code), repository);
    executeTransaction(blockchain, blockStore, tx, repository, blockTxSignatureCache);
    byte[] contractAddress = tx.getContractAddress().getBytes();
    CallTransaction.Contract contract1 = new CallTransaction.Contract(abi);
    byte[] callData = contract1.getByName("multipleHomicide").encode();
    Assert.assertNull(contract1.getConstructor());
    Assert.assertNotNull(contract1.parseInvocation(callData));
    Assert.assertNotNull(contract1.parseInvocation(callData).toString());
    try {
        contract1.parseInvocation(new byte[32]);
        Assert.fail();
    } catch (RuntimeException ex) {
    }
    try {
        contract1.parseInvocation(new byte[2]);
        Assert.fail();
    } catch (RuntimeException ex) {
    }
    Transaction tx1 = createTx(sender, contractAddress, callData, repository);
    ProgramResult programResult = executeTransaction(blockchain, blockStore, tx1, repository, blockTxSignatureCache).getResult();
    // suicide of a single account should be counted only once
    Assert.assertEquals(24000, programResult.getFutureRefund());
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) ProgramResult(org.ethereum.vm.program.ProgramResult) ECKey(org.ethereum.crypto.ECKey) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) MutableRepository(org.ethereum.db.MutableRepository) BigInteger(java.math.BigInteger) MutableTrieImpl(co.rsk.db.MutableTrieImpl) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 5 with TestGenesisLoader

use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.

the class BlockchainLoaderTest method testLoadBlockchainWithInconsistentBlock.

@Test
public void testLoadBlockchainWithInconsistentBlock() {
    RskTestFactory objects = new RskTestFactory() {

        @Override
        protected synchronized RepositoryLocator buildRepositoryLocator() {
            RepositoryLocator repositoryLocatorSpy = spy(super.buildRepositoryLocator());
            doReturn(Optional.empty()).when(repositoryLocatorSpy).findSnapshotAt(any());
            return repositoryLocatorSpy;
        }

        @Override
        protected GenesisLoader buildGenesisLoader() {
            return new TestGenesisLoader(getTrieStore(), "blockchain_loader_genesis.json", BigInteger.ZERO, true, true, true);
        }
    };
    try {
        // calls loadBlockchain
        objects.getBlockchain();
        fail();
    } catch (RuntimeException e) {
        String errorMessage = String.format("Best block is not consistent with the state db. Consider using `%s` cli tool to rewind inconsistent blocks", RewindBlocks.class.getSimpleName());
        assertEquals(errorMessage, e.getMessage());
    }
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) RskTestFactory(org.ethereum.util.RskTestFactory) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) Test(org.junit.Test)

Aggregations

TestGenesisLoader (co.rsk.core.genesis.TestGenesisLoader)10 RskTestFactory (org.ethereum.util.RskTestFactory)5 Before (org.junit.Before)4 Test (org.junit.Test)4 TrieStore (co.rsk.trie.TrieStore)3 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)3 GenesisLoader (org.ethereum.core.genesis.GenesisLoader)3 HashMapDB (org.ethereum.datasource.HashMapDB)3 TestSystemProperties (co.rsk.config.TestSystemProperties)2 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)2 MutableTrieImpl (co.rsk.db.MutableTrieImpl)2 RepositoryLocator (co.rsk.db.RepositoryLocator)2 Trie (co.rsk.trie.Trie)2 BigInteger (java.math.BigInteger)2 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)2 Blockchain (org.ethereum.core.Blockchain)2 ECKey (org.ethereum.crypto.ECKey)2 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)2 MutableRepository (org.ethereum.db.MutableRepository)2 RskTestContext (org.ethereum.util.RskTestContext)2