-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp-deploy.spec.ts
729 lines (663 loc) · 26.6 KB
/
app-deploy.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
import { getApplicationAddress } from 'algosdk'
import invariant from 'tiny-invariant'
import { afterEach, beforeEach, describe, expect, test } from 'vitest'
import { getTestingAppCreateParams, getTestingAppDeployParams } from '../tests/example-contracts/testing-app/contract'
import { Config } from './config'
import { algoKitLogCaptureFixture, algorandFixture } from './testing'
import { AppDeployMetadata } from './types/app'
import { AppDeployParams } from './types/app-deployer'
import { AppManager } from './types/app-manager'
import { LogicError } from './types/logic-error'
describe('deploy-app', () => {
const localnet = algorandFixture()
beforeEach(localnet.newScope, 10_000)
const logging = algoKitLogCaptureFixture()
beforeEach(logging.beforeEach)
afterEach(logging.afterEach)
const name = 'MY_APP'
test('Created app is retrieved by name with deployment metadata', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const creationMetadata = { name, version: '1.0', updatable: true, deletable: false }
const app1 = await algorand.send.appCreate(await getTestingAppCreateParams(testAccount, creationMetadata))
await waitForIndexer()
const apps = await algorand.appDeployer.getCreatorAppsByName(testAccount)
expect(apps.creator).toBe(testAccount)
expect(Object.keys(apps.apps)).toEqual([name])
const app = apps.apps[name]
expect(app.appId).toBe(app1.appId)
expect(app.appAddress).toEqual(app1.appAddress)
expect(app.createdRound).toBe(BigInt(app1.confirmation.confirmedRound!))
expect(app.createdMetadata).toEqual(creationMetadata)
expect(app.updatedRound).toBe(app.createdRound)
expect(app.name).toBe(creationMetadata.name)
expect(app.updatable).toBe(creationMetadata.updatable)
expect(app.deletable).toBe(creationMetadata.deletable)
expect(app.version).toBe(creationMetadata.version)
})
test('Latest created app is retrieved', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const creationMetadata = { name, version: '1.0', updatable: true, deletable: false }
const app1 = await algorand.send.appCreate({ ...(await getTestingAppCreateParams(testAccount, creationMetadata)), lease: '1' })
const app2 = await algorand.send.appCreate({ ...(await getTestingAppCreateParams(testAccount, creationMetadata)), lease: '2' })
const app3 = await algorand.send.appCreate({ ...(await getTestingAppCreateParams(testAccount, creationMetadata)), lease: '3' })
await waitForIndexer()
const apps = await algorand.appDeployer.getCreatorAppsByName(testAccount)
expect(apps.apps[name].appId).not.toBe(app1.appId)
expect(apps.apps[name].appId).not.toBe(app2.appId)
expect(apps.apps[name].appId).toBe(app3.appId)
})
test('Created, updated and deleted apps are retrieved by name with deployment metadata', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const creationMetadata = { name, version: '1.0', updatable: true, deletable: true }
const name2 = 'APP_2'
const name3 = 'APP_3'
const app1 = await algorand.send.appCreate(await getTestingAppCreateParams(testAccount, creationMetadata))
const app2 = await algorand.send.appCreate(await getTestingAppCreateParams(testAccount, { ...creationMetadata, name: name2 }))
const app3 = await algorand.send.appCreate(await getTestingAppCreateParams(testAccount, { ...creationMetadata, name: name3 }))
const updateMetadata = { name, version: '2.0', updatable: false, deletable: false }
const update1 = await algorand.send.appUpdate({ ...(await getTestingAppCreateParams(testAccount, updateMetadata)), appId: app1.appId })
const _delete3 = await algorand.send.appDelete({ appId: app3.appId, sender: testAccount })
await waitForIndexer()
const apps = await algorand.appDeployer.getCreatorAppsByName(testAccount)
expect(apps.creator).toBe(testAccount)
expect(Object.keys(apps.apps).sort()).toEqual([name, name2, name3].sort())
const app1Data = apps.apps[name]
expect(app1Data.appId).toBe(app1.appId)
expect(app1Data.appAddress).toEqual(app1.appAddress)
expect(app1Data.createdRound).toBe(BigInt(app1.confirmation.confirmedRound!))
expect(app1Data.createdMetadata).toEqual(creationMetadata)
expect(app1Data.updatedRound).toBe(BigInt(update1.confirmation.confirmedRound!))
expect(app1Data.name).toBe(updateMetadata.name)
expect(app1Data.updatable).toBe(updateMetadata.updatable)
expect(app1Data.deletable).toBe(updateMetadata.deletable)
expect(app1Data.version).toBe(updateMetadata.version)
expect(app1Data.deleted).toBe(false)
const app2Data = apps.apps[name2]
expect(app2Data.appId).toBe(app2.appId)
expect(app2Data.deleted).toBe(false)
const app3Data = apps.apps[name3]
expect(app3Data.appId).toBe(app3.appId)
expect(app3Data.deleted).toBe(true)
})
test('Deploy new app', async () => {
const { algorand, testAccount } = localnet.context
const deployment = await getTestingAppDeployParams({
sender: testAccount,
metadata: getMetadata(),
})
const result = await algorand.appDeployer.deploy(deployment)
invariant('transaction' in result)
invariant(result.confirmation)
expect(result.appId).toBe(BigInt(result.confirmation.applicationIndex!))
expect(result.appAddress).toEqual(getApplicationAddress(result.appId))
expect(result.createdMetadata).toEqual(deployment.metadata)
expect(result.createdRound).toBe(BigInt(result.confirmation.confirmedRound!))
expect(result.updatedRound).toBe(result.createdRound)
expect(result.name).toBe(deployment.metadata.name)
expect(result.version).toBe(deployment.metadata.version)
expect(result.updatable).toBe(deployment.metadata.updatable)
expect(result.deletable).toBe(deployment.metadata.deletable)
expect(result.deleted).toBe(false)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result.transaction],
apps: [result.appId],
}),
).toMatchSnapshot()
})
test('Fail to deploy immutable app without TMPL_UPDATABLE', async () => {
const { algorand, testAccount } = localnet.context
const deployment = await getTestingAppDeployParams({
sender: testAccount,
metadata: getMetadata({ updatable: true }),
})
deployment.createParams.approvalProgram = deployment.createParams.approvalProgram.replace(/TMPL_UPDATABLE/g, '0')
await expect(async () => await algorand.appDeployer.deploy(deployment)).rejects.toThrowError(
'Deploy-time updatability control requested for app deployment, but TMPL_UPDATABLE not present in TEAL code',
)
})
test('Fail to deploy permanent app without TMPL_DELETABLE', async () => {
const { algorand, testAccount } = localnet.context
const deployment = await getTestingAppDeployParams({
sender: testAccount,
metadata: getMetadata({ deletable: true }),
})
deployment.createParams.approvalProgram = deployment.createParams.approvalProgram.replace(/TMPL_DELETABLE/g, '0')
await expect(async () => await algorand.appDeployer.deploy(deployment)).rejects.toThrowError(
'Deploy-time deletability control requested for app deployment, but TMPL_DELETABLE not present in TEAL code',
)
})
test('Deploy update to updatable updated app', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata({ updatable: true })
const deployment1 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = await getTestingAppDeployParams({
sender: testAccount,
metadata: { ...metadata, version: '2.0' },
codeInjectionValue: 2,
onUpdate: 'update',
})
const result2 = await algorand.appDeployer.deploy(deployment2)
invariant('transaction' in result1)
invariant('transaction' in result2)
invariant(result2.confirmation)
expect(result2.appId).toBe(result1.appId)
expect(result2.createdMetadata).toEqual(deployment1.metadata)
expect(result2.createdRound).toBe(result1.createdRound)
expect(result2.updatedRound).toBe(BigInt(result2.confirmation.confirmedRound!))
expect(result2.name).toBe(deployment2.metadata.name)
expect(result2.version).toBe(deployment2.metadata.version)
expect(result2.updatable).toBe(deployment2.metadata.updatable)
expect(result2.deletable).toBe(deployment2.metadata.deletable)
expect(result2.deleted).toBe(false)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction, result2.transaction],
apps: [result1.appId],
}),
).toMatchSnapshot()
})
test('Deploy update to immutable updated app fails', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata({ updatable: false })
const deployment1 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = await getTestingAppDeployParams({
sender: testAccount,
metadata: { ...metadata, version: '2.0' },
codeInjectionValue: 2,
onUpdate: 'update',
})
try {
await algorand.appDeployer.deploy(deployment2)
invariant(false)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
expect(e.message).toMatch(/logic eval error: assert failed/)
const logicError = LogicError.parseLogicError(e)
invariant('transaction' in result1)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction, logicError!.txId],
apps: [result1.appId],
}),
).toMatchSnapshot()
}
})
test('Deploy failure for updated app fails if onupdate = Fail', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata()
const deployment1 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
codeInjectionValue: 2,
onUpdate: 'fail',
})
await expect(() => algorand.appDeployer.deploy(deployment2)).rejects.toThrow(
'Update detected and onUpdate=Fail, stopping deployment. Try a different onUpdate value to not fail.',
)
invariant('transaction' in result1)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction],
apps: [result1.appId],
}),
).toMatchSnapshot()
})
test('Deploy replacement to deletable, updated app', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata({ deletable: true })
const deployment1 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = await getTestingAppDeployParams({
sender: testAccount,
metadata: { ...metadata, version: '2.0' },
codeInjectionValue: 2,
onUpdate: 'replace',
})
const result2 = await algorand.appDeployer.deploy(deployment2)
invariant('transaction' in result1)
invariant('transaction' in result2)
invariant(result2.confirmation)
invariant(result2.operationPerformed === 'replace')
invariant(result2.deleteResult)
expect(result2.appId).not.toBe(result1.appId)
expect(result2.createdMetadata).toEqual(deployment2.metadata)
expect(result2.createdRound).toBe(BigInt(result2.confirmation.confirmedRound!))
expect(result2.updatedRound).toBe(BigInt(result2.confirmation.confirmedRound!))
expect(result2.name).toBe(deployment2.metadata.name)
expect(result2.version).toBe(deployment2.metadata.version)
expect(result2.updatable).toBe(deployment2.metadata.updatable)
expect(result2.deletable).toBe(deployment2.metadata.deletable)
expect(result2.deleted).toBe(false)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction, result2.transaction, result2.deleteResult.transaction],
apps: [result1.appId, result2.appId],
filterPredicate: filterVerboseAndDebugLogs,
}),
).toMatchSnapshot()
})
test('Deploy failure for replacement of permanent, updated app', async () => {
Config.configure({ debug: false }) // Remove noise from snapshot
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata({ deletable: false })
const deployment1 = (await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})) as AppDeployParams
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = (await getTestingAppDeployParams({
sender: testAccount,
metadata: { ...metadata, version: '2.0' },
codeInjectionValue: 2,
onUpdate: 'replace',
})) as AppDeployParams
try {
await algorand.appDeployer.deploy(deployment2)
invariant(false)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
expect(e.message).toMatch(/logic eval error: assert failed/)
const logicError = LogicError.parseLogicError(e)
invariant('transaction' in result1)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction, logicError!.txId],
apps: [result1.appId],
filterPredicate: filterVerboseAndDebugLogs,
}),
).toMatchSnapshot()
}
})
test('Deploy replacement of deletable schema broken app', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata({ deletable: true })
const deployment1 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = await getTestingAppDeployParams({
sender: testAccount,
metadata: { ...metadata, version: '2.0' },
breakSchema: true,
onSchemaBreak: 'replace',
})
const result2 = await algorand.appDeployer.deploy(deployment2)
invariant('transaction' in result1)
invariant('transaction' in result2)
invariant(result2.confirmation)
invariant(result2.operationPerformed === 'replace')
invariant(result2.deleteResult)
expect(result2.appId).not.toBe(result1.appId)
expect(result2.createdMetadata).toEqual(deployment2.metadata)
expect(result2.createdRound).toBe(result2.createdRound)
expect(result2.updatedRound).toBe(result2.createdRound)
expect(result2.name).toBe(deployment2.metadata.name)
expect(result2.version).toBe(deployment2.metadata.version)
expect(result2.updatable).toBe(deployment2.metadata.updatable)
expect(result2.deletable).toBe(deployment2.metadata.deletable)
expect(result2.deleted).toBe(false)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction, result2.transaction, result2.deleteResult.transaction],
apps: [result1.appId, result2.appId],
filterPredicate: filterVerboseAndDebugLogs,
}),
).toMatchSnapshot()
})
test('Deploy replacement to schema broken, permanent app fails', async () => {
Config.configure({ debug: false }) // Remove noise from snapshot
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata({ deletable: false })
const deployment1 = (await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})) as AppDeployParams
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = (await getTestingAppDeployParams({
sender: testAccount,
metadata: { ...metadata, version: '2.0' },
breakSchema: true,
onSchemaBreak: 'replace',
})) as AppDeployParams
try {
await algorand.appDeployer.deploy(deployment2)
invariant(false)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
expect(e.message).toMatch(/logic eval error: assert failed/)
const logicError = LogicError.parseLogicError(e)
invariant('transaction' in result1)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction, logicError!.txId],
apps: [result1.appId],
filterPredicate: filterVerboseAndDebugLogs,
}),
).toMatchSnapshot()
}
})
test('Deploy failure for replacement of schema broken app fails if onSchemaBreak = Fail', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata()
const deployment1 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
onSchemaBreak: 'fail',
breakSchema: true,
})
await expect(() => algorand.appDeployer.deploy(deployment2)).rejects.toThrow(
'Schema break detected and onSchemaBreak=OnSchemaBreak.Fail, stopping deployment. ' +
'If you want to try deleting and recreating the app then ' +
're-run with onSchemaBreak=OnSchemaBreak.ReplaceApp',
)
invariant('transaction' in result1)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction],
apps: [result1.appId],
}),
).toMatchSnapshot()
})
test('Do nothing if deploying app with no changes', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const deployment = await getTestingAppDeployParams({
sender: testAccount,
metadata: getMetadata(),
})
const initialDeployment = await algorand.appDeployer.deploy(deployment)
await waitForIndexer()
logging.testLogger.clear()
const result = await algorand.appDeployer.deploy(deployment)
invariant('transaction' in initialDeployment)
invariant(!('transaction' in result))
expect(result.appId).toBe(initialDeployment.appId)
expect(result.appAddress).toEqual(getApplicationAddress(initialDeployment.appId))
expect(result.createdMetadata).toEqual(deployment.metadata)
expect(result.createdRound).toBe(initialDeployment.createdRound)
expect(result.updatedRound).toBe(initialDeployment.createdRound)
expect(result.name).toBe(deployment.metadata.name)
expect(result.version).toBe(deployment.metadata.version)
expect(result.updatable).toBe(deployment.metadata.updatable)
expect(result.deletable).toBe(deployment.metadata.deletable)
expect(result.deleted).toBe(false)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [initialDeployment.transaction],
apps: [result.appId],
}),
).toMatchSnapshot()
})
test('Deploy append for schema broken app if onSchemaBreak = AppendApp', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata()
const deployment1 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
onSchemaBreak: 'append',
breakSchema: true,
})
const result2 = await algorand.appDeployer.deploy(deployment2)
invariant('transaction' in result1)
invariant('transaction' in result2)
invariant(result2.confirmation)
invariant(result2.operationPerformed === 'create')
expect(result2.appId).not.toBe(result1.appId)
expect(result2.createdMetadata).toEqual(deployment1.metadata)
expect(result2.createdRound).not.toBe(result1.createdRound)
expect(result2.name).toBe(deployment2.metadata.name)
expect(result2.version).toBe(deployment2.metadata.version)
expect(result2.updatable).toBe(deployment2.metadata.updatable)
expect(result2.deletable).toBe(deployment2.metadata.deletable)
expect(result2.deleted).toBe(false)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction, result2.transaction],
apps: [result1.appId, result2.appId],
}),
).toMatchSnapshot()
})
test('Deploy append for update app if onUpdate = AppendApp', async () => {
const { algorand, testAccount, waitForIndexer } = localnet.context
const metadata = getMetadata()
const deployment1 = await getTestingAppDeployParams({
sender: testAccount,
metadata: metadata,
})
const result1 = await algorand.appDeployer.deploy(deployment1)
await waitForIndexer()
logging.testLogger.clear()
const deployment2 = await getTestingAppDeployParams({
sender: testAccount,
metadata: { ...metadata, version: '2.0' },
codeInjectionValue: 3,
onUpdate: 'append',
})
const result2 = await algorand.appDeployer.deploy(deployment2)
invariant('transaction' in result1)
invariant('transaction' in result2)
invariant(result2.confirmation)
invariant(result2.operationPerformed === 'create')
expect(result2.appId).not.toBe(result1.appId)
expect(result2.createdMetadata).not.toEqual(deployment1.metadata)
expect(result2.createdRound).not.toBe(result1.createdRound)
expect(result2.name).toBe(deployment2.metadata.name)
expect(result2.version).toBe(deployment2.metadata.version)
expect(result2.updatable).toBe(deployment2.metadata.updatable)
expect(result2.deletable).toBe(deployment2.metadata.deletable)
expect(result2.deleted).toBe(false)
expect(
logging.testLogger.getLogSnapshot({
accounts: [testAccount],
transactions: [result1.transaction, result2.transaction],
apps: [result1.appId, result2.appId],
}),
).toMatchSnapshot()
})
const filterVerboseAndDebugLogs = (log: string) => !log.startsWith('VERBOSE:') && !log.startsWith('DEBUG:')
})
test('Strip comments remove comments without removing commands', async () => {
const tealCode = `//comment
op arg //comment
op "arg" //comment
op "//" //comment
op " //comment " //comment
op "\\" //" //comment
op "" //comment
//
op 123
op 123 // something
op "" // more comments
op "//" //op "//"
op "//"
pushbytes base64(//8=)
pushbytes b64(//8=)
pushbytes base64(//8=) // pushbytes base64(//8=)
pushbytes b64(//8=) // pushbytes b64(//8=)
pushbytes "base64(//8=)" // pushbytes "base64(//8=)"
pushbytes "b64(//8=)" // pushbytes "b64(//8=)"
pushbytes base64 //8=
pushbytes b64 //8=
pushbytes base64 //8= // pushbytes base64 //8=
pushbytes b64 //8= // pushbytes b64 //8=
pushbytes "base64 //8=" // pushbytes "base64 //8="
pushbytes "b64 //8=" // pushbytes "b64 //8="
`
const tealCodeResult = `
op arg
op "arg"
op "//"
op " //comment "
op "\\" //"
op ""
op 123
op 123
op ""
op "//"
op "//"
pushbytes base64(//8=)
pushbytes b64(//8=)
pushbytes base64(//8=)
pushbytes b64(//8=)
pushbytes "base64(//8=)"
pushbytes "b64(//8=)"
pushbytes base64 //8=
pushbytes b64 //8=
pushbytes base64 //8=
pushbytes b64 //8=
pushbytes "base64 //8="
pushbytes "b64 //8="
`
const result = AppManager.stripTealComments(tealCode)
expect(result).toBe(tealCodeResult)
})
test('Can substitute template variable with multiple underscores', async () => {
const testTeal = `
int TMPL_SOME_VALUE
return
`
const testParams = {
SOME_VALUE: 123,
}
const substituted = AppManager.replaceTealTemplateParams(testTeal, testParams)
expect(substituted).toBe(`
int 123
return
`)
})
test('Can substitue both bytes and int uint64', async () => {
const testTeal = `
int TMPL_SOME_VALUE
pushint TMPL_SOME_VALUE
bytes TMPL_SOME_VALUE
pushbytes TMPL_SOME_VALUE
return
`
const testParams = {
SOME_VALUE: 123,
}
const substituted = AppManager.replaceTealTemplateParams(testTeal, testParams)
expect(substituted).toBe(`
int 123
pushint 123
bytes 0x000000000000007b
pushbytes 0x000000000000007b
return
`)
})
test('Does not substitute template variables in comments or when quoted', async () => {
const testTeal = `
test TMPL_INT // TMPL_INT
test TMPL_INT
no change
test TMPL_STR // TMPL_STR
TMPL_STR
TMPL_STR // TMPL_INT
TMPL_STR // foo //
TMPL_STR // bar
test "TMPL_STR" // not replaced
test "TMPL_STRING" // not replaced
test TMPL_STRING // not replaced
test TMPL_STRI // not replaced
test TMPL_STR TMPL_INT TMPL_INT TMPL_STR // TMPL_STR TMPL_INT TMPL_INT TMPL_STR
test TMPL_INT TMPL_STR TMPL_STRING "TMPL_INT TMPL_STR TMPL_STRING" //TMPL_INT TMPL_STR TMPL_STRING
test TMPL_INT TMPL_INT TMPL_STRING TMPL_STRING TMPL_STRING TMPL_INT TMPL_STRING //keep
TMPL_STR TMPL_STR TMPL_STR
TMPL_STRING
test NOTTMPL_STR // not replaced
NOTTMPL_STR // not replaced
TMPL_STR // replaced
`
const testParams = {
INT: 123,
STR: 'ABC',
}
const substituted = AppManager.replaceTealTemplateParams(testTeal, testParams)
expect(substituted).toBe(`
test 123 // TMPL_INT
test 123
no change
test 0x414243 // TMPL_STR
0x414243
0x414243 // TMPL_INT
0x414243 // foo //
0x414243 // bar
test "TMPL_STR" // not replaced
test "TMPL_STRING" // not replaced
test TMPL_STRING // not replaced
test TMPL_STRI // not replaced
test 0x414243 123 123 0x414243 // TMPL_STR TMPL_INT TMPL_INT TMPL_STR
test 123 0x414243 TMPL_STRING "TMPL_INT TMPL_STR TMPL_STRING" //TMPL_INT TMPL_STR TMPL_STRING
test 123 123 TMPL_STRING TMPL_STRING TMPL_STRING 123 TMPL_STRING //keep
0x414243 0x414243 0x414243
TMPL_STRING
test NOTTMPL_STR // not replaced
NOTTMPL_STR // not replaced
0x414243 // replaced
`)
})
function getMetadata(overrides?: Partial<AppDeployMetadata>): AppDeployMetadata {
return {
name: 'test',
version: '1.0',
updatable: false,
deletable: false,
...(overrides ?? {}),
}
}