use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class ProgramTest method testCallToPrecompiledAddress_throwPrecompiledConstractException.
@Test
public void testCallToPrecompiledAddress_throwPrecompiledConstractException() throws VMException {
when(precompiledContract.execute(any())).thenThrow(new VMException("Revert exception"));
program.callToPrecompiledAddress(msg, precompiledContract);
assertStack(STACK_STATE_ERROR);
assertEquals(gasCost, program.getResult().getGasUsed());
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class RemascContract method execute.
@Override
public byte[] execute(byte[] data) throws VMException {
try {
CallTransaction.Function function = this.getFunction(data);
Method m = this.getClass().getMethod(function.name);
Object result = this.invoke(m);
remasc.save();
return this.encodeResult(function, result);
} catch (RemascInvalidInvocationException ex) {
// Remasc contract was invoked with invalid parameters / out of place, throw VMException to avoid funds being transferred
logger.warn(ex.getMessage(), ex);
throw new VMException(ex.getMessage());
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
panicProcessor.panic("remascExecute", ex.getMessage());
throw new VMException("Exception executing remasc", ex);
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class BridgeTestPowerMock method executeWithInexistentFunctionAfterRskip88.
@Test
public void executeWithInexistentFunctionAfterRskip88() {
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[4]);
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 BridgeTestPowerMock method getBtcTransactionConfirmationsAfterWasabi_merkleBranchConstructionError.
@Test
public void getBtcTransactionConfirmationsAfterWasabi_merkleBranchConstructionError() throws Exception {
Transaction txMock = mock(Transaction.class);
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), bridgeConstants, activationConfig);
Bridge bridge = PowerMockito.spy(new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory));
bridge.init(txMock, getGenesisBlock(), createRepository().startTracking(), null, null, null);
BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
byte[] btcTxHash = Sha256Hash.of(Hex.decode("aabbcc")).getBytes();
byte[] btcBlockHash = Sha256Hash.of(Hex.decode("ddeeff")).getBytes();
byte[][] merkleBranchHashes = new byte[][] { Sha256Hash.of(Hex.decode("11")).getBytes(), Sha256Hash.of(Hex.decode("22")).getBytes(), Sha256Hash.of(Hex.decode("33")).getBytes() };
BigInteger merkleBranchBits = BigInteger.valueOf(123);
MerkleBranch merkleBranch = mock(MerkleBranch.class);
PowerMockito.whenNew(MerkleBranch.class).withArguments(any(List.class), any(Integer.class)).then((Answer<MerkleBranch>) invocation -> {
List<Sha256Hash> hashes = invocation.getArgument(0);
Assert.assertArrayEquals(merkleBranchHashes[0], hashes.get(0).getBytes());
Assert.assertArrayEquals(merkleBranchHashes[1], hashes.get(1).getBytes());
Assert.assertArrayEquals(merkleBranchHashes[2], hashes.get(2).getBytes());
Integer bits = invocation.getArgument(1);
Assert.assertEquals(123, bits.intValue());
throw new IllegalArgumentException("blabla");
});
try {
bridge.getBtcTransactionConfirmations(new Object[] { btcTxHash, btcBlockHash, merkleBranchBits, merkleBranchHashes });
Assert.fail();
} catch (VMException e) {
Assert.assertTrue(e.getMessage().contains("in getBtcTransactionConfirmations"));
Assert.assertEquals(IllegalArgumentException.class, e.getCause().getClass());
verify(bridgeSupportMock, never()).getBtcTransactionConfirmations(any(), any(), any());
}
}
use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.
the class BridgeTestPowerMock method getBtcTransactionConfirmationsAfterWasabi_errorInBridgeSupport.
@Test
public void getBtcTransactionConfirmationsAfterWasabi_errorInBridgeSupport() throws Exception {
Transaction txMock = mock(Transaction.class);
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), bridgeConstants, activationConfig);
Bridge bridge = PowerMockito.spy(new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory));
bridge.init(txMock, getGenesisBlock(), createRepository().startTracking(), null, null, null);
BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
byte[] btcTxHash = Sha256Hash.of(Hex.decode("aabbcc")).getBytes();
byte[] btcBlockHash = Sha256Hash.of(Hex.decode("ddeeff")).getBytes();
byte[][] merkleBranchHashes = new byte[][] { Sha256Hash.of(Hex.decode("11")).getBytes(), Sha256Hash.of(Hex.decode("22")).getBytes(), Sha256Hash.of(Hex.decode("33")).getBytes() };
BigInteger merkleBranchBits = BigInteger.valueOf(123);
MerkleBranch merkleBranch = mock(MerkleBranch.class);
PowerMockito.whenNew(MerkleBranch.class).withArguments(any(List.class), any(Integer.class)).then((Answer<MerkleBranch>) invocation -> {
List<Sha256Hash> hashes = invocation.getArgument(0);
Assert.assertArrayEquals(merkleBranchHashes[0], hashes.get(0).getBytes());
Assert.assertArrayEquals(merkleBranchHashes[1], hashes.get(1).getBytes());
Assert.assertArrayEquals(merkleBranchHashes[2], hashes.get(2).getBytes());
Integer bits = invocation.getArgument(1);
Assert.assertEquals(123, bits.intValue());
return merkleBranch;
});
when(bridgeSupportMock.getBtcTransactionConfirmations(any(Sha256Hash.class), any(Sha256Hash.class), any(MerkleBranch.class))).then((Answer<Integer>) invocation -> {
Sha256Hash txHash = invocation.getArgument(0);
Assert.assertArrayEquals(btcTxHash, txHash.getBytes());
Sha256Hash blockHash = invocation.getArgument(1);
Assert.assertArrayEquals(btcBlockHash, blockHash.getBytes());
MerkleBranch merkleBranchArg = invocation.getArgument(2);
Assert.assertEquals(merkleBranch, merkleBranchArg);
throw new VMException("bla bla bla");
});
try {
bridge.getBtcTransactionConfirmations(new Object[] { btcTxHash, btcBlockHash, merkleBranchBits, merkleBranchHashes });
Assert.fail();
} catch (VMException e) {
Assert.assertTrue(e.getMessage().contains("in getBtcTransactionConfirmations"));
Assert.assertEquals(VMException.class, e.getCause().getClass());
Assert.assertTrue(e.getCause().getMessage().contains("bla bla bla"));
}
}
Aggregations