]> Untitled Git - bdk/commitdiff
Run blockchain tests on esplora
authorLLFourn <lloyd.fourn@gmail.com>
Tue, 18 May 2021 05:21:48 +0000 (15:21 +1000)
committerLLFourn <lloyd.fourn@gmail.com>
Wed, 19 May 2021 05:47:44 +0000 (15:47 +1000)
They were only being run on electrum before.

.github/workflows/cont_integration.yml
Cargo.toml
ci/start-core.sh
src/blockchain/esplora.rs
testutils/src/blockchain_tests.rs

index 3a92f052a64c3fa5c5268af5a989fde8f843b817..dd899cd4087e3b63b13a14c2dc1150a69a8269a5 100644 (file)
@@ -73,10 +73,19 @@ jobs:
       - name: Test
         run: cargo test --features test-md-docs --no-default-features -- doctest::ReadmeDoctests
 
-  test-electrum:
-    name: Test electrum
+  test-blockchains:
+    name: test ${{ matrix.blockchain.name }}
     runs-on: ubuntu-16.04
-    container: bitcoindevkit/electrs:0.2.0
+    strategy:
+      matrix:
+        blockchain:
+          - name: electrum
+            container: bitcoindevkit/electrs
+            start: /root/electrs --network regtest --jsonrpc-import
+          - name: esplora
+            container: bitcoindevkit/esplora
+            start: /root/electrs --network regtest -vvv --cookie admin:passw --jsonrpc-import --electrum-rpc-addr=0.0.0.0:60401 --http-addr 0.0.0.0:3002
+    container: ${{ matrix.blockchain.container }}
     env:
       BDK_RPC_AUTH: USER_PASS
       BDK_RPC_USER: admin
@@ -84,6 +93,7 @@ jobs:
       BDK_RPC_URL: 127.0.0.1:18443
       BDK_RPC_WALLET: bdk-test
       BDK_ELECTRUM_URL: tcp://127.0.0.1:60401
+      BDK_ESPLORA_URL: http://127.0.0.1:3002
     steps:
       - name: Checkout
         uses: actions/checkout@v2
@@ -95,6 +105,8 @@ jobs:
             ~/.cargo/git
             target
           key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
+      - name: get pkg-config # running eslpora tests seems to need this
+        run: apt update && apt install -y --fix-missing pkg-config libssl-dev
       - name: Install rustup
         run: curl https://sh.rustup.rs -sSf | sh -s -- -y
       - name: Set default toolchain
@@ -105,8 +117,10 @@ jobs:
         run: $HOME/.cargo/bin/rustup update
       - name: Start core
         run: ./ci/start-core.sh
+      - name: start ${{ matrix.blockchain.name }}
+        run: nohup ${{ matrix.blockchain.start }} & sleep 5
       - name: Test
-        run: $HOME/.cargo/bin/cargo test --features test-electrum --no-default-features
+        run: $HOME/.cargo/bin/cargo test --features test-${{ matrix.blockchain.name }} --no-default-features ${{ matrix.blockchain.name }}::bdk_blockchain_tests
 
   check-wasm:
     name: Check WASM
index 52176e5dadf1e418ec04e70af47c8cb3ae9e0649..44a5623caacad65e461ab7708e6d111f01f6b125 100644 (file)
@@ -55,6 +55,7 @@ keys-bip39 = ["tiny-bip39"]
 
 # Debug/Test features
 test-electrum = ["electrum"]
+test-esplora = ["esplora"]
 test-md-docs = ["electrum"]
 
 [dev-dependencies]
index 59c024e120a834a677928c3eeba6dcfc589d45b6..455442b45f24d8786bb7478fd7578740728e8e11 100755 (executable)
@@ -11,7 +11,3 @@ done
 echo "Generating 150 bitcoin blocks."
 ADDR=$(/root/bitcoin-cli -regtest -rpcuser=$BDK_RPC_USER -rpcpassword=$BDK_RPC_PASS -rpcwallet=$BDK_RPC_WALLET getnewaddress)
 /root/bitcoin-cli -regtest -rpcuser=$BDK_RPC_USER -rpcpassword=$BDK_RPC_PASS generatetoaddress 150 $ADDR
-
-echo "Starting electrs node."
-nohup /root/electrs --network regtest --jsonrpc-import &
-sleep 5
index 793da96b8cfdbc3444fbb00b13b4b7805554be2a..5214fcec049efaf3d6bbb133f0ab0ed8f7a369df 100644 (file)
@@ -414,3 +414,11 @@ impl_error!(reqwest::Error, Reqwest, EsploraError);
 impl_error!(std::num::ParseIntError, Parsing, EsploraError);
 impl_error!(consensus::encode::Error, BitcoinEncoding, EsploraError);
 impl_error!(bitcoin::hashes::hex::Error, Hex, EsploraError);
+
+#[cfg(all(feature = "test-esplora", test))]
+testutils::bdk_blockchain_tests! {
+    bdk => crate,
+    fn test_instance() -> EsploraBlockchain {
+        EsploraBlockchain::new(std::env::var("BDK_ESPLORA_URL").unwrap_or("127.0.0.1:3002".into()).as_str(), None)
+    }
+}
index 95ebcc4b99237b7d89a07c9a4bec4dff0365b1bd..07953a3d44684af6151739eb03cd8314f250f2e4 100644 (file)
@@ -193,6 +193,9 @@ macro_rules! bdk_blockchain_tests {
                 assert_eq!(list_tx_item.height, None);
             }
 
+            // FIXME: I would like this to be cfg_attr(not(feature = "test-esplora"), ignore) but it
+            // doesn't work for some reason.
+            #[cfg(not(feature = "test-esplora"))]
             #[test]
             #[serial]
             fn test_sync_reorg_block() {