Skip to content

Commit

Permalink
test: add mark as non last
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Aug 28, 2024
1 parent a7e91cd commit 5ef7802
Showing 1 changed file with 96 additions and 22 deletions.
118 changes: 96 additions & 22 deletions packages/indexer-common/src/allocations/__tests__/tap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ const setup = async () => {
receiptCollector = network.receiptCollector
}

const ALLOCATION_ID_1 = toAddress('edde47df40c29949a75a6693c77834c00b8ad626')
const ALLOCATION_ID_2 = toAddress('dead47df40c29949a75a6693c77834c00b8ad624')

const SENDER_ADDRESS_1 = toAddress('ffcf8fdee72ac11b5c542428b35eef5769c409f0')
const SENDER_ADDRESS_2 = toAddress('dead47df40c29949a75a6693c77834c00b8ad624')

// last rav not redeemed
const rav = {
allocationId: toAddress('edde47df40c29949a75a6693c77834c00b8ad626'),
allocationId: ALLOCATION_ID_1,
last: true,
final: false,
timestampNs: 1709067401177959664n,
Expand All @@ -73,15 +80,52 @@ const rav = {
'ede3f7ca5ace3629009f190bb51271f30c1aeaf565f82c25c447c7c9501f3ff31b628efcaf69138bf12960dd663924a692ee91f401785901848d8d7a639003ad1b',
'hex',
),
senderAddress: toAddress('ffcf8fdee72ac11b5c542428b35eef5769c409f0'),
senderAddress: SENDER_ADDRESS_1,
redeemedAt: null,
createdAt: new Date(),
updatedAt: new Date(),
}

const SIGNATURE = Buffer.from(
'ede3f7ca5ace3629009f190bb51271f30c1aeaf565f82c25c447c7c9501f3ff31b628efcaf69138bf12960dd663924a692ee91f401785901848d8d7a639003ad1b',
'hex',
)

const rav_list = [
rav,
// redeemed rav but non-final
{
allocationId: ALLOCATION_ID_2,
last: true,
final: false,
timestampNs: 1709067401177959664n,
valueAggregate: 20000000000000n,
signature: SIGNATURE,
senderAddress: SENDER_ADDRESS_1,
redeemedAt: new Date(),
createdAt: new Date(),
updatedAt: new Date(),
},
]

const setupEach = async () => {
sequelize = await sequelize.sync({ force: true })
await queryFeeModels.receiptAggregateVouchers.create(rav)
await queryFeeModels.receiptAggregateVouchers.bulkCreate(rav_list)

jest
.spyOn(receiptCollector.tapSubgraph!, 'query')
.mockImplementation(async (): Promise<QueryResult<unknown>> => {
return {
data: {
transactions: [],
_meta: {
block: {
timestamp: Date.now(),
},
},
},
}
})
}
const teardownEach = async () => {
// Clear out query fee model tables
Expand Down Expand Up @@ -125,22 +169,47 @@ describe('TAP', () => {
timeout,
)

test('should revert the rav request', async () => {
// we have a redeemed non-final rav in our database
// it's not showing on the subgraph on a specific point in time
// the timestamp of the subgraph is greater than the receipt id
// should revert the rav
// const finalRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
// where: { last: true, final: true },
// })
//
// const allocationIds = [ALLOCATION_ID_1.toString()]
// const blockTimestamp = 1000
// await receiptCollector['revertRavsRedeemed'](allocationIds, blockTimestamp)
})

test('should not revert the rav request, allocation_id not in the list ', async () => {
// we have a redeemed non-final rav in our database
// it's showing on the subgraph on a specific point in time
// the timestamp of the subgraph is greater than the receipt id
// should not revert the rav
})

test('should not revert the rav request, timestamp not greater than the subgraph timestamp', async () => {
// we have a redeemed non-final rav in our database
// it's not showing on the subgraph on a specific point in time
// the timestamp of the subgraph is lower than the receipt id
// should not revert the rav
})

test(
'test ignore final rav',
async () => {
const date = new Date()
const redeemDate = date.setHours(date.getHours() - 2)
const rav2 = {
allocationId: toAddress('dead47df40c29949a75a6693c77834c00b8ad624'),
allocationId: ALLOCATION_ID_2,
last: true,
final: true,
timestampNs: 1709067401177959664n,
valueAggregate: 20000000000000n,
signature: Buffer.from(
'ede3f7ca5ace3629009f190bb51271f30c1aeaf565f82c25c447c7c9501f3ff31b628efcaf69138bf12960dd663924a692ee91f401785901848d8d7a639003ad1b',
'hex',
),
senderAddress: toAddress('deadbeefcafedeadceefcafedeadbeefcafedead'),
signature: SIGNATURE,
senderAddress: SENDER_ADDRESS_2,
redeemedAt: new Date(redeemDate),
createdAt: new Date(),
updatedAt: new Date(),
Expand Down Expand Up @@ -171,23 +240,21 @@ describe('TAP', () => {
const date = new Date()
const redeemDate = date.setHours(date.getHours() - 2)
const rav2 = {
allocationId: toAddress('dead47df40c29949a75a6693c77834c00b8ad624'),
allocationId: ALLOCATION_ID_2,
last: true,
final: false,
timestampNs: 1709067401177959664n,
valueAggregate: 20000000000000n,
signature: Buffer.from(
'ede3f7ca5ace3629009f190bb51271f30c1aeaf565f82c25c447c7c9501f3ff31b628efcaf69138bf12960dd663924a692ee91f401785901848d8d7a639003ad1b',
'hex',
),
senderAddress: toAddress('deadbeefcafedeadceefcafedeadbeefcafedead'),
signature: SIGNATURE,
senderAddress: SENDER_ADDRESS_2,
redeemedAt: new Date(redeemDate),
createdAt: new Date(),
updatedAt: new Date(),
}
await queryFeeModels.receiptAggregateVouchers.create(rav2)
const ravs = await receiptCollector['pendingRAVs']()
// The point is it will only return the rav that is not final

expect(ravs).toEqual([
expect.objectContaining({
allocationId: rav.allocationId,
Expand Down Expand Up @@ -253,25 +320,32 @@ describe('TAP', () => {
return {
data: {
transactions: [
{ allocationID: '0xdead47df40c29949a75a6693c77834c00b8ad624' },
{
allocationID: '0xdead47df40c29949a75a6693c77834c00b8ad624',
sender: {
id: '0xdead47df40c29949a75a6693c77834c00b8ad624',
},
},
],
_meta: {
block: {
timestamp: Date.now(),
},
},
},
}
})

const date = new Date()
const redeemDate = date.setHours(date.getHours() - 2)
const rav2 = {
allocationId: toAddress('dead47df40c29949a75a6693c77834c00b8ad624'),
allocationId: ALLOCATION_ID_2,
last: true,
final: false,
timestampNs: 1709067401177959664n,
valueAggregate: 20000000000000n,
signature: Buffer.from(
'ede3f7ca5ace3629009f190bb51271f30c1aeaf565f82c25c447c7c9501f3ff31b628efcaf69138bf12960dd663924a692ee91f401785901848d8d7a639003ad1b',
'hex',
),
senderAddress: toAddress('deadbeefcafedeadceefcafedeadbeefcafedead'),
signature: SIGNATURE,
senderAddress: SENDER_ADDRESS_2,
redeemedAt: new Date(redeemDate),
createdAt: new Date(),
updatedAt: new Date(),
Expand Down

0 comments on commit 5ef7802

Please sign in to comment.