Search in sources :

Example 1 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig 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 ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class BlockExecutorTest method validateStateRootWithRskip126DisabledAndValidStateRoot.

@Test
public void validateStateRootWithRskip126DisabledAndValidStateRoot() {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Trie trie = new Trie(trieStore);
    Block block = new BlockGenerator().getBlock(1);
    block.setStateRoot(trie.getHash().getBytes());
    BlockResult blockResult = new BlockResult(block, Collections.emptyList(), Collections.emptyList(), 0, Coin.ZERO, trie);
    RskSystemProperties cfg = spy(CONFIG);
    ActivationConfig activationConfig = spy(cfg.getActivationConfig());
    doReturn(false).when(activationConfig).isActive(eq(RSKIP126), anyLong());
    doReturn(activationConfig).when(cfg).getActivationConfig();
    BlockExecutor executor = buildBlockExecutor(trieStore, cfg);
    Assert.assertTrue(executor.validateStateRoot(block.getHeader(), blockResult));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) RskSystemProperties(co.rsk.config.RskSystemProperties) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Example 3 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class BlockExecutorTest method validateStateRootWithRskip126DisabledAndInvalidStateRoot.

@Test
public void validateStateRootWithRskip126DisabledAndInvalidStateRoot() {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Trie trie = new Trie(trieStore);
    Block block = new BlockGenerator().getBlock(1);
    block.setStateRoot(new byte[] { 1, 2, 3, 4 });
    BlockResult blockResult = new BlockResult(block, Collections.emptyList(), Collections.emptyList(), 0, Coin.ZERO, trie);
    RskSystemProperties cfg = spy(CONFIG);
    ActivationConfig activationConfig = spy(cfg.getActivationConfig());
    doReturn(false).when(activationConfig).isActive(eq(RSKIP126), anyLong());
    doReturn(activationConfig).when(cfg).getActivationConfig();
    BlockExecutor executor = buildBlockExecutor(trieStore, cfg);
    Assert.assertTrue(executor.validateStateRoot(block.getHeader(), blockResult));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) RskSystemProperties(co.rsk.config.RskSystemProperties) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Example 4 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class BridgeTest method registerBtcCoinbaseTransaction_after_RSKIP143_activation.

@Test
public void registerBtcCoinbaseTransaction_after_RSKIP143_activation() throws VMException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(true).when(activations).isActive(eq(RSKIP143), anyLong());
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Bridge bridge = getBridgeInstance(bridgeSupportMock, activations);
    byte[] value = Sha256Hash.ZERO_HASH.getBytes();
    Integer zero = new Integer(0);
    byte[] data = Bridge.REGISTER_BTC_COINBASE_TRANSACTION.encode(new Object[] { value, zero, value, zero, zero });
    bridge.execute(data);
    verify(bridgeSupportMock, times(1)).registerBtcCoinbaseTransaction(value, Sha256Hash.wrap(value), value, Sha256Hash.wrap(value), value);
}
Also used : BigInteger(java.math.BigInteger) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 5 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class BridgeTest method getBridgeInstance.

private Bridge getBridgeInstance(Federation activeFederation, Federation retiringFederation, int senderPK, BridgeSupport bridgeSupportMock) {
    doReturn(activeFederation).when(bridgeSupportMock).getActiveFederation();
    doReturn(retiringFederation).when(bridgeSupportMock).getRetiringFederation();
    ECKey key = ECKey.fromPrivate(BigInteger.valueOf(senderPK));
    Transaction rskTxMock = mock(Transaction.class);
    doReturn(new RskAddress(key.getAddress())).when(rskTxMock).getSender();
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(true).when(activations).isActive(eq(RSKIP143), anyLong());
    return getBridgeInstance(rskTxMock, bridgeSupportMock, activations);
}
Also used : CallTransaction(org.ethereum.core.CallTransaction) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) ECKey(org.ethereum.crypto.ECKey) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig)

Aggregations

ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)30 Test (org.junit.Test)25 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)19 RskAddress (co.rsk.core.RskAddress)9 RskSystemProperties (co.rsk.config.RskSystemProperties)8 Before (org.junit.Before)8 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)7 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)6 Keccak256 (co.rsk.crypto.Keccak256)5 Trie (co.rsk.trie.Trie)5 TrieStore (co.rsk.trie.TrieStore)5 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)5 BigInteger (java.math.BigInteger)5 Constants (org.ethereum.config.Constants)5 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)4 TestSystemProperties (co.rsk.config.TestSystemProperties)4 IOException (java.io.IOException)4 CallTransaction (org.ethereum.core.CallTransaction)4 Transaction (org.ethereum.core.Transaction)4 EVMAssembler (co.rsk.asm.EVMAssembler)3