-
Notifications
You must be signed in to change notification settings - Fork 4
HCP publishing endpoint for first time account creation #996
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
base: main
Are you sure you want to change the base?
Conversation
fab113b to
4ca5f94
Compare
94c965f to
cca8f45
Compare
| const mockApiPromise = { | ||
| ...EventEmitter2.prototype, | ||
| isReady: Promise.resolve(), | ||
| tx: { | ||
| statefulStorage: { | ||
| applyItemActionsWithSignatureV2: jest.fn().mockImplementation(() => mockSubmittableExtrinsic('0x01020304')), | ||
| upsertPageWithSignatureV2: jest.fn().mockImplementation(() => mockSubmittableExtrinsic('0x05060708')), | ||
| }, | ||
| }, | ||
| }; |
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.
nit: In order to keep mocks in a single place, and build up a complete chain mock over time, there's mockApiPromise in testlib/polkadot-api.mock.spec.ts. The pattern has been:
- Add the mocked functions with an empty
jest.fn()as the implementation - Override with a specific mock implementation in your test; this can be done in the top
beforeAll(...)or in any specific test.
ie, in testlib/polkadot-api.mock.spec.ts, add to the tx property:
statefulStorage: {
applyItemActionsWithSignatureV2: jest.fn(),
upsertPageWithSignatureV2: jest.fn(),
}Then in your test suite, just:
jest.spyOn(mockApiPromise.tx.statefulStorage, 'applyItemActionsWithSignatureV2').mockResolvedValue(mockSubmittableExtrinsic('0x01020304'));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.
nit: The pattern may not always have been followed, but we can try... my opinion, FWIW:
controllers should have little to no business logic. They just marshall the request/response; business logic is in a service component. This makes it easy to propagate endpoints to new controllers/API versions without having to duplicate business logic.
This also means that unit tests can focus on the service components, while controllers get tested primarily with a live HTTP request/response in an E2E test.
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.
I had intended to make a service for this and backed out because it seemed like it was not enough code to be worth it. But I buy your separation of concerns argument.
| await this.cacheTransactionStatus(payWithCapacityTxHash, status); | ||
| } catch (error: unknown) { | ||
| if (error instanceof DelayedError) { | ||
| job.moveToDelayed(Date.now(), job.token); |
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.
nit: worth noting here that this is a "fake" delay simply to put this job back on the queue--under proper circumstances, since we've now detected we're out of Capacity, an event should have been emitted that paused the queue until the next epoch, which prevents us from just spinning on transactions while we're out of Capacity.
| @@ -1,10 +1,16 @@ | |||
| #!/bin/bash | |||
|
|
|||
| function exit_err() { | |||
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.
I was tired of this script continuing even when e.g. Docker daemon wasn't running.
* spellchecking update: add to dictionary, make it quiet
Exit startup script on error Regen package-lock.json
- fix reference - controller tests passing
- e2e tests running properly
Co-authored-by: Joe Caputo <joseph.caputo@projectliberty.io>
Co-authored-by: Joe Caputo <joseph.caputo@projectliberty.io>
- remove some console logs - linting
ac7fcc0 to
7d9085b
Compare
This PR implements one endpoint in the account-api to be called by the MCP server, which will be sending it 3 payloads. It creates an array of 3 encoded calls and enqueues it to a separate HCP queue. The account-worker has a new function for processing the HCP queue, which calls payWithCapacityBatchAll with each set of 3 calls.
I'm not fond of the name ('publishAll') I came up with, happy to hear suggestions