Skip to content

Commit 2597208

Browse files
authored
Merge pull request #456 from algorandfoundation/fix/deploy-use-extra-pages
fix: use extra pages available when deploying
2 parents 6cbac4d + 5db3e83 commit 2597208

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/types/app-deployer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export class AppDeployer {
364364
const existingAppRecord = await this._appManager.getById(existingApp.appId)
365365
const existingApproval = Buffer.from(existingAppRecord.approvalProgram).toString('base64')
366366
const existingClear = Buffer.from(existingAppRecord.clearStateProgram).toString('base64')
367-
const existingExtraPages = calculateExtraProgramPages(existingAppRecord.approvalProgram, existingAppRecord.clearStateProgram)
367+
const extraPages = existingAppRecord.extraProgramPages ?? 0
368368

369369
const newApprovalBytes = Buffer.from(approvalProgram)
370370
const newClearBytes = Buffer.from(clearStateProgram)
@@ -380,7 +380,7 @@ export class AppDeployer {
380380
existingAppRecord.globalInts < (createParams.schema?.globalInts ?? 0) ||
381381
existingAppRecord.localByteSlices < (createParams.schema?.localByteSlices ?? 0) ||
382382
existingAppRecord.globalByteSlices < (createParams.schema?.globalByteSlices ?? 0) ||
383-
existingExtraPages < newExtraPages
383+
extraPages < newExtraPages
384384

385385
if (isSchemaBreak) {
386386
Config.getLogger(sendParams?.suppressLog).warn(`Detected a breaking app schema change in app ${existingApp.appId}:`, {
@@ -389,7 +389,7 @@ export class AppDeployer {
389389
globalByteSlices: existingAppRecord.globalByteSlices,
390390
localInts: existingAppRecord.localInts,
391391
localByteSlices: existingAppRecord.localByteSlices,
392-
extraProgramPages: existingExtraPages,
392+
extraProgramPages: extraPages,
393393
},
394394
to: { ...createParams.schema, extraProgramPages: newExtraPages },
395395
})

src/types/app-factory-and-client.spec.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('ARC32: app-factory-and-app-client', () => {
192192
expect(app.return).toBe('arg_io')
193193
})
194194

195-
test('Deploy app - update detects extra pages as breaking change', async () => {
195+
test('Deploy app - update detects extra page deficit as a breaking change', async () => {
196196
let appFactory = localnet.algorand.client.getAppFactory({
197197
appSpec: asJson(smallAppArc56Json),
198198
defaultSender: localnet.context.testAccount,
@@ -232,6 +232,37 @@ describe('ARC32: app-factory-and-app-client', () => {
232232
expect(appCreateResult.appId).not.toEqual(appAppendResult.appId)
233233
})
234234

235+
test('Deploy app - update detects extra page surplus as a non breaking change', async () => {
236+
let appFactory = localnet.algorand.client.getAppFactory({
237+
appSpec: asJson(smallAppArc56Json),
238+
defaultSender: localnet.context.testAccount,
239+
})
240+
241+
const { result: appCreateResult } = await appFactory.deploy({
242+
updatable: true,
243+
createParams: {
244+
extraProgramPages: 1,
245+
},
246+
})
247+
248+
expect(appCreateResult.operationPerformed).toBe('create')
249+
250+
// Update the app to a larger program which needs more pages than the previous program
251+
appFactory = localnet.algorand.client.getAppFactory({
252+
appSpec: asJson(largeAppArc56Json),
253+
defaultSender: localnet.context.testAccount,
254+
})
255+
256+
const { result: appUpdateResult } = await appFactory.deploy({
257+
updatable: true,
258+
onSchemaBreak: OnSchemaBreak.Fail,
259+
onUpdate: OnUpdate.UpdateApp,
260+
})
261+
262+
expect(appUpdateResult.operationPerformed).toBe('update')
263+
expect(appCreateResult.appId).toEqual(appUpdateResult.appId)
264+
})
265+
235266
test('Deploy app - replace', async () => {
236267
const { result: createdApp } = await factory.deploy({
237268
deployTimeParams: {

0 commit comments

Comments
 (0)