Search in sources :

Example 6 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 = mock(BridgeSupport.class);
    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)

Example 7 with ActivationConfig

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

the class BridgeTest method receiveHeaders_after_RSKIP200_notFederation.

@Test
public void receiveHeaders_after_RSKIP200_notFederation() {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(true).when(activations).isActive(eq(RSKIP200), anyLong());
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    when(bridgeSupportMock.getRetiringFederation()).thenReturn(null);
    when(bridgeSupportMock.getActiveFederation()).thenReturn(BridgeRegTestConstants.getInstance().getGenesisFederation());
    Transaction txMock = mock(Transaction.class);
    // acces for anyone
    when(txMock.getSender()).thenReturn(new RskAddress(new ECKey().getAddress()));
    Bridge bridge = getBridgeInstance(txMock, bridgeSupportMock, activations);
    try {
        bridge.execute(Bridge.RECEIVE_HEADERS.encode());
        fail();
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("Sender is not part of the active or retiring federation"));
    }
}
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) VMException(org.ethereum.vm.exception.VMException) IOException(java.io.IOException) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 8 with ActivationConfig

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

the class BridgeTest method registerBtcCoinbaseTransaction_before_RSKIP143_activation.

@Test
public void registerBtcCoinbaseTransaction_before_RSKIP143_activation() throws VMException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(false).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 });
    assertNull(bridge.execute(data));
}
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 9 with ActivationConfig

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

the class BridgeTest method receiveHeaders_after_RSKIP200_header_wrong_size.

@Test
public void receiveHeaders_after_RSKIP200_header_wrong_size() throws VMException, IOException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(true).when(activations).isActive(eq(RSKIP200), anyLong());
    // It is used to check the size of the header
    doReturn(true).when(activations).isActive(eq(RSKIP124), anyLong());
    Bridge bridge = getBridgeInstance(mock(BridgeSupport.class), activations);
    Object[] parameters = new Object[] { Sha256Hash.ZERO_HASH.getBytes() };
    byte[] data = Bridge.RECEIVE_HEADER.encode(parameters);
    byte[] result = bridge.execute(data);
    assertEquals(BigInteger.valueOf(-20), Bridge.RECEIVE_HEADER.decodeResult(result)[0]);
}
Also used : ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 10 with ActivationConfig

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

the class BridgeTest method registerBtcTransaction_beforeRskip199_rejectsExternalCalls.

@Test
public void registerBtcTransaction_beforeRskip199_rejectsExternalCalls() throws VMException, IOException, BlockStoreException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(false).when(activations).isActive(eq(RSKIP199), anyLong());
    Federation activeFederation = new Federation(FederationTestUtils.getFederationMembers(3), 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(new RskAddress("0000000000000000000000000000000000000001"));
    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 });
    try {
        bridge.execute(data);
        fail();
    } catch (VMException e) {
        assertEquals("Exception executing bridge: Sender is not part of the active or retiring federations, so he is not enabled to call the function 'registerBtcTransaction'", e.getMessage());
    }
    verify(bridgeSupportMock, never()).registerBtcTransaction(any(Transaction.class), any(byte[].class), anyInt(), any(byte[].class));
}
Also used : CallTransaction(org.ethereum.core.CallTransaction) Transaction(org.ethereum.core.Transaction) VMException(org.ethereum.vm.exception.VMException) RskAddress(co.rsk.core.RskAddress) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) 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