Adding block height to all db models

This commit is contained in:
Chris Troutner
2026-06-03 12:07:53 -07:00
parent 638207a8e1
commit d885ffcd26
6 changed files with 30 additions and 68 deletions
+5 -12
View File
@@ -6,29 +6,23 @@ describe('#PostQuery', () => {
let uut
let sandbox
let postsDb
let ptxsDb
beforeEach(() => {
sandbox = sinon.createSandbox()
postsDb = {
iterator: sandbox.stub()
}
ptxsDb = {
get: sandbox.stub()
}
uut = new PostQuery({ postsDb, ptxsDb })
uut = new PostQuery({ postsDb })
})
afterEach(() => sandbox.restore())
it('should scan posts and attach block height from ptx', async () => {
it('should scan posts and read block height from stored document', async () => {
async function * mockIterator () {
yield ['tx1', { addr: 'addr1', text: 'hello', seen: 1000 }]
yield ['tx2', { addr: 'addr2', text: 'world', seen: 2000 }]
yield ['tx1', { addr: 'addr1', text: 'hello', seen: 1000, blockHeight: 600100 }]
yield ['tx2', { addr: 'addr2', text: 'world', seen: 2000, blockHeight: 600200 }]
}
postsDb.iterator.returns(mockIterator())
ptxsDb.get.withArgs('tx1').resolves({ blockHeight: 600100 })
ptxsDb.get.withArgs('tx2').resolves({ blockHeight: 600200 })
const result = await uut.scanPostsWithBlockHeight()
@@ -39,12 +33,11 @@ describe('#PostQuery', () => {
assert.equal(result[1].blockHeight, 600200)
})
it('should use block height 0 when ptx is missing', async () => {
it('should use block height 0 when field is missing', async () => {
async function * mockIterator () {
yield ['tx-missing', { addr: 'addr1', text: 'hi', seen: 1000 }]
}
postsDb.iterator.returns(mockIterator())
ptxsDb.get.rejects(new Error('not found'))
const result = await uut.scanPostsWithBlockHeight()