|
| 1 | +// Jest Snapshot v1, https://goo.gl/fbAQLP |
| 2 | + |
| 3 | +exports[`main generateCode 1`] = ` |
| 4 | +"import { Builder } from '@ton/core' |
| 5 | +import { Slice } from '@ton/core' |
| 6 | +import { beginCell } from '@ton/core' |
| 7 | +import { BitString } from '@ton/core' |
| 8 | +import { Cell } from '@ton/core' |
| 9 | +import { Address } from '@ton/core' |
| 10 | +import { ExternalAddress } from '@ton/core' |
| 11 | +import { Dictionary } from '@ton/core' |
| 12 | +import { DictionaryValue } from '@ton/core' |
| 13 | +import { TupleItem } from '@ton/core' |
| 14 | +import { parseTuple } from '@ton/core' |
| 15 | +import { serializeTuple } from '@ton/core' |
| 16 | +export function bitLen(n: number) { |
| 17 | + return n.toString(2).length; |
| 18 | +} |
| 19 | +
|
| 20 | +export interface Bool { |
| 21 | + readonly kind: 'Bool'; |
| 22 | + readonly value: boolean; |
| 23 | +} |
| 24 | +
|
| 25 | +export function loadBool(slice: Slice): Bool { |
| 26 | + if (slice.remainingBits >= 1) { |
| 27 | + let value = slice.loadUint(1); |
| 28 | + return { |
| 29 | + kind: 'Bool', |
| 30 | + value: value == 1 |
| 31 | + } |
| 32 | +
|
| 33 | + } |
| 34 | + throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor'); |
| 35 | +} |
| 36 | +
|
| 37 | +export function storeBool(bool: Bool): (builder: Builder) => void { |
| 38 | + return ((builder: Builder) => { |
| 39 | + builder.storeUint(bool.value ? 1: 0, 1); |
| 40 | + }) |
| 41 | +
|
| 42 | +} |
| 43 | +
|
| 44 | +
|
| 45 | +
|
| 46 | +export function loadBoolFalse(slice: Slice): Bool { |
| 47 | + if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) { |
| 48 | + slice.loadUint(1); |
| 49 | + return { |
| 50 | + kind: 'Bool', |
| 51 | + value: false |
| 52 | + } |
| 53 | +
|
| 54 | + } |
| 55 | + throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor'); |
| 56 | +} |
| 57 | +
|
| 58 | +export function loadBoolTrue(slice: Slice): Bool { |
| 59 | + if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) { |
| 60 | + slice.loadUint(1); |
| 61 | + return { |
| 62 | + kind: 'Bool', |
| 63 | + value: true |
| 64 | + } |
| 65 | +
|
| 66 | + } |
| 67 | + throw new Error('Expected one of "BoolTrue" in loading "BoolTrue", but data does not satisfy any constructor'); |
| 68 | +} |
| 69 | +
|
| 70 | +export function copyCellToBuilder(from: Cell, to: Builder): void { |
| 71 | + let slice = from.beginParse(); |
| 72 | + to.storeBits(slice.loadBits(slice.remainingBits)); |
| 73 | + while (slice.remainingRefs) { |
| 74 | + to.storeRef(slice.loadRef()); |
| 75 | + } |
| 76 | +} |
| 77 | +// _ x:# = Foo; |
| 78 | +
|
| 79 | +export interface Foo { |
| 80 | + readonly kind: 'Foo'; |
| 81 | + readonly x: number; |
| 82 | +} |
| 83 | +
|
| 84 | +// _ x:# = Foo; |
| 85 | +
|
| 86 | +export function loadFoo(slice: Slice): Foo { |
| 87 | + let x: number = slice.loadUint(32); |
| 88 | + return { |
| 89 | + kind: 'Foo', |
| 90 | + x: x, |
| 91 | + } |
| 92 | +
|
| 93 | +} |
| 94 | +
|
| 95 | +export function storeFoo(foo: Foo): (builder: Builder) => void { |
| 96 | + return ((builder: Builder) => { |
| 97 | + builder.storeUint(foo.x, 32); |
| 98 | + }) |
| 99 | +
|
| 100 | +} |
| 101 | +
|
| 102 | +" |
| 103 | +`; |
| 104 | + |
| 105 | +exports[`main getTLBCode 1`] = ` |
| 106 | +TLBCode { |
| 107 | + "types": Map { |
| 108 | + "Foo" => TLBType { |
| 109 | + "constructors": [ |
| 110 | + TLBConstructor { |
| 111 | + "constraints": [], |
| 112 | + "declaration": "_ x:# = Foo;", |
| 113 | + "fields": [ |
| 114 | + { |
| 115 | + "anonymous": false, |
| 116 | + "fieldType": { |
| 117 | + "bits": TLBNumberExpr { |
| 118 | + "hasNeg": false, |
| 119 | + "n": 32, |
| 120 | + "variables": Set {}, |
| 121 | + }, |
| 122 | + "kind": "TLBNumberType", |
| 123 | + "maxBits": 32, |
| 124 | + "signed": false, |
| 125 | + "storeBits": TLBNumberExpr { |
| 126 | + "hasNeg": false, |
| 127 | + "n": 32, |
| 128 | + "variables": Set {}, |
| 129 | + }, |
| 130 | + }, |
| 131 | + "name": "x", |
| 132 | + "subFields": [], |
| 133 | + }, |
| 134 | + ], |
| 135 | + "name": "_", |
| 136 | + "parameters": [], |
| 137 | + "parametersMap": Map {}, |
| 138 | + "tag": { |
| 139 | + "binary": "", |
| 140 | + "bitLen": 0, |
| 141 | + }, |
| 142 | + "tlbType": "Foo", |
| 143 | + "variables": [ |
| 144 | + TLBVariable { |
| 145 | + "deriveExpr": undefined, |
| 146 | + "initialExpr": undefined, |
| 147 | + "isConst": false, |
| 148 | + "isField": true, |
| 149 | + "name": "x", |
| 150 | + "negated": false, |
| 151 | + "type": "#", |
| 152 | + }, |
| 153 | + ], |
| 154 | + "variablesMap": Map { |
| 155 | + "x" => TLBVariable { |
| 156 | + "deriveExpr": undefined, |
| 157 | + "initialExpr": undefined, |
| 158 | + "isConst": false, |
| 159 | + "isField": true, |
| 160 | + "name": "x", |
| 161 | + "negated": false, |
| 162 | + "type": "#", |
| 163 | + }, |
| 164 | + }, |
| 165 | + }, |
| 166 | + ], |
| 167 | + "name": "Foo", |
| 168 | + }, |
| 169 | + }, |
| 170 | +} |
| 171 | +`; |
0 commit comments