Skip to content

Commit

Permalink
Fix tests for Taproot, use pytest instead of coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alecalve committed Mar 23, 2024
1 parent c4302f1 commit f519fa0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pip install -r requirements.txt

Run the test suite by lauching
```
./tests.sh
pytest
```

## Examples
Expand Down
13 changes: 13 additions & 0 deletions blockchain_parser/tests/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ def test_from_ripemd160(self):
ripemd160 = "010966776006953D5567439E5E39F86A0D273BEE"
address = Address.from_ripemd160(a2b_hex(ripemd160))
self.assertEqual(address.address, "16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM")

def test_from_bech32(self):
# Example sourced from https://en.bitcoin.it/wiki/Bech32
bech32 = "751e76e8199196d454941c45d1b3a323f1433bd6"
address = Address.from_bech32(a2b_hex(bech32), segwit_version=0)
self.assertEqual(address.address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4")

def test_from_bech32m(self):
# https://blockstream.info/tx/33e794d097969002ee05d336686fc03c9e15a597c1b9827669460fac98799036?expand
# Second output
bech32m = "a37c3903c8d0db6512e2b40b0dffa05e5a3ab73603ce8c9c4b7771e5412328f9"
address = Address.from_bech32m(a2b_hex(bech32m), segwit_version=1)
self.assertEqual(address.address, "bc1p5d7rjq7g6rdk2yhzks9smlaqtedr4dekq08ge8ztwac72sfr9rusxg3297")
23 changes: 23 additions & 0 deletions blockchain_parser/tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_op_return_script(self):
self.assertFalse(script.is_pubkeyhash())
self.assertFalse(script.is_unknown())
self.assertTrue(script.is_return())
self.assertFalse(script.is_p2tr())

def test_unknown_script(self):
case = "40"
Expand All @@ -40,6 +41,7 @@ def test_unknown_script(self):
self.assertFalse(script.is_pubkeyhash())
self.assertTrue(script.is_unknown())
self.assertFalse(script.is_return())
self.assertFalse(script.is_p2tr())

case = ""
script = Script.from_hex(a2b_hex(case))
Expand All @@ -52,6 +54,7 @@ def test_unknown_script(self):
self.assertFalse(script.is_pubkeyhash())
self.assertTrue(script.is_unknown())
self.assertFalse(script.is_return())
self.assertFalse(script.is_p2tr())

def test_multisig_script(self):
case = "514104cc71eb30d653c0c3163990c47b976f3fb3f37cccdcbedb169a1dfef58bbfbfaff7d8a473e7e2e6d317b87bafe8bde97e3cf8f065dec022b51d11fcdd0d348ac4410461cbdcc5409fb4b4d42b51d33381354d80e550078cb532a34bfa2fcfdeb7d76519aecc62770f5b0e4ef8551946d8a540911abe3e7854a26f39f58b25c15342af52ae"
Expand All @@ -64,6 +67,7 @@ def test_multisig_script(self):
self.assertFalse(script.is_pubkeyhash())
self.assertFalse(script.is_unknown())
self.assertFalse(script.is_return())
self.assertFalse(script.is_p2tr())

def test_p2sh_script(self):
case = "a91428ad3e63dcae36e5010527578e2eef0e9eeaf3e487"
Expand All @@ -76,6 +80,7 @@ def test_p2sh_script(self):
self.assertFalse(script.is_pubkeyhash())
self.assertFalse(script.is_unknown())
self.assertFalse(script.is_return())
self.assertFalse(script.is_p2tr())

def test_p2wpkh_script(self):
case = "0014c958269b5b6469b6e4b87de1062028ad3bb83cc2"
Expand All @@ -88,6 +93,7 @@ def test_p2wpkh_script(self):
self.assertFalse(script.is_pubkeyhash())
self.assertFalse(script.is_unknown())
self.assertFalse(script.is_return())
self.assertFalse(script.is_p2tr())

def test_p2wsh_script(self):
case = "0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d"
Expand All @@ -100,6 +106,7 @@ def test_p2wsh_script(self):
self.assertFalse(script.is_pubkeyhash())
self.assertFalse(script.is_unknown())
self.assertFalse(script.is_return())
self.assertFalse(script.is_p2tr())

def test_pubkeyhash_script(self):
case = "76a914e9629ef6f5b82564a9b2ecae6c288c56fb33710888ac"
Expand All @@ -112,6 +119,7 @@ def test_pubkeyhash_script(self):
self.assertTrue(script.is_pubkeyhash())
self.assertFalse(script.is_unknown())
self.assertFalse(script.is_return())
self.assertFalse(script.is_p2tr())

def test_pubkey_script(self):
script = Script.from_hex(a2b_hex("4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"))
Expand All @@ -123,3 +131,18 @@ def test_pubkey_script(self):
self.assertFalse(script.is_pubkeyhash())
self.assertFalse(script.is_unknown())
self.assertFalse(script.is_return())
self.assertFalse(script.is_p2tr())

def test_taproot_script(self):
# https://blockstream.info/tx/33e794d097969002ee05d336686fc03c9e15a597c1b9827669460fac98799036?expand
# Second output
script = Script.from_hex(a2b_hex("5120a37c3903c8d0db6512e2b40b0dffa05e5a3ab73603ce8c9c4b7771e5412328f9"))
self.assertFalse(script.is_pubkey())
self.assertFalse(script.is_multisig())
self.assertFalse(script.is_p2sh())
self.assertFalse(script.is_p2wpkh())
self.assertFalse(script.is_p2wsh())
self.assertFalse(script.is_pubkeyhash())
self.assertFalse(script.is_unknown())
self.assertFalse(script.is_return())
self.assertTrue(script.is_p2tr())
55 changes: 0 additions & 55 deletions blockchain_parser/tests/test_taproot.py

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
python-bitcoinlib==0.11.0
plyvel==1.5.1
ripemd-hash==1.0.1
coverage==7.4.4
pytest==8.1.1
5 changes: 0 additions & 5 deletions tests.sh

This file was deleted.

0 comments on commit f519fa0

Please sign in to comment.