Skip to content

Commit 83d28a8

Browse files
INT-406: fix move CLI version checks (LayerZero-Labs#1593)
Co-authored-by: alexanderliteplo <alexanderliteplo@gmail.com>
1 parent e015fa4 commit 83d28a8

4 files changed

Lines changed: 84 additions & 8 deletions

File tree

.changeset/wet-colts-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@layerzerolabs/devtools-move": patch
3+
---
4+
5+
fix move CLI version checks
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { expect } from 'chai'
2+
import { isVersionGreaterOrEqualTo, isVersionLessThanOrEqualTo } from '../tasks/move/utils/config'
3+
4+
describe('tasks/move/utils/config', () => {
5+
describe('isVersionGreaterOrEqualTo', () => {
6+
it('works', () => {
7+
expect(isVersionGreaterOrEqualTo('6.0.1', '6.0.1')).to.equal(true)
8+
expect(isVersionGreaterOrEqualTo('6.0.1', '6.0.0')).to.equal(true)
9+
expect(isVersionGreaterOrEqualTo('6.0.1', '5.0.0')).to.equal(true)
10+
expect(isVersionGreaterOrEqualTo('7.5.0', '6.0.1')).to.equal(true)
11+
expect(isVersionGreaterOrEqualTo('6.0.1', '7.0.0')).to.equal(false)
12+
expect(isVersionGreaterOrEqualTo('5.0.0', '6.0.1')).to.equal(false)
13+
expect(isVersionGreaterOrEqualTo('5.0.0', '7.0.0')).to.equal(false)
14+
expect(isVersionGreaterOrEqualTo('7.0.0', '6.0.1')).to.equal(true)
15+
expect(isVersionGreaterOrEqualTo('7.0.0', '5.0.0')).to.equal(true)
16+
expect(isVersionGreaterOrEqualTo('7.0.0', '7.0.0')).to.equal(true)
17+
expect(isVersionGreaterOrEqualTo('7.0.0', '8.0.0')).to.equal(false)
18+
})
19+
})
20+
21+
describe('isVersionLessThanOrEqualTo', () => {
22+
it('works', () => {
23+
expect(isVersionLessThanOrEqualTo('6.0.1', '6.0.1')).to.equal(true)
24+
expect(isVersionLessThanOrEqualTo('6.0.1', '6.0.0')).to.equal(false)
25+
expect(isVersionLessThanOrEqualTo('6.0.1', '5.0.0')).to.equal(false)
26+
expect(isVersionLessThanOrEqualTo('7.5.0', '6.0.1')).to.equal(false)
27+
expect(isVersionLessThanOrEqualTo('6.0.1', '7.0.0')).to.equal(true)
28+
expect(isVersionLessThanOrEqualTo('5.0.0', '6.0.1')).to.equal(true)
29+
expect(isVersionLessThanOrEqualTo('5.0.0', '7.0.0')).to.equal(true)
30+
expect(isVersionLessThanOrEqualTo('7.0.0', '6.0.1')).to.equal(false)
31+
expect(isVersionLessThanOrEqualTo('7.0.0', '5.0.0')).to.equal(false)
32+
expect(isVersionLessThanOrEqualTo('7.0.0', '7.0.0')).to.equal(true)
33+
expect(isVersionLessThanOrEqualTo('7.0.0', '8.0.0')).to.equal(true)
34+
})
35+
})
36+
})

packages/devtools-move/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"clean": "rm -rf dist",
3131
"dev": "$npm_execpath tsup --watch",
3232
"lint": "$npm_execpath eslint '**/*.{js,ts,json}'",
33-
"lint:fix": "eslint --fix '**/*.{js,ts,json}'"
33+
"lint:fix": "eslint --fix '**/*.{js,ts,json}'",
34+
"test": "INITIA_CHAIN_ID=\"initiation-2\" jest"
3435
},
3536
"dependencies": {
3637
"@types/chai": "^4.3.11",

packages/devtools-move/tasks/move/utils/config.ts

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,23 +314,51 @@ async function getInitiaVersion(): Promise<string> {
314314
})
315315
}
316316

317+
async function promptVersionWarningConfirmation(): Promise<void> {
318+
const { shouldContinue } = await inquirer.prompt([
319+
{
320+
type: 'confirm',
321+
name: 'shouldContinue',
322+
message: 'Are you sure you want to continue?',
323+
default: false,
324+
},
325+
])
326+
327+
if (!shouldContinue) {
328+
console.log('❌ Operation cancelled.')
329+
process.exit(1)
330+
}
331+
}
332+
317333
export async function getAptosCLICommand(chain: string, stage: string): Promise<string> {
318334
const aptosCommand = 'aptos'
319335
const version = await getAptosVersion(aptosCommand)
320336
if (chain === 'aptos') {
321337
console.log('Aptos chain detected')
322338
const MIN_VERSION = '6.0.1'
323339

324-
if (greaterThanOrEqualTo(version, MIN_VERSION)) {
340+
if (isVersionGreaterOrEqualTo(version, MIN_VERSION)) {
325341
console.log(`🚀 Aptos CLI version ${version} is compatible.`)
342+
if (version !== MIN_VERSION) {
343+
console.log(
344+
`\x1b[33m⚠️ Warning: You are deploying to Aptos chain but your Aptos CLI version is set to "${version}".\n\n\tOur recommended and tested version is ${MIN_VERSION}. Using other versions is at your own risk and may result in unexpected behavior.\x1b[0m`
345+
)
346+
await promptVersionWarningConfirmation()
347+
}
326348
} else {
327349
throw new Error(`❌ Aptos CLI version too old. Required: ${MIN_VERSION} or newer, Found: ${version}`)
328350
}
329351
} else if (chain === 'movement') {
330352
const MAX_VERSION = '3.5.0'
331353

332-
if (lessThanOrEqualTo(version, MAX_VERSION)) {
354+
if (isVersionLessThanOrEqualTo(version, MAX_VERSION)) {
333355
console.log(`🚀 Aptos CLI version ${version} is compatible.`)
356+
if (version !== '3.5.0') {
357+
console.log(
358+
`\x1b[33m⚠️ Warning: You are deploying to Movement chain but your Aptos CLI version is set to "${version}".\n\n\tOur recommended and tested version is 3.5.0. Using other versions is at your own risk and may result in unexpected behavior.\x1b[0m`
359+
)
360+
await promptVersionWarningConfirmation()
361+
}
334362
} else {
335363
throw new Error(`❌ Aptos CLI version too new. Required: ${MAX_VERSION} or older, Found: ${version}`)
336364
}
@@ -351,28 +379,34 @@ export async function checkInitiaCLIVersion(): Promise<void> {
351379
}
352380
}
353381

354-
function greaterThanOrEqualTo(installed: string, required: string): boolean {
382+
export function isVersionGreaterOrEqualTo(installed: string, required: string): boolean {
355383
const installedParts = installed.split('.').map(Number)
356384
const requiredParts = required.split('.').map(Number)
357385

358386
for (let i = 0; i < 3; i++) {
359-
if (installedParts[i] < requiredParts[i]) {
387+
if (installedParts[i] > requiredParts[i]) {
388+
return true
389+
} else if (installedParts[i] < requiredParts[i]) {
360390
return false
361391
}
362392
}
363-
// all parts are greater than or equal to the required version
393+
394+
// all parts are equal to the required version
364395
return true
365396
}
366397

367-
function lessThanOrEqualTo(installed: string, required: string): boolean {
398+
export function isVersionLessThanOrEqualTo(installed: string, required: string): boolean {
368399
const installedParts = installed.split('.').map(Number)
369400
const requiredParts = required.split('.').map(Number)
370401

371402
for (let i = 0; i < 3; i++) {
372403
if (installedParts[i] > requiredParts[i]) {
373404
return false
405+
} else if (installedParts[i] < requiredParts[i]) {
406+
return true
374407
}
375408
}
376-
// all parts are less than or equal to the required version
409+
410+
// all parts are equal to the required version
377411
return true
378412
}

0 commit comments

Comments
 (0)