Skip to content

Commit

Permalink
add the util
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Jul 15, 2024
1 parent 2dc62d0 commit 3373514
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ target/
*.pdb

# dist and move_compile
dist
move_comile
move_compile
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export function updateMoveToml(packageName: string, packageId: string, moveDir:
fs.writeFileSync(path, toml);
}

export function copyMovePackage(packageName: string, fromDir: null | string, toDir: string) {
if(fromDir == null) {
fromDir = `${__dirname}/../move`
}

fs.cpSync(`${fromDir}/${packageName}`,`${toDir}/${packageName}`, {recursive: true});
}

export function parseEnv(arg: string) {
switch (arg?.toLowerCase()) {
case 'localnet':
Expand Down
8 changes: 5 additions & 3 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const { keccak256, defaultAbiCoder } = require('ethers/lib/utils');
const { TxBuilder } = require('../dist/tx-builder');
const { updateMoveToml } = require('../dist/utils');
const { updateMoveToml, copyMovePackage } = require('../dist/utils');
const chai = require('chai');
const { expect } = chai;

async function publishPackage(client, keypair, packageName) {
const compileDir = `${__dirname}/../move_compile`;
copyMovePackage(packageName, null, compileDir);
const builder = new TxBuilder(client);
await builder.publishPackageAndTransferCap(packageName, keypair.toSuiAddress());
await builder.publishPackageAndTransferCap(packageName, keypair.toSuiAddress(), compileDir);
const publishTxn = await builder.signAndExecute(keypair);

const packageId = (publishTxn.objectChanges?.find((a) => a.type === 'published') ?? []).packageId;

updateMoveToml(packageName, packageId);
updateMoveToml(packageName, packageId, compileDir);
return { packageId, publishTxn };
}

Expand Down

0 comments on commit 3373514

Please sign in to comment.