-
Notifications
You must be signed in to change notification settings - Fork 347
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
Reload chainTypes #2505
Merged
Merged
Reload chainTypes #2505
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05ea8b7
Reload chainTypes when project changed, also fixed UTC issue in docke…
jiqiang90 9006d56
Merge branch 'main' into reload-chainTypes
jiqiang90 bd28510
generalize load/reload
jiqiang90 c2af092
Merge remote-tracking branch 'origin/main' into reload-chainTypes
jiqiang90 3ca37de
update
jiqiang90 456ab1a
update
jiqiang90 a38a27d
Update packages/node/CHANGELOG.md
jiqiang90 e51c4cc
address comments
jiqiang90 9791576
remove unused
jiqiang90 8121e48
remove unused
jiqiang90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
import { EventEmitter2 } from '@nestjs/event-emitter'; | ||
import { | ||
ConnectionPoolService, | ||
ConnectionPoolStateManager, | ||
NodeConfig, | ||
ProjectUpgradeService, | ||
} from '@subql/node-core'; | ||
import { SubstrateDatasourceKind, SubstrateHandlerKind } from '@subql/types'; | ||
import { GraphQLSchema } from 'graphql'; | ||
import { SubqueryProject } from '../configure/SubqueryProject'; | ||
import { ApiService } from './api.service'; | ||
import { ApiPromiseConnection } from './apiPromise.connection'; | ||
import { DsProcessorService } from './ds-processor.service'; | ||
import { DynamicDsService } from './dynamic-ds.service'; | ||
import { ProjectService } from './project.service'; | ||
|
||
const nodeConfig = new NodeConfig({ | ||
subquery: 'test', | ||
subqueryName: 'test', | ||
networkEndpoint: ['https://polkadot.api.onfinality.io/public'], | ||
dictionaryTimeout: 10, | ||
}); | ||
|
||
function testSubqueryProject(): SubqueryProject { | ||
return { | ||
id: 'test', | ||
root: './', | ||
network: { | ||
endpoint: ['https://polkadot.api.onfinality.io/public'], | ||
chainId: | ||
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', | ||
}, | ||
dataSources: [ | ||
{ | ||
kind: SubstrateDatasourceKind.Runtime, | ||
startBlock: 1, | ||
mapping: { | ||
file: '', | ||
handlers: [ | ||
{ handler: 'testSandbox', kind: SubstrateHandlerKind.Event }, | ||
], | ||
}, | ||
}, | ||
], | ||
schema: new GraphQLSchema({}), | ||
templates: [], | ||
chainTypes: { | ||
types: { | ||
TestType: 'u32', | ||
}, | ||
}, | ||
applyCronTimestamps: () => jest.fn(), | ||
} as unknown as SubqueryProject; | ||
} | ||
|
||
const demoProjects = [ | ||
testSubqueryProject(), | ||
{ | ||
parent: { | ||
utilBlock: 5, | ||
reference: '0', | ||
}, | ||
...testSubqueryProject(), | ||
}, | ||
] as SubqueryProject[]; | ||
|
||
jest.setTimeout(10_000); | ||
|
||
describe('ProjectService', () => { | ||
let service: ProjectService; | ||
|
||
const apiService = new ApiService( | ||
demoProjects[0], | ||
new ConnectionPoolService<ApiPromiseConnection>( | ||
nodeConfig, | ||
new ConnectionPoolStateManager(), | ||
), | ||
new EventEmitter2(), | ||
nodeConfig, | ||
); | ||
|
||
beforeEach(async () => { | ||
// Api service init at bootstrap | ||
await apiService.init(); | ||
|
||
const projectUpgradeService = await ProjectUpgradeService.create( | ||
demoProjects[0], | ||
(id) => Promise.resolve(demoProjects[parseInt(id, 10)]), | ||
1, | ||
); | ||
|
||
(projectUpgradeService as any).init = jest.fn(); | ||
(projectUpgradeService as any).updateIndexedDeployments = jest.fn(); | ||
|
||
service = new ProjectService( | ||
{ | ||
validateProjectCustomDatasources: jest.fn(), | ||
} as unknown as DsProcessorService, | ||
apiService, | ||
null as unknown as any, | ||
null as unknown as any, | ||
{ query: jest.fn() } as unknown as any, | ||
demoProjects[0], | ||
projectUpgradeService, | ||
{ | ||
initCoreTables: jest.fn(), | ||
storeCache: { metadata: {}, flushCache: jest.fn() }, | ||
} as unknown as any, | ||
{ unsafe: false } as unknown as NodeConfig, | ||
{ | ||
getDynamicDatasources: jest.fn().mockResolvedValue([]), | ||
init: jest.fn(), | ||
} as unknown as DynamicDsService, | ||
null as unknown as any, | ||
null as unknown as any, | ||
); | ||
|
||
// Mock db related returns | ||
(service as any).ensureProject = jest.fn().mockResolvedValue('mock-schema'); | ||
(service as any).ensureMetadata = jest.fn(); | ||
(service as any).initDbSchema = jest.fn(); | ||
(service as any).initUnfinalizedInternal = jest | ||
.fn() | ||
.mockResolvedValue(undefined); | ||
}); | ||
|
||
it('reload chainTypes when project changed, on init', async () => { | ||
const spyOnApiUpdateChainTypes = jest.spyOn(apiService, 'updateChainTypes'); | ||
// mock last processed height | ||
(service as any).getLastProcessedHeight = jest.fn().mockResolvedValue(4); | ||
|
||
await service.init(5); | ||
|
||
expect(spyOnApiUpdateChainTypes).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be same line as https://github.com/subquery/subql/pull/2505/files#diff-c9f4c413e59e6f6047e10cd5abdc7e5aef91fd9d24a84732459c7d6acf395631R84