diff --git a/sui/deploy-contract.js b/sui/deploy-contract.js index bb9da4e1..9aa99b58 100644 --- a/sui/deploy-contract.js +++ b/sui/deploy-contract.js @@ -27,6 +27,7 @@ const { getSingletonChannelId, getItsChannelId, getSquidChannelId, + checkSuiVersionMatch, } = require('./utils'); /** @@ -246,6 +247,9 @@ async function postDeploySquid(published, keypair, client, config, chain, option async function deploy(keypair, client, supportedContract, config, chain, options) { const { packageDir, packageName } = supportedContract; + // Print warning if version mismatch from defined version in version.json + checkSuiVersionMatch(); + // Deploy package const published = await deployPackage(packageDir, client, keypair, options); diff --git a/sui/utils/utils.js b/sui/utils/utils.js index 46753402..7d083767 100644 --- a/sui/utils/utils.js +++ b/sui/utils/utils.js @@ -2,7 +2,8 @@ const { ethers } = require('hardhat'); const toml = require('toml'); -const { printInfo, printError } = require('../../common/utils'); +const { execSync } = require('child_process'); +const { printInfo, printError, printWarn } = require('../../common/utils'); const { BigNumber, utils: { arrayify, hexlify, toUtf8Bytes, keccak256 }, @@ -73,6 +74,33 @@ const findPublishedObject = (published, packageDir, contractName) => { return published.publishTxn.objectChanges.find((change) => change.objectType === `${packageId}::${packageDir}::${contractName}`); }; +const getInstalledSuiVersion = () => { + const suiVersion = execSync('sui --version').toString().trim(); + return parseVersion(suiVersion); +}; + +const getDefinedSuiVersion = () => { + const version = fs.readFileSync(`${__dirname}/../version.json`, 'utf8'); + const suiVersion = JSON.parse(version).SUI_VERSION; + return parseVersion(suiVersion); +}; + +const parseVersion = (version) => { + const versionMatch = version.match(/\d+\.\d+\.\d+/); + return versionMatch[0]; +}; + +const checkSuiVersionMatch = () => { + const installedVersion = getInstalledSuiVersion(); + const definedVersion = getDefinedSuiVersion(); + + if (installedVersion !== definedVersion) { + printWarn('Version mismatch detected:'); + printWarn(`- Installed SUI version: ${installedVersion}`); + printWarn(`- Version used for tests: ${definedVersion}`); + } +}; + const readMovePackageName = (moveDir) => { try { const moveToml = fs.readFileSync( @@ -220,6 +248,7 @@ module.exports = { paginateAll, suiPackageAddress, suiClockAddress, + checkSuiVersionMatch, findOwnedObjectId, getBcsBytesByObjectId, deployPackage,