mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
Client likes, replies, poll options, and poll votes now embed the referenced txid in little-endian wire order, matching the indexer's byte reversal. Add a psf-memo-db repair library and CLI that rewrites byte-reversed references in likes, postParents, pollOptions, and pollVotes and rebuilds the postLikes and postChildren indexes, leaving correct and unknown references untouched and staying idempotent. By coder.
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
/*
|
|
Unit tests for the Memo reply wire encoding.
|
|
|
|
A reply action embeds the parent transaction txid as 32 raw bytes in
|
|
little-endian wire order: the reverse of the 64-character display txid. The
|
|
indexer reverses those bytes back into display order, so the client must
|
|
reverse before embedding.
|
|
*/
|
|
|
|
'use strict'
|
|
|
|
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
const MemoReply = require('../../src/services/memo-reply')
|
|
|
|
const MY_ADDRESS = 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d'
|
|
const PARENT_TXID = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
const WIRE_HEX = 'efcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301'
|
|
|
|
function makeWallet () {
|
|
return {
|
|
walletInfo: { cashAddress: MY_ADDRESS },
|
|
broadcasts: [],
|
|
async getUtxos () {
|
|
return []
|
|
},
|
|
async sendOpReturn (msg, prefix) {
|
|
this.broadcasts.push({ msg, prefix })
|
|
return 'aa'.repeat(32)
|
|
}
|
|
}
|
|
}
|
|
|
|
test('reply broadcasts the parent txid in little-endian wire order', async () => {
|
|
const wallet = makeWallet()
|
|
const memoReply = new MemoReply({ wallet })
|
|
|
|
await memoReply.reply('hello memo', PARENT_TXID)
|
|
|
|
assert.equal(wallet.broadcasts.length, 1)
|
|
assert.equal(wallet.broadcasts[0].prefix, MemoReply.MEMO_REPLY_PREFIX)
|
|
const buf = Buffer.from(wallet.broadcasts[0].msg)
|
|
assert.equal(buf.slice(0, 32).toString('hex'), WIRE_HEX)
|
|
assert.equal(buf.slice(32).toString('utf8'), 'hello memo')
|
|
})
|
|
|
|
test('reply reflects the parent txid in display order on the thread store', async () => {
|
|
const wallet = makeWallet()
|
|
const added = []
|
|
const thread = {
|
|
addReply (reply) {
|
|
added.push(reply)
|
|
}
|
|
}
|
|
const memoReply = new MemoReply({ wallet, thread })
|
|
|
|
await memoReply.reply('hello memo', PARENT_TXID)
|
|
|
|
assert.equal(added.length, 1)
|
|
assert.equal(added[0].parentTxid, PARENT_TXID)
|
|
})
|