use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class BridgeTestPowerMock method receiveHeadersAccess_beforePublic_noAccessIfNotFromFederationMember.
@Test
public void receiveHeadersAccess_beforePublic_noAccessIfNotFromFederationMember() throws Exception {
doReturn(false).when(activationConfig).isActive(eq(RSKIP124), anyLong());
RskAddress sender = new RskAddress("2acc95758f8b5f583470ba265eb685a8f45fc9d5");
Transaction txMock = mock(Transaction.class);
when(txMock.getReceiveAddress()).thenReturn(PrecompiledContracts.BRIDGE_ADDR);
when(txMock.getSender()).thenReturn(sender);
BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
when(bridgeSupportMock.getRetiringFederation()).thenReturn(null);
when(bridgeSupportMock.getActiveFederation()).thenReturn(BridgeRegTestConstants.getInstance().getGenesisFederation());
BridgeSupportFactory bridgeSupportFactoryMock = mock(BridgeSupportFactory.class);
Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactoryMock);
when(bridgeSupportFactoryMock.newInstance(any(), any(), any(), any())).thenReturn(bridgeSupportMock);
bridge.init(txMock, getGenesisBlock(), null, null, null, null);
byte[][] headers = new byte[][] { Hex.decode("0000002006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910ff698ee112158f5573a90b7403cfba074addd61c547b3639c6afdcf52588eb8e2a1ef825cffff7f2000000000") };
byte[] data = BridgeMethods.RECEIVE_HEADERS.getFunction().encode(new Object[] { headers });
try {
bridge.execute(data);
Assert.fail();
} catch (VMException e) {
Assert.assertTrue(e.getMessage().contains("Sender is not part of the active"));
}
verify(bridgeSupportMock, never()).receiveHeaders(any(BtcBlock[].class));
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class BridgeTestPowerMock method executeWithFunctionSignatureLengthTooShortAfterRskip88.
@Test
public void executeWithFunctionSignatureLengthTooShortAfterRskip88() {
doReturn(false).when(activationConfig).isActive(eq(RSKIP87), anyLong());
doReturn(true).when(activationConfig).isActive(eq(RSKIP88), anyLong());
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), bridgeConstants, activationConfig);
Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory);
Transaction mockedTx = mock(Transaction.class);
try {
bridge.init(mockedTx, getGenesisBlock(), createRepository().startTracking(), null, null, null);
bridge.execute(new byte[3]);
Assert.fail();
} catch (VMException e) {
Assert.assertTrue(e.getMessage().contains("Invalid data given"));
}
}
use of org.ethereum.vm.exception.VMException 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));
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class BridgeTestPowerMock method executeMethodWithOnlyLocalCallsAllowed_nonLocalCallTx.
@Test
public void executeMethodWithOnlyLocalCallsAllowed_nonLocalCallTx() {
doReturn(false).when(activationConfig).isActive(eq(RSKIP87), anyLong());
doReturn(true).when(activationConfig).isActive(eq(RSKIP88), anyLong());
BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
try {
Transaction tx = mock(Transaction.class);
when(tx.isLocalCallTransaction()).thenReturn(false);
BridgeSupportFactory bridgeSupportFactoryMock = mock(BridgeSupportFactory.class);
Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactoryMock);
when(bridgeSupportFactoryMock.newInstance(any(), any(), any(), any())).thenReturn(bridgeSupportMock);
bridge.init(tx, getGenesisBlock(), null, null, null, null);
byte[] data = BridgeMethods.GET_FEDERATION_ADDRESS.getFunction().encode(new Object[] {});
bridge.execute(data);
Assert.fail();
} catch (VMException e) {
verify(bridgeSupportMock, never()).getFederationAddress();
Assert.assertTrue(e.getMessage().contains("Non-local-call"));
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class BridgeTestPowerMock method getBtcBlockchainBlockLocatorAfterRskip88And89Fork.
@Test
public void getBtcBlockchainBlockLocatorAfterRskip88And89Fork() {
doReturn(true).when(activationConfig).isActive(eq(RSKIP88), anyLong());
doReturn(true).when(activationConfig).isActive(eq(RSKIP89), anyLong());
Repository repository = createRepository();
Repository track = repository.startTracking();
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), bridgeConstants, activationConfig);
Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory);
bridge.init(mock(Transaction.class), getGenesisBlock(), track, null, null, null);
try {
bridge.execute(Bridge.GET_BTC_BLOCKCHAIN_BLOCK_LOCATOR.encode(new Object[] {}));
Assert.fail();
} catch (VMException e) {
Assert.assertTrue(e.getMessage().contains("Invalid data given:"));
}
}
Aggregations