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(weavedrive): store headers as utf8 encoded #396

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions extensions/weavedrive/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module.exports = function weaveDrive(mod, FS) {

var bytesLength = result.length;

var node = FS.createDataFile('/', 'block/' + id, result, true, false);
var node = FS.createDataFile('/', 'block/' + id, Buffer.from(result, 'utf-8'), true, false);

var stream = FS.open('/block/' + id, 'r');
return stream;
Expand Down Expand Up @@ -135,7 +135,7 @@ module.exports = function weaveDrive(mod, FS) {
//.then(x => (console.error(x), x))
.then(x => JSON.stringify(x));

var node = FS.createDataFile('/', 'tx/' + id, result, true, false);
var node = FS.createDataFile('/', 'tx/' + id, Buffer.from(result, 'utf-8'), true, false);
var stream = FS.open('/tx/' + id, 'r');
return stream;
},
Expand Down Expand Up @@ -220,7 +220,7 @@ module.exports = function weaveDrive(mod, FS) {
if (result === 'No results') {
return result
}
FS.createDataFile('/', 'tx2/' + id, result, true, false);
FS.createDataFile('/', 'tx2/' + id, Buffer.from(result, 'utf-8'), true, false);
var stream = FS.open('/tx2/' + id, 'r');

return stream;
Expand Down
18 changes: 18 additions & 0 deletions extensions/weavedrive/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,24 @@ return result
assert.equal(data.block.height, 1290333)
})

test('data item with chinese characters', async () => {
const chineseCharacterTx = 'Xg82mcAfQNgJetk_kSKqMkwYDfoMJLGw8fdheU3evWk'
const handle = await AoLoader(wasm, options)
const result = await handle(memory, {
...Msg,
Data: `
local data = require('WeaveDrive').getDataItem('${chineseCharacterTx}')
local json = require('json')
local decoded = json.decode(data)
return data
`
}, { Process, Module })
memory = result.Memory
const data = JSON.parse(result.Output.data)
const description = data.tags.find(tag => tag.name === 'Description')?.value
assert.equal(description, "Smartweave是不是要转到AO了?\n本文档介绍原子资产SmartWeave合约的标准接口。原子资产是SmartWeave合约及其在发布到Arweave的同一事务中初始化的数据。SmartWeave合约和数据共享一个交易ID。")
})

test('read data item tx, no result', async () => {
const handle = await AoLoader(wasm, options)
const result = await handle(memory, {
Expand Down
Loading