11import kotlinx.io.bytestring.hexToByteString
22import org.ton.sdk.bitstring.BitString
3+ import org.ton.sdk.cell.Cell
34import org.ton.sdk.cell.CellBuilder
45import org.ton.sdk.cell.LevelMask
56import org.ton.sdk.cell.boc.BagOfCellSerializer
@@ -8,6 +9,7 @@ import org.ton.sdk.crypto.HashBytes
89import utils.XorShift128Plus
910import utils.genRandomCell
1011import kotlin.io.encoding.Base64
12+ import kotlin.random.Random
1113import kotlin.test.Test
1214import kotlin.test.assertContentEquals
1315import kotlin.test.assertEquals
@@ -38,25 +40,32 @@ class BocTest {
3840 }
3941 }
4042
41- fun randomEncodeOption (random : XorShift128Plus ): BagOfCells .EncodeOptions {
43+ fun randomEncodeOption (random : Random ): BagOfCells .EncodeOptions {
4244 return encodeOptions[random.nextInt(encodeOptions.size)]
4345 }
4446
4547 @Test
4648 fun testBoc () {
47- val random = XorShift128Plus (12311 )
49+ val random = XorShift128Plus (1231112 )
4850 repeat(1 ) {
4951 val cell = genRandomCell(random.nextInt(1 , 1001 ), random)
50- val cellHash = cell.hash( )
51- val encodeOption = randomEncodeOption(random)
52- val serialized = BagOfCells .encodeToByteArray(cell, encodeOption)
52+ testBoc(cell, random )
53+ }
54+ }
5355
54- val loadedCell = BagOfCells .decodeFromByteArray(serialized).first()
55- assertEquals(cellHash, loadedCell.hash())
56+ fun testBoc (cell : Cell , random : Random ) {
57+ val cellHash = cell.hash()
58+ val encodeOption = randomEncodeOption(random)
59+ val serialized = BagOfCells .encodeToByteArray(cell, encodeOption)
5660
57- val newSerialized = BagOfCells .encodeToByteArray(loadedCell, encodeOption)
58- assertContentEquals(serialized, newSerialized)
59- }
61+ println (" serialized size: ${serialized.size} " )
62+ println (" serialized hex: ${serialized.toHexString()} " )
63+
64+ val loadedCell = BagOfCells .decodeFromByteArray(serialized).first()
65+ assertEquals(cellHash, loadedCell.hash())
66+
67+ val newSerialized = BagOfCells .encodeToByteArray(loadedCell, encodeOption)
68+ assertContentEquals(serialized, newSerialized)
6069 }
6170
6271 @Test
0 commit comments