Skip to content

Commit

Permalink
Merge pull request #22 from art-by-city/16-fetch-legacy-tips
Browse files Browse the repository at this point in the history
Adds querying of legacy tips
  • Loading branch information
jim-toth authored Sep 6, 2023
2 parents dff9a0b + cd0b6ed commit 1e67e13
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ export const mapLegacyLikeFromTransaction = (
liked: likedEntityTag?.value || ''
}
}

export interface LegacyTipsFeed {
tips: LegacyTip[]
cursor: string
}
36 changes: 35 additions & 1 deletion src/legacy/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
LegacyPublicationManifestLicense,
LegacyPublicationFeed,
LegacyLikesFeed,
mapLegacyLikeFromTransaction
mapLegacyLikeFromTransaction,
LegacyTipsFeed
} from './'

export default class ArtByCityLegacy {
Expand Down Expand Up @@ -348,4 +349,37 @@ export default class ArtByCityLegacy {
likes: transactions.map(mapLegacyLikeFromTransaction)
}
}

async queryTips(
address: string,
receivedOrSent: 'received' | 'sent',
limit: number | 'all' = 100,
cursor?: string
): Promise<LegacyTipsFeed> {
const receivedOrSentOpts = receivedOrSent === 'received'
? { to: address }
: { from: address }

const {
transactions,
cursor: nextCursor
} = await this.transactions.query('tip', {
...receivedOrSentOpts,
limit,
cursor
})

return {
cursor: nextCursor,
tips: transactions.map(tx => {
return {
id: tx.id,
amount: tx.quantity.winston,
from: tx.owner.address,
to: tx.recipient,
timestamp: tx.block.timestamp
}
})
}
}
}
74 changes: 74 additions & 0 deletions test/e2e/artbycity.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const PROFILE_ID = '2aLkIcBH52s2LtZoyRQC_YaFGGSB2r2yGUtgYM5MjZc'
const ARTIST_ADDRESS = 'YftBIDY3rUeITuEhhXBHCGY77K6VkBj70STjRyGFE4k'
const LIKER_ADDRESS = '36Ar8VmyC7YS7JGaep9ca2ANjLABETTpxSeA7WOV45Y'
const LIKED_PUBLICATION = 'VAcSNlptOPg6Brf4Ur4tnmzziebTWux5VnWowHZkDLM'
const TIPPER_ADDRESS = 'Uy2XZ7P7F4zBllF5uPdd1ih9jiQrIGvD3X8L13cc5_s'
const TIPPEE_ADDRESS = 'x3GW6wfBZ3wHTflETInuzJ5rOv_6JvlFi-dl6yYAr8Y'

const arweave = Arweave.init({
protocol: 'https',
Expand Down Expand Up @@ -553,5 +555,77 @@ describe(`ArtByCity (web)`, () => {
})
})
})

context('Querying Tips', () => {
it('received by address', async () => {
const abc = new ArtByCity(arweave)

const { tips } = await abc.legacy.queryTips(TIPPEE_ADDRESS, 'received')

expect(tips).to.be.an('array')
expect(tips).to.not.be.empty
for (const tip of tips) {
expect(tip.id).to.be.a('string')
expect(tip.amount).to.be.a('string')
expect(tip.from).to.be.a('string')
expect(tip.to).to.equal(TIPPEE_ADDRESS)
expect(tip.timestamp).to.be.a('number')
}
})

it('sent by address', async () => {
const abc = new ArtByCity(arweave)

const { tips } = await abc.legacy.queryTips(TIPPER_ADDRESS, 'sent')

expect(tips).to.be.an('array')
expect(tips).to.not.be.empty
for (const tip of tips) {
expect(tip.id).to.be.a('string')
expect(tip.amount).to.be.a('string')
expect(tip.from).to.equal(TIPPER_ADDRESS)
expect(tip.to).to.be.a('string')
expect(tip.timestamp).to.be.a('number')
}
})

it('given a limit', async () => {
const abc = new ArtByCity(arweave)

const { tips } = await abc.legacy.queryTips(TIPPER_ADDRESS, 'sent', 2)

expect(tips).to.be.an('array')
expect(tips).to.have.lengthOf(2)
})

// TODO -> re-enable this test when using arlocal mock data
it.skip('given a limit of all', async () => {
const abc = new ArtByCity(arweave)

const { tips } = await abc
.legacy
.queryTips(TIPPER_ADDRESS, 'sent', 'all')

expect(tips).to.be.an('array')
expect(tips).to.not.be.empty
// TODO -> more specific test
})

it('given a cursor', async () => {
const abc = new ArtByCity(arweave)

const {
tips: firstBatch,
cursor
} = await abc.legacy.queryTips(TIPPER_ADDRESS, 'sent', 2)
const {
tips: secondBatch
} = await abc.legacy.queryTips(TIPPER_ADDRESS, 'sent', 2, cursor)

expect(firstBatch).to.be.an('array')
expect(secondBatch).to.be.an('array')
expect(firstBatch).to.not.deep.equal(secondBatch)
})
})
})
})

0 comments on commit 1e67e13

Please sign in to comment.