diff --git a/package.json b/package.json index 7dac40f8..e18a409f 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ }, "main": "index.js", "scripts": { - "build": "for d in ./move/*/; do cd $d; sui move build --lint --warnings-are-errors & cd ../../; done; wait", - "test": "for d in ./move/*/; do sui move test --path $d ; done", + "build": "./scripts/run.sh build", + "test": "./scripts/run.sh test", "coverage": "./scripts/coverage.sh", "lint": "eslint --fix './scripts/*.js'", "prettier": "prettier --write './scripts/*.js'" diff --git a/scripts/coverage.sh b/scripts/coverage.sh index 5ddf3d2f..1b437ab1 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -19,30 +19,30 @@ if ! which "$SUI" >/dev/null 2>&1; then fi fi -for d in ./move/*/; do - "$SUI" move test --path "$d" --coverage & +for module in ./move/*/; do + "$SUI" move test --path "$module" --coverage & done wait found=0 -for d in ./move/*/; do - echo "Generating coverage info for package $d" +for module in ./move/*/; do + echo "Generating coverage info for package ${module}" - if [ ! -f "$d/.coverage_map.mvcov" ]; then - echo "\n NO tests found for module $d. Skipped.\n" >> .coverage.info - echo "\n NO tests found for module $d. Skipped.\n" >> .coverage.extended.info + if [ ! -f "${module}/.coverage_map.mvcov" ]; then + echo "\n NO tests found for module ${module}. Skipped.\n" >> .coverage.info + echo "\n NO tests found for module ${module}. Skipped.\n" >> .coverage.extended.info continue fi found=1 - echo "Coverage report for module $d\n" >> .coverage.info - echo "Coverage report for module $d\n" >> .coverage.extended.info + echo "Coverage report for module ${module}\n" >> .coverage.info + echo "Coverage report for module ${module}\n" >> .coverage.extended.info - "$SUI" move coverage summary --path "$d" >> .coverage.info - "$SUI" move coverage summary --summarize-functions --path "$d" >> .coverage.extended.info + "$SUI" move coverage summary --path "${module}" >> .coverage.info + "$SUI" move coverage summary --summarize-functions --path "${module}" >> .coverage.extended.info echo "" >> .coverage.info echo "" >> .coverage.extended.info diff --git a/scripts/gateway.js b/scripts/gateway.js index 6b518213..ae54fd74 100644 --- a/scripts/gateway.js +++ b/scripts/gateway.js @@ -85,7 +85,7 @@ function getRandomOperators(n = 5) { for (let i = 0; i < pubKeyLength; i++) { const aByte = pubKeys[a][i]; const bByte = pubKeys[b][i]; - if (aByte != bByte) return aByte - bByte; + if (aByte !== bByte) return aByte - bByte; } return 0; @@ -198,7 +198,7 @@ async function approveContractCall(client, keypair, axelarInfo, sourceChain, sou arguments: [tx.object(validators.objectId), tx.pure(String.fromCharCode(...input))], typeArguments: [], }); - const approveTxn = await client.signAndExecuteTransactionBlock({ + await client.signAndExecuteTransactionBlock({ transactionBlock: tx, signer: keypair, options: { diff --git a/scripts/governance.js b/scripts/governance.js index 05843a61..f52c162d 100644 --- a/scripts/governance.js +++ b/scripts/governance.js @@ -38,7 +38,7 @@ async function initializeGovernance(upgradeCap, client, keypair, env) { async function takeUpgradeCaps(upgradeCaps, client, keypair, env) { const governanceConfig = getConfig('governance', env.alias); const packageId = governanceConfig.packageId; - tx = new TransactionBlock(); + const tx = new TransactionBlock(); for (const upgradeCap of upgradeCaps) { tx.moveCall({ diff --git a/scripts/publish-all.js b/scripts/publish-all.js index 436ad74f..1dcc047f 100644 --- a/scripts/publish-all.js +++ b/scripts/publish-all.js @@ -17,7 +17,7 @@ async function publishAll(client, keypair, env) { while (true) try { const { packageId, publishTxn } = await publishPackageFull(packagePath, client, keypair, env); - upgradeCaps[packagePath] = publishTxn.objectChanges.find((obj) => obj.objectType == '0x2::package::UpgradeCap'); + upgradeCaps[packagePath] = publishTxn.objectChanges.find((obj) => obj.objectType === '0x2::package::UpgradeCap'); packageIds[packagePath] = packageId; break; } catch (e) { diff --git a/scripts/publish-package.js b/scripts/publish-package.js index 76278869..78a3210c 100644 --- a/scripts/publish-package.js +++ b/scripts/publish-package.js @@ -7,6 +7,7 @@ const { execSync } = require('child_process'); const { parseEnv } = require('./utils'); const tmp = require('tmp'); const fs = require('fs'); +const path = require('path'); async function publishPackage(packageName, client, keypair) { const toml = fs.readFileSync(`${__dirname}/../move/${packageName}/Move.toml`, 'utf8'); @@ -19,10 +20,15 @@ async function publishPackage(packageName, client, keypair) { const tmpobj = tmp.dirSync({ unsafeCleanup: true }); const { modules, dependencies } = JSON.parse( - execSync(`sui move build --dump-bytecode-as-base64 --path ${__dirname + '/../move/' + packageName} --install-dir ${tmpobj.name}`, { - encoding: 'utf-8', - stdio: 'pipe', // silent the output - }), + execSync( + `sui move build --dump-bytecode-as-base64 --path ${path.join(__dirname, '/../move/', packageName)} --install-dir ${ + tmpobj.name + }`, + { + encoding: 'utf-8', + stdio: 'pipe', // silent the output + }, + ), ); const tx = new TransactionBlock(); @@ -44,7 +50,7 @@ async function publishPackage(packageName, client, keypair) { }, requestType: 'WaitForLocalExecution', }); - if (publishTxn.effects?.status.status != 'success') throw new Error('Publish Tx failed'); + if (publishTxn.effects?.status.status !== 'success') throw new Error('Publish Tx failed'); const packageId = (publishTxn.objectChanges?.filter((a) => a.type === 'published') ?? [])[0].packageId; diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 00000000..f07aefcb --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [[ ${#} -ne 1 || ( "$1" != "build" && "$1" != "test" ) ]]; then + echo "Usage: $0 [build|test]" + exit 1 +fi + +exit_code=0 + +for module in ./move/*/; do + if ! sui move build --lint --warnings-are-errors --path "$module"; then + exit_code=1 + fi +done + +if [ $exit_code -ne 0 ]; then + echo "" + echo -e "\033[0;31mBuild failed\033[0m" + exit 1 +fi diff --git a/scripts/test-receive-call.js b/scripts/test-receive-call.js index 7ea2125a..c805c583 100644 --- a/scripts/test-receive-call.js +++ b/scripts/test-receive-call.js @@ -1,6 +1,6 @@ require('dotenv').config(); -const { BcsReader, BCS, fromHEX, getSuiMoveConfig, bcs: bcsEncoder } = require('@mysten/bcs'); +const { BCS, getSuiMoveConfig, bcs: bcsEncoder } = require('@mysten/bcs'); const { utils: { keccak256, arrayify, hexlify }, } = require('ethers'); @@ -39,9 +39,9 @@ async function receiveCall(client, keypair, axelarInfo, sourceChain, sourceAddre type_arguments: [], }, ]; - let is_final = false; + let isFinal = false; - while (!is_final) { + while (!isFinal) { const tx = new TransactionBlock(); makeCalls(tx, moveCalls, payload); const resp = await client.devInspectTransactionBlock({ @@ -51,7 +51,7 @@ async function receiveCall(client, keypair, axelarInfo, sourceChain, sourceAddre const txData = resp.results[0].returnValues[0][0]; const nextTx = getTransactionBcs().de('Transaction', new Uint8Array(txData)); - is_final = nextTx.is_final; + isFinal = nextTx.isFinal; moveCalls = nextTx.move_calls; } @@ -105,7 +105,7 @@ function getTransactionBcs() { type_arguments: 'vector', }); bcs.registerStructType('Transaction', { - is_final: 'bool', + isFinal: 'bool', move_calls: 'vector', }); return bcs; @@ -185,6 +185,6 @@ if (require.main === module) { }) ).data[0].parsedJson; - if (hexlify(event.data) != payload) throw new Error(`Emmited payload missmatch: ${hexlify(event.data)} != ${payload}`); + if (hexlify(event.data) !== payload) throw new Error(`Emmited payload missmatch: ${hexlify(event.data)} != ${payload}`); })(); } diff --git a/scripts/test-send-call.js b/scripts/test-send-call.js index 005abc78..46849a35 100644 --- a/scripts/test-send-call.js +++ b/scripts/test-send-call.js @@ -1,6 +1,6 @@ require('dotenv').config(); -const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client'); +const { SuiClient } = require('@mysten/sui.js/client'); const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519'); const { TransactionBlock } = require('@mysten/sui.js/transactions'); @@ -55,5 +55,6 @@ const { toPure, parseEnv } = require('./utils'); ).data[0].parsedJson; console.log(event); - if (hexlify(event.source_id) != test.channel) throw new Error(`Emmited payload missmatch: ${hexlify(event.source)} != ${test.channel}`); + if (hexlify(event.source_id) !== test.channel) + throw new Error(`Emmited payload missmatch: ${hexlify(event.source)} != ${test.channel}`); })(); diff --git a/scripts/test-transfer-operatorship.js b/scripts/test-transfer-operatorship.js index 96a82a34..31773801 100644 --- a/scripts/test-transfer-operatorship.js +++ b/scripts/test-transfer-operatorship.js @@ -3,7 +3,6 @@ const { transferOperatorship, getRandomOperators } = require('./gateway'); const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519'); const { SuiClient } = require('@mysten/sui.js/client'); const { parseEnv } = require('./utils'); -const secp256k1 = require('secp256k1'); const fs = require('fs'); (async () => { diff --git a/scripts/utils.js b/scripts/utils.js index 6e4882d1..b722b17b 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -37,7 +37,7 @@ function getModuleNameFromSymbol(symbol) { moduleName += char; } else if (isUppercase(char)) { moduleName += char.toLowerCase(); - } else if (char == '_' || char == ' ') { + } else if (char === '_' || char === ' ') { moduleName += '_'; } @@ -84,7 +84,7 @@ function setConfig(packagePath, envAlias, config) { async function requestSuiFromFaucet(env, address) { try { - const resp = await requestSuiFromFaucetV0({ + await requestSuiFromFaucetV0({ // use getFaucetHost to make sure you're using correct faucet address // you can also just use the address (see Sui Typescript SDK Quick Start for values) host: getFaucetHost(env.alias),