Skip to content

Commit ead1668

Browse files
committed
fix tests
1 parent 6f0b1f8 commit ead1668

File tree

11 files changed

+67
-62
lines changed

11 files changed

+67
-62
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

ton-kotlin-block/src/commonMain/kotlin/org/ton/block/Block.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ data class Block(
1515
val stateUpdateCell: CellRef<MerkleUpdate<ShardState>>,
1616
val extraCell: CellRef<BlockExtra>
1717
) {
18-
val info by infoCell
19-
val valueFlow by valueFlowCell
20-
val stateUpdate by stateUpdateCell
21-
val extra by extraCell
18+
val info: BlockInfo by infoCell
19+
val valueFlow: ValueFlow by valueFlowCell
20+
val stateUpdate: MerkleUpdate<ShardState> by stateUpdateCell
21+
val extra: BlockExtra by extraCell
2222

23-
companion object : TlbCombinatorProvider<Block> by TlbConstructor.asTlbCombinator()
23+
public companion object : TlbCombinatorProvider<Block> by TlbConstructor.asTlbCombinator()
2424

2525
private object TlbConstructor : org.ton.tlb.TlbConstructor<Block>(
2626
schema = "block#11ef55aa global_id:int32 " +
@@ -35,10 +35,10 @@ data class Block(
3535
value: Block
3636
) = cellBuilder {
3737
storeInt(value.global_id, 32)
38-
storeRef(value.infoCell.cell)
39-
storeRef(value.valueFlowCell.cell)
40-
storeRef(value.stateUpdateCell.cell)
41-
storeRef(value.extraCell.cell)
38+
storeRef(value.infoCell.toCell(BlockInfo))
39+
storeRef(value.valueFlowCell.toCell(ValueFlow))
40+
storeRef(value.stateUpdateCell.toCell(merkleUpdate))
41+
storeRef(value.extraCell.toCell(BlockExtra))
4242
}
4343

4444
override fun loadTlb(

ton-kotlin-block/src/commonMain/kotlin/org/ton/block/MerkleUpdate.kt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,54 @@ import org.ton.bitstring.BitString
66
import org.ton.cell.CellBuilder
77
import org.ton.cell.CellSlice
88
import org.ton.cell.invoke
9-
import org.ton.tlb.CellRef
10-
import org.ton.tlb.TlbCodec
11-
import org.ton.tlb.TlbConstructor
12-
import org.ton.tlb.asRef
9+
import org.ton.tlb.*
1310
import kotlin.jvm.JvmStatic
1411

1512
@SerialName("merkle_update")
1613
@Serializable
17-
data class MerkleUpdate<X>(
18-
val old_hash: BitString,
19-
val new_hash: BitString,
14+
public data class MerkleUpdate<X>(
15+
val oldHash: BitString,
16+
val newHash: BitString,
2017
val old: CellRef<X>,
2118
val new: CellRef<X>
2219
) {
2320
init {
24-
require(old_hash.size == 256) { "required: old_hash.size = 256, actual: ${old_hash.size}" }
25-
require(new_hash.size == 256) { "required: new_hash.size = 256, actual: ${new_hash.size}" }
21+
require(oldHash.size == 256) { "required: old_hash.size = 256, actual: ${oldHash.size}" }
22+
require(newHash.size == 256) { "required: new_hash.size = 256, actual: ${newHash.size}" }
2623
}
2724

28-
companion object {
25+
public companion object {
2926
@JvmStatic
30-
fun <X> tlbCodec(
27+
public fun <X> tlbCodec(
3128
x: TlbCodec<X>
3229
): TlbCodec<MerkleUpdate<X>> = MerkleUpdateTlbConstructor(x)
3330
}
3431
}
3532

3633
private class MerkleUpdateTlbConstructor<X>(
37-
val x: TlbCodec<X>
34+
x: TlbCodec<X>
3835
) : TlbConstructor<MerkleUpdate<X>>(
3936
schema = "!merkle_update#02 {X:Type} old_hash:bits256 new_hash:bits256 old:^X new:^X = MERKLE_UPDATE X;"
4037
) {
38+
val xCellRef = CellRef.tlbCodec(x)
39+
4140
override fun storeTlb(
4241
cellBuilder: CellBuilder,
4342
value: MerkleUpdate<X>
4443
) = cellBuilder {
45-
storeBits(value.old_hash)
46-
storeBits(value.new_hash)
47-
storeRef(value.old.cell)
48-
storeRef(value.new.cell)
44+
storeBits(value.oldHash)
45+
storeBits(value.newHash)
46+
storeTlb(xCellRef, value.old)
47+
storeTlb(xCellRef, value.new)
4948
}
5049

5150
override fun loadTlb(
5251
cellSlice: CellSlice
5352
): MerkleUpdate<X> = cellSlice {
5453
val oldHash = loadBits(256)
5554
val newHash = loadBits(256)
56-
val old = loadRef().asRef(x)
57-
val new = loadRef().asRef(x)
55+
val old = loadTlb(xCellRef)
56+
val new = loadTlb(xCellRef)
5857
// TODO: hash check
5958
MerkleUpdate(oldHash, newHash, old, new)
6059
}

ton-kotlin-block/src/commonMain/kotlin/org/ton/block/PrevBlksInfo.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,41 @@ import kotlinx.serialization.Serializable
55
import org.ton.cell.*
66
import org.ton.tlb.CellRef
77
import org.ton.tlb.TlbConstructor
8+
import org.ton.tlb.loadTlb
9+
import org.ton.tlb.storeTlb
810
import kotlin.jvm.JvmStatic
911

1012
@Serializable
1113
@SerialName("prev_blks_info")
12-
data class PrevBlksInfo(
14+
public data class PrevBlksInfo(
1315
val prev1: CellRef<ExtBlkRef>,
1416
val prev2: CellRef<ExtBlkRef>
1517
) : BlkPrevInfo {
1618
override fun prevs(): List<ExtBlkRef> = listOf(prev1.value, prev2.value)
1719

18-
companion object {
20+
public companion object {
1921
@JvmStatic
20-
fun tlbCodec(): TlbConstructor<PrevBlksInfo> = PrevBlksInfoTlbConstructor
22+
public fun tlbCodec(): TlbConstructor<PrevBlksInfo> = PrevBlksInfoTlbConstructor
2123
}
2224
}
2325

2426
private object PrevBlksInfoTlbConstructor : TlbConstructor<PrevBlksInfo>(
2527
schema = "prev_blks_info\$_ prev1:^ExtBlkRef prev2:^ExtBlkRef = BlkPrevInfo 1;"
2628
) {
29+
private val cellRef = CellRef.tlbCodec(ExtBlkRef)
2730
override fun storeTlb(
2831
cellBuilder: CellBuilder,
2932
value: PrevBlksInfo
3033
) = cellBuilder {
31-
storeRef(value.prev1.cell)
32-
storeRef(value.prev2.cell)
34+
storeTlb(cellRef, value.prev1)
35+
storeTlb(cellRef, value.prev2)
3336
}
3437

3538
override fun loadTlb(
3639
cellSlice: CellSlice
3740
): PrevBlksInfo = cellSlice {
38-
val prev1 = CellRef(loadRef(), ExtBlkRef)
39-
val prev2 = CellRef(loadRef(), ExtBlkRef)
41+
val prev1 = loadTlb(cellRef)
42+
val prev2 = loadTlb(cellRef)
4043
PrevBlksInfo(prev1, prev2)
4144
}
4245
}

ton-kotlin-cell/src/commonMain/kotlin/org/ton/cell/CellSlice.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private open class CellSliceImpl(
9393
override var refsPosition: Int = 0
9494
) : CellSlice {
9595
override fun endParse() =
96-
check(bitsPosition == bits.size) { "bitsPosition: $bitsPosition != bits.length: ${bits.size}" }
96+
check(bitsPosition >= bits.size) { "bitsPosition: $bitsPosition != bits.length: ${bits.size}" }
9797

9898
override fun loadRef(): Cell {
9999
checkRefsOverflow()

ton-kotlin-hashmap/src/commonMain/kotlin/org/ton/hashmap/HashMapEdge.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.jvm.JvmStatic
1010

1111
@Serializable
1212
@SerialName("hm_edge")
13-
public data class HashMapEdge<out T>(
13+
public data class HashMapEdge<T>(
1414
val label: HashMapLabel,
1515
val node: HashMapNode<T>
1616
) : Iterable<Pair<BitString, T>> {
@@ -23,10 +23,10 @@ public data class HashMapEdge<out T>(
2323
is HashMapNodeLeaf -> sequenceOf(BitString.empty() to node.value)
2424
is HashMapNodeFork -> {
2525
// Note: left and right branches implicitly contain prefixes '0' and '1' respectively
26-
val left = node.leftCellRef.value.nodes().map { (label, value) ->
26+
val left = node.left.nodes().map { (label, value) ->
2727
(BitString(false) + label) to value
2828
}
29-
val right = node.rightCellRef.value.nodes().map { (label, value) ->
29+
val right = node.right.nodes().map { (label, value) ->
3030
(BitString(true) + label) to value
3131
}
3232
left + right

ton-kotlin-hashmap/src/commonMain/kotlin/org/ton/hashmap/HashMapNodeFork.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ public data class HashMapNodeFork<T>(
2424
public constructor(
2525
left: HashMapEdge<T>,
2626
right: HashMapEdge<T>,
27-
codec: TlbCodec<HashMapEdge<T>>
2827
) : this(
29-
leftCellRef = CellRef(left, codec),
30-
rightCellRef = CellRef(right, codec)
28+
leftCellRef = CellRef(left),
29+
rightCellRef = CellRef(right)
3130
)
3231

3332
val left: HashMapEdge<T> by leftCellRef

ton-kotlin-hashmap/src/commonMain/kotlin/org/ton/hashmap/RootHashMapE.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public data class RootHashMapE<T>(
1515
val rootCellRef: CellRef<HashMapEdge<T>>
1616
) : HashMapE<T> {
1717
public constructor(root: Cell, tlbCodec: TlbCodec<HashMapEdge<T>>) : this(CellRef(root, tlbCodec))
18-
public constructor(root: HashMapEdge<T>, tlbCodec: TlbCodec<HashMapEdge<T>>) : this(CellRef(root, tlbCodec))
18+
public constructor(root: HashMapEdge<T>) : this(CellRef(root))
1919

2020
val root: HashMapEdge<T> by rootCellRef
2121

ton-kotlin-hashmap/src/commonTest/kotlin/org/ton/hashmap/HashMapEdgeTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ class HashMapEdgeTest {
3131
val e = HashMapEdge(
3232
label = HashMapLabelShort(UnaryZero, BitString()),
3333
node = HashMapNodeFork(
34-
leftCellRef = HashMapEdge(
34+
left = HashMapEdge(
3535
label = HashMapLabelLong(
3636
255,
3737
BitString("C20BAD98ED5E80064BD29AB119CA237CB7FB76E7686FB8A3D948722FAF487C7B_")
3838
),
3939
node = HashMapNodeLeaf(Cell.of("69696969"))
4040
),
41-
rightCellRef = HashMapEdge(
41+
right = HashMapEdge(
4242
label = HashMapLabelShort(UnaryZero, BitString()),
4343
node = HashMapNodeFork(
44-
leftCellRef = HashMapEdge(
44+
left = HashMapEdge(
4545
label = HashMapLabelShort(UnaryZero, BitString()),
4646
node = HashMapNodeFork(
47-
leftCellRef = HashMapEdge(
47+
left = HashMapEdge(
4848
label = HashMapLabelLong(
4949
253,
5050
BitString("151A9BFF86DE73F761AEB4F6E1D0C4F7378BEC179A9D2A9FCD54B6585F1E744C_")
5151
),
5252
node = HashMapNodeLeaf(Cell.of("42424242"))
5353
),
54-
rightCellRef = HashMapEdge(
54+
right = HashMapEdge(
5555
label = HashMapLabelLong(
5656
253,
5757
BitString("BB53E50A9E12338B2C19ADDE844A31A87FE310FD0E28B7389184AEA7FEAE2C0C_")
@@ -60,7 +60,7 @@ class HashMapEdgeTest {
6060
)
6161
)
6262
),
63-
rightCellRef = HashMapEdge(
63+
right = HashMapEdge(
6464
label = HashMapLabelLong(
6565
254,
6666
BitString("2411BDE8DEB43A9F3B9CCD56613E950A260BE2CDF23DEF3B247DEB1C69F34412_")

ton-kotlin-liteapi/src/commonMain/kotlin/org/ton/lite/api/liteserver/functions/LiteServerSendMessage.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import org.ton.tlb.constructor.AnyTlbConstructor
1616
public data class LiteServerSendMessage(
1717
val body: BagOfCells
1818
) {
19-
public constructor(body: CellRef<Message<Cell>>) : this(BagOfCells(body.cell))
20-
public constructor(body: Message<Cell>) : this(CellRef(body, Message.tlbCodec(AnyTlbConstructor)))
19+
public constructor(body: CellRef<Message<Cell>>) : this(BagOfCells(body.toCell(Message.tlbCodec(AnyTlbConstructor))))
20+
public constructor(body: Message<Cell>) : this(CellRef(body))
2121

2222
public fun parseBody(): CellRef<Message<Cell>> = CellRef(body.first(), Message.tlbCodec(AnyTlbConstructor))
2323

0 commit comments

Comments
 (0)