Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split tap and scalar #1012

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions packages/indexer-common/src/allocations/__tests__/tap.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
AllocationReceiptCollector,
defineQueryFeeModels,
GraphNode,
Network,
QueryFeeModels,
TapSubgraphResponse,
TapCollector,
} from '@graphprotocol/indexer-common'
import {
Address,
Expand All @@ -24,16 +24,13 @@ import { utils } from 'ethers'
declare const __DATABASE__: any
declare const __LOG_LEVEL__: never
let logger: Logger
let receiptCollector: AllocationReceiptCollector
let tapCollector: TapCollector
let metrics: Metrics
let queryFeeModels: QueryFeeModels
let sequelize: Sequelize
const timeout = 30000

const startRAVProcessing = jest.spyOn(
AllocationReceiptCollector.prototype,
'startRAVProcessing',
)
const startRAVProcessing = jest.spyOn(TapCollector.prototype, 'startRAVProcessing')
const setup = async () => {
logger = createLogger({
name: 'Indexer API Client',
Expand Down Expand Up @@ -61,7 +58,7 @@ const setup = async () => {
graphNode,
metrics,
)
receiptCollector = network.receiptCollector
tapCollector = network.tapCollector!
}

const ALLOCATION_ID_1 = toAddress('edde47df40c29949a75a6693c77834c00b8ad626')
Expand Down Expand Up @@ -97,7 +94,7 @@ const setupEach = async () => {
await queryFeeModels.receiptAggregateVouchers.create(rav)

jest
.spyOn(receiptCollector, 'findTransactionsForRavs')
.spyOn(tapCollector, 'findTransactionsForRavs')
.mockImplementation(async (): Promise<TapSubgraphResponse> => {
return {
transactions: [],
Expand Down Expand Up @@ -134,7 +131,7 @@ describe('TAP', () => {
test(
'test getPendingRAVs',
async () => {
const ravs = await receiptCollector['pendingRAVs']()
const ravs = await tapCollector['pendingRAVs']()

expect(ravs).toEqual([
expect.objectContaining({
Expand Down Expand Up @@ -174,7 +171,7 @@ describe('TAP', () => {
// 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
await receiptCollector['revertRavsRedeemed'](ravList, nowSecs - 1)
await tapCollector['revertRavsRedeemed'](ravList, nowSecs - 1)

let lastRedeemedRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: {
Expand All @@ -191,7 +188,7 @@ describe('TAP', () => {
expect.objectContaining(ravList[2]),
])

await receiptCollector['revertRavsRedeemed'](ravList, nowSecs)
await tapCollector['revertRavsRedeemed'](ravList, nowSecs)

lastRedeemedRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: {
Expand All @@ -207,7 +204,7 @@ describe('TAP', () => {
expect.objectContaining(ravList[2]),
])

await receiptCollector['revertRavsRedeemed'](ravList, nowSecs + 1)
await tapCollector['revertRavsRedeemed'](ravList, nowSecs + 1)

lastRedeemedRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: {
Expand All @@ -220,7 +217,7 @@ describe('TAP', () => {
})
expect(lastRedeemedRavs).toEqual([expect.objectContaining(ravList[2])])

await receiptCollector['revertRavsRedeemed'](ravList, nowSecs + 2)
await tapCollector['revertRavsRedeemed'](ravList, nowSecs + 2)

lastRedeemedRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: {
Expand Down Expand Up @@ -253,7 +250,7 @@ describe('TAP', () => {
await queryFeeModels.receiptAggregateVouchers.bulkCreate(ravList)

// it's showing on the subgraph on a specific point in time
await receiptCollector['revertRavsRedeemed'](
await tapCollector['revertRavsRedeemed'](
[
{
allocationId: ALLOCATION_ID_1,
Expand Down Expand Up @@ -305,21 +302,21 @@ describe('TAP', () => {
]
await queryFeeModels.receiptAggregateVouchers.bulkCreate(ravList)

await receiptCollector['markRavsAsFinal'](nowSecs - 1)
await tapCollector['markRavsAsFinal'](nowSecs - 1)

let finalRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: { last: true, final: true },
})

expect(finalRavs).toEqual([])

await receiptCollector['markRavsAsFinal'](nowSecs)
await tapCollector['markRavsAsFinal'](nowSecs)
finalRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: { last: true, final: true },
})
expect(finalRavs).toEqual([expect.objectContaining({ ...ravList[0], final: true })])

await receiptCollector['markRavsAsFinal'](nowSecs + 1)
await tapCollector['markRavsAsFinal'](nowSecs + 1)
finalRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: { last: true, final: true },
})
Expand All @@ -328,7 +325,7 @@ describe('TAP', () => {
expect.objectContaining({ ...ravList[1], final: true }),
])

await receiptCollector['markRavsAsFinal'](nowSecs + 2)
await tapCollector['markRavsAsFinal'](nowSecs + 2)
finalRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: { last: true, final: true },
})
Expand All @@ -354,7 +351,7 @@ describe('TAP', () => {
redeemedAt: new Date(redeemDate),
}
await queryFeeModels.receiptAggregateVouchers.create(rav2)
const ravs = await receiptCollector['pendingRAVs']()
const ravs = await tapCollector['pendingRAVs']()
// The point is it will only return the rav that is not final
expect(ravs.length).toEqual(1)
expect(ravs).toEqual([
Expand Down Expand Up @@ -390,8 +387,8 @@ describe('TAP', () => {
}
await queryFeeModels.receiptAggregateVouchers.create(rav2)

let ravs = await receiptCollector['pendingRAVs']()
ravs = await receiptCollector['filterAndUpdateRavs'](ravs)
let ravs = await tapCollector['pendingRAVs']()
ravs = await tapCollector['filterAndUpdateRavs'](ravs)
// The point is it will only return the rav that is not final

expect(ravs).toEqual([
Expand Down Expand Up @@ -458,7 +455,7 @@ describe('TAP', () => {
const redeemDateSecs = Math.floor(redeemDate / 1000)
const nowSecs = Math.floor(Date.now() / 1000)
const anotherFuncSpy = jest
.spyOn(receiptCollector, 'findTransactionsForRavs')
.spyOn(tapCollector, 'findTransactionsForRavs')
.mockImplementation(async (): Promise<TapSubgraphResponse> => {
return {
transactions: [
Expand Down Expand Up @@ -489,8 +486,8 @@ describe('TAP', () => {
redeemedAt: new Date(redeemDate),
}
await queryFeeModels.receiptAggregateVouchers.create(rav2)
let ravs = await receiptCollector['pendingRAVs']()
ravs = await receiptCollector['filterAndUpdateRavs'](ravs)
let ravs = await tapCollector['pendingRAVs']()
ravs = await tapCollector['filterAndUpdateRavs'](ravs)
expect(anotherFuncSpy).toBeCalled()
const finalRavs = await queryFeeModels.receiptAggregateVouchers.findAll({
where: { last: true, final: true },
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-common/src/allocations/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './keys'
export * from './query-fees'
export * from './tap-collector'
export * from './monitor'
export * from './types'
Loading
Loading