Skip to content

Commit

Permalink
feat: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger committed Nov 22, 2023
1 parent 655b761 commit ee32cd8
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ path = 'contracts/tests/clarity-bitcoin_test.clar'
clarity_version = 2
epoch = 2.1

[contracts.clarity-bitcoin-read_test]
path = 'contracts/tests/clarity-bitcoin-read_test.clar'
clarity_version = 2
epoch = 2.1

[contracts.helper]
path = 'contracts/helper.clar'
clarity_version = 2
Expand Down
76 changes: 76 additions & 0 deletions contracts/tests/clarity-bitcoin-read_test.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
(define-public (test-read-varints-8-zero)
(let ((result (contract-call? .clarity-bitcoin read-varint {index: u0, txbuff: 0x00112233445566})))
(asserts! (is-ok result) (err result))
(asserts! (is-eq (unwrap-panic result) {varint: u0, ctx: {index: u1, txbuff: 0x00112233445566}}) (err result))
(ok true))
)

(define-public (test-read-varints-8-252)
(let ((result (contract-call? .clarity-bitcoin read-varint {index: u0, txbuff: 0xfc112233445566})))
(asserts! (is-ok result) (err result))
(asserts! (is-eq (unwrap-panic result) {varint: u252, ctx: {index: u1, txbuff: 0xfc112233445566}}) (err result))
(ok true))
)


(define-public (test-read-varints-16)
(let ((result (contract-call? .clarity-bitcoin read-varint {index: u0, txbuff: 0xfd112233445566})))
(asserts! (is-ok result) (err result))
(asserts! (is-eq (unwrap-panic result) {varint: u8721, ctx: {index: u3, txbuff: 0xfd112233445566}}) (err result))
(ok true))
)
(define-public (test-read-varints-32)
(let ((result (contract-call? .clarity-bitcoin read-varint {index: u0, txbuff: 0xfe112233445566})))
(asserts! (is-ok result) (err result))
(asserts! (is-eq (unwrap-panic result) {varint: u1144201745, ctx: {index: u5, txbuff: 0xfe112233445566}}) (err result))
(ok true))
)

(define-public (test-read-varints-64)
(let ((result (contract-call? .clarity-bitcoin read-varint {index: u0, txbuff: 0xff112233445566778899aa})))
(asserts! (is-ok result) (err result))
(asserts! (is-eq (unwrap-panic result) {varint: u9833440827789222417, ctx: {index: u9, txbuff: 0xff112233445566778899aa}}) (err result))
(ok true))
)

;; @name try to read txins of tx with 10 inputs
;; txid: 22fbb0e9488bbd79363511cf70e736f434c7ced6f0c9c678a2c9f638007d3823
(define-public (test-read-txins)
(let (
(tx 0x0100000000010b9b9c7ede9e627e28554c89299ace1f059e1db31e4e39944a8f1c7c93d26d96360100000000ffffffff8ba6d6b2b1bffbc659461219ee3a1b97a760a912dd599393920218f79e6a02430000000000ffffffff047b5457e71c6591b0c93660cfb1543d1208711678083a1751abdda8c2bca3a700000000fc004730440220631aad9885f4fe575163be069df6227ee36dd20d925f77dbbd12fdc4a48bc6e3022065befd89086f3a6b2115e62c0ba4ce50cfb4e866b3f7c72e9cd1064fb0629fb3014730440220647c0399beaee128b38b0bdb386a1f9854626191fbe515c5634782242eea1300022012f2388191c4bf89d3f00c8ae365ccc876d5f871916a6bb71d9f2a0dce8ef628014c6952210218d1c463e57f7f185c0c373022a99e53d07d37749965a9d811d69ecdc6eb666b2103fa1d2244418b5e5463bc29ca64b854521b11c80f2e429b2ab05d37ddb7bcf54d2103d618ce6aa14beaaa2164e8c74d16885a646512cca06f66f31181bab3469ada2a53aeffffffff44f20fbc918679c4d226ac57b4825ca7bc95e6b5d0adcce96c146be54d9db8d200000000fdfd00004730440220138672ad8b72c9eb76f268f3ea35719ca388b9b52c7a8523f88429d86671a766022037d4308f6d6db452eac0b57a454c1c2573adccd10ae63edc98c6f4bab9503b0f0148304502210099bc54b48d6cd39d1171229030b1d0705f9799ffb920d60a2bbb8c5be6faa0b3022033ffda30601e8ce472c2b782ba8af3f38e1085e1fa0072e5a64491b180687390014c6952210218d67a00a5404754f06b225aa2dc5ce5df249d24e36f76667a0b8feecb2aa39d2103002653b65b53018ad5d433115f602a5f70fa0c4dd773dc1c6c247a23a4435b0b2103366e7bc89aa358957097839f22a636d9eaf536375d100a44cdfa4083a5d921d853aefffffffffa105c600ad67e50a467f0245db6d928915c903fc45bd923f15341c2498428ec00000000fdfe0000483045022100d429a59020c6a58ba20a3580a8efa9e22c94a4cb28646af0c933b536d5db4e5502205f87bebca92d3a8bd90b293c7b59e795ea0ff8a1abe9912ba3e96bdd58f6539901483045022100f66785b825aa03bb7671f63429c0a86f887843dfa005a012bf75024a2b057ae802206d252832d5698fc7ff9b02efba306a55b77cc717b84d8ceed5a7c874daf01a29014c69522103357db6cc594a55a2c2be7b47ce438ba1e9869879695aa90a583dcdfeea2234ed2103daa551c0f44cbc90ba02a5f01047e6b8cba3381f49e0f91d00a8a4aeba88e22f21030e9d5a1fc1c27af5e7eb9d7fbab1aedf752471b087dde50969b19f04429e4e1653aeffffffff2e2fba20f1e0f7821cde712d085ca87b2ad6c96e35e019854c1acf230905a4b500000000fc004730440220707b29cf4f7dbee9c433102ae38ada2934fb0b6d58967eead2d2516e8ac47809022079bc462c5833381a5dc94d3aeef8a9c2ca4fe3a96db2ac1c52c4f778929c542001473044022009645b4491469952d45297e237404b79905348e32edf278ff3c28f91d6db321902202fc8c95144e367d2fcc88c066bd8516a2b06849329ece8917ac08262650c5c80014c6952210240e0419ab49aa200c4f8e3f2d377ea16d2a15f5ce49f07c64be25ed33502191321031565b10587835ef1a5ed4c08b7b977a397689c8a6884fe1b2504ae6cc6378cfb2102f74938e94cc396bb0516507a651618cfa804a0021fb704267327fb127b56b3d953aeffffffff153813cf1edb1ce5aa0cd2725a2aef0a35b57e840b40fe670e06fac7838103b700000000fdfd000047304402202e39a6bbe002d52e4fbf2edee4a819a9555b6cd686cece0ea82decefb90df4380220183903206941857696a4e31f40ce6d2a1bae53a47df38c894462f8192bc05c1701483045022100e7fd464e73fd7a8bc7075800897a0465ccd99e6087036061ed2758f2689c393202207ff9e22dba62c55da198fc2f307285e51cb48818f7ab2749e8bddeb90dc6e1c4014c6952210240e0419ab49aa200c4f8e3f2d377ea16d2a15f5ce49f07c64be25ed33502191321031565b10587835ef1a5ed4c08b7b977a397689c8a6884fe1b2504ae6cc6378cfb2102f74938e94cc396bb0516507a651618cfa804a0021fb704267327fb127b56b3d953aeffffffffbc4c173252561d7706007ecf8d0b409fa2f040ba63ade2ec13826440f00bc8bc0d00000000fffffffff3c5c010e892ec8ac7f4eb267abdd32329a3ccd8241907bec91f8c97d0c2125b00000000fc004730440220640d8ec19fbb1ead9da35e3182ac4b3848be64f9159ff29c6aebec7138c20c4a022058c9d5106a975e5516cfce4ecf1bb4e308ca5a221ab9a021c87c7387570dc62a0147304402207850e395673d505c90f0869eff20f67736bace235ca961aeb6faca1c7a87105c02200d7addca0c0b20bbb502cd2d94c70b9917c1bf9b321c1a5a74b2eb651af286e8014c6952210240e0419ab49aa200c4f8e3f2d377ea16d2a15f5ce49f07c64be25ed33502191321031565b10587835ef1a5ed4c08b7b977a397689c8a6884fe1b2504ae6cc6378cfb2102f74938e94cc396bb0516507a651618cfa804a0021fb704267327fb127b56b3d953aeffffffffe3860e47856525159bddba008da8fd749ef54463d2d4f3c3ea4c0839512a0a1201000000fdfe0000483045022100ec03eb5ec26f7d85f28294747654876f06da29f32bfc28620fb4c0b2f77d8189022063c1910aef2921a94de3e8e61acb44154754c91eb6f96322dba3d47c9ad9625701483045022100c0e675b453943126c7c51e697d08b34450145a035587071845284c36707163f902202ef35e679db969e3287ff53927c1a923655ddc0c421cea0b90926e98c16b9664014c69522103539605c087f1acd23035fe55aa30d0961c98684238b317ee719e5a7623f5d4ce2102e77b4104f41d484aea11ea3551dba6f62f26b14855518b00e03c491821defb9a2103e2fde0764ea302bcefbf5691bf282527850c39f094fc039272fcbdc14d5e8e8753aeffffffff411cffafb443f0f6c36bf321eee06dcd03395809e851ac85f80d04cc682958e30800000000ffffffff0a00375f000000000017a914cdd60c80f6f574da0e499a8006b29b5007d434a687af5aa40000000000160014a00faf9355cee3ce7d997829307b688023cc3aea60186bee000000001976a91447ecb7761bd21abffd0671b3d82e65e59c25f3fc88acd02c0c00000000001600142bdf779ef8474704335bad6c684d38cec27dc91d8e2b2900000000001976a914f83b8ede0aa1c75aa677467d8103fa5568f06a9d88ac386d050000000000225120d2db3e3cf9bc85abb8e25babf79a67f7f7454d364e27cf516f853d88a7fecdfdd7bb67020000000016001493f4264fbe4bb88b82366f34f3bd22bae8aa91e0a0860100000000001976a914fe22c69bb4db54bb23cf15370e12114034e3061f88ac69362a0000000000160014cb76d3719e0f8c6e933c93acb32b5b9f7b328e0fbf70bd0100000000220020e5c7c00d174631d2d1e365d6347b016fb87b6a0c08902d8e443989cb771fa7ec0400473044022005bcd7ffa1641e624e6414886feadea7cee437017d289361e8bfd6e64d30c182022039327af6722461683e3bf98b7551c3cabd77a01cf3ad3f7458b6ba213d2d8b98014830450221009074a3aab0031e43fa15256b1e5ad3f736b296db31998ca2fe784d3790a8192902202af32944b58415ce7e31184e4db8ab6d53124c99dc6cffa17486c2136bc7030601695221039859358416537517aeedeb3c28ffbf7a467bb78f35340e2595a608559950924721037ce9d5c70c0e38bbba66df7075d20738948058e62d69c578cb45114317e25ee1210389be2227f2ba88e9994830871e0e672d3fac4d68361b262a4b066246e53306f053ae04004830450221009f77b8ebdbaeef367d8e97797ad8a695f44c3b2930926afbd0d4205fa93dc4a6022040b6bd55883857b6c9eae1201da3abd7152734a62e5deb7c9eeeb7af508b301d01483045022100a6f02384815a5a0a954bdfaa19b829a9a85d8a7d83999f73ba7fdc0d00c4e6d502204aff2524aa8a1519678ba3c898db07b1846c84b5d7f0ef66061b1b6af02f4b2701695221039859358416537517aeedeb3c28ffbf7a467bb78f35340e2595a608559950924721037ce9d5c70c0e38bbba66df7075d20738948058e62d69c578cb45114317e25ee1210389be2227f2ba88e9994830871e0e672d3fac4d68361b262a4b066246e53306f053ae000000000004004830450221009909c9b2c7008a996985b056b7516e2d5ff150c747282a628e2e3a254dee6d2402203eee2719df04f287815c712d1f6ef7f8cc9f14a45e784d7c9688efb549d180610147304402203b56107a5248c8ab4287be690623169c531cbf9e2771895f840c4010a1881c7b02200f02e110838bdaad4e5a20e6df35d78bb9a94bc0897543263298187b4183a10801695221026064e5b88c4fff7dba7dc0300db8dbfc1faff14f9ddbaacbcaa4f70124de0e93210331870350912385ca9a9d537e9cf9d80c6c9558e31d654f82f3164fdc5955e9642103c7b133a0f463a501d8c58c8eb8c7b6e9e4ddfb7d4a7bf6365a4732201569bc8353ae00000400483045022100b35603383f85ddd5327c79e8a79d08ea34953731f70b311b16caa00a6440e7c3022074da71aa45e8e3e0ca942dfcdd63cf341577f738f222d11bd59d000d3318ec1401483045022100dd824d429a6d317bcabcd1bb31953ac8ea76dbd69eaef368d0b23c15b000c44302203cb15f10229de8d4cca99dc0a79622752ef685af68800eba86e6a679bc7bb3b901695221026064e5b88c4fff7dba7dc0300db8dbfc1faff14f9ddbaacbcaa4f70124de0e93210331870350912385ca9a9d537e9cf9d80c6c9558e31d654f82f3164fdc5955e9642103c7b133a0f463a501d8c58c8eb8c7b6e9e4ddfb7d4a7bf6365a4732201569bc8353ae00000000)
(result (contract-call? .clarity-bitcoin read-txins {index: u6, txbuff: tx})))
(asserts! (is-eq result (err ERR-TOO-MANY-TXINS)) (err result))
(ok true))
)

;; @name try to read txouts of tx with 10 outputs
;; txid: 39edd81aa374a3fc590b4f118efb02273593caa2ba941559b6e56e6f3309cbd4
(define-public (test-read-txouts)
(let (
(tx 0x01000000000103aa981c0c66b5f29c9125136bf1fcc1d4b06b990f49a2bf3f4da8ed9a0901c62600000000fc0047304402204deede93a9d1fafbc08160042b5a577e2977b4d57ee827469d78672eae660bd9022069735e1249d2988f31e7fa665f6c5611b7220ae2c040ddbbaf682312a95cfd5401473044022071181566837a7483909fc9d39b8e6ff2c7219fa0d9f84938cc4f560d4b700ff102200215ffa6633ed432d93749be7527ad4bda6545543dfaae3fed4dc4327822e419014c6952210301286b902a17167257aa4e6b7378c42039d05d5c856844835446c149d0e874ae2102b4d90713d1c291b9a24c10e75220d0e1e12bf30a5e8669e181a90c4f1079bc8121020d79724c15771923cf9957d7053bd80abe0a6aece4835775087c8e72a63c34fd53aeffffffffab5a4f02c3b740a47a7b6fee9125657432cbd73e4627151cc4e1b088c7e101ba0300000000ffffffffb43a6d06c64e2a105bc2a339d802a8544c78ccd54a6804385efaa0868047b0d800000000fc0047304402207fb4a9c5ccc8abb0cb68398e54b6548d03824b9af6046327c1ee68ed7fe51a810220347a62c094ed225cba0d3f831461c222be39dc6d6a61a31a36c2c8a4e98aea4c0147304402202dd1424b3cf00c9c6bc05f3034cd1774864d0f419e73edba0f59ee392ab989a302200cb5002787613354fb5749dcad37387ab96e89f6b5db4dc963fea3952e314f0e014c695221025d2ade738149943d25628f8eac89019b7de29cd48f315b97ae33d66e73fbaec82103091d8e82ba9e1537a49d0890f6a7398c091eb10dd24057aac399d80b70f5179e210391a811ec40a7ca4efe671078f013b1d8308788f67da52720162306f9e9a624e553aeffffffff0a9c3e02000000000017a914afca0d408ae72adc9873d7aecf6606666fdf44d787f1b101000000000017a9147cad3c4095aec2b59fa0ea9a7fb55ba0c081c6e287af364d0c0000000017a914e498426ebfdbc21204e60682482ab1443d0b4fea8700093d0000000000160014c3270c47826bd88a1a6ae9aa4dbcb7aa3a1fa645c0c62d00000000001976a91403c0718ebc2bb7961859dc5dd1f0495d199067fe88ac8688670000000000160014cb5385b7ab0e68d90292951667c391e3b0947b96f40f0b000000000017a9140e5c035423d49cdd7d806feabf6362d07b9331fc87e01b18000000000017a9145f4110da3b787fb6ddd75c8b26c495c0c9bfc4db87485904000000000017a9141abe89eac94cde04b90de1605ae112c92054f03f870fa6520100000000220020e5c7c00d174631d2d1e365d6347b016fb87b6a0c08902d8e443989cb771fa7ec0004004830450221009b03a576d52fb1c4cf24deb5deb3d443a052acd3e6d770af4f3fab4bd8764ed002202c02a4f1d98cade0d1bb5d9e33e2472329ed670c48b5a22b4004cacd50c8dc5101473044022036573e0eddbfec14ab741425f8f36a11116cf612d4eb64de6c2e7acb38b6a1a102207fab226452d0d09beaebfeb321080d5d5de0696b9a79921ea6df196686aa973d01695221026064e5b88c4fff7dba7dc0300db8dbfc1faff14f9ddbaacbcaa4f70124de0e93210331870350912385ca9a9d537e9cf9d80c6c9558e31d654f82f3164fdc5955e9642103c7b133a0f463a501d8c58c8eb8c7b6e9e4ddfb7d4a7bf6365a4732201569bc8353ae0000000000)
(result (contract-call? .clarity-bitcoin read-txouts {index: u634, txbuff: tx})))
(asserts! (is-eq result (err ERR-TOO-MANY-TXOUTS)) (err result))
(ok true))
)

;; @name try to read witnesses of tx with 0 witnesses
(define-public (test-read-next-witness)
(let (
(tx 0x00)
(result (contract-call? .clarity-bitcoin read-next-witness false (ok {ctx: {index: u0, txbuff: tx}, witnesses:(list)}))))
(asserts! (is-eq result (ok {ctx: {index: u1, txbuff: tx}, witnesses: (list (list))})) (err result))
(ok true))
)

(define-constant ERR-OUT-OF-BOUNDS u1)
(define-constant ERR-TOO-MANY-TXINS u2)
(define-constant ERR-TOO-MANY-TXOUTS u3)
(define-constant ERR-VARSLICE-TOO-LONG u4)
(define-constant ERR-BAD-HEADER u5)
(define-constant ERR-HEADER-HEIGHT-MISMATCH u6)
(define-constant ERR-INVALID-MERKLE-PROOF u7)
(define-constant ERR-PROOF-TOO-SHORT u8)
(define-constant ERR-TOO-MANY-WITNESSES u9)
(define-constant ERR-INVALID-COMMITMENT u10)
(define-constant ERR-WITNESS-TX-NOT-IN-COMMITMENT u11)
(define-constant ERR-LEFTOVER-DATA u13)
15 changes: 15 additions & 0 deletions contracts/tests/clarity-bitcoin_segwit_test.clar
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@
)
)

;; @name verify segwit transaction with left over data
(define-public (test-parse-wtx)
(let (
(burnchain-block-height u2431087)
;; txid: 3b3a7a31c949048fabf759e670a55ffd5b9472a12e748b684db5d264b6852084
(raw-tx 0x0200000000010218f905443202116524547142bd55b69335dfc4e4c66ff3afaaaab6267b557c4b030000000000000000e0dbdf1039321ab7a2626ca5458e766c6107690b1a1923e075c4f691cc4928ac0000000000000000000220a10700000000002200208730dbfaa29c49f00312812aa12a62335113909711deb8da5ecedd14688188363c5f26010000000022512036f4ff452cb82e505436e73d0a8b630041b71e037e5997290ba1fe0ae7f4d8d50140a50417be5a056f63e052294cb20643f83038d5cd90e2f90c1ad3f80180026cb99d78cd4480fadbbc5b9cad5fb2248828fb21549e7cb3f7dbd7aefd2d541bd34f0140acde555b7689eae41d5ccf872bb32a270893bdaa1defc828b76c282f6c87fc387d7d4343c5f7288cfd9aa5da0765c7740ca97e44a0205a1abafa279b530d5fe36d182500ffffff)
;; block id: 000000000000000606f86a5bc8fb6e38b16050fb4676dea26cba5222583c4d86
)
(let ((result (contract-call? .clarity-bitcoin parse-wtx raw-tx false)))
(asserts! (is-eq result (err ERR-LEFTOVER-DATA)) (err "expected ERR-LEFTOVER-DATA"))
(ok true))
)
)

;; @name parse-wtx is unable to parse a non-segwit transaction (returns unpredictable values)
(define-public (test-parse-wtx-on-non-segwit-1)
(let (
Expand Down Expand Up @@ -279,3 +293,4 @@
(define-constant ERR-INVALID-COMMITMENT u10)
(define-constant ERR-WITNESS-TX-NOT-IN-COMMITMENT u11)
(define-constant ERR-NOT-SEGWIT-TRANSACTION u12)
(define-constant ERR-LEFTOVER-DATA u13)
54 changes: 54 additions & 0 deletions contracts/tests/clarity-bitcoin_test.clar
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,60 @@
)
)

;; @name verify segwit transaction where merkle proof is wrong
;; arbitrary segwit transaction
(define-public (test-was-tx-mined-internal-7)
(let (
(burnchain-block-height u2431087)
(txid 0x3b3a7a31c949048fabf759e670a55ffd5b9472a12e748b684db5d264b6852084)
(raw-tx 0x020000000218f905443202116524547142bd55b69335dfc4e4c66ff3afaaaab6267b557c4b030000000000000000e0dbdf1039321ab7a2626ca5458e766c6107690b1a1923e075c4f691cc4928ac0000000000000000000220a10700000000002200208730dbfaa29c49f00312812aa12a62335113909711deb8da5ecedd14688188363c5f26010000000022512036f4ff452cb82e505436e73d0a8b630041b71e037e5997290ba1fe0ae7f4d8d56d182500)
;; block id: 000000000000000606f86a5bc8fb6e38b16050fb4676dea26cba5222583c4d86
(raw-block-header 0x0000a02065bc9201b5b5a1d695a18e4d5efe5d52d8ccc4129a2499141d000000000000009160ba7ae5f29f9632dc0cd89f466ee64e2dddfde737a40808ddc147cd82406f18b8486488a127199842cec7)
(parsed-block-header (contract-call? .clarity-bitcoin parse-block-header raw-block-header))
(parsed-tx (contract-call? .clarity-bitcoin parse-tx raw-tx))
)
;; prepare

(let ((result (contract-call? .clarity-bitcoin was-tx-mined-compact
burnchain-block-height
raw-tx
raw-block-header
{tx-index: u3,
tree-depth: u2,
hashes: (list 0x3313f803502a6f9a89ac09ff9e8f9d8032aa7c35cc6d1679487622e944c8ccb8 0x3313f803502a6f9a89ac09ff9e8f9d8032aa7c35cc6d1679487622e944c8ccb8)}
)))
(asserts! (is-eq result (err ERR-INVALID-MERKLE-PROOF)) (err "expected ERR-INVALID-MERKLE-PROOF"))
(ok true))
)
)


;; @name verify segwit transaction with left over data
(define-public (test-parse-tx)
(let (
(burnchain-block-height u2431087)
;; 0x3b3a7a31c949048fabf759e670a55ffd5b9472a12e748b684db5d264b6852084 + 0xffffff
(raw-tx 0x020000000218f905443202116524547142bd55b69335dfc4e4c66ff3afaaaab6267b557c4b030000000000000000e0dbdf1039321ab7a2626ca5458e766c6107690b1a1923e075c4f691cc4928ac0000000000000000000220a10700000000002200208730dbfaa29c49f00312812aa12a62335113909711deb8da5ecedd14688188363c5f26010000000022512036f4ff452cb82e505436e73d0a8b630041b71e037e5997290ba1fe0ae7f4d8d56d182500ffffff)
;; block id: 000000000000000606f86a5bc8fb6e38b16050fb4676dea26cba5222583c4d86
)
(let ((result (contract-call? .clarity-bitcoin parse-tx raw-tx)))
(asserts! (is-eq result (err ERR-LEFTOVER-DATA)) (err "expected ERR-LEFTOVER-DATA"))
(ok true))
)
)

;; @name verify block header with invalid block
(define-public (test-verify-block-header)
(let (
(burnchain-block-height u0)
;; block id: 000000000000000606f86a5bc8fb6e38b16050fb4676dea26cba5222583c4d86
(raw-block-header 0x0000a02065bc9201b5b5a1d695a18e4d5efe5d52d8ccc4129a2499141d000000000000009160ba7ae5f29f9632dc0cd89f466ee64e2dddfde737a40808ddc147cd82406f18b8486488a127199842cec7)
)
(let ((result (contract-call? .clarity-bitcoin verify-block-header raw-block-header burnchain-block-height)))
(asserts! (is-eq result false) (err "expected invalid block header"))
(ok true))
)
)

;; @name verify transaction with header object
(define-public (test-was-tx-mined-with-header-object-1)
Expand Down
13 changes: 10 additions & 3 deletions tests/clar.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ParsedTransactionResult, tx } from "@hirosystems/clarinet-sdk";
import { Cl, cvToString } from "@stacks/transactions";
import { Cl, ClarityType, cvToString } from "@stacks/transactions";
import { describe, expect, it } from "vitest";

const accounts = simnet.getAccounts();
Expand All @@ -8,7 +8,8 @@ simnet.getContractsInterfaces().forEach((contract, name) => {
return;
}
describe(name, () => {
const prepare = contract.functions.findIndex((f) => f.name === "prepare");
const prepare =
contract.functions.findIndex((f) => f.name === "prepare") >= 0;
let block: ParsedTransactionResult[];

contract.functions.forEach((fn) => {
Expand All @@ -23,14 +24,20 @@ simnet.getContractsInterfaces().forEach((contract, name) => {
tx.callPublicFn(name, fn.name, [], accounts.get("deployer")!),
]);
expect(block[0].result).toBeOk(Cl.bool(true));
expect(

if (block[1].result.type === ClarityType.ResponseErr) {
console.log(cvToString(block[1].result));
} expect(
block[1].result,
`${name}, ${fn.name}, ${cvToString(block[0].result)}`
).toBeOk(Cl.bool(true));
} else {
block = simnet.mineBlock([
tx.callPublicFn(name, fn.name, [], accounts.get("deployer")!),
]);
if (block[0].result.type === ClarityType.ResponseErr) {
console.log(cvToString(block[0].result));
}
expect(
block[0].result,
`${name}, ${fn.name}, ${cvToString(block[0].result)}`
Expand Down
1 change: 0 additions & 1 deletion tests/clarity-bitcoin_parse_wtx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { ResponseCV } from "@stacks/transactions";

const accounts = simnet.getAccounts();
const chain = simnet;

describe("Parse bitcoin txs with whitness data", () => {
it("Ensure that segwit bitcoin txs can be parsed", () => {
Expand Down

0 comments on commit ee32cd8

Please sign in to comment.