Search in sources :

Example 11 with VMException

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));
}
Also used : SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) VMException(org.ethereum.vm.exception.VMException) RskAddress(co.rsk.core.RskAddress) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with VMException

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"));
    }
}
Also used : SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) VMException(org.ethereum.vm.exception.VMException) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with VMException

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));
}
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)

Example 14 with VMException

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"));
    }
}
Also used : SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) VMException(org.ethereum.vm.exception.VMException) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with VMException

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:"));
    }
}
Also used : MutableRepository(org.ethereum.db.MutableRepository) SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) VMException(org.ethereum.vm.exception.VMException) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

VMException (org.ethereum.vm.exception.VMException)29 IOException (java.io.IOException)16 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)14 Test (org.junit.Test)11 BigInteger (java.math.BigInteger)9 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)9 SimpleBtcTransaction (co.rsk.peg.bitcoin.SimpleBtcTransaction)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 RskAddress (co.rsk.core.RskAddress)6 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)5 Keccak256 (co.rsk.crypto.Keccak256)4 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)3 BtcBlockStore (co.rsk.bitcoinj.store.BtcBlockStore)3 BridgeConstants (co.rsk.config.BridgeConstants)3 BridgeRegTestConstants (co.rsk.config.BridgeRegTestConstants)3 TestSystemProperties (co.rsk.config.TestSystemProperties)3 MerkleBranch (co.rsk.peg.bitcoin.MerkleBranch)3 OneOffWhiteListEntry (co.rsk.peg.whitelist.OneOffWhiteListEntry)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Instant (java.time.Instant)3