mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
Refactor multi-push helpers and add adapter property tests
Share a single UTF-8 encoding helper across hex, poll-create, and topic-post instead of repeating new TextEncoder().encode(), drop the redundant Uint8Array branch in the push normalizer, rename the txid-action push builder parameter from buildPayload to buildPushes to match what it returns, and factor the db repair unit-test setup into a repairedFixture helper. Add property tests for the multi-push adapter covering prefix/ordering, field-byte conservation, buffer round trips, array expansion, single field delegation, and idempotent attach, plus a unit test for the unsupported-wallet guard. By refactorer.
This commit is contained in:
@@ -44,6 +44,15 @@ function loadReversedFixture (level) {
|
||||
level.pollVotesDb.put('vote-2', { pollTxid: DISPLAY_POLL, comment: 'no', blockHeight: 11 })
|
||||
}
|
||||
|
||||
// Load the reversed-reference fixture, run the repair once, and return the
|
||||
// repaired level for assertions.
|
||||
async function repairedFixture () {
|
||||
const level = makeLevel()
|
||||
loadReversedFixture(level)
|
||||
await repairTxidEncoding(level)
|
||||
return level
|
||||
}
|
||||
|
||||
describe('#RepairTxidEncoding', () => {
|
||||
describe('reverseTxid', () => {
|
||||
it('reverses the byte order of a display txid', () => {
|
||||
@@ -98,10 +107,7 @@ describe('#RepairTxidEncoding', () => {
|
||||
|
||||
describe('repairTxidEncoding', () => {
|
||||
it('corrects a reversed like reference and rebuilds postLikes', async () => {
|
||||
const level = makeLevel()
|
||||
loadReversedFixture(level)
|
||||
|
||||
await repairTxidEncoding(level)
|
||||
const level = await repairedFixture()
|
||||
|
||||
assert.equal((await level.likesDb.get('like-1')).postTxid, DISPLAY_POST)
|
||||
assert.include(level.postLikesDb.keys(), `${DISPLAY_POST}:like-1`)
|
||||
@@ -109,10 +115,7 @@ describe('#RepairTxidEncoding', () => {
|
||||
})
|
||||
|
||||
it('corrects a reversed reply reference and rebuilds postChildren', async () => {
|
||||
const level = makeLevel()
|
||||
loadReversedFixture(level)
|
||||
|
||||
await repairTxidEncoding(level)
|
||||
const level = await repairedFixture()
|
||||
|
||||
assert.equal((await level.postParentsDb.get('reply-1')).parentTxid, DISPLAY_POST)
|
||||
assert.include(level.postChildrenDb.keys(), `${DISPLAY_POST}:reply-1`)
|
||||
@@ -120,20 +123,14 @@ describe('#RepairTxidEncoding', () => {
|
||||
})
|
||||
|
||||
it('corrects reversed poll option and vote references', async () => {
|
||||
const level = makeLevel()
|
||||
loadReversedFixture(level)
|
||||
|
||||
await repairTxidEncoding(level)
|
||||
const level = await repairedFixture()
|
||||
|
||||
assert.equal((await level.pollOptionsDb.get('option-1')).pollTxid, DISPLAY_POLL)
|
||||
assert.equal((await level.pollVotesDb.get('vote-1')).pollTxid, DISPLAY_POLL)
|
||||
})
|
||||
|
||||
it('leaves correctly-encoded references unchanged', async () => {
|
||||
const level = makeLevel()
|
||||
loadReversedFixture(level)
|
||||
|
||||
await repairTxidEncoding(level)
|
||||
const level = await repairedFixture()
|
||||
|
||||
assert.equal((await level.likesDb.get('like-2')).postTxid, DISPLAY_POST)
|
||||
assert.equal((await level.postParentsDb.get('reply-2')).parentTxid, DISPLAY_POST)
|
||||
@@ -142,10 +139,7 @@ describe('#RepairTxidEncoding', () => {
|
||||
})
|
||||
|
||||
it('leaves an unknown reference unchanged', async () => {
|
||||
const level = makeLevel()
|
||||
loadReversedFixture(level)
|
||||
|
||||
await repairTxidEncoding(level)
|
||||
const level = await repairedFixture()
|
||||
|
||||
assert.equal((await level.likesDb.get('like-3')).postTxid, UNKNOWN)
|
||||
})
|
||||
@@ -163,10 +157,7 @@ describe('#RepairTxidEncoding', () => {
|
||||
})
|
||||
|
||||
it('is idempotent', async () => {
|
||||
const level = makeLevel()
|
||||
loadReversedFixture(level)
|
||||
|
||||
await repairTxidEncoding(level)
|
||||
const level = await repairedFixture()
|
||||
await repairTxidEncoding(level)
|
||||
|
||||
const postLikes = level.postLikesDb.keys()
|
||||
|
||||
Reference in New Issue
Block a user