Search in sources :

Example 26 with ActivationConfig

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

the class BridgeTest method receiveHeader_empty_parameter.

@Test
public void receiveHeader_empty_parameter() throws VMException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(true).when(activations).isActive(eq(RSKIP200), anyLong());
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Bridge bridge = spy(getBridgeInstance(bridgeSupportMock, activations));
    byte[] data = Bridge.RECEIVE_HEADER.encode(new Object[] {});
    assertNull(bridge.execute(data));
    verify(bridge, never()).receiveHeader(any(Object[].class));
    verifyZeroInteractions(bridgeSupportMock);
}
Also used : ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 27 with ActivationConfig

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

the class BridgeTest method registerBtcTransaction_afterRskip199_acceptsExternalCalls.

@Test
public void registerBtcTransaction_afterRskip199_acceptsExternalCalls() throws VMException, IOException, BlockStoreException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(true).when(activations).isActive(eq(RSKIP199), anyLong());
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Bridge bridge = getBridgeInstance(bridgeSupportMock, activations);
    byte[] value = Sha256Hash.ZERO_HASH.getBytes();
    int zero = 0;
    byte[] data = Bridge.REGISTER_BTC_TRANSACTION.encode(new Object[] { value, zero, value });
    bridge.execute(data);
    verify(bridgeSupportMock, times(1)).registerBtcTransaction(any(Transaction.class), any(byte[].class), anyInt(), any(byte[].class));
}
Also used : CallTransaction(org.ethereum.core.CallTransaction) Transaction(org.ethereum.core.Transaction) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 28 with ActivationConfig

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

the class BridgeTest method registerBtcTransaction_beforeRskip199_acceptsCallFromFederationMember.

@Test
public void registerBtcTransaction_beforeRskip199_acceptsCallFromFederationMember() throws VMException, IOException, BlockStoreException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(false).when(activations).isActive(eq(RSKIP199), anyLong());
    BtcECKey fed1Key = new BtcECKey();
    RskAddress fed1Address = new RskAddress(ECKey.fromPublicOnly(fed1Key.getPubKey()).getAddress());
    List<BtcECKey> federationKeys = Arrays.asList(fed1Key, new BtcECKey(), new BtcECKey());
    federationKeys.sort(BtcECKey.PUBKEY_COMPARATOR);
    Federation activeFederation = new Federation(FederationTestUtils.getFederationMembersWithKeys(federationKeys), Instant.ofEpochMilli(1000), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST));
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    when(bridgeSupportMock.getActiveFederation()).thenReturn(activeFederation);
    Transaction rskTx = mock(Transaction.class);
    when(rskTx.getSender()).thenReturn(fed1Address);
    Bridge bridge = getBridgeInstance(rskTx, bridgeSupportMock, activations);
    byte[] value = Sha256Hash.ZERO_HASH.getBytes();
    int zero = 0;
    byte[] data = Bridge.REGISTER_BTC_TRANSACTION.encode(new Object[] { value, zero, value });
    bridge.execute(data);
    verify(bridgeSupportMock, times(1)).registerBtcTransaction(any(Transaction.class), any(byte[].class), anyInt(), any(byte[].class));
}
Also used : CallTransaction(org.ethereum.core.CallTransaction) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 29 with ActivationConfig

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

the class RemascRskAddressActivationTest method testActivation.

@Test
public void testActivation() {
    final RskAddress rskLabsAddress = new RskAddress("14d3065c8Eb89895f4df12450EC6b130049F8034");
    final RskAddress rskLabsAddressRskip218 = new RskAddress("dcb12179ba4697350f66224c959bdd9c282818df");
    final RemascTransaction txMock = mock(RemascTransaction.class);
    final Repository repositoryMock = mock(Repository.class);
    final BlockStore blockStoreMock = mock(BlockStore.class);
    final List<LogInfo> logs = Collections.emptyList();
    final ActivationConfig activationConfig = mock(ActivationConfig.class);
    final Block blockMock = mock(Block.class);
    final RemascConfig remascConfig = spy(new RemascConfigFactory(RemascContract.REMASC_CONFIG).createRemascConfig("regtest"));
    final Remasc remasc = new Remasc(Constants.regtest(), activationConfig, repositoryMock, blockStoreMock, remascConfig, txMock, PrecompiledContracts.REMASC_ADDR, blockMock, logs);
    when(remascConfig.getRskLabsAddress()).thenReturn(rskLabsAddress);
    when(remascConfig.getRskLabsAddressRskip218()).thenReturn(rskLabsAddressRskip218);
    when(activationConfig.isActive(ConsensusRule.RSKIP218, 1)).thenReturn(false);
    when(activationConfig.isActive(ConsensusRule.RSKIP218, 2)).thenReturn(true);
    when(blockMock.getNumber()).thenReturn(1L);
    RskAddress actualAddress = remasc.getRskLabsAddress();
    Assert.assertEquals(rskLabsAddress, actualAddress);
    Assert.assertEquals(blockMock.getNumber(), 1L);
    Assert.assertFalse(activationConfig.isActive(ConsensusRule.RSKIP218, blockMock.getNumber()));
    verify(remascConfig).getRskLabsAddress();
    when(blockMock.getNumber()).thenReturn(2L);
    actualAddress = remasc.getRskLabsAddress();
    Assert.assertEquals(rskLabsAddressRskip218, actualAddress);
    Assert.assertEquals(blockMock.getNumber(), 2L);
    Assert.assertTrue(activationConfig.isActive(ConsensusRule.RSKIP218, blockMock.getNumber()));
    verify(remascConfig).getRskLabsAddressRskip218();
}
Also used : RemascConfig(co.rsk.config.RemascConfig) Repository(org.ethereum.core.Repository) BlockStore(org.ethereum.db.BlockStore) LogInfo(org.ethereum.vm.LogInfo) RemascConfigFactory(co.rsk.config.RemascConfigFactory) RskAddress(co.rsk.core.RskAddress) Block(org.ethereum.core.Block) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Example 30 with ActivationConfig

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

the class ProofOfWorkRuleTest method bytesAfterMergedMiningHashAreMoreThan128.

@Test
public void bytesAfterMergedMiningHashAreMoreThan128() {
    // This test shows that a Mining Pools can not add more than 2 outputs with 36 bytes each,
    // otherwise solutions will not be taken as valid.
    RskSystemProperties props = new TestSystemProperties() {

        @Override
        public ActivationConfig getActivationConfig() {
            return ActivationConfigsForTest.all();
        }
    };
    ActivationConfig config = props.getActivationConfig();
    Constants networkConstants = props.getNetworkConstants();
    BlockGenerator blockGenerator = new BlockGenerator(networkConstants, config);
    Block newBlock = blockGenerator.getBlock(1);
    // fork detection data is for heights > 449
    while (newBlock.getNumber() < 455) newBlock = blockGenerator.createChildBlock(newBlock);
    String output1 = "6a24b9e11b6de9aa87561948d72e494fed2fb56bf8fd4193425f9350037f34dec5b13be7";
    String output2 = "aa21a9ed90a5e7d6d8093d20aa54fb01f57da374e016d4a01ddec0210088675e5e3fee4e";
    String output3 = "1111a9ed90a5e7d6d8093d20aa54fb01f57da374e016d4a01ddec0210088675e5e3fee4e";
    byte[] mergedMiningLink = org.bouncycastle.util.Arrays.concatenate(RskMiningConstants.RSK_TAG, newBlock.getHashForMergedMining());
    co.rsk.bitcoinj.core.NetworkParameters params = co.rsk.bitcoinj.params.RegTestParams.get();
    co.rsk.bitcoinj.core.BtcTransaction coinbaseTransaction = MinerUtils.getBitcoinCoinbaseTransaction(params, mergedMiningLink);
    coinbaseTransaction.addOutput(new co.rsk.bitcoinj.core.TransactionOutput(params, coinbaseTransaction, co.rsk.bitcoinj.core.Coin.valueOf(0), Hex.decode(output1)));
    coinbaseTransaction.addOutput(new co.rsk.bitcoinj.core.TransactionOutput(params, coinbaseTransaction, co.rsk.bitcoinj.core.Coin.valueOf(0), Hex.decode(output2)));
    coinbaseTransaction.addOutput(new co.rsk.bitcoinj.core.TransactionOutput(params, coinbaseTransaction, co.rsk.bitcoinj.core.Coin.valueOf(0), Hex.decode(output3)));
    Block block = new BlockMiner(config).mineBlock(newBlock, coinbaseTransaction);
    ProofOfWorkRule rule = new ProofOfWorkRule(props);
    assertFalse(rule.isValid(block));
}
Also used : RskMiningConstants(co.rsk.config.RskMiningConstants) Constants(org.ethereum.config.Constants) BlockMiner(co.rsk.blockchain.utils.BlockMiner) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) TestSystemProperties(co.rsk.config.TestSystemProperties) ParameterizedNetworkUpgradeTest(co.rsk.mine.ParameterizedNetworkUpgradeTest) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

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