Skip to content

Commit 3feba11

Browse files
committed
[Tolk] Universal createMessage and createExternalLogMessage
Features: - extra currencies - stateInit (code+data) with automatic address computation - different workchains - sharding (formerly splitDepth) - auto-serialized body - auto-detect "body ref or not" - more efficient than handwritten code
1 parent ba0f983 commit 3feba11

32 files changed

+2489
-173
lines changed

crypto/smartcont/tolk-stdlib/common.tolk

Lines changed: 312 additions & 61 deletions
Large diffs are not rendered by default.

tolk-tester/tests/cells-slices.tolk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
fun builder.store_u32(mutate self, value: int): self {
22
return self.storeUint(value, 32);
33
}
4+
fun builder.storeMessageOp(mutate self, op: int): self
5+
asm(op self) "32 STU";
6+
fun builder.storeMessageQueryId(mutate self, queryId: int): self
7+
asm(queryId self) "64 STU";
48

59
fun slice.load_u32(mutate self): int {
610
return self.loadUint(32);
@@ -195,7 +199,6 @@ fun test111() {
195199
var q2 = s.loadMessageQueryId();
196200
s.skipBits(64);
197201
s.assertEnd();
198-
assert(isMessageBounced(0x001) && !isMessageBounced(0x002)) throw 444;
199202
return (op1, q1, op2, q2);
200203
}
201204

tolk-tester/tests/generics-2.tolk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,23 +451,23 @@ fun main(c: Wrapper<slice>, d: WrappedInt) {
451451
@testcase | 104 | | 11 11 13 13 13 2
452452
@testcase | 105 | 0 | 80
453453
@testcase | 105 | -1 | (null)
454-
@testcase | 106 | | (null) (null) 0 777 1 2 142
454+
@testcase | 106 | | (null) (null) 0 777 1 2 typeid-14
455455
@testcase | 107 | 5 | 20 20 5 5 20 777 (null) (null) (null) 0
456-
@testcase | 108 | 0 | 777 143 777 143
456+
@testcase | 108 | 0 | 777 typeid-15 777 typeid-15
457457
@testcase | 108 | -1 | 777 0 777 0
458458
@testcase | 109 | | 40 40 70
459459
@testcase | 110 | | 20 1 20 42
460-
@testcase | 111 | | 5 1 132 5 1 132 5 1 132 5 1 132
461-
@testcase | 112 | -1 | 10 1 777 10 1 133
462-
@testcase | 112 | 0 | 20 1 777 (null) 0 134
460+
@testcase | 111 | | 5 1 typeid-4 5 1 typeid-4 5 1 typeid-4 5 1 typeid-4
461+
@testcase | 112 | -1 | 10 1 777 10 1 typeid-5
462+
@testcase | 112 | 0 | 20 1 777 (null) 0 typeid-6
463463
@testcase | 113 | | 30 -1
464464
@testcase | 114 | | 999 (null) 2
465465
@testcase | 115 | | 10 0 200 1 -1 200 1 -1
466466
@testcase | 116 | | 1 2 3 4
467467
@testcase | 117 | | 100 123
468468
@testcase | 118 | | 123 1 777 123 1 -1 2
469469
@testcase | 119 | | 40 40 -1 -1 -1 -1
470-
@testcase | 120 | | (null) 137 777 (null) (null) 0 139 -1 -1
470+
@testcase | 120 | | (null) typeid-9 777 (null) (null) 0 typeid-11 -1 -1
471471
@testcase | 123 | | 10 10 10 10 10
472472

473473

tolk-tester/tests/generics-3.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fun main() {
130130
@testcase | 101 | -1 | 10
131131
@testcase | 101 | 0 | -1
132132
@testcase | 103 | | 10 -1 0
133-
@testcase | 104 | | 12 129 132 -1 -1 -1 0 0 -1 0 0
133+
@testcase | 104 | | 12 typeid-1 typeid-4 -1 -1 -1 0 0 -1 0 0
134134
@testcase | 105 | | -1 -1 -1 -1 0 0
135135
@testcase | 108 | | 50000000 (null) (null) 100000000 12 12 24
136136

tolk-tester/tests/generics-4.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fun main() {
172172
/**
173173
@testcase | 103 | | 10 20 30 777 40 40
174174
@testcase | 104 | | (null) (null) (null)
175-
@testcase | 105 | | -1 (null) 0 (null) 134 777 0 123 0 456 133
175+
@testcase | 105 | | -1 (null) 0 (null) typeid-6 777 0 123 0 456 typeid-5
176176
@testcase | 106 | | -1 0 -1 -1
177177
@testcase | 107 | | 1 10 110 117
178178
@testcase | 108 | | 10 (null) 20

tolk-tester/tests/intN-tests.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fun main() {
246246
@testcase | 110 | | 50000000 50000100 1234000000 51000000
247247
@testcase | 111 | | [ 1000000000 1000000000 1000000000 -321123456789 321123456789 1100000000 ]
248248
@testcase | 114 | 5 | (null) (null) 0
249-
@testcase | 114 | 15 | 15 2 130
249+
@testcase | 114 | 15 | 15 2 typeid-2
250250

251251
@fif_codegen DECLPROC assign0<int8>
252252
@fif_codegen DECLPROC assign0<uint16>

tolk-tester/tests/invalid-serialization/err-7114.tolk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ struct Demo {
66
c: NotSerializableTensor;
77
}
88

9-
fun main(p: Demo?) {
10-
p.toCell();
9+
fun main() {
10+
Demo.fromSlice("");
1111
}
1212

1313
/**
1414
@compilation_should_fail
15-
@stderr auto-serialization via toCell() is not available for type `Demo?`
15+
@stderr auto-serialization via fromSlice() is not available for type `Demo`
1616
@stderr because field `Demo.c` of type `NotSerializableTensor` can't be serialized
1717
@stderr because alias `NotSerializableTensor` expands to `(int8, slice)`
1818
@stderr because element `tensor.1` of type `slice` can't be serialized
19-
@stderr because type `slice` is not serializable, it doesn't define binary width
19+
@stderr because type `slice` can not be used for reading, it doesn't define binary width
2020
@stderr hint: replace `slice` with `address` if it's an address, actually
2121
@stderr hint: replace `slice` with `bits128` and similar if it represents fixed-width data without refs
2222
*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
struct CCC {
2+
v: int;
3+
}
4+
5+
fun main() {
6+
var options = CreateMessageOptions {
7+
bounce: true,
8+
dest: createAddressNone(),
9+
value: 0,
10+
body: CCC { v: 10 }
11+
};
12+
createMessage(options);
13+
}
14+
15+
/**
16+
@compilation_should_fail
17+
@stderr error: auto-serialization via createMessage() is not available for type `CCC`
18+
@stderr because field `CCC.v` of type `int` can't be serialized
19+
@stderr because type `int` is not serializable, it doesn't define binary width
20+
@stderr hint: replace `int` with `int32` / `uint64` / `coins` / etc.
21+
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
struct BigBodyMessage {
2+
v1: int256;
3+
v2: int256;
4+
v3: int256;
5+
a1: address;
6+
a2: address;
7+
}
8+
9+
fun testFail(body: BigBodyMessage) {
10+
createExternalLogMessage({
11+
dest: createAddressNone(),
12+
body,
13+
});
14+
}
15+
16+
/**
17+
@compilation_should_fail
18+
@stderr struct `BigBodyMessage` can exceed 1023 bits in serialization (estimated size: 772..1302 bits)
19+
*/

tolk-tester/tests/nullable-tensors.tolk

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -494,59 +494,59 @@ fun test143(setBNull: bool, setANullMid: bool) {
494494
fun main(){}
495495

496496
/**
497-
@testcase | 101 | | 1 2 129
498-
@testcase | 102 | | 1 2 129 (null) (null) 0
497+
@testcase | 101 | | 1 2 typeid-1
498+
@testcase | 102 | | 1 2 typeid-1 (null) (null) 0
499499
@testcase | 103 | 1 2 | 3 3 0 1 2
500500
@testcase | 104 | | 1 2 (null) (null) 0
501-
@testcase | 105 | | (null) (null) (null) 0 1 2 3 131
501+
@testcase | 105 | | (null) (null) (null) 0 1 2 3 typeid-3
502502
@testcase | 106 | | 1 2
503503
@testcase | 107 | | 0 0 -1 0 0 -1
504-
@testcase | 108 | 5 6 | 7 8 10 11 129 (null) (null) 0
504+
@testcase | 108 | 5 6 | 7 8 10 11 typeid-1 (null) (null) 0
505505
@testcase | 109 | | 0 0 -1 0 -1 0 0 -1 -1
506-
@testcase | 110 | | 3 4 (null) (null) 0 6 7 129
506+
@testcase | 110 | | 3 4 (null) (null) 0 6 7 typeid-1
507507
@testcase | 111 | | 50 30 70 90 100
508508
@testcase | 112 | | 12 22
509509
@testcase | 113 | | -1
510510
@testcase | 114 | | (null) (null) (null) 0 (null) (null) (null) 0
511-
@testcase | 115 | | 2 3 7 (null) (null) 0 5 0 129 0
511+
@testcase | 115 | | 2 3 7 (null) (null) 0 5 0 typeid-1 0
512512
@testcase | 116 | -1 | (null) (null) 0 (null) (null) 0
513-
@testcase | 116 | 0 | 1 2 129 1 2 129
513+
@testcase | 116 | 0 | 1 2 typeid-1 1 2 typeid-1
514514
@testcase | 117 | | (null) 1 3
515-
@testcase | 118 | 5 | 5 10 129
515+
@testcase | 118 | 5 | 5 10 typeid-1
516516
@testcase | 118 | null | (null) (null) 0
517-
@testcase | 119 | | (null) (null) 1 2 129 100
517+
@testcase | 119 | | (null) (null) 1 2 typeid-1 100
518518
@testcase | 120 | -1 | (null) (null) 0
519-
@testcase | 120 | 0 | 1 2 129
519+
@testcase | 120 | 0 | 1 2 typeid-1
520520
@testcase | 121 | | [ 1 [ 3 4 ] ]
521521
@testcase | 122 | 0 | [ 1 [ 3 4 ] 4 (null) ]
522522
@testcase | 122 | -1 | [ 1 (null) 4 (null) ]
523-
@testcase | 123 | | 1 3 4 132
524-
@testcase | 124 | 0 | 1 3 4 132 4 (null) (null) 0
523+
@testcase | 123 | | 1 3 4 typeid-4
524+
@testcase | 124 | 0 | 1 3 4 typeid-4 4 (null) (null) 0
525525
@testcase | 124 | -1 | 1 (null) (null) 0 4 (null) (null) 0
526526
@testcase | 125 | | 3
527527
@testcase | 126 | | 1 (null) 2
528528
@testcase | 127 | 1 | 1 (null) (null) 0 2
529-
@testcase | 127 | 2 | 1 2 3 129 4
529+
@testcase | 127 | 2 | 1 2 3 typeid-1 4
530530
@testcase | 127 | 3 | 1 (null) (null) 0 5
531-
@testcase | 128 | 1 | 1 (null) (null) 0 2 139
531+
@testcase | 128 | 1 | 1 (null) (null) 0 2 typeid-11
532532
@testcase | 128 | 2 | (null) (null) (null) (null) (null) 0
533-
@testcase | 128 | 3 | 1 2 3 129 4 139
533+
@testcase | 128 | 3 | 1 2 3 typeid-1 4 typeid-11
534534
@testcase | 129 | 0 | 5 5 0 -1 1 2 0 -1
535535
@testcase | 129 | -1 | 5 5 0 -1 (null) (null) 0 -1
536-
@testcase | 130 | 0 | 1 2 3 129
536+
@testcase | 130 | 0 | 1 2 3 typeid-1
537537
@testcase | 130 | -1 | 1 (null) (null) 0
538-
@testcase | 131 | | 140 777 0 777 777 777 0 0 140 140 777 140 140 141 777
538+
@testcase | 131 | | typeid-12 777 0 777 777 777 0 0 typeid-12 typeid-12 777 typeid-12 typeid-12 typeid-13 777
539539
@testcase | 132 | | -1 0 -1 0 777 (null) (null) -1 0 0
540540
@testcase | 133 | | 60
541-
@testcase | 134 | | 11 21 129
542-
@testcase | 135 | | [ 10 ] [ (null) ] (null) 777 10 143 (null) 143 (null) 0 777 10 144 (null) 144 (null) 0 777 0 0 -1 0 0 -1 0 0 -1 777 0 -1 0 0 -1 0
541+
@testcase | 134 | | 11 21 typeid-1
542+
@testcase | 135 | | [ 10 ] [ (null) ] (null) 777 10 typeid-15 (null) typeid-15 (null) 0 777 10 typeid-16 (null) typeid-16 (null) 0 777 0 0 -1 0 0 -1 0 0 -1 777 0 -1 0 0 -1 0
543543
@testcase | 136 | 9 | 9 0
544544
@testcase | 136 | null | (null) -1
545-
@testcase | 140 | 8 9 | 8 9 145 (null) (null) 0
545+
@testcase | 140 | 8 9 | 8 9 typeid-17 (null) (null) 0
546546
@testcase | 141 | | (null) 10
547547
@testcase | 142 | | 3 3 1 2
548548
@testcase | 143 | -1 0 | 1 2 1 3 777 (null) (null) (null) (null) 0
549-
@testcase | 143 | 0 -1 | 1 (null) 0 3 777 1 2 1 3 146
549+
@testcase | 143 | 0 -1 | 1 (null) 0 3 777 1 2 1 3 typeid-18
550550

551551
@fif_codegen
552552
"""

0 commit comments

Comments
 (0)