Skip to content

Commit

Permalink
chore: print version mismatch message when deploy a contract
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Aug 27, 2024
1 parent 0f49900 commit 4efc586
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
getSingletonChannelId,
getItsChannelId,
getSquidChannelId,
checkSuiVersionMatch,
} = require('./utils');

/**
Expand Down Expand Up @@ -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);

Expand Down
31 changes: 30 additions & 1 deletion sui/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -220,6 +248,7 @@ module.exports = {
paginateAll,
suiPackageAddress,
suiClockAddress,
checkSuiVersionMatch,
findOwnedObjectId,
getBcsBytesByObjectId,
deployPackage,
Expand Down

0 comments on commit 4efc586

Please sign in to comment.