diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ea9fa6e..6dd4687 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,11 @@ jobs: RUST_BACKTRACE: 1 steps: - uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' - run: npm install - run: npm run build - run: npm run test diff --git a/package.json b/package.json index 69a7029..8e442e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@initia/builder.js", - "version": "0.2.5", + "version": "0.2.6", "description": "The JavaScript Move Builder for Initia", "license": "MIT", "author": "Initia Foundation", diff --git a/src/builder.ts b/src/builder.ts index dc45011..b36cf2f 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -33,8 +33,8 @@ export class MoveBuilder { */ private makeRawBuildConfig = () => { const additionalNamedAddresses: [string, Uint8Array][] = this.buildOptions - .addtionalNamedAddresses - ? this.buildOptions.addtionalNamedAddresses.map(([name, address]) => { + .additionalNamedAddresses + ? this.buildOptions.additionalNamedAddresses.map(([name, address]) => { if (address.startsWith('0x')) { address = address.slice(2).padStart(64, '0') } @@ -71,8 +71,8 @@ export class MoveBuilder { rawCompilerPayload.is_nil = false rawCompilerPayload.len = compilerPayloadBytes.length rawCompilerPayload.ptr = ref.allocCString( - compilerPayloadBytes.toString(), - 'utf-8' + compilerPayloadBytes.toString('base64'), + 'base64' ) return rawCompilerPayload @@ -206,7 +206,7 @@ export class MoveBuilder { const rawTestOpt = testOpt.deref() rawTestOpt.is_nil = false rawTestOpt.len = testOptBytes.length - rawTestOpt.ptr = ref.allocCString(testOptBytes.toString(), 'utf-8') + rawTestOpt.ptr = ref.allocCString(testOptBytes.toString('base64'), 'base64') return handleResponse( libcompiler.test_move_package.async, diff --git a/src/types/options.ts b/src/types/options.ts index b747a51..cff319e 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -60,7 +60,7 @@ export interface BuildOptions { /** * Additional named address mapping. Useful for tools in Rust. */ - addtionalNamedAddresses?: [string, string][] + additionalNamedAddresses?: [string, string][] } export interface CleanOptions { diff --git a/test/build.spec.ts b/test/build.spec.ts index cc4c10b..a4f94b9 100644 --- a/test/build.spec.ts +++ b/test/build.spec.ts @@ -15,9 +15,9 @@ describe('build move package', () => { bytecodeVersion: 7, compilerVersion: '2', languageVersion: '1', - addtionalNamedAddresses: [ + additionalNamedAddresses: [ ['test', '0x4'], - ['test2', '0x5'], + ['test2', '0x4c4e8f7def3c24453ae7eee7d9aee9b7556a26a0'], ], }) const dummyModulePath = path.join( @@ -35,44 +35,77 @@ describe('build move package', () => { }) it('decodes module bytes correctly', async () => { - const binary = await builder.get('dummy') - const expectedDecoded = JSON.stringify({ - address: '0x4', - 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 dummy = await builder.get('dummy') - expect(await MoveBuilder.decode_module_bytes(binary)).toEqual( - expectedDecoded + expect(await MoveBuilder.decode_module_bytes(dummy)).toEqual( + JSON.stringify({ + address: '0x4', + 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 hihi = await builder.get('hihi') + + expect(await MoveBuilder.decode_module_bytes(hihi)).toEqual( + JSON.stringify({ + address: '0x4c4e8f7def3c24453ae7eee7d9aee9b7556a26a0', + name: 'hihi', + 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: [], + }) ) }) it('reads module info correctly', async () => { - const binary = await builder.get('dummy') - expect(await MoveBuilder.read_module_info(binary)).toEqual( + const dummy = await builder.get('dummy') + expect(await MoveBuilder.read_module_info(dummy)).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,0,4],"name":"dummy"}' ) + const hihi = await builder.get('hihi') + expect(await MoveBuilder.read_module_info(hihi)).toEqual( + '{"address":[0,0,0,0,0,0,0,0,0,0,0,0,76,78,143,125,239,60,36,69,58,231,238,231,217,174,233,183,85,106,38,160],"name":"hihi"}' + ) }) it('reads module info correctly', async () => {