Skip to content

Commit

Permalink
Enable unittests for PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Feb 7, 2024
1 parent 429e2df commit e9dc5c1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
1 change: 0 additions & 1 deletion .github/workflows/unittests-noscrypt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ jobs:
- name: Test with coverage
env:
BCL_CONFIG_FILE: config_encryption.ini.unittest
UNITTESTS_FULL_DATABASE_TEST: False
DB_FIELD_ENCRYPTION_KEY: 11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff
run: coverage run --source=bitcoinlib -m unittest -v
26 changes: 26 additions & 0 deletions .github/workflows/unittests-postgresql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Bitcoinlib Tests Ubuntu - PostgreSQL
on: [push]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python: ["3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install .[dev]
- name: Test with coverage
env:
BCL_CONFIG_FILE: config.ini.unittest
UNITTEST_DATABASE: postgresql
run: coverage run --source=bitcoinlib -m unittest -v
3 changes: 1 addition & 2 deletions .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:

strategy:
matrix:
python: ["3.8", "3.10", "3.11"]
python: ["3.8", "3.11"]

steps:
- uses: actions/checkout@v3
Expand All @@ -22,7 +22,6 @@ jobs:
- name: Test with coverage
env:
BCL_CONFIG_FILE: config.ini.unittest
UNITTESTS_FULL_DATABASE_TEST: False
run: coverage run --source=bitcoinlib -m unittest -v

- name: Coveralls
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/unittests_windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ jobs:
- name: Test with coverage
env:
BCL_CONFIG_FILE: config.ini.unittest
UNITTESTS_FULL_DATABASE_TEST: False
PYTHONUTF8: 1
run: coverage run --source=bitcoinlib -m unittest -v
23 changes: 13 additions & 10 deletions tests/test_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def database_init(dbname=DATABASE_NAME):
try:
cur.execute(sql.SQL("DROP DATABASE IF EXISTS {}").format(sql.Identifier(dbname)))
cur.execute(sql.SQL("CREATE DATABASE {}").format(sql.Identifier(dbname)))
except:
except Exception as e:
print("Error exception %s" % str(e))
pass
cur.close()
con.close()
Expand Down Expand Up @@ -140,7 +141,9 @@ def test_wallet_create_key(self):

def test_wallets_list(self):
wallets = wallets_list(db_uri=self.database_uri)
self.assertEqual(wallets[0]['name'], 'test_wallet_create')
wallet_names = [w['name'] for w in wallets]
# self.assertEqual(wallets[0]['name'], 'test_wallet_create')
self.assertIn('test_wallet_create', wallet_names)

def test_delete_wallet(self):
Wallet.create(
Expand Down Expand Up @@ -467,7 +470,7 @@ def setUpClass(cls):
def test_wallet_export_hdwifs(self):
# p2wpkh
p = 'garage million cheese nephew original subject pass reward month practice advance decide'
w = Wallet.create("wif_import_p2wpkh", p, network='bitcoin', witness_type='segwit',
w = Wallet.create("wif_export_p2wpkh", p, network='bitcoin', witness_type='segwit',
db_uri=self.database_uri)
wif = 'zpub6s7HTSrGmNUWSgfbDMhYbXVuxA14yNnycS25v6ogicEauzUrRUkuCLQUWbJXP1NyXNqGmwpU6hZw7vr22a4yspwH8XQFjjwRmx' \
'CKkXdDAXN'
Expand All @@ -476,7 +479,7 @@ def test_wallet_export_hdwifs(self):

# # p2sh_p2wpkh
p = 'cluster census trash van rack skill feed inflict mixture vocal crew sea'
w = Wallet.create("wif_import_p2sh_p2wpkh", p, network='bitcoin', witness_type='p2sh-segwit',
w = Wallet.create("wif_export_p2sh_p2wpkh", p, network='bitcoin', witness_type='p2sh-segwit',
db_uri=self.database_uri)
wif = 'ypub6YMgBd4GfQjtxUf8ExorFUQEpBfUYTDz7E1tvfNgDqZeDEUuNNVXSNfsebis2cyeqWYXx6yaBBEQV7sJW3NGoXw5wsp9kkEsB2' \
'DqiVquYLE'
Expand All @@ -490,7 +493,7 @@ def test_wallet_export_hdwifs(self):
'Ba5zbv9',
'Zpub74JTMKMB9cTWwE9Hs4UVaHvddqPtR51D99x2B5EGyXyxEg3PW77vfmD15RZ86TVdwwwuUaCueBtvaL921mgyKe9Ya6LHCaMXnEp1'
'PMw4vDy']
w = Wallet.create("wif_import_p2wsh", [p1, p2], witness_type='segwit', network='bitcoin', cosigner_id=0,
w = Wallet.create("wif_export_p2wsh", [p1, p2], witness_type='segwit', network='bitcoin', cosigner_id=0,
db_uri=self.database_uri)
for wif in w.wif(is_private=False):
self.assertIn(wif, wifs)
Expand All @@ -506,7 +509,7 @@ def test_wallet_export_hdwifs(self):
'P8nxY8N',
'Ypub6jVwyh6yYiRoA5zAnGY1g88G5LdaxkHX65d2kSW97yTBAF1RQwAs3UGPz8bX7LvQfg8tc9MQz7eZ79qVigELqSJzfFbGmPak4PZr'
'vW8fZXy']
w = Wallet.create("wif_import_p2sh_p2wsh", [p1, p2, p3], sigs_required=2, witness_type='p2sh-segwit',
w = Wallet.create("wif_export_p2sh_p2wsh", [p1, p2, p3], sigs_required=2, witness_type='p2sh-segwit',
network='bitcoin', cosigner_id=0, db_uri=self.database_uri)
for wif in w.wif(is_private=False):
self.assertIn(wif, wifs)
Expand Down Expand Up @@ -1292,8 +1295,8 @@ def test_wallet_multisig_sign_with_external_single_key(self):
HDKey(network=network),
hdkey.public()
]
wallet = Wallet.create('Multisig-2-of-3-example', key_list, sigs_required=2, network=network,
db_uri=self.database_uri)
wallet = Wallet.create('test_wallet_multisig_sign_with_external_single_key',
key_list, sigs_required=2, network=network, db_uri=self.database_uri)
wallet.new_key()
wallet.utxos_update()
wt = wallet.send_to('21A6yyUPRL9hZZo1Rw4qP5G6h9idVVLUncE', 10000000, offline=False)
Expand Down Expand Up @@ -2464,7 +2467,7 @@ def test_wallet_segwit_litecoin_sweep(self):
def test_wallet_segwit_litecoin_multisig(self):
p1 = 'only sing document speed outer gauge stand govern way column material odor'
p2 = 'oyster pelican debate mass scene title pipe lock recipe flavor razor accident'
w = wallet_create_or_open('ltcswms', [p1, p2], network='litecoin', witness_type='segwit',
w = wallet_create_or_open('ltc_segwit_ms', [p1, p2], network='litecoin', witness_type='segwit',
cosigner_id=0, db_uri=self.database_uri)
w.get_keys(number_of_keys=2)
w.utxo_add('ltc1qkewaz7lxn75y6wppvqlsfhrnq5p5mksmlp26n8xsef0556cdfzqq2uhdrt', 2100000000000001,
Expand Down Expand Up @@ -2512,7 +2515,7 @@ def test_wallet_segwit_multiple_account_paths(self):
def test_wallet_segwit_multiple_networks_accounts(self):
pk1 = 'surround vacant shoot aunt acoustic liar barely you expand rug industry grain'
pk2 = 'defy push try brush ceiling sugar film present goat settle praise toilet'
wallet = Wallet.create(keys=[pk1, pk2], network='bitcoin', name='test_wallet_multicurrency',
wallet = Wallet.create(keys=[pk1, pk2], network='bitcoin', name='test_wallet_segwit_multicurrency',
witness_type='segwit', cosigner_id=0, encoding='base58',
db_uri=self.database_uri)
wallet.new_account(network='litecoin')
Expand Down

0 comments on commit e9dc5c1

Please sign in to comment.