1+ package xyz.mcxross.kaptos.unit.serialize
2+
3+ import xyz.mcxross.bcs.Bcs
4+ import kotlin.test.Test
5+ import xyz.mcxross.kaptos.model.MoveVector
6+ import kotlin.test.assertContentEquals
7+
8+ class MoveVectorSerializerTest {
9+ @Test()
10+ fun `can serialize a vector with less than 128 items` () {
11+ val base = listOf (1 .toByte(), 2 .toByte(), 3 .toByte()).toByteArray()
12+ val vec = MoveVector .u8(base)
13+
14+ val encoded = Bcs .encodeToByteArray(vec)
15+ val expected = listOf (3 .toByte(), 1 .toByte(), 2 .toByte(), 3 .toByte()).toByteArray()
16+
17+ assertContentEquals(expected, encoded)
18+ }
19+
20+ @Test()
21+ fun `can serialize an empty vector` () {
22+ val base = emptyList<Byte >().toByteArray()
23+ val vec = MoveVector .u8(base)
24+
25+ val encoded = Bcs .encodeToByteArray(vec)
26+ val expected = listOf (0 .toByte()).toByteArray()
27+
28+ assertContentEquals(expected, encoded)
29+ }
30+
31+ @Test()
32+ fun `can serialize a vector with 128 items` () {
33+ val base = ByteArray (128 ) { it.toByte() }
34+ val vec = MoveVector .u8(base)
35+
36+ val encoded = Bcs .encodeToByteArray(vec)
37+ val expectedLengthTag = listOf (0x80 .toByte(), 0x01 .toByte()).toByteArray()
38+ val expected = expectedLengthTag + base
39+
40+ assertContentEquals(expected, encoded)
41+ }
42+ }
0 commit comments