Skip to content

Commit

Permalink
fix(weavedrive): store headers as utf8 encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrain99 committed Nov 6, 2024
1 parent d12b436 commit 80e512e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
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

0 comments on commit 80e512e

Please sign in to comment.