use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.
the class BlockFactoryTest method setUp.
@Before
public void setUp() {
activationConfig = mock(ActivationConfig.class);
factory = new BlockFactory(activationConfig);
}
use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.
the class RskContextTest method shouldBuildAsyncNodeBlockProcessor.
@Test
public void shouldBuildAsyncNodeBlockProcessor() {
doReturn(new GarbageCollectorConfig(false, 1000, 3)).when(testProperties).garbageCollectorConfig();
doReturn(1).when(testProperties).getNumOfAccountSlots();
doReturn(true).when(testProperties).fastBlockPropagation();
ActivationConfig config = mock(ActivationConfig.class);
doReturn(true).when(config).isActive(eq(ConsensusRule.RSKIP126), anyLong());
doReturn(config).when(testProperties).getActivationConfig();
Constants constants = mock(Constants.class);
doReturn(constants).when(testProperties).getNetworkConstants();
BridgeConstants bridgeConstants = mock(BridgeConstants.class);
doReturn(bridgeConstants).when(constants).getBridgeConstants();
doReturn(1024).when(constants).getGasLimitBoundDivisor();
NodeBlockProcessor nodeBlockProcessor = rskContext.getNodeBlockProcessor();
assertThat(nodeBlockProcessor, is(instanceOf(AsyncNodeBlockProcessor.class)));
}
use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.
the class BridgeTestPowerMock method getBtcTransactionConfirmationsAfterWasabi_ok.
@Test
public void getBtcTransactionConfirmationsAfterWasabi_ok() throws Exception {
Transaction txMock = mock(Transaction.class);
BridgeSupportFactory bridgeSupportFactoryMock = mock(BridgeSupportFactory.class);
Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactoryMock);
bridge.init(txMock, getGenesisBlock(), createRepository().startTracking(), null, null, null);
BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
when(bridgeSupportFactoryMock.newInstance(any(), any(), any(), any())).thenReturn(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);
return 78;
});
Assert.assertEquals(78, bridge.getBtcTransactionConfirmations(new Object[] { btcTxHash, btcBlockHash, merkleBranchBits, merkleBranchHashes }));
}
use of org.ethereum.config.blockchain.upgrades.ActivationConfig 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.config.blockchain.upgrades.ActivationConfig 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