-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store
Epoch
s in IndexedDB and serve from extension (#699)
* Add epochs to IndexedDB * Fix how epochs are stored in IndexedDB * Store epochs in the database via the block processor * Make an extension-local impl of the SCT Service * Clean up * Revert styling * Use descriptive naming * Fix mock
- Loading branch information
1 parent
fae5b05
commit 873303d
Showing
11 changed files
with
220 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
PRAX=lkpmkhpnhknhmibgnmmhdhgdilepfghe | ||
IDB_VERSION=25 | ||
IDB_VERSION=26 | ||
USDC_ASSET_ID="reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg=" | ||
MINIFRONT_URL=https://app.testnet.penumbra.zone/ | ||
PENUMBRA_NODE_PD_URL=https://grpc.testnet.penumbra.zone/ |
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,53 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { epochByHeight } from './epoch-by-height'; | ||
import { IndexedDbMock, MockServices } from '../test-utils'; | ||
import { HandlerContext, createContextValues, createHandlerContext } from '@connectrpc/connect'; | ||
import { QueryService as SctService } from '@buf/penumbra-zone_penumbra.connectrpc_es/penumbra/core/component/sct/v1/sct_connect'; | ||
import { ServicesInterface } from '@penumbra-zone/types'; | ||
import { servicesCtx } from '../../ctx'; | ||
import { | ||
Epoch, | ||
EpochByHeightRequest, | ||
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/sct/v1/sct_pb'; | ||
|
||
describe('EpochByHeight request handler', () => { | ||
let mockServices: MockServices; | ||
let mockIndexedDb: IndexedDbMock; | ||
let mockCtx: HandlerContext; | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
|
||
mockIndexedDb = { | ||
getEpochByHeight: vi.fn(), | ||
}; | ||
mockServices = { | ||
getWalletServices: vi.fn(() => | ||
Promise.resolve({ indexedDb: mockIndexedDb }), | ||
) as MockServices['getWalletServices'], | ||
}; | ||
mockCtx = createHandlerContext({ | ||
service: SctService, | ||
method: SctService.methods.epochByHeight, | ||
protocolName: 'mock', | ||
requestMethod: 'MOCK', | ||
url: '/mock', | ||
contextValues: createContextValues().set( | ||
servicesCtx, | ||
mockServices as unknown as ServicesInterface, | ||
), | ||
}); | ||
}); | ||
|
||
it('returns an `EpochByHeightResponse` with the result of the database query', async () => { | ||
const expected = new Epoch({ startHeight: 0n, index: 0n }); | ||
|
||
mockIndexedDb.getEpochByHeight?.mockResolvedValue(expected); | ||
const req = new EpochByHeightRequest({ height: 0n }); | ||
|
||
const result = await epochByHeight(req, mockCtx); | ||
|
||
expect(result.epoch).toBeInstanceOf(Epoch); | ||
expect((result.epoch as Epoch).toJson()).toEqual(expected.toJson()); | ||
}); | ||
}); |
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,14 @@ | ||
import { EpochByHeightResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/sct/v1/sct_pb'; | ||
import { Impl } from '.'; | ||
import { servicesCtx } from '../../ctx'; | ||
|
||
export const epochByHeight: Impl['epochByHeight'] = async (req, ctx) => { | ||
const { height } = req; | ||
|
||
const services = ctx.values.get(servicesCtx); | ||
const { indexedDb } = await services.getWalletServices(); | ||
|
||
const epoch = await indexedDb.getEpochByHeight(height); | ||
|
||
return new EpochByHeightResponse({ epoch }); | ||
}; |
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,9 @@ | ||
import { QueryService as SctService } from '@buf/penumbra-zone_penumbra.connectrpc_es/penumbra/core/component/sct/v1/sct_connect'; | ||
import { ServiceImpl } from '@connectrpc/connect'; | ||
import { epochByHeight } from './epoch-by-height'; | ||
|
||
export type Impl = ServiceImpl<typeof SctService>; | ||
|
||
export const sctImpl: Impl = { | ||
epochByHeight, | ||
}; |
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