Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use base64 encode instead of utf8 in cString #24

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
RUST_BACKTRACE: 1
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
djm07073 marked this conversation as resolved.
Show resolved Hide resolved
- run: npm install
- run: npm run build
- run: npm run test
Expand Down
6 changes: 3 additions & 3 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
97 changes: 65 additions & 32 deletions test/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('build move package', () => {
languageVersion: '1',
addtionalNamedAddresses: [
['test', '0x4'],
['test2', '0x5'],
['test2', '0x4c4e8f7def3c24453ae7eee7d9aee9b7556a26a0'],
],
})
const dummyModulePath = path.join(
Expand All @@ -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 () => {
Expand Down
Loading