diff --git a/db/migrations/1706166961258-Data.js b/db/migrations/1706166961258-Data.js deleted file mode 100644 index d3e6cd9..0000000 --- a/db/migrations/1706166961258-Data.js +++ /dev/null @@ -1,31 +0,0 @@ -module.exports = class Data1706166961258 { - name = 'Data1706166961258' - - async up(db) { - await db.query(`CREATE TABLE "authority" ("id" character varying NOT NULL, CONSTRAINT "PK_b0f9bb35ff132fc6bd92d0582ce" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "validator_node" ("id" character varying NOT NULL, "runway" numeric, "location" text, "application_id" character varying, "provider_id" character varying, CONSTRAINT "PK_cc0fae80b68d3c7e4929b846da8" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_620ac06bbf5dcf4692fcd7d6da" ON "validator_node" ("application_id") `) - await db.query(`CREATE INDEX "IDX_ca05fc469559790a26dd6bca6b" ON "validator_node" ("provider_id") `) - await db.query(`CREATE TABLE "validator_node_provider" ("id" character varying NOT NULL, "payee" text NOT NULL, "price" numeric NOT NULL, "paused" boolean NOT NULL, "authority_id" character varying, "token_id" character varying, CONSTRAINT "PK_ca05fc469559790a26dd6bca6be" PRIMARY KEY ("id"))`) - await db.query(`CREATE INDEX "IDX_0551b931f1793eeaad67e0b254" ON "validator_node_provider" ("authority_id") `) - await db.query(`CREATE INDEX "IDX_ba5f3d920d2961e583599fbfda" ON "validator_node_provider" ("token_id") `) - await db.query(`ALTER TABLE "validator_node" ADD CONSTRAINT "FK_620ac06bbf5dcf4692fcd7d6da0" FOREIGN KEY ("application_id") REFERENCES "application"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "validator_node" ADD CONSTRAINT "FK_ca05fc469559790a26dd6bca6be" FOREIGN KEY ("provider_id") REFERENCES "validator_node_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "validator_node_provider" ADD CONSTRAINT "FK_0551b931f1793eeaad67e0b254d" FOREIGN KEY ("authority_id") REFERENCES "authority"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - await db.query(`ALTER TABLE "validator_node_provider" ADD CONSTRAINT "FK_ba5f3d920d2961e583599fbfdae" FOREIGN KEY ("token_id") REFERENCES "token"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) - } - - async down(db) { - await db.query(`DROP TABLE "authority"`) - await db.query(`DROP TABLE "validator_node"`) - await db.query(`DROP INDEX "public"."IDX_620ac06bbf5dcf4692fcd7d6da"`) - await db.query(`DROP INDEX "public"."IDX_ca05fc469559790a26dd6bca6b"`) - await db.query(`DROP TABLE "validator_node_provider"`) - await db.query(`DROP INDEX "public"."IDX_0551b931f1793eeaad67e0b254"`) - await db.query(`DROP INDEX "public"."IDX_ba5f3d920d2961e583599fbfda"`) - await db.query(`ALTER TABLE "validator_node" DROP CONSTRAINT "FK_620ac06bbf5dcf4692fcd7d6da0"`) - await db.query(`ALTER TABLE "validator_node" DROP CONSTRAINT "FK_ca05fc469559790a26dd6bca6be"`) - await db.query(`ALTER TABLE "validator_node_provider" DROP CONSTRAINT "FK_0551b931f1793eeaad67e0b254d"`) - await db.query(`ALTER TABLE "validator_node_provider" DROP CONSTRAINT "FK_ba5f3d920d2961e583599fbfdae"`) - } -} diff --git a/db/migrations/1706849548900-Data.js b/db/migrations/1706849548900-Data.js new file mode 100644 index 0000000..5442e73 --- /dev/null +++ b/db/migrations/1706849548900-Data.js @@ -0,0 +1,31 @@ +module.exports = class Data1706849548900 { + name = 'Data1706849548900' + + async up(db) { + await db.query(`CREATE TABLE "authority" ("id" character varying NOT NULL, CONSTRAINT "PK_b0f9bb35ff132fc6bd92d0582ce" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "node" ("id" character varying NOT NULL, "runway" numeric, "location" text, "type" character varying(9) NOT NULL, "application_id" character varying, "provider_id" character varying, CONSTRAINT "PK_8c8caf5f29d25264abe9eaf94dd" PRIMARY KEY ("id"))`) + await db.query(`CREATE INDEX "IDX_7a1582c5c19e59eaee8baf3b7c" ON "node" ("application_id") `) + await db.query(`CREATE INDEX "IDX_bc6bc99eaa9a0b593c745054dd" ON "node" ("provider_id") `) + await db.query(`CREATE TABLE "node_provider" ("id" character varying NOT NULL, "payee" text NOT NULL, "price" numeric NOT NULL, "paused" boolean NOT NULL, "type" character varying(9) NOT NULL, "authority_id" character varying, "token_id" character varying, CONSTRAINT "PK_bc6bc99eaa9a0b593c745054dd4" PRIMARY KEY ("id"))`) + await db.query(`CREATE INDEX "IDX_bf6c4c99e8df6a9004e9e8d0e3" ON "node_provider" ("authority_id") `) + await db.query(`CREATE INDEX "IDX_12cd0de307dec107ad3184038a" ON "node_provider" ("token_id") `) + await db.query(`ALTER TABLE "node" ADD CONSTRAINT "FK_7a1582c5c19e59eaee8baf3b7c2" FOREIGN KEY ("application_id") REFERENCES "application"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await db.query(`ALTER TABLE "node" ADD CONSTRAINT "FK_bc6bc99eaa9a0b593c745054dd4" FOREIGN KEY ("provider_id") REFERENCES "node_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await db.query(`ALTER TABLE "node_provider" ADD CONSTRAINT "FK_bf6c4c99e8df6a9004e9e8d0e3a" FOREIGN KEY ("authority_id") REFERENCES "authority"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + await db.query(`ALTER TABLE "node_provider" ADD CONSTRAINT "FK_12cd0de307dec107ad3184038a1" FOREIGN KEY ("token_id") REFERENCES "token"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`) + } + + async down(db) { + await db.query(`DROP TABLE "authority"`) + await db.query(`DROP TABLE "node"`) + await db.query(`DROP INDEX "public"."IDX_7a1582c5c19e59eaee8baf3b7c"`) + await db.query(`DROP INDEX "public"."IDX_bc6bc99eaa9a0b593c745054dd"`) + await db.query(`DROP TABLE "node_provider"`) + await db.query(`DROP INDEX "public"."IDX_bf6c4c99e8df6a9004e9e8d0e3"`) + await db.query(`DROP INDEX "public"."IDX_12cd0de307dec107ad3184038a"`) + await db.query(`ALTER TABLE "node" DROP CONSTRAINT "FK_7a1582c5c19e59eaee8baf3b7c2"`) + await db.query(`ALTER TABLE "node" DROP CONSTRAINT "FK_bc6bc99eaa9a0b593c745054dd4"`) + await db.query(`ALTER TABLE "node_provider" DROP CONSTRAINT "FK_bf6c4c99e8df6a9004e9e8d0e3a"`) + await db.query(`ALTER TABLE "node_provider" DROP CONSTRAINT "FK_12cd0de307dec107ad3184038a1"`) + } +} diff --git a/schema.graphql b/schema.graphql index 8d58db6..559e916 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,23 +1,30 @@ +enum FunctionType { + READER + VALIDATOR +} + type Authority @entity @cardinality(value: 5) { id: ID! } -type ValidatorNodeProvider @entity @cardinality(value: 100) { +type NodeProvider @entity @cardinality(value: 100) { id: ID! - authority: Authority! + authority: Authority token: Token! payee: String! price: BigInt! paused: Boolean! - nodes: [ValidatorNode!] @derivedFrom(field: "provider") + nodes: [Node!] @derivedFrom(field: "provider") + type: FunctionType! } -type ValidatorNode @entity @cardinality(value: 100) { +type Node @entity @cardinality(value: 100) { id: ID! application: Application! - provider: ValidatorNodeProvider! + provider: NodeProvider! runway: BigInt location: String + type: FunctionType! } type ApplicationFactory @entity @cardinality(value: 5) { @@ -31,6 +38,7 @@ type Application @entity @cardinality(value: 100) { timestamp: BigInt! factory: ApplicationFactory inputs: [Input!] @derivedFrom(field: "application") + nodes: [Node!] @derivedFrom(field: "application") } type Token @entity @cardinality(value: 10) { diff --git a/src/handlers/EventHandler.ts b/src/handlers/EventHandler.ts index 406fb71..ebe7130 100644 --- a/src/handlers/EventHandler.ts +++ b/src/handlers/EventHandler.ts @@ -8,9 +8,9 @@ import { Erc721Deposit, Input, NFT, + Node, + NodeProvider, Token, - ValidatorNode, - ValidatorNodeProvider, } from '../model'; import ApplicationCreated from './ApplicationCreated'; import AuthorityCreated from './AuthorityCreated'; @@ -32,8 +32,8 @@ export default class EventHandler { private readonly nfts: Map; private readonly erc721Deposits: Map; private readonly authorities: Map; - private readonly validatorNodeProviders: Map; - private readonly validatorNodes: Map; + private readonly nodeProviders: Map; + private readonly nodes: Map; private readonly applicationCreated: Handler; private readonly inputAdded: Handler; private readonly ownershipTransferred: Handler; @@ -53,8 +53,8 @@ export default class EventHandler { this.nfts = new Map(); this.erc721Deposits = new Map(); this.authorities = new Map(); - this.validatorNodeProviders = new Map(); - this.validatorNodes = new Map(); + this.nodeProviders = new Map(); + this.nodes = new Map(); this.applicationCreated = new ApplicationCreated( this.factories, @@ -74,25 +74,25 @@ export default class EventHandler { this.authorityCreated = new AuthorityCreated(this.authorities); this.validatorNodeProviderCreated = new ValidatorNodeProviderCreated( this.authorities, - this.validatorNodeProviders, + this.nodeProviders, this.tokens, ); this.validatorNodeProviderPaused = new ValidatorNodeProviderPaused( - this.validatorNodeProviders, + this.nodeProviders, ); this.validatorNodeProviderUnpaused = new validatorNodeProviderUnpaused( - this.validatorNodeProviders, + this.nodeProviders, ); this.validatorNodeFinancialRunway = new ValidatorNodeFinancialRunway( this.applications, - this.validatorNodes, - this.validatorNodeProviders, + this.nodes, + this.nodeProviders, ); this.validatorNodeMachineLocation = new ValidatorNodeMachineLocation( this.applications, - this.validatorNodes, - this.validatorNodeProviders, + this.nodes, + this.nodeProviders, ); } @@ -119,8 +119,8 @@ export default class EventHandler { nfts: this.nfts, erc721Deposits: this.erc721Deposits, authorities: this.authorities, - validatorNodeProviders: this.validatorNodeProviders, - validatorNodes: this.validatorNodes, + nodeProviders: this.nodeProviders, + nodes: this.nodes, }; } diff --git a/src/handlers/ValidatorNodeFinancialRunway.ts b/src/handlers/ValidatorNodeFinancialRunway.ts index acffbbf..3b0e9d5 100644 --- a/src/handlers/ValidatorNodeFinancialRunway.ts +++ b/src/handlers/ValidatorNodeFinancialRunway.ts @@ -1,14 +1,14 @@ import { BlockData, DataHandlerContext, Log } from '@subsquid/evm-processor'; import { Store } from '@subsquid/typeorm-store'; import { events as ValidatorNodeProviderEvents } from '../abi/ValidatorNodeProvider'; -import { Application, ValidatorNode, ValidatorNodeProvider } from '../model'; +import { Application, FunctionType, Node, NodeProvider } from '../model'; import Handler from './Handler'; export default class ValidatorNodeFinancialRunway implements Handler { constructor( private apps: Map, - private nodes: Map, - private providers: Map, + private nodes: Map, + private providers: Map, ) {} async handle(log: Log, block: BlockData, ctx: DataHandlerContext) { @@ -18,7 +18,7 @@ export default class ValidatorNodeFinancialRunway implements Handler { const providerAddress = log.address.toLowerCase(); const provider = this.providers.get(providerAddress) ?? - (await ctx.store.get(ValidatorNodeProvider, providerAddress)); + (await ctx.store.get(NodeProvider, providerAddress)); if (provider) { const { dapp, until } = @@ -27,13 +27,14 @@ export default class ValidatorNodeFinancialRunway implements Handler { const nodeId = `${providerAddress}-${appId}`; let node = this.nodes.get(nodeId) ?? - (await ctx.store.get(ValidatorNode, nodeId)); + (await ctx.store.get(Node, nodeId)); if (!node) { const application = this.apps.get(appId) ?? (await ctx.store.get(Application, appId)); - node = new ValidatorNode({ + node = new Node({ + type: FunctionType.VALIDATOR, id: nodeId, provider, application, diff --git a/src/handlers/ValidatorNodeMachineLocation.ts b/src/handlers/ValidatorNodeMachineLocation.ts index 86a2c1c..a87684b 100644 --- a/src/handlers/ValidatorNodeMachineLocation.ts +++ b/src/handlers/ValidatorNodeMachineLocation.ts @@ -1,14 +1,14 @@ import { BlockData, DataHandlerContext, Log } from '@subsquid/evm-processor'; import { Store } from '@subsquid/typeorm-store'; import { events as ValidatorNodeProviderEvents } from '../abi/ValidatorNodeProvider'; -import { Application, ValidatorNode, ValidatorNodeProvider } from '../model'; +import { Application, FunctionType, Node, NodeProvider } from '../model'; import Handler from './Handler'; export default class ValidatorNodeMachineLocation implements Handler { constructor( private apps: Map, - private nodes: Map, - private providers: Map, + private nodes: Map, + private providers: Map, ) {} async handle(log: Log, block: BlockData, ctx: DataHandlerContext) { @@ -18,7 +18,7 @@ export default class ValidatorNodeMachineLocation implements Handler { const providerAddress = log.address.toLowerCase(); const provider = this.providers.get(providerAddress) ?? - (await ctx.store.get(ValidatorNodeProvider, providerAddress)); + (await ctx.store.get(NodeProvider, providerAddress)); if (provider) { const { dapp, location } = @@ -27,13 +27,14 @@ export default class ValidatorNodeMachineLocation implements Handler { const nodeId = `${providerAddress}-${appId}`; let node = this.nodes.get(nodeId) ?? - (await ctx.store.get(ValidatorNode, nodeId)); + (await ctx.store.get(Node, nodeId)); if (!node) { const application = this.apps.get(appId) ?? (await ctx.store.get(Application, appId)); - node = new ValidatorNode({ + node = new Node({ + type: FunctionType.VALIDATOR, id: nodeId, provider, application, diff --git a/src/handlers/ValidatorNodeProviderCreated.ts b/src/handlers/ValidatorNodeProviderCreated.ts index 5a12093..85fc5c9 100644 --- a/src/handlers/ValidatorNodeProviderCreated.ts +++ b/src/handlers/ValidatorNodeProviderCreated.ts @@ -2,14 +2,14 @@ import { BlockData, DataHandlerContext, Log } from '@subsquid/evm-processor'; import { Store } from '@subsquid/typeorm-store'; import { events as MarketplaceEvents } from '../abi/Marketplace'; import { MarketplaceAddress } from '../config'; -import { Authority, Token, ValidatorNodeProvider } from '../model'; +import { Authority, FunctionType, NodeProvider, Token } from '../model'; import Handler from './Handler'; import TokenHelper from './helpers/TokenHelper'; export default class ValidatorNodeProviderCreated implements Handler { constructor( private authorities: Map, - private providers: Map, + private providers: Map, private tokens: Map, ) {} @@ -49,7 +49,8 @@ export default class ValidatorNodeProviderCreated implements Handler { ctx.log.info(`${providerId} (ValidatorNodeProvider) stored`); this.providers.set( providerId, - new ValidatorNodeProvider({ + new NodeProvider({ + type: FunctionType.VALIDATOR, id: providerId, token: tokenInstance, paused: false, diff --git a/src/handlers/ValidatorNodeProviderPaused.ts b/src/handlers/ValidatorNodeProviderPaused.ts index 30f0bbb..ab084eb 100644 --- a/src/handlers/ValidatorNodeProviderPaused.ts +++ b/src/handlers/ValidatorNodeProviderPaused.ts @@ -1,18 +1,18 @@ import { BlockData, DataHandlerContext, Log } from '@subsquid/evm-processor'; import { Store } from '@subsquid/typeorm-store'; import { events as ValidatorNodeProviderEvents } from '../abi/ValidatorNodeProvider'; -import { ValidatorNodeProvider } from '../model'; +import { NodeProvider } from '../model'; import Handler from './Handler'; export default class ValidatorNodeProviderPaused implements Handler { - constructor(private providers: Map) {} + constructor(private providers: Map) {} async handle(log: Log, block: BlockData, ctx: DataHandlerContext) { if (log.topics[0] === ValidatorNodeProviderEvents.Paused.topic) { const address = log.address.toLowerCase(); const provider = this.providers.get(address) ?? - (await ctx.store.get(ValidatorNodeProvider, address)); + (await ctx.store.get(NodeProvider, address)); if (provider) { provider.paused = true; diff --git a/src/handlers/ValidatorNodeProviderUnpaused.ts b/src/handlers/ValidatorNodeProviderUnpaused.ts index eb3fad1..a5dfca1 100644 --- a/src/handlers/ValidatorNodeProviderUnpaused.ts +++ b/src/handlers/ValidatorNodeProviderUnpaused.ts @@ -1,18 +1,18 @@ import { BlockData, DataHandlerContext, Log } from '@subsquid/evm-processor'; import { Store } from '@subsquid/typeorm-store'; import { events as ValidatorNodeProviderEvents } from '../abi/ValidatorNodeProvider'; -import { ValidatorNodeProvider } from '../model'; +import { NodeProvider } from '../model'; import Handler from './Handler'; export default class validatorNodeProviderUnpaused implements Handler { - constructor(private providers: Map) {} + constructor(private providers: Map) {} async handle(log: Log, block: BlockData, ctx: DataHandlerContext) { if (log.topics[0] === ValidatorNodeProviderEvents.Unpaused.topic) { const address = log.address.toLowerCase(); const provider = this.providers.get(address) ?? - (await ctx.store.get(ValidatorNodeProvider, address)); + (await ctx.store.get(NodeProvider, address)); if (provider) { provider.paused = false; diff --git a/src/main.ts b/src/main.ts index cbf9888..9005f21 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,8 +36,8 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { nfts, erc721Deposits, authorities, - validatorNodeProviders, - validatorNodes, + nodeProviders, + nodes, } = eventHandler.getValues(); const total = eventHandler.getTotalHandled(); @@ -56,6 +56,6 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { await ctx.store.upsert([...deposits.values()]); await ctx.store.upsert([...erc721Deposits.values()]); await ctx.store.upsert([...inputs.values()]); - await ctx.store.upsert([...validatorNodeProviders.values()]); - await ctx.store.upsert([...validatorNodes.values()]); + await ctx.store.upsert([...nodeProviders.values()]); + await ctx.store.upsert([...nodes.values()]); }); diff --git a/tests/handlers/ValidatorNodeFinancialRunway.test.ts b/tests/handlers/ValidatorNodeFinancialRunway.test.ts index c60055d..fd33212 100644 --- a/tests/handlers/ValidatorNodeFinancialRunway.test.ts +++ b/tests/handlers/ValidatorNodeFinancialRunway.test.ts @@ -1,11 +1,7 @@ import { EntityClass, FindOneOptions } from '@subsquid/typeorm-store'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import ValidatorNodeFinancialRunway from '../../src/handlers/ValidatorNodeFinancialRunway'; -import { - Application, - ValidatorNode, - ValidatorNodeProvider, -} from '../../src/model'; +import { Application, Node, NodeProvider } from '../../src/model'; import { Logs, application, @@ -15,29 +11,29 @@ import { } from '../stubs/validatorNodeProvider'; vi.mock('../../src/model/', async () => { - const ValidatorNodeProvider = vi.fn(); - const ValidatorNode = vi.fn(); + const NodeProvider = vi.fn(); + const Node = vi.fn(); const Application = vi.fn(); + const FunctionType = { READER: 'READER', VALIDATOR: 'VALIDATOR' }; return { - ValidatorNodeProvider, - ValidatorNode, + NodeProvider, + Node, Application, + FunctionType, }; }); -const ValidatorNodeMock = vi.mocked(ValidatorNode); +const NodeMock = vi.mocked(Node); describe('ValidatorNodeFinancialRunway', () => { let handler: ValidatorNodeFinancialRunway; - const providersStorage = new Map(); - const nodesStorage = new Map(); + const providersStorage = new Map(); + const nodesStorage = new Map(); const applicationStorage = new Map(); beforeEach(() => { - ValidatorNodeMock.mockImplementation( - (args) => ({ ...args } as ValidatorNode), - ); + NodeMock.mockImplementation((args) => ({ ...args } as Node)); handler = new ValidatorNodeFinancialRunway( applicationStorage, @@ -79,6 +75,7 @@ describe('ValidatorNodeFinancialRunway', () => { expect(node.id).toEqual(`${node.provider.id}-${node.application.id}`); expect(node.application).toBeDefined(); + expect(node.type).toEqual('VALIDATOR'); expect(node.provider).toBeDefined(); expect(node.runway).toEqual(1702321200000n); expect(node.location).not.toBeDefined(); @@ -91,8 +88,7 @@ describe('ValidatorNodeFinancialRunway', () => { id: FindOneOptions | string, ): Promise => { if (entityClass === Application) return application; - if (entityClass === ValidatorNodeProvider) - return validatorNodeProvider; + if (entityClass === NodeProvider) return validatorNodeProvider; return undefined; }, diff --git a/tests/handlers/ValidatorNodeMachineLocation.test.ts b/tests/handlers/ValidatorNodeMachineLocation.test.ts index 9a091dc..82c510e 100644 --- a/tests/handlers/ValidatorNodeMachineLocation.test.ts +++ b/tests/handlers/ValidatorNodeMachineLocation.test.ts @@ -1,11 +1,7 @@ import { EntityClass, FindOneOptions } from '@subsquid/typeorm-store'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import ValidatorNodeMachineLocation from '../../src/handlers/ValidatorNodeMachineLocation'; -import { - Application, - ValidatorNode, - ValidatorNodeProvider, -} from '../../src/model'; +import { Application, Node, NodeProvider } from '../../src/model'; import { Logs, application, @@ -15,29 +11,29 @@ import { } from '../stubs/validatorNodeProvider'; vi.mock('../../src/model/', async () => { - const ValidatorNodeProvider = vi.fn(); - const ValidatorNode = vi.fn(); + const NodeProvider = vi.fn(); + const Node = vi.fn(); const Application = vi.fn(); + const FunctionType = { READER: 'READER', VALIDATOR: 'VALIDATOR' }; return { - ValidatorNodeProvider, - ValidatorNode, + NodeProvider, + Node, Application, + FunctionType, }; }); -const ValidatorNodeMock = vi.mocked(ValidatorNode); +const NodeMock = vi.mocked(Node); describe('ValidatorNodeMachineLocation', () => { let handler: ValidatorNodeMachineLocation; - const providersStorage = new Map(); - const nodesStorage = new Map(); + const providersStorage = new Map(); + const nodesStorage = new Map(); const applicationStorage = new Map(); beforeEach(() => { - ValidatorNodeMock.mockImplementation( - (args) => ({ ...args } as ValidatorNode), - ); + NodeMock.mockImplementation((args) => ({ ...args } as Node)); // defaults to find nothing in the "DB" vi.spyOn(ctx.store, 'get').mockResolvedValue(undefined); @@ -80,6 +76,7 @@ describe('ValidatorNodeMachineLocation', () => { const [[id, node]] = nodesStorage.entries(); expect(node.id).toEqual(`${node.provider.id}-${node.application.id}`); + expect(node.type).toEqual('VALIDATOR'); expect(node.application).toBeDefined(); expect(node.provider).toBeDefined(); expect(node.location).toEqual( @@ -94,8 +91,7 @@ describe('ValidatorNodeMachineLocation', () => { id: FindOneOptions | string, ): Promise => { if (entityClass === Application) return application; - if (entityClass === ValidatorNodeProvider) - return validatorNodeProvider; + if (entityClass === NodeProvider) return validatorNodeProvider; return undefined; }, diff --git a/tests/handlers/ValidatorNodeProviderCreated.test.ts b/tests/handlers/ValidatorNodeProviderCreated.test.ts index 704f144..129bfec 100644 --- a/tests/handlers/ValidatorNodeProviderCreated.test.ts +++ b/tests/handlers/ValidatorNodeProviderCreated.test.ts @@ -2,7 +2,7 @@ import { EntityClass, FindOneOptions } from '@subsquid/typeorm-store'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import ValidatorNodeProviderCreated from '../../src/handlers/ValidatorNodeProviderCreated'; import TokenHelper from '../../src/handlers/helpers/TokenHelper'; -import { Authority, Token, ValidatorNodeProvider } from '../../src/model'; +import { Authority, NodeProvider, Token } from '../../src/model'; import { Logs, TokenAddress, @@ -15,26 +15,29 @@ import { } from '../stubs/validatorNodeProvider'; vi.mock('../../src/model/', async () => { - const ValidatorNodeProvider = vi.fn(); + const NodeProvider = vi.fn(); const Authority = vi.fn(); const Token = vi.fn(); + const FunctionType = { READER: 'READER', VALIDATOR: 'VALIDATOR' }; return { - ValidatorNodeProvider, + NodeProvider, Authority, Token, + FunctionType, }; }); -const ValidatorNodeProviderMock = vi.mocked(ValidatorNodeProvider); +const NodeProviderMock = vi.mocked(NodeProvider); const AuthorityMock = vi.mocked(Authority); describe('ValidatorNodeProviderCreated', () => { let handler: ValidatorNodeProviderCreated; - const providerStorage = new Map(); + const providerStorage = new Map(); const tokenStorage = new Map(); const authorityStorage = new Map(); const expectedProvider = { + type: 'VALIDATOR', authority: { id: '0x83e4283f7eab201b06f749f683f27cfda294ab81', }, @@ -51,8 +54,8 @@ describe('ValidatorNodeProviderCreated', () => { }; beforeEach(() => { - ValidatorNodeProviderMock.mockImplementation( - (args) => ({ ...args } as ValidatorNodeProvider), + NodeProviderMock.mockImplementation( + (args) => ({ ...args } as NodeProvider), ); AuthorityMock.mockImplementation((args) => ({ ...args } as Authority)); diff --git a/tests/handlers/ValidatorNodeProviderPaused.test.ts b/tests/handlers/ValidatorNodeProviderPaused.test.ts index 35e741c..a03c064 100644 --- a/tests/handlers/ValidatorNodeProviderPaused.test.ts +++ b/tests/handlers/ValidatorNodeProviderPaused.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import ValidatorNodeProviderPaused from '../../src/handlers/ValidatorNodeProviderPaused'; -import { ValidatorNodeProvider } from '../../src/model'; +import { NodeProvider } from '../../src/model'; import { Logs, blockData, @@ -9,16 +9,18 @@ import { } from '../stubs/validatorNodeProvider'; vi.mock('../../src/model/', async () => { - const ValidatorNodeProvider = vi.fn(); + const NodeProvider = vi.fn(); + const FunctionType = { READER: 'READER', VALIDATOR: 'VALIDATOR' }; return { - ValidatorNodeProvider, + NodeProvider, + FunctionType, }; }); describe('ValidatorNodeProviderPaused', () => { let handler: ValidatorNodeProviderPaused; - const providerStorage = new Map(); + const providerStorage = new Map(); beforeEach(() => { handler = new ValidatorNodeProviderPaused(providerStorage); diff --git a/tests/handlers/ValidatorNodeProviderUnpaused.test.ts b/tests/handlers/ValidatorNodeProviderUnpaused.test.ts index 6af86fc..28a84c0 100644 --- a/tests/handlers/ValidatorNodeProviderUnpaused.test.ts +++ b/tests/handlers/ValidatorNodeProviderUnpaused.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import ValidatorNodeProviderUnpaused from '../../src/handlers/ValidatorNodeProviderUnpaused'; -import { ValidatorNodeProvider } from '../../src/model'; +import { NodeProvider } from '../../src/model'; import { Logs, blockData, @@ -9,16 +9,18 @@ import { } from '../stubs/validatorNodeProvider'; vi.mock('../../src/model/', async () => { - const ValidatorNodeProvider = vi.fn(); + const NodeProvider = vi.fn(); + const FunctionType = { READER: 'READER', VALIDATOR: 'VALIDATOR' }; return { - ValidatorNodeProvider, + NodeProvider, + FunctionType, }; }); describe('ValidatorNodeProviderUnpaused', () => { let handler: ValidatorNodeProviderUnpaused; - const providerStorage = new Map(); + const providerStorage = new Map(); beforeEach(() => { handler = new ValidatorNodeProviderUnpaused(providerStorage); diff --git a/tests/stubs/validatorNodeProvider.ts b/tests/stubs/validatorNodeProvider.ts index 72933e0..6da0318 100644 --- a/tests/stubs/validatorNodeProvider.ts +++ b/tests/stubs/validatorNodeProvider.ts @@ -12,9 +12,10 @@ import { import { Application, Authority, + FunctionType, + Node, + NodeProvider, Token, - ValidatorNode, - ValidatorNodeProvider, } from '../../src/model'; export const CID = 'QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR'; @@ -41,6 +42,7 @@ export const application = { factory: { id: CartesiDAppFactoryAddress, applications: [] }, id: DappAddress.toLowerCase(), inputs: [], + nodes: [], owner: '0x', timestamp: 1691779848n, } satisfies Application; @@ -53,7 +55,8 @@ export const validatorNodeProvider = { price: 400000000000000n, paused: false, nodes: [], -} satisfies ValidatorNodeProvider; + type: FunctionType.VALIDATOR, +} satisfies NodeProvider; export const validatorNode = { application, @@ -61,7 +64,8 @@ export const validatorNode = { id: `${validatorNodeProvider.id}-${application.id}`, location: null, runway: null, -} satisfies ValidatorNode; + type: FunctionType.VALIDATOR, +} satisfies Node; export const Logs = { paused: {