Skip to content

Commit

Permalink
macOS fixes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapsk committed Oct 25, 2022
1 parent 8bdc9db commit 2eedf0a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: Test Bitcoin scripts
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
name: bitcoind ${{ matrix.bitcoind-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
bitcoind-version: ["0.16.3", "23.0"]
bitcoind-version: ["0.17.2", "23.0"]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: Setup BATS
Expand All @@ -21,10 +23,10 @@ jobs:
BITCOIND_VERSION: ${{ matrix.bitcoind-version }}
with:
path: ~/bitcoin/*/bin/bitcoin*
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.BITCOIND_VERSION }}-${{ hashFiles('tests/install_bitcoind.sh') }}
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.BITCOIND_VERSION }}-${{ hashFiles('tests/functional/install_deps.sh') }}
- name: Install bitcoind
env:
BITCOIND_VERSION: ${{ matrix.bitcoind-version }}
run: ./tests/install_bitcoind.sh
run: ./tests/functional/install_deps.sh
- name: Run functional tests
run: ./tests/functional/test_all.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Various shell scripts, mainly to be used together with [Bitcoin Core](https://github.com/bitcoin/bitcoin) (bitcoind or bitcoin-qt) wallet. I also have [some scripts for CLN (Core Lightning / c-lightning)](https://github.com/kristapsk/cln-scripts).

Dependencies: `bash`, `bitcoin-cli` (v0.15 or newer), `awk`, `bc`, [`jq`](https://github.com/stedolan/jq), `sed`.
Dependencies: `bash` 4+, `bitcoin-cli` (v0.17 or newer), `awk`, `bc`, [`jq`](https://github.com/stedolan/jq), `sed`.

Scripts use Bitcoin JSON-RPC API, so it must be enabled in `bitcoin.conf` (`server=1`, `rpcuser=` and `rpcpassword=` settings).

Expand Down
11 changes: 10 additions & 1 deletion inc.common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,19 @@ function signrawtransactionwithwallet()
echo "$signedtx"
}

function sha256()
{
if [[ "$(uname)" == "Darwin" ]]; then
shasum -a 256
else
sha256sum
fi
}

# Returns SHA-256d of input, where SHA-256d(x) = SHA-256(SHA-256(x))
function sha256d()
{
echo -en "$(sha256sum | grep -Eo "[a-z0-9]{64}" | sed 's/.\{2\}/\\x&/g')" | sha256sum | grep -Eo "[a-z0-9]{64}"
echo -en "$(sha256 | grep -Eo "[a-z0-9]{64}" | sed 's/.\{2\}/\\x&/g')" | sha256 | grep -Eo "[a-z0-9]{64}"
}

# show_tx_by_id txid [blockhash]
Expand Down
12 changes: 7 additions & 5 deletions tests/functional/inc.setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ echo -e "[regtest]\nrpcuser=bitcoinrpc\nrpcpassword=123456abcdef" \
$bitcoind -daemon || exit 1
# Wait until bitcoind has started properly
while ! $bitcoin_cli getblockchaininfo 2> /dev/null; do sleep 0.1; done
# Create and load wallet (descriptor wallets aren't supported yet)
if ! $bitcoin_cli -named createwallet wallet_name=tests descriptors=false; then
# fallback for old Core versions
$bitcoin_cli createwallet tests
# Create and load wallet if there is no default wallet (descriptor wallets aren't supported yet)
if [[ "$($bitcoin_cli listwallets | jq ". | length")" == "0" ]]; then
if ! $bitcoin_cli -named createwallet wallet_name=tests descriptors=false 2> /dev/null; then
# fallback for old Core versions
$bitcoin_cli createwallet tests
fi
fi
$bitcoin_cli loadwallet tests
#$bitcoin_cli loadwallet tests
# Generate some coins
$bitcoin_cli generatetoaddress 1 "$($bitcoin_cli getnewaddress "" "legacy")"
$bitcoin_cli generatetoaddress 1 "$($bitcoin_cli getnewaddress "" "legacy")"
Expand Down
19 changes: 17 additions & 2 deletions tests/install_bitcoind.sh → tests/functional/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@ if [[ -z "$BITCOIND_VERSION" ]]; then
exit 1
fi

if [[ "$(uname)" == "Linux" ]]; then
platform="x86_64-linux-gnu"
elif [[ "$(uname)" == "Darwin" ]]; then
if [[ $BITCOIND_VERSION > 23.0 || $BITCOIND_VERSION == 23.0 ]]; then
platform="x86_64-apple-darwin"
else
platform="osx64"
fi

brew install bash coreutils jq
else
echo "Unsupported platform: $(uname)"
exit 1
fi

if sudo cp ~/bitcoin/bitcoin-$BITCOIND_VERSION/bin/bitcoind /usr/local/bin/bitcoind; then
echo "found cached bitcoind"
sudo cp ~/bitcoin/bitcoin-$BITCOIND_VERSION/bin/bitcoin-cli /usr/local/bin/bitcoin-cli
else
mkdir -p ~/bitcoin && \
pushd ~/bitcoin && \
wget https://bitcoincore.org/bin/bitcoin-core-$BITCOIND_VERSION/bitcoin-$BITCOIND_VERSION-x86_64-linux-gnu.tar.gz && \
tar xvfz bitcoin-$BITCOIND_VERSION-x86_64-linux-gnu.tar.gz && \
wget https://bitcoincore.org/bin/bitcoin-core-$BITCOIND_VERSION/bitcoin-$BITCOIND_VERSION-$platform.tar.gz && \
tar xvfz bitcoin-$BITCOIND_VERSION-$platform.tar.gz && \
sudo cp ./bitcoin-$BITCOIND_VERSION/bin/bitcoind /usr/local/bin/bitcoind && \
sudo cp ./bitcoin-$BITCOIND_VERSION/bin/bitcoin-cli /usr/local/bin/bitcoin-cli && \
popd
Expand Down

0 comments on commit 2eedf0a

Please sign in to comment.