use of co.rsk.bitcoinj.core.BtcBlock in project rskj by rsksmart.
the class ReceiveHeadersTest method receiveHeaders.
@Test
public void receiveHeaders() throws IOException {
final int minBtcBlocks = 1000;
final int maxBtcBlocks = 2000;
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
BtcBlockStore btcBlockStore = new RepositoryBlockStore(new RskSystemProperties(), repository, PrecompiledContracts.BRIDGE_ADDR);
Context btcContext = new Context(networkParameters);
BtcBlockChain btcBlockChain;
try {
btcBlockChain = new BtcBlockChain(btcContext, btcBlockStore);
} catch (BlockStoreException e) {
throw new RuntimeException("Error initializing btc blockchain for tests");
}
int blocksToGenerate = Helper.randomInRange(minBtcBlocks, maxBtcBlocks);
BtcBlock lastBlock = Helper.generateAndAddBlocks(btcBlockChain, blocksToGenerate);
blockToTry = Helper.generateBtcBlock(lastBlock);
};
ABIEncoder abiEncoder = (int executionIndex) -> {
List<BtcBlock> headersToSendToBridge = new ArrayList<>();
// Send just one header (that's the only case we're interested in measuring atm
headersToSendToBridge.add(blockToTry);
Object[] headersEncoded = headersToSendToBridge.stream().map(h -> h.bitcoinSerialize()).toArray();
return Bridge.RECEIVE_HEADERS.encode(new Object[] { headersEncoded });
};
ExecutionStats stats = new ExecutionStats("receiveHeaders");
executeAndAverage("receiveHeaders", 200, abiEncoder, storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats);
BridgePerformanceTest.addStats(stats);
}
Aggregations