-
Notifications
You must be signed in to change notification settings - Fork 1
feat(mbe): use generated client for type safety #32
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import nock from 'nock'; | |
| import { app as expressApp } from '../../masterExpressApp'; | ||
| import { AppMode, MasterExpressConfig, TlsMode } from '../../types'; | ||
| import { Environments } from '@bitgo/sdk-core'; | ||
| import assert from 'assert'; | ||
|
|
||
| describe('POST /api/:coin/wallet/generate', () => { | ||
| let agent: request.SuperAgentTest; | ||
|
|
@@ -45,8 +46,6 @@ describe('POST /api/:coin/wallet/generate', () => { | |
| const userKeychainNock = nock(enclavedExpressUrl) | ||
| .post(`/api/${coin}/key/independent`, { | ||
| source: 'user', | ||
| coin: coin, | ||
| type: 'independent', | ||
| }) | ||
| .reply(200, { | ||
| pub: 'xpub_user', | ||
|
|
@@ -57,8 +56,6 @@ describe('POST /api/:coin/wallet/generate', () => { | |
| const backupKeychainNock = nock(enclavedExpressUrl) | ||
| .post(`/api/${coin}/key/independent`, { | ||
| source: 'backup', | ||
| coin: coin, | ||
| type: 'independent', | ||
| }) | ||
| .reply(200, { | ||
| pub: 'xpub_backup', | ||
|
|
@@ -155,18 +152,11 @@ describe('POST /api/:coin/wallet/generate', () => { | |
| allowSelfSigned: true, | ||
| }; | ||
|
|
||
| const app = expressApp(invalidConfig as MasterExpressConfig); | ||
| const testAgent = request.agent(app); | ||
|
|
||
| const response = await testAgent | ||
| .post(`/api/${coin}/wallet/generate`) | ||
| .set('Authorization', `Bearer ${accessToken}`) | ||
| .send({ | ||
| label: 'test-wallet', | ||
| }); | ||
|
|
||
| response.status.should.equal(500); | ||
| response.body.should.have.property('error'); | ||
| response.body.error.should.equal('Please configure enclaved express configs.'); | ||
| try { | ||
| expressApp(invalidConfig as MasterExpressConfig); | ||
| assert(false, 'Expected error to be thrown when enclaved express client is not configured'); | ||
| } catch (e) { | ||
| (e as Error).message.should.equal('enclavedExpressUrl and enclavedExpressCert are required'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait im v confused. why is this removing the calls to the actual API?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because the client is constructed when the routes are configured, so it'll fail here: https://github.com/BitGo/enclaved-bitgo-express/blob/3cb0dc2f3cee8eee5b5644abbc9360f9847379e5/src/masterBitgoExpress/enclavedExpressClient.ts#L62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what i mean is, how is this test defining the client to make calls to generate wallet?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for this case (when the config is invalid), the app won't startup. I can modify it so that the client is only created during the request, so it would fail then. |
||
| } | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { app as expressApp } from '../../masterExpressApp'; | |
| import { AppMode, MasterExpressConfig, TlsMode } from '../../types'; | ||
| import { Environments, Wallet } from '@bitgo/sdk-core'; | ||
| import { Coin } from 'bitgo'; | ||
| import assert from 'assert'; | ||
|
|
||
| describe('POST /api/:coin/wallet/:walletId/sendmany', () => { | ||
| let agent: request.SuperAgentTest; | ||
|
|
@@ -277,26 +278,14 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => { | |
| allowSelfSigned: true, | ||
| }; | ||
|
|
||
| const app = expressApp(invalidConfig as MasterExpressConfig); | ||
| const testAgent = request.agent(app); | ||
|
|
||
| const response = await testAgent | ||
| .post(`/api/${coin}/wallet/${walletId}/sendMany`) | ||
| .set('Authorization', `Bearer ${accessToken}`) | ||
| .send({ | ||
| recipients: [ | ||
| { | ||
| address: 'tb1qtest1', | ||
| amount: '100000', | ||
| }, | ||
| ], | ||
| source: 'user', | ||
| pubkey: 'xpub_user', | ||
| }); | ||
|
|
||
| response.status.should.equal(500); | ||
| response.body.should.have.property('error'); | ||
| response.body.error.should.equal('Please configure enclaved express configs.'); | ||
| try { | ||
| expressApp(invalidConfig as MasterExpressConfig); | ||
| assert(false, 'Expected error to be thrown when enclaved express client is not configured'); | ||
| } catch (error) { | ||
| (error as Error).message.should.equal( | ||
| 'enclavedExpressUrl and enclavedExpressCert are required', | ||
| ); | ||
| } | ||
|
Comment on lines
+281
to
+288
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? why is this just calling the app?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above. |
||
| }); | ||
|
|
||
| it('should fail when transaction verification returns false', async () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { EnclavedAPiSpec as ApiSpec } from './enclavedApiSpec'; | ||
| import { HealthCheckApiSpec } from './healthCheck'; | ||
|
|
||
| export const EnclavedApiSpec = { | ||
| ...HealthCheckApiSpec, | ||
| ...ApiSpec, | ||
| }; | ||
| export type EnclavedApiSpec = typeof EnclavedApiSpec; |
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.
why is this removed?
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.
because it's not used in the actual request. Look at the Api spec for Enclaved Express.
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.