SNAPKITTYWEST commited on
Commit
8d5d845
·
verified ·
1 Parent(s): 62f8e92

Mirror from SNAPKITTYWEST: tests/test_bytes.py

Browse files
Files changed (1) hide show
  1. tests/test_bytes.py +27 -0
tests/test_bytes.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from runtime.types import Bytes, Integer, String
2
+ from runtime.stdlib.bytes import concat_bytes, len_bytes, slice_bytes
3
+ from runtime.stdlib.hex import bytes_to_hex, hex_to_bytes
4
+
5
+ def test_concat():
6
+ a = Bytes(b'\x01\x02')
7
+ b = Bytes(b'\x03\x04')
8
+ assert concat_bytes(a, b).data == b'\x01\x02\x03\x04'
9
+
10
+ def test_len():
11
+ assert len_bytes(Bytes(b'hello')).value == 5
12
+
13
+ def test_slice():
14
+ b = Bytes(b'\x00\x01\x02\x03\x04')
15
+ assert slice_bytes(b, Integer(1), Integer(3)).data == b'\x01\x02'
16
+
17
+ def test_hex_roundtrip():
18
+ original = Bytes(b'\xde\xad\xbe\xef')
19
+ hex_str = bytes_to_hex(original)
20
+ assert hex_str.text == 'deadbeef'
21
+ back = hex_to_bytes(hex_str)
22
+ assert back.data == original.data
23
+
24
+ def test_hex_input():
25
+ result = hex_to_bytes(String('0000000000000000000000000000000000000000000000000000000000000000'))
26
+ assert len(result.data) == 32
27
+ assert result.data == b'\x00' * 32