Skip to content

Commit f519fa0

Browse files
committed
Fix tests for Taproot, use pytest instead of coverage
1 parent c4302f1 commit f519fa0

File tree

6 files changed

+38
-62
lines changed

6 files changed

+38
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pip install -r requirements.txt
5151

5252
Run the test suite by lauching
5353
```
54-
./tests.sh
54+
pytest
5555
```
5656

5757
## Examples

blockchain_parser/tests/test_address.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ def test_from_ripemd160(self):
3030
ripemd160 = "010966776006953D5567439E5E39F86A0D273BEE"
3131
address = Address.from_ripemd160(a2b_hex(ripemd160))
3232
self.assertEqual(address.address, "16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM")
33+
34+
def test_from_bech32(self):
35+
# Example sourced from https://en.bitcoin.it/wiki/Bech32
36+
bech32 = "751e76e8199196d454941c45d1b3a323f1433bd6"
37+
address = Address.from_bech32(a2b_hex(bech32), segwit_version=0)
38+
self.assertEqual(address.address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4")
39+
40+
def test_from_bech32m(self):
41+
# https://blockstream.info/tx/33e794d097969002ee05d336686fc03c9e15a597c1b9827669460fac98799036?expand
42+
# Second output
43+
bech32m = "a37c3903c8d0db6512e2b40b0dffa05e5a3ab73603ce8c9c4b7771e5412328f9"
44+
address = Address.from_bech32m(a2b_hex(bech32m), segwit_version=1)
45+
self.assertEqual(address.address, "bc1p5d7rjq7g6rdk2yhzks9smlaqtedr4dekq08ge8ztwac72sfr9rusxg3297")

blockchain_parser/tests/test_script.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_op_return_script(self):
2727
self.assertFalse(script.is_pubkeyhash())
2828
self.assertFalse(script.is_unknown())
2929
self.assertTrue(script.is_return())
30+
self.assertFalse(script.is_p2tr())
3031

3132
def test_unknown_script(self):
3233
case = "40"
@@ -40,6 +41,7 @@ def test_unknown_script(self):
4041
self.assertFalse(script.is_pubkeyhash())
4142
self.assertTrue(script.is_unknown())
4243
self.assertFalse(script.is_return())
44+
self.assertFalse(script.is_p2tr())
4345

4446
case = ""
4547
script = Script.from_hex(a2b_hex(case))
@@ -52,6 +54,7 @@ def test_unknown_script(self):
5254
self.assertFalse(script.is_pubkeyhash())
5355
self.assertTrue(script.is_unknown())
5456
self.assertFalse(script.is_return())
57+
self.assertFalse(script.is_p2tr())
5558

5659
def test_multisig_script(self):
5760
case = "514104cc71eb30d653c0c3163990c47b976f3fb3f37cccdcbedb169a1dfef58bbfbfaff7d8a473e7e2e6d317b87bafe8bde97e3cf8f065dec022b51d11fcdd0d348ac4410461cbdcc5409fb4b4d42b51d33381354d80e550078cb532a34bfa2fcfdeb7d76519aecc62770f5b0e4ef8551946d8a540911abe3e7854a26f39f58b25c15342af52ae"
@@ -64,6 +67,7 @@ def test_multisig_script(self):
6467
self.assertFalse(script.is_pubkeyhash())
6568
self.assertFalse(script.is_unknown())
6669
self.assertFalse(script.is_return())
70+
self.assertFalse(script.is_p2tr())
6771

6872
def test_p2sh_script(self):
6973
case = "a91428ad3e63dcae36e5010527578e2eef0e9eeaf3e487"
@@ -76,6 +80,7 @@ def test_p2sh_script(self):
7680
self.assertFalse(script.is_pubkeyhash())
7781
self.assertFalse(script.is_unknown())
7882
self.assertFalse(script.is_return())
83+
self.assertFalse(script.is_p2tr())
7984

8085
def test_p2wpkh_script(self):
8186
case = "0014c958269b5b6469b6e4b87de1062028ad3bb83cc2"
@@ -88,6 +93,7 @@ def test_p2wpkh_script(self):
8893
self.assertFalse(script.is_pubkeyhash())
8994
self.assertFalse(script.is_unknown())
9095
self.assertFalse(script.is_return())
96+
self.assertFalse(script.is_p2tr())
9197

9298
def test_p2wsh_script(self):
9399
case = "0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d"
@@ -100,6 +106,7 @@ def test_p2wsh_script(self):
100106
self.assertFalse(script.is_pubkeyhash())
101107
self.assertFalse(script.is_unknown())
102108
self.assertFalse(script.is_return())
109+
self.assertFalse(script.is_p2tr())
103110

104111
def test_pubkeyhash_script(self):
105112
case = "76a914e9629ef6f5b82564a9b2ecae6c288c56fb33710888ac"
@@ -112,6 +119,7 @@ def test_pubkeyhash_script(self):
112119
self.assertTrue(script.is_pubkeyhash())
113120
self.assertFalse(script.is_unknown())
114121
self.assertFalse(script.is_return())
122+
self.assertFalse(script.is_p2tr())
115123

116124
def test_pubkey_script(self):
117125
script = Script.from_hex(a2b_hex("4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"))
@@ -123,3 +131,18 @@ def test_pubkey_script(self):
123131
self.assertFalse(script.is_pubkeyhash())
124132
self.assertFalse(script.is_unknown())
125133
self.assertFalse(script.is_return())
134+
self.assertFalse(script.is_p2tr())
135+
136+
def test_taproot_script(self):
137+
# https://blockstream.info/tx/33e794d097969002ee05d336686fc03c9e15a597c1b9827669460fac98799036?expand
138+
# Second output
139+
script = Script.from_hex(a2b_hex("5120a37c3903c8d0db6512e2b40b0dffa05e5a3ab73603ce8c9c4b7771e5412328f9"))
140+
self.assertFalse(script.is_pubkey())
141+
self.assertFalse(script.is_multisig())
142+
self.assertFalse(script.is_p2sh())
143+
self.assertFalse(script.is_p2wpkh())
144+
self.assertFalse(script.is_p2wsh())
145+
self.assertFalse(script.is_pubkeyhash())
146+
self.assertFalse(script.is_unknown())
147+
self.assertFalse(script.is_return())
148+
self.assertTrue(script.is_p2tr())

blockchain_parser/tests/test_taproot.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
python-bitcoinlib==0.11.0
22
plyvel==1.5.1
33
ripemd-hash==1.0.1
4-
coverage==7.4.4
4+
pytest==8.1.1

tests.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)