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);
}
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"));
}
}
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));
}
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]);
}
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));
}
Aggregations