Skip to content

Commit

Permalink
test: add bitcoin test data
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Jul 17, 2023
1 parent e24fcc6 commit 05ab0fb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Binary file modified data/bitcoin-testdata.gzip
Binary file not shown.
3 changes: 1 addition & 2 deletions parachain/runtime/runtime-tests/src/bitcoin_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use std::{
};

/// Bitcoin blocks and transaction from mainnet taken from blockstream.com
const PATH_MAINNET_BLOCKS_AND_TRANSACTIONS: &str =
"/home/sander/workspace/interlay/btc-parachain/data/bitcoin-testdata.gzip";
const PATH_MAINNET_BLOCKS_AND_TRANSACTIONS: &str = "../../../data/bitcoin-testdata.gzip";

/// Bitcoin core fork testdata from testnet3: https://raw.githubusercontent.com/bitcoin/bitcoin/d6a59166a1879c1dd5b3a301847961f4b3f17742/test/functional/data/blockheader_testnet3.hex
/// The headers data is taken from testnet3 for early blocks from genesis until the first checkpoint. There are
Expand Down
9 changes: 7 additions & 2 deletions parachain/runtime/runtime-tests/src/parachain/btc_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ use btc_relay::DIFFICULTY_ADJUSTMENT_INTERVAL;
#[cfg_attr(feature = "skip-slow-tests", ignore)]
fn integration_test_transaction_formatting_and_txid_calculation() {
// reduce number of blocks to reduce testing time, but higher than 2016 blocks for difficulty adjustment
const BLOCKS_TO_TEST: usize = 5_000;
const BLOCKS_TO_TEST: usize = 2 * 2016 + 1;

// load blocks with transactions
let test_data = get_bitcoin_testdata();

assert!(test_data.len() > BLOCKS_TO_TEST);

// verify all transactions
for block in test_data.iter().take(BLOCKS_TO_TEST) {
assert!(block.test_txs[0].get_tx().is_coinbase());
Expand All @@ -39,7 +41,7 @@ fn integration_test_submit_block_headers_and_verify_transaction_inclusion() {
assert!(!BTCRelayPallet::disable_difficulty_check());

// reduce number of blocks to reduce testing time, but higher than 2016 blocks for difficulty adjustment
const BLOCKS_TO_TEST: usize = 5_000;
const BLOCKS_TO_TEST: usize = 2 * 2016 + 1;

// load blocks with transactions
let test_data = get_bitcoin_testdata();
Expand All @@ -65,6 +67,9 @@ fn integration_test_submit_block_headers_and_verify_transaction_inclusion() {
})
.dispatch(origin_of(account_of(ALICE))));

assert_eq!(skip_blocks, 0);
assert!(test_data.len() > skip_blocks + BLOCKS_TO_TEST);

for block in test_data.iter().skip(skip_blocks + 1).take(BLOCKS_TO_TEST) {
let block_header = block.get_block_header();
let prev_header_hash = block_header.hash_prev_block;
Expand Down
4 changes: 2 additions & 2 deletions scripts/fetch_bitcoin_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
TESTDATA_FILE = os.path.join(TESTDATA_DIR, "bitcoin-testdata.json")
TESTDATA_ZIPPED = os.path.join(TESTDATA_DIR, "bitcoin-testdata.gzip")
BASE_URL = "https://blockstream.info/api"
MAX_BITCOIN_BLOCKS = 5 # recommended to run this script in a loop. 5 blocks will take about a minute
MAX_TXS_PER_BITCOIN_BLOCK = 20
MAX_BITCOIN_BLOCKS = 100 # recommended to run this script in a loop
MAX_TXS_PER_BITCOIN_BLOCK = 2

#######################
# Blockstream queries #
Expand Down

0 comments on commit 05ab0fb

Please sign in to comment.