diff --git a/.gitignore b/.gitignore index 9f1c05d..a3c5beb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,108 +1,12 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - # Dependency directories node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm -# Optional eslint cache -.eslintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ +# node-waf configuration +.lock-wscript # Optional REPL history .node_repl_history -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and *not* Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - # IDEs .vscode/ .idea/ @@ -110,4 +14,6 @@ dist # MacOS .DS_Store -build/ \ No newline at end of file +dist/ +build/ +doc/ \ No newline at end of file diff --git a/README.md b/README.md index 2e2bcae..99b720d 100644 --- a/README.md +++ b/README.md @@ -78,4 +78,50 @@ async function readExample() { const decodedModule = await MoveBuilder.decode_module_bytes(binary); console.log(decodedModule) } +``` + +## Options + +For more details on the available options, refer to the [source code](src/types/options.ts). + +### BuildOptions +The `BuildOptions` interface provides various options to customize the build process. + +```ts +export interface BuildOptions { + devMode?: boolean + testMode?: boolean + generateDocs?: boolean + generateAbis?: boolean + installDir?: string + forceRecompilation?: boolean + fetchDepsOnly?: boolean + skipFetchLatestGitDeps?: boolean + bytecodeVersion?: number + compilerVersion?: string + languageVersion?: string + addtionalNamedAddresses?: [string, string][] +} +``` + +### CleanOptions +The `CleanOptions` interface provides options to clean the build artifacts. + +```ts +export interface CleanOptions { + cleanCache?: boolean + cleanByProduct?: boolean +} +``` + +### TestOptions +The `TestOptions` interface provides options to customize the testing process. + +```ts +export interface TestOptions { + filter?: string + reportStatistics?: boolean + reportStorageOnError?: boolean + ignoreCompileWarnings?: boolean +} ``` \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index d401c28..54d549e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,4 +2,9 @@ module.exports = { testEnvironment: 'node', preset: 'ts-jest', roots: ['/test'], + moduleNameMapper: { + '^builder': '/src/builder.ts', + '^types$': '/src/types', + '^lib$': '/src/lib', + } } diff --git a/package.json b/package.json index 6c97196..8f87c44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@initia/builder.js", - "version": "0.2.3", + "version": "0.2.4", "description": "The JavaScript Move Builder for Initia", "license": "MIT", "author": "Initia Foundation", @@ -20,7 +20,7 @@ "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ - "dist", + "dist/src", "library" ], "engines": { diff --git a/src/build.ts b/src/builder.ts similarity index 81% rename from src/build.ts rename to src/builder.ts index b1462d6..7b1c3c7 100644 --- a/src/build.ts +++ b/src/builder.ts @@ -2,32 +2,36 @@ import ref from '@eleccookie/ref-napi' import path = require('path') import { readFile } from 'fs/promises' +import { handleResponse, createRawErrMsg, libcompiler, libmovevm } from 'lib' import { ByteSliceViewType, - BuildOptions, - TestOptions, FFIResult, + BuildOptions, CleanOptions, -} from './types' -import { libcompiler, libmovevm } from './vm' -import { handleResponse, createRawErrMsg } from './utils' -import { compilerPayloadBcsType, testOptBcsType } from './types/bcs' + compilerPayloadBcsType, + testOptBcsType, + TestOptions, +} from 'types' export class MoveBuilder { private readonly packagePath: string private buildOptions: BuildOptions /** - * - * @param packagePath full path to package directory - * @param buildOptions move package build options + * Create a MoveBuilder. + * @param packagePath - Full path to package directory. + * @param buildOptions - Move package build options. */ constructor(packagePath: string, buildOptions: BuildOptions) { this.packagePath = packagePath this.buildOptions = buildOptions } - makeRawBuildConfig = () => { + /** + * Create raw build configuration. + * @returns Raw build configuration. + */ + private makeRawBuildConfig = () => { const additionalNamedAddresses: [string, Uint8Array][] = this.buildOptions .addtionalNamedAddresses ? this.buildOptions.addtionalNamedAddresses.map(([name, address]) => { @@ -37,6 +41,7 @@ export class MoveBuilder { return [name, Buffer.from(address, 'hex')] }) : [] + const compilerPayloadBytes = Buffer.from( compilerPayloadBcsType .serialize({ @@ -60,6 +65,7 @@ export class MoveBuilder { }) .toBytes() ) + const compilerPayload = ref.alloc(ByteSliceViewType) const rawCompilerPayload = compilerPayload.deref() rawCompilerPayload.is_nil = false @@ -68,14 +74,16 @@ export class MoveBuilder { compilerPayloadBytes.toString(), 'utf-8' ) + return rawCompilerPayload } /** - * - * Execute move compiler to generate new move package - * - * @returns if success return "ok", else throw an error + * Execute move compiler to generate new move package. + * @param packageName - Name of the package. + * @param moveVersion - Version of the move (default is 'main'). + * @param minitia - Boolean flag for minitia (default is false). + * @returns If success, return "ok", else throw an error. */ public new( packageName: string, @@ -98,6 +106,7 @@ export class MoveBuilder { ? ref.allocCString(moveVersion) : ref.NULL rawMoveVersionView.len = Buffer.from(moveVersion, 'utf-8').length + return handleResponse( libcompiler.create_new_move_package.async, errMsg, @@ -109,10 +118,9 @@ export class MoveBuilder { } /** - * - * Execute move compiler to clean move package - * - * @returns if success return "ok", else throw an error + * Execute move compiler to clean move package. + * @param options - Options for cleaning the package. + * @returns If success, return "ok", else throw an error. */ public async clean(options?: CleanOptions): Promise { const errMsg = createRawErrMsg() @@ -124,15 +132,13 @@ export class MoveBuilder { rawCompilerArgsPayload, options?.cleanCache || false, options?.cleanByProduct || false, - options?.force === undefined ? true : options?.force + true ) } /** - * - * Execute move compiler to generate move bytecode - * - * @returns if success return "ok", else throw an error + * Execute move compiler to generate move bytecode. + * @returns If success, return "ok", else throw an error. */ public async build(): Promise { const errMsg = createRawErrMsg() @@ -146,11 +152,9 @@ export class MoveBuilder { } /** - * * Return compiled Move module bytecode. - * - * @param moduleName the module name to retrieve - * @returns the module bytecode + * @param moduleName - The module name to retrieve. + * @returns The module bytecode. */ public async get(moduleName: string): Promise { const moveTomlPath = path.join(this.packagePath, 'Move.toml') @@ -180,12 +184,9 @@ export class MoveBuilder { } /** - * - * Execute move compiler to unittest - * - * @param options move package test options - * - * @returns if success return "ok", else throw an error + * Execute move compiler to unittest. + * @param options - Move package test options. + * @returns If success, return "ok", else throw an error. */ public async test(options?: TestOptions): Promise { const errMsg = createRawErrMsg() @@ -197,7 +198,7 @@ export class MoveBuilder { report_statistics: options?.reportStatistics || false, report_storage_on_error: options?.reportStorageOnError || false, ignore_compile_warnings: options?.ignoreCompileWarnings || false, - compute_coverage: options?.computeCoverage || false, + compute_coverage: false, }) .toBytes() ) @@ -206,6 +207,7 @@ export class MoveBuilder { rawTestOpt.is_nil = false rawTestOpt.len = testOptBytes.length rawTestOpt.ptr = ref.allocCString(testOptBytes.toString(), 'utf-8') + return handleResponse( libcompiler.test_move_package.async, errMsg, @@ -215,12 +217,9 @@ export class MoveBuilder { } /** - * - * Decode module bytes to move module - * - * @param moduleBytes move module bytes - * - * @returns if success return buffer, else throw an error + * Decode module bytes to move module. + * @param moduleBytes - Move module bytes. + * @returns If success, return buffer, else throw an error. */ public static async decode_module_bytes( moduleBytes: Buffer @@ -244,12 +243,9 @@ export class MoveBuilder { } /** - * - * Decode script bytes to move function - * - * @param scriptBytes move script bytes - * - * @returns if success return buffer, else throw an error + * Decode script bytes to move function. + * @param scriptBytes - Move script bytes. + * @returns If success, return buffer, else throw an error. */ public static async decode_script_bytes( scriptBytes: Buffer @@ -273,12 +269,9 @@ export class MoveBuilder { } /** - * - * Read module info from bytes - * - * @param compiledBinary move compiled bytes - * - * @returns if success return buffer, else throw an error + * Read module info from bytes. + * @param compiledBinary - Move compiled bytes. + * @returns If success, return buffer, else throw an error. */ public static async read_module_info( compiledBinary: Buffer diff --git a/src/index.ts b/src/index.ts index 9601e35..9973dbb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ -export * from './build' -export { FFIResult, BuildOptions, TestOptions } from './types/index' +export { FFIResult, BuildOptions, TestOptions } from 'types' +export * from './builder' diff --git a/src/lib/index.ts b/src/lib/index.ts new file mode 100644 index 0000000..9410b6f --- /dev/null +++ b/src/lib/index.ts @@ -0,0 +1,2 @@ +export * from './utils' +export * from './vm' diff --git a/src/utils.ts b/src/lib/utils.ts similarity index 82% rename from src/utils.ts rename to src/lib/utils.ts index 17ea9d7..ff98d6d 100644 --- a/src/utils.ts +++ b/src/lib/utils.ts @@ -1,24 +1,9 @@ import ref from '@eleccookie/ref-napi' -import struct from 'ref-struct-di' -import { UnmanagedVectorType, FFIResult } from './types' +import { UnmanagedVectorType, FFIResult, MethodType, ErrMsgStruct } from 'types' import { Buffer } from 'buffer' -// define the structure for ErrMsg and Result -type ErrMsgStruct = struct.StructObject<{ - is_none: boolean - ptr: ref.Pointer - len: number - cap: number -}> - -// Define MethodType as a function that accepts ErrMsg and arguments -type MethodType = ( - errMsg: ref.Pointer, - ...args: unknown[] -) => void - /** - * Handles the response from an FFI call. + * Handles the response from an FFI call from libmovevm shared library. * * @param method - The FFI method to invoke. * @param errMsg - A pointer to the ErrMsg structure for capturing errors. diff --git a/src/vm.ts b/src/lib/vm.ts similarity index 89% rename from src/vm.ts rename to src/lib/vm.ts index 522bb67..bb2882b 100644 --- a/src/vm.ts +++ b/src/lib/vm.ts @@ -5,9 +5,8 @@ import { UnmanagedVectorPtr, ByteSliceViewType, UnmanagedVectorType, -} from './types' +} from 'types' -// determine library file names based on platform and architecture let compilerName: string let movevmName: string @@ -28,9 +27,9 @@ if (process.platform == 'darwin') { throw new Error(`${process.platform}/${process.arch} not supported`) } -// load the libcompiler library and define its FFI function signatures +// Load the libcompiler library and define its FFI function signatures export const libcompiler = ffi.Library( - path.resolve(__dirname, `../library/${compilerName}`), + path.resolve(__dirname, `../../library/${compilerName}`), { create_new_move_package: [ UnmanagedVectorType, @@ -65,7 +64,7 @@ export const libcompiler = ffi.Library( // load the libmovevm library and define its FFI function signatures export const libmovevm = ffi.Library( - path.resolve(__dirname, `../library/${movevmName}`), + path.resolve(__dirname, `../../library/${movevmName}`), { read_module_info: [ UnmanagedVectorType, diff --git a/src/types/bcs.ts b/src/types/bcs.ts index bca5130..2562a8d 100644 --- a/src/types/bcs.ts +++ b/src/types/bcs.ts @@ -1,25 +1,6 @@ -import { bcs, BcsType } from '@mysten/bcs' - -interface CompilerBuildConfig { - [key: string]: BcsType - dev_mode: BcsType - test_mode: BcsType - generate_docs: BcsType - generate_abis: BcsType - install_dir: BcsType - force_recompilation: BcsType - fetch_deps_only: BcsType - skip_fetch_latest_git_deps: BcsType - bytecode_version: BcsType - compiler_version: BcsType - language_version: BcsType - additional_named_addresses: BcsType< - [string, Uint8Array][], - Iterable & { length: number } - > -} -// Build Config with BCS -const compilerBuildConfig: CompilerBuildConfig = { +import { bcs } from '@mysten/bcs' +// BCS Type for serializing CompilerBuildConfig +const compilerBuildConfig = { dev_mode: bcs.bool(), test_mode: bcs.bool(), generate_docs: bcs.bool(), @@ -36,12 +17,7 @@ const compilerBuildConfig: CompilerBuildConfig = { ), } -export const compilerPayloadBcsType = bcs.struct('CompilerArguments', { - package_path: bcs.option(bcs.string()), - verbose: bcs.bool(), - build_config: bcs.struct('BuildConfig', compilerBuildConfig), -}) - +// BCS Type for serializing CompilerBuildConfig const testOption = { filter: bcs.option(bcs.string()), report_statistics: bcs.bool(), @@ -50,4 +26,10 @@ const testOption = { compute_coverage: bcs.bool(), } +export const compilerPayloadBcsType = bcs.struct('CompilerArguments', { + package_path: bcs.option(bcs.string()), + verbose: bcs.bool(), + build_config: bcs.struct('BuildConfig', compilerBuildConfig), +}) + export const testOptBcsType = bcs.struct('TestOptions', testOption) diff --git a/src/types/ffi.ts b/src/types/ffi.ts new file mode 100644 index 0000000..69d5f83 --- /dev/null +++ b/src/types/ffi.ts @@ -0,0 +1,14 @@ +import struct from 'ref-struct-di' +import ref from '@eleccookie/ref-napi' + +export type ErrMsgStruct = struct.StructObject<{ + is_none: boolean + ptr: ref.Pointer + len: number + cap: number +}> + +export type MethodType = ( + errMsg: ref.Pointer, + ...args: unknown[] +) => void diff --git a/src/types/index.ts b/src/types/index.ts index 7dc13c5..2b55c32 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,5 +1,8 @@ -import ref from '@eleccookie/ref-napi' import struct from 'ref-struct-di' +import ref from '@eleccookie/ref-napi' +export * from './options' +export * from './bcs' +export * from './ffi' const StructType = struct(ref) @@ -20,32 +23,3 @@ export const ByteSliceViewType = StructType({ ptr: ref.refType(ref.types.CString), len: ref.types.size_t, }) - -export interface CleanOptions { - cleanCache?: boolean - cleanByProduct?: boolean - force?: boolean -} - -export interface BuildOptions { - devMode?: boolean - testMode?: boolean - generateDocs?: boolean - generateAbis?: boolean - installDir?: string - forceRecompilation?: boolean - fetchDepsOnly?: boolean - skipFetchLatestGitDeps?: boolean - bytecodeVersion?: number - compilerVersion?: string - languageVersion?: string - addtionalNamedAddresses?: [string, string][] -} - -export interface TestOptions { - filter?: string - reportStatistics?: boolean - reportStorageOnError?: boolean - ignoreCompileWarnings?: boolean - computeCoverage?: boolean -} diff --git a/src/types/options.ts b/src/types/options.ts new file mode 100644 index 0000000..b747a51 --- /dev/null +++ b/src/types/options.ts @@ -0,0 +1,99 @@ +export interface BuildOptions { + /** + * Compile in 'dev' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used if + * this flag is set. This flag is useful for development of packages that expose named + * addresses that are not set to a specific value.(default false) + */ + devMode?: boolean + + /** + * Compile in 'test' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used + * along with any code in the 'tests' directory.(default false) + */ + testMode?: boolean + + /** + * Generate documentation for packages.(default false) + */ + generateDocs?: boolean + + /** + * Generate ABIs for packages.(default false) + */ + generateAbis?: boolean + + /** + * Installation directory for compiled artifacts. Defaults to current directory. + */ + installDir?: string + + /** + * Force recompilation of all packages.(default false) + */ + forceRecompilation?: boolean + + /** + * Only fetch dependency repos to MOVE_HOME.(default false) + */ + fetchDepsOnly?: boolean + + /** + * Skip fetching latest git dependencies.(default false) + */ + skipFetchLatestGitDeps?: boolean + + /** + * Bytecode version. Set to 0 to unset and use default. + */ + bytecodeVersion?: number + + /** + * Compiler version. Set to 0 to unset and use default. + */ + compilerVersion?: string + + /** + * Language version. Set to 0 to unset and use default. + */ + languageVersion?: string + + /** + * Additional named address mapping. Useful for tools in Rust. + */ + addtionalNamedAddresses?: [string, string][] +} + +export interface CleanOptions { + /** + * Flush cache directory. (default false) + */ + cleanCache?: boolean + + /** + * Flush other byproducts from compiler. It only removes files and directories with default name. (default false) + */ + cleanByProduct?: boolean +} + +export interface TestOptions { + /** + * A filter string to determine which unit tests to run. A unit test will be run only if it + * contains this string in its fully qualified (::::) name. + */ + filter?: string + + /** + * Report test statistics at the end of testing.(default false) + */ + reportStatistics?: boolean + + /** + * Show the storage state at the end of execution of a failing test.(default false) + */ + reportStorageOnError?: boolean + + /** + * Ignore compiler's warning, and continue run tests.(default false) + */ + ignoreCompileWarnings?: boolean +} diff --git a/test/build.spec.ts b/test/build.spec.ts index d400849..8b84f70 100644 --- a/test/build.spec.ts +++ b/test/build.spec.ts @@ -1,18 +1,30 @@ -import { readFile } from 'fs/promises' -import { MoveBuilder } from '../src/build' import path from 'path' +import { readFile } from 'fs/promises' +import { MoveBuilder } from 'builder' describe('build move package', () => { const contractDir = path.resolve(__dirname, 'contract/dummy') const builder = new MoveBuilder(path.resolve(__dirname, contractDir), { devMode: true, - addtionalNamedAddresses: [['test', '0x4']], + testMode: true, + generateDocs: true, + generateAbis: true, + forceRecompilation: true, + fetchDepsOnly: true, + skipFetchLatestGitDeps: true, + bytecodeVersion: 7, + compilerVersion: '2', + languageVersion: '1', + addtionalNamedAddresses: [ + ['test', '0x4'], + ['test2', '0x5'], + ], }) const dummyModulePath = path.join( contractDir, 'build/DummyContract/bytecode_modules/dummy.mv' ) - jest.setTimeout(20000) + jest.setTimeout(200000) it('builds the package correctly', async () => { const buildResult = await builder.build() @@ -24,35 +36,8 @@ describe('build move package', () => { it('decodes module bytes correctly', async () => { const binary = await builder.get('dummy') - // { - // "address":"0x999", - // "name":"dummy", - // "friends":[], - // "exposed_functions": - // [ - // { - // "name":"return_0", - // "visibility":"public", - // "is_entry":false, - // "is_view":false, - // "generic_type_params":[], - // "params":[], - // "return":["u32"] - // }, - // { - // "name":"return_10", - // "visibility":"public", - // "is_entry":false, - // "is_view":false, - // "generic_type_params":[], - // "params":[], - // "return":["u32"] - // } - // ], - // "structs":[] - // } const expectedDecoded = JSON.stringify({ - address: '0x999', + address: '0x4', name: 'dummy', friends: [], exposed_functions: [ @@ -86,21 +71,17 @@ describe('build move package', () => { it('reads module info correctly', async () => { const binary = await builder.get('dummy') expect(await MoveBuilder.read_module_info(binary)).toEqual( - '{"address":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,153],"name":"dummy"}' + '{"address":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4],"name":"dummy"}' ) }) it('reads module info correctly', async () => { const binary = await builder.get('dummy') const moduleInfo = await MoveBuilder.read_module_info(binary) - // { - // "address":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,153], - // "name":"dummy" - // } const expectedModuleInfo = JSON.stringify({ address: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 9, 153, + 0, 0, 0, 0, 0, 0, 0, 4, ], name: 'dummy', }) diff --git a/test/contract/dummy/Move.toml b/test/contract/dummy/Move.toml index 3ae20b3..ea62bd4 100644 --- a/test/contract/dummy/Move.toml +++ b/test/contract/dummy/Move.toml @@ -7,4 +7,5 @@ version = "1.0.0" [addresses] std = "0x1" initia_std = "0x1" -test="_" \ No newline at end of file +test="_" +test2 = "_" \ No newline at end of file diff --git a/test/contract/dummy/sources/dummy.move b/test/contract/dummy/sources/dummy.move index 23b9361..e8afa56 100644 --- a/test/contract/dummy/sources/dummy.move +++ b/test/contract/dummy/sources/dummy.move @@ -1,4 +1,4 @@ -module 0x999::dummy { +module test::dummy { public fun return_0(): u32 { 0 } diff --git a/test/contract/dummy/sources/hihi.move b/test/contract/dummy/sources/hihi.move index 1e3de87..2d10d24 100644 --- a/test/contract/dummy/sources/hihi.move +++ b/test/contract/dummy/sources/hihi.move @@ -1,4 +1,4 @@ -module 0x999::hihi { +module test2::hihi { public fun return_0(): u32 { 0 } diff --git a/test/contract/new/Move.toml b/test/contract/new/Move.toml index 9cb27f4..4f4cc28 100644 --- a/test/contract/new/Move.toml +++ b/test/contract/new/Move.toml @@ -3,7 +3,8 @@ name = "new" version = "0.0.0" [dependencies] -InitiaStdlib = { git = "https://github.com/initia-labs/movevm.git", subdir = "precompile/modules/initia_stdlib", rev = "main" } +InitiaStdlib = { git = "https://github.com/initia-labs/move-natives.git", subdir = "initia_stdlib", rev = "main"} [addresses] -std = "0x1" +std = "0x1" + diff --git a/test/contract/simple/sources/simple.move b/test/contract/simple/sources/simple.move index 7f6c618..bcbf5c2 100644 --- a/test/contract/simple/sources/simple.move +++ b/test/contract/simple/sources/simple.move @@ -1,6 +1,18 @@ module 0x999::simple { + + fun add(a: u64, b:u64): u64 { + a + b + } + #[test] - fun simple(){ + fun test_simple(){ assert!(1==1,1); } + + #[test] + fun test_simple2(){ + let addr: address = @0x11; + assert!(add(1,1)==2,2); + } + } diff --git a/test/create.spec.ts b/test/create.spec.ts index b8ca5db..07c9f28 100644 --- a/test/create.spec.ts +++ b/test/create.spec.ts @@ -1,6 +1,6 @@ -import { describe, expect, it } from '@jest/globals' -import { MoveBuilder } from '../src/build' import path from 'path' +import { MoveBuilder } from 'builder' + describe('create and clean new move package', () => { const contractDir = path.resolve(__dirname, 'contract/new') const builder = new MoveBuilder(contractDir, {}) @@ -10,6 +10,6 @@ describe('create and clean new move package', () => { }, 6000) it('cleans the move package', async () => { - expect(await builder.clean()).toEqual('ok') - }, 6000) + expect(await builder.clean({})).toEqual('ok') + }, 20000) }) diff --git a/test/script.spec.ts b/test/script.spec.ts index b003af3..05ca4d7 100644 --- a/test/script.spec.ts +++ b/test/script.spec.ts @@ -1,6 +1,6 @@ -import { MoveBuilder } from '../src/build' import path from 'path' import { readFile } from 'fs/promises' +import { MoveBuilder } from 'builder' describe('build script and decode', () => { const contractDir = path.resolve(__dirname, 'contract/script') diff --git a/test/test.spec.ts b/test/test.spec.ts index bf0401c..8e481bb 100644 --- a/test/test.spec.ts +++ b/test/test.spec.ts @@ -1,12 +1,24 @@ -import { MoveBuilder } from '../src/build' import path from 'path' +import { MoveBuilder } from 'builder' describe('test move package', () => { const contractDir = path.resolve(__dirname, 'contract/simple') const builder = new MoveBuilder(contractDir, {}) it('executes tests successfully', async () => { - const testResult = await builder.test() + const testResult = await builder.test({ + filter: 'test_simple', + }) + expect(testResult).toEqual('ok') + }, 100000000) + + it('executes tests with options', async () => { + const testResult = await builder.test({ + filter: 'test_simple2', + reportStatistics: true, + reportStorageOnError: true, + ignoreCompileWarnings: true, + }) expect(testResult).toEqual('ok') }, 100000000) })