@@ -19,7 +19,7 @@ import ResultGenerator from '../src/generation/result_generator.mjs';
19
19
import PrimitiveWrapperGenerator from '../src/generation/primitive_wrapper_generator.mjs' ;
20
20
import * as chai from 'chai' ;
21
21
import PrimitiveEnumGenerator from '../src/generation/primitive_enum_generator.mjs' ;
22
- import Generator , { AuxiliaryArtifacts } from '../src/generation/index.mjs' ;
22
+ import { AuxiliaryArtifacts } from '../src/generation/index.mjs' ;
23
23
import TraitGenerator from '../src/generation/trait_generator.mjs' ;
24
24
25
25
class TestConfig extends Config {
@@ -56,7 +56,7 @@ describe('Generator Tests', () => {
56
56
chai . expect ( output ) . contains ( 'public func getClaimableBalances() -> [UInt8] {' ) ;
57
57
chai . expect ( output ) . contains ( 'internal func free() {' ) ;
58
58
59
- chai . expect ( output ) . contains ( 'let chainSourceOption = Option_FilterZ(value : chainSource)' ) ;
59
+ chai . expect ( output ) . contains ( 'let chainSourceOption = Option_FilterZ(some : chainSource)' ) ;
60
60
chai . expect ( output ) . contains ( 'let nativeCallResult = ChainMonitor_free(self.cType!)' ) ;
61
61
} ) ;
62
62
@@ -105,9 +105,6 @@ describe('Generator Tests', () => {
105
105
const vectorVectorOutput = generator . generateFileContents ( routeVectorVector ) ;
106
106
107
107
chai . expect ( vectorVectorOutput ) . includes ( 'public init(array: [[RouteHop]]) {' ) ;
108
- chai . expect ( vectorVectorOutput ) . includes ( 'let rustArray = array.map { (currentValueDepth1) in' ) ;
109
- chai . expect ( vectorVectorOutput ) . includes ( 'currentValueDepth1.map { (currentValueDepth2) in' ) ;
110
- chai . expect ( vectorVectorOutput ) . includes ( 'currentValueDepth2.danglingClone().cType!' ) ;
111
108
chai . expect ( vectorVectorOutput )
112
109
. includes ( 'let dataContainer = UnsafeMutablePointer<LDKCVec_RouteHopZ>.allocate(capacity: array.count)' ) ;
113
110
chai . expect ( vectorVectorOutput )
@@ -122,24 +119,24 @@ describe('Generator Tests', () => {
122
119
chai . expect ( vectorVectorOutput ) . includes ( 'var convertedEntry1 = [LDKRouteHop]()' ) ;
123
120
chai . expect ( vectorVectorOutput ) . includes ( 'let currentEntry2 = currentEntry1.data[index2]' ) ;
124
121
chai . expect ( vectorVectorOutput ) . includes ( 'convertedEntry1.append(currentEntry2)' ) ;
125
- chai . expect ( vectorVectorOutput ) . includes ( 'let swiftArray = array.map { (currentCType) in' ) ;
126
- chai . expect ( vectorVectorOutput ) . includes ( 'currentCType.map { (currentCType) in' ) ;
127
- chai . expect ( vectorVectorOutput ) . includes ( 'RouteHop(pointer : currentCType)' ) ;
122
+ chai . expect ( vectorVectorOutput ) . includes ( 'let swiftArray = array.map { (currentCType: [LDKRouteHop]) -> [RouteHop] in' ) ;
123
+ chai . expect ( vectorVectorOutput ) . includes ( 'currentCType.map { (currentCType: LDKRouteHop) -> RouteHop in' ) ;
124
+ chai . expect ( vectorVectorOutput ) . includes ( 'RouteHop(cType : currentCType, anchor: self).dangle( )' ) ;
128
125
129
126
const routeVector = < RustVector > glossary [ 'LDKCVec_RouteHopZ' ] ;
130
127
const vectorOutput = generator . generateFileContents ( routeVector ) ;
131
128
chai . expect ( vectorOutput ) . includes ( 'public init(array: [RouteHop]) {' ) ;
132
- chai . expect ( vectorOutput ) . includes ( 'let rustArray = array.map { (currentValueDepth1) in' ) ;
133
- chai . expect ( vectorOutput ) . includes ( 'currentValueDepth1.danglingClone() .cType!' ) ;
129
+ chai . expect ( vectorOutput ) . includes ( 'let rustArray = array.map { (currentValueDepth1: RouteHop) -> LDKRouteHop in' ) ;
130
+ chai . expect ( vectorOutput ) . includes ( 'return currentValueDepth1.cType!' ) ;
134
131
chai . expect ( vectorOutput )
135
132
. includes ( 'let dataContainer = UnsafeMutablePointer<LDKRouteHop>.allocate(capacity: array.count)' ) ;
136
133
chai . expect ( vectorOutput )
137
134
. includes ( 'let vector = LDKCVec_RouteHopZ(data: dataContainer, datalen: UInt(array.count))' ) ;
138
135
139
136
chai . expect ( vectorOutput ) . includes ( 'public func getValue() -> [RouteHop] {' ) ;
140
137
chai . expect ( vectorOutput ) . includes ( 'var array = [LDKRouteHop]()' ) ;
141
- chai . expect ( vectorOutput ) . includes ( 'let swiftArray = array.map { (currentCType) in' ) ;
142
- chai . expect ( vectorOutput ) . includes ( 'RouteHop(pointer : currentCType)' ) ;
138
+ chai . expect ( vectorOutput ) . includes ( 'let swiftArray = array.map { (currentCType: LDKRouteHop) -> RouteHop in' ) ;
139
+ chai . expect ( vectorOutput ) . includes ( 'RouteHop(cType : currentCType, anchor: self).dangle( )' ) ;
143
140
} ) ;
144
141
145
142
it ( 'should generate Vec<u8>' , ( ) => {
@@ -191,15 +188,15 @@ describe('Generator Tests', () => {
191
188
const accessErrorOutput = generator . generateFileContents ( accessError ) ;
192
189
chai . expect ( accessErrorOutput ) . includes ( 'internal init (value: LDKAccessError) {' ) ;
193
190
chai . expect ( accessErrorOutput ) . includes ( 'self = .UnknownTx' ) ;
194
- chai . expect ( accessErrorOutput ) . includes ( 'if value == LDKAccessError_UnknownChain { ' ) ;
191
+ chai . expect ( accessErrorOutput ) . includes ( 'case LDKAccessError_UnknownTx: ' ) ;
195
192
chai . expect ( accessErrorOutput ) . includes ( 'internal func getCValue() -> LDKAccessError {' ) ;
196
193
chai . expect ( accessErrorOutput ) . includes ( 'case .UnknownChain:' ) ;
197
194
chai . expect ( accessErrorOutput ) . includes ( 'return LDKAccessError_UnknownChain' ) ;
198
195
199
196
const monitorUpdateStatusOutput = generator . generateFileContents ( monitorUpdateStatus ) ;
200
197
chai . expect ( monitorUpdateStatusOutput ) . includes ( 'internal init (value: LDKChannelMonitorUpdateStatus) {' ) ;
201
198
chai . expect ( monitorUpdateStatusOutput ) . includes ( 'self = .PermanentFailure' ) ;
202
- chai . expect ( monitorUpdateStatusOutput ) . includes ( 'if value == LDKChannelMonitorUpdateStatus_Completed { ' ) ;
199
+ chai . expect ( monitorUpdateStatusOutput ) . includes ( 'case LDKChannelMonitorUpdateStatus_Completed: ' ) ;
203
200
chai . expect ( monitorUpdateStatusOutput ) . includes ( 'internal func getCValue() -> LDKChannelMonitorUpdateStatus {' ) ;
204
201
chai . expect ( monitorUpdateStatusOutput ) . includes ( 'case .Completed:' ) ;
205
202
chai . expect ( monitorUpdateStatusOutput ) . includes ( 'return LDKChannelMonitorUpdateStatus_Completed' ) ;
@@ -238,7 +235,7 @@ describe('Generator Tests', () => {
238
235
} ) ;
239
236
240
237
describe ( 'Primitive Wrapper Generation Tests' , ( ) => {
241
- it ( 'should generate LDKu5 ' , ( ) => {
238
+ it ( 'should generate LDKU5 ' , ( ) => {
242
239
// only the new and get_claimable_balances methods are present
243
240
// some parameters have been removed
244
241
const __dirname = url . fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
@@ -248,7 +245,7 @@ describe('Generator Tests', () => {
248
245
249
246
const generator = new PrimitiveWrapperGenerator ( config , new AuxiliaryArtifacts ( ) ) ;
250
247
251
- const ldku5 = < RustPrimitiveWrapper > parser . glossary [ 'LDKu5 ' ] ;
248
+ const ldku5 = < RustPrimitiveWrapper > parser . glossary [ 'LDKU5 ' ] ;
252
249
const ldkStr = < RustPrimitiveWrapper > parser . glossary [ 'LDKStr' ] ;
253
250
const thirtyTwoBytes = < RustPrimitiveWrapper > parser . glossary [ 'LDKThirtyTwoBytes' ] ;
254
251
const transaction = < RustPrimitiveWrapper > parser . glossary [ 'LDKTransaction' ] ;
@@ -261,24 +258,26 @@ describe('Generator Tests', () => {
261
258
chai . expect ( transactionOutput ) . includes ( 'public init(value: [UInt8]) {' ) ;
262
259
chai . expect ( transactionOutput ) . includes ( 'public func getValue() -> [UInt8] {' ) ;
263
260
chai . expect ( transactionOutput )
264
- . includes ( 'self.cType = LDKTransaction(data: dataContainer, datalen: UInt(value.count), data_is_owned: false )' ) ;
261
+ . includes ( 'self.cType = LDKTransaction(data: dataContainer, datalen: UInt(value.count), data_is_owned: true )' ) ;
265
262
266
263
chai . expect ( thirtyTwoBytesOutput ) . includes ( 'public init(value: [UInt8]) {' ) ;
267
264
chai . expect ( thirtyTwoBytesOutput ) . includes ( 'public func getValue() -> [UInt8] {' ) ;
268
265
chai . expect ( thirtyTwoBytesOutput )
269
- . includes ( 'self.cType = LDKThirtyTwoBytes(data: (value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9], value[10], value[11], value[12], value[13], value[14], value[15], value[16], value[17], value[18], value[19], value[20], value[21], value[22], value[23], value[24], value[25], value[26], value[27], value[28], value[29], value[30], value[31]))' ) ;
266
+ . includes ( 'self.cType = LDKThirtyTwoBytes(data: Bindings.arrayToUInt8Tuple32(array: value))' ) ;
267
+
270
268
chai . expect ( thirtyTwoBytesOutput )
271
- . includes ( 'return [self.cType!.data.0, self.cType!.data.1, self.cType!.data.2, self.cType!.data.3, self.cType!.data.4, self.cType!.data.5, self.cType!.data.6, self.cType!.data.7, self.cType!.data.8, self.cType!.data.9, self.cType!.data.10, self.cType!.data.11, self.cType!.data.12, self.cType!.data.13, self.cType!.data.14, self.cType!.data.15, self.cType!.data.16, self.cType!.data.17, self.cType!.data.18, self.cType!.data.19, self.cType!.data.20, self.cType!.data.21, self.cType!.data.22, self.cType!.data.23, self.cType!.data.24, self.cType!.data.25, self.cType!.data.26, self.cType!.data.27, self.cType!.data.28, self.cType!.data.29, self.cType!.data.30, self.cType!.data.31] ' ) ;
269
+ . includes ( 'return Bindings.UInt8Tuple32ToArray(tuple: self.cType!.data) ' ) ;
272
270
273
271
chai . expect ( strOutput ) . includes ( 'public init(value: String) {' ) ;
274
272
chai . expect ( strOutput ) . includes ( 'public func getValue() -> String {' ) ;
275
273
chai . expect ( strOutput )
276
- . includes ( 'self.cType = LDKStr(chars: Bindings.string_to_unsafe_uint8_pointer(string: value), len: UInt(value.count), chars_is_owned: false)' ) ;
274
+ . includes ( 'self.cType = LDKStr(chars: Bindings.string_to_unsafe_uint8_pointer(string: value), len: UInt(value.count), chars_is_owned: true)' ) ;
275
+
277
276
chai . expect ( strOutput ) . includes ( 'return String(data: data, encoding: .utf8)!' ) ;
278
277
279
278
chai . expect ( u5Output ) . includes ( 'public init(value: UInt8) {' ) ;
280
279
chai . expect ( u5Output ) . includes ( 'public func getValue() -> UInt8 {' ) ;
281
- chai . expect ( u5Output ) . includes ( 'self.cType = LDKu5 (_0: value)' ) ;
280
+ chai . expect ( u5Output ) . includes ( 'self.cType = LDKU5 (_0: value)' ) ;
282
281
chai . expect ( u5Output ) . includes ( 'return self.cType!._0' ) ;
283
282
} ) ;
284
283
} ) ;
0 commit comments