Skip to content

Commit

Permalink
test(tests): add tests on clarity functions using sha256 function on …
Browse files Browse the repository at this point in the history
…int and uint
  • Loading branch information
Acaccia committed Oct 11, 2023
1 parent 4261492 commit 6c9abee
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/contracts/sha256.clar
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
(define-public (sha256-buffer)
(ok (sha256 0x4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f726520657420646f6c6f7265206d61676e6120616c697175612e))
)

(define-public (sha256-integer)
(ok (sha256 123456789))
)

(define-public (sha256-unsigned)
(ok (sha256 u987654321))
)
40 changes: 40 additions & 0 deletions tests/tests/lib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,46 @@ test_contract_call_response!(
}
);

test_contract_call_response!(
test_sha256_int,
"sha256",
"sha256-integer",
|response: ResponseData| {
assert!(response.committed);
assert_eq!(
*response.data,
Value::Sequence(clarity::vm::types::SequenceData::Buffer(
clarity::vm::types::BuffData {
data: Vec::from_hex(
"bf9d9b2cf6fa58e2d98fe7357d73ddf052aba366ea543741510591fbf64cd60d"
)
.unwrap(),
},
)),
);
}
);

test_contract_call_response!(
test_sha256_uint,
"sha256",
"sha256-unsigned",
|response: ResponseData| {
assert!(response.committed);
assert_eq!(
*response.data,
Value::Sequence(clarity::vm::types::SequenceData::Buffer(
clarity::vm::types::BuffData {
data: Vec::from_hex(
"3c9f0d5d10486e680b92df0124aaa55ec061c7684e5e67241b44ed42a323aa5b"
)
.unwrap(),
},
)),
);
}
);

// These tests are disabled because they require a block to be present in the
// chain, which is not the case when running the tests. Once the test framework
// supports this, these tests can be re-enabled.
Expand Down

0 comments on commit 6c9abee

Please sign in to comment.