-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add async support for sendMany #243
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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,216 @@ | ||
| import 'should'; | ||
| import assert from 'assert'; | ||
| import nock from 'nock'; | ||
| import sinon from 'sinon'; | ||
| import { Keychain, PrebuildTransactionResult } from '@bitgo-beta/sdk-core'; | ||
| import { | ||
| buildMultisigSignBody, | ||
| parseMultisigSignJobContext, | ||
| SignedMultisigTransactionSchema, | ||
| submitMultisigSignJob, | ||
| } from '../../../masterBitgoExpress/handlers/utils/multisigSignUtils'; | ||
| import { AppMode, KeySource, MasterExpressConfig } from '../../../shared/types'; | ||
| import { BitGoRequest } from '../../../types/request'; | ||
| import { DEFAULT_ASYNC_MODE_CONFIG } from './testUtils'; | ||
| import { OsoBridgeClient } from '../../../masterBitgoExpress/clients/bridgeClient'; | ||
|
|
||
| describe('multisigSignUtils', () => { | ||
| const bridgeUrl = 'http://bridge.invalid'; | ||
| const coin = 'tbtc'; | ||
| const txPrebuild = { | ||
| txHex: '70736274ff', | ||
| txInfo: { nP2SHInputs: 0, nSegwitInputs: 1, nOutputs: 1 }, | ||
| walletId: 'test-wallet-id', | ||
| } as PrebuildTransactionResult; | ||
| const userPub = | ||
| 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'; | ||
|
|
||
| describe('buildMultisigSignBody', () => { | ||
| it('builds the AWM multisig sign payload', () => { | ||
| const body = buildMultisigSignBody({ | ||
| source: 'user', | ||
| signingKeychain: { pub: userPub, source: 'user' } as Keychain, | ||
| txPrebuilt: txPrebuild, | ||
| walletPubs: [userPub, 'backup-pub', 'bitgo-pub'], | ||
| }); | ||
|
|
||
| body.should.eql({ | ||
| source: 'user', | ||
| pub: userPub, | ||
| txPrebuild, | ||
| walletPubs: [userPub, 'backup-pub', 'bitgo-pub'], | ||
| }); | ||
| }); | ||
|
|
||
| it('omits walletPubs when not provided', () => { | ||
| const body = buildMultisigSignBody({ | ||
| source: 'backup', | ||
| signingKeychain: { pub: userPub, source: 'backup' } as Keychain, | ||
| txPrebuilt: txPrebuild, | ||
| }); | ||
|
|
||
| body.should.eql({ | ||
| source: 'backup', | ||
| pub: userPub, | ||
| txPrebuild, | ||
| }); | ||
| assert(!('walletPubs' in body)); | ||
| }); | ||
|
|
||
| it('throws when signing keychain pub is missing', () => { | ||
| (() => | ||
| buildMultisigSignBody({ | ||
| source: 'user', | ||
| signingKeychain: { source: 'user' } as Keychain, | ||
| txPrebuilt: txPrebuild, | ||
| })).should.throw(/Signing keychain pub not found for user/); | ||
| }); | ||
| }); | ||
|
|
||
| describe('submitMultisigSignJob', () => { | ||
| afterEach(() => { | ||
| sinon.restore(); | ||
| nock.cleanAll(); | ||
| }); | ||
|
|
||
| function makeAsyncReq(): BitGoRequest<MasterExpressConfig> { | ||
| return { | ||
| config: { | ||
| appMode: AppMode.MASTER_EXPRESS, | ||
| asyncModeConfig: { | ||
| enabled: true, | ||
| awmAsyncUrl: bridgeUrl, | ||
| pollIntervalInMs: 30000, | ||
| jobTtlInSeconds: 3600, | ||
| jobTtlMpcInSeconds: 7200, | ||
| }, | ||
| } as MasterExpressConfig, | ||
| bridgeClient: new OsoBridgeClient(bridgeUrl, 60000), | ||
| } as unknown as BitGoRequest<MasterExpressConfig>; | ||
| } | ||
|
|
||
| it('returns null when async mode is disabled', async () => { | ||
| const req = { | ||
| config: { asyncModeConfig: DEFAULT_ASYNC_MODE_CONFIG }, | ||
| } as BitGoRequest<MasterExpressConfig>; | ||
|
|
||
| const result = await submitMultisigSignJob( | ||
| req, | ||
| coin, | ||
| { | ||
| source: 'user', | ||
| pub: userPub, | ||
| txPrebuild, | ||
| }, | ||
| { | ||
| walletId: 'test-wallet-id', | ||
| wpSubmitKind: 'sendMany', | ||
| wpSubmitParams: { recipients: [] }, | ||
| }, | ||
| ); | ||
|
|
||
| assert.strictEqual(result, null); | ||
| }); | ||
|
|
||
| it('submits multisig_sign to the bridge with correct path and headers', async () => { | ||
| const jobId = 'job-123'; | ||
| const signBody = buildMultisigSignBody({ | ||
| source: 'user', | ||
| signingKeychain: { pub: userPub, source: 'user' } as Keychain, | ||
| txPrebuilt: txPrebuild, | ||
| }); | ||
| const jobContext = { | ||
| walletId: 'test-wallet-id', | ||
| wpSubmitKind: 'sendMany' as const, | ||
| wpSubmitParams: { recipients: [{ address: 'tb1qtest', amount: '100000' }] }, | ||
| }; | ||
|
|
||
| const bridgeNock = nock(bridgeUrl) | ||
| .post(`/api/${coin}/multisig/sign`, (body) => { | ||
| body.should.eql({ ...signBody, ...jobContext }); | ||
| return true; | ||
| }) | ||
| .matchHeader('X-OSO-Source', KeySource.USER) | ||
| .matchHeader('X-OSO-Operation', 'multisig_sign') | ||
| .reply(202, { jobId }); | ||
|
|
||
| const result = await submitMultisigSignJob(makeAsyncReq(), coin, signBody, jobContext); | ||
| assert(result); | ||
| result.should.eql({ jobId, status: 'pending' }); | ||
| bridgeNock.done(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('SignedMultisigTransactionSchema', () => { | ||
| it('accepts a top-level txHex', () => { | ||
| SignedMultisigTransactionSchema.parse({ txHex: 'signed-tx-hex' }).should.eql({ | ||
| txHex: 'signed-tx-hex', | ||
| }); | ||
| }); | ||
|
|
||
| it('accepts halfSigned.txHex from UTXO user signing', () => { | ||
| SignedMultisigTransactionSchema.parse({ | ||
| halfSigned: { txHex: 'signed-tx-hex' }, | ||
| source: 'user', | ||
| pub: userPub, | ||
| }).should.eql({ | ||
| halfSigned: { txHex: 'signed-tx-hex' }, | ||
| source: 'user', | ||
| pub: userPub, | ||
| }); | ||
| }); | ||
|
|
||
| it('accepts halfSigned.signature from ETH-style signing', () => { | ||
| SignedMultisigTransactionSchema.parse({ | ||
| halfSigned: { | ||
| signature: '0xabc', | ||
| operationHash: '0xdef', | ||
| recipients: [{ address: '0x123', amount: '1000' }], | ||
| }, | ||
| }).should.eql({ | ||
| halfSigned: { | ||
| signature: '0xabc', | ||
| operationHash: '0xdef', | ||
| recipients: [{ address: '0x123', amount: '1000' }], | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('rejects bodies missing txHex and halfSigned', () => { | ||
| (() => SignedMultisigTransactionSchema.parse({ bad: 'shape' })).should.throw( | ||
| /expected txHex or halfSigned/, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('parseMultisigSignJobContext', () => { | ||
| it('parses walletId, wpSubmitKind, and wpSubmitParams from job body', () => { | ||
| parseMultisigSignJobContext({ | ||
| walletId: 'test-wallet-id', | ||
| wpSubmitKind: 'sendMany', | ||
| wpSubmitParams: { recipients: [] }, | ||
| source: 'user', | ||
| pub: userPub, | ||
| }).should.eql({ | ||
| walletId: 'test-wallet-id', | ||
| wpSubmitKind: 'sendMany', | ||
| wpSubmitParams: { recipients: [] }, | ||
| }); | ||
| }); | ||
|
|
||
| it('throws when wpSubmitKind is missing or unsupported', () => { | ||
| (() => | ||
| parseMultisigSignJobContext({ | ||
| walletId: 'test-wallet-id', | ||
| wpSubmitParams: { recipients: [] }, | ||
| })).should.throw(/unsupported wpSubmitKind/); | ||
|
|
||
| (() => | ||
| parseMultisigSignJobContext({ | ||
| walletId: 'test-wallet-id', | ||
| wpSubmitKind: 'accelerate', | ||
| wpSubmitParams: { recipients: [] }, | ||
| })).should.throw(/unsupported wpSubmitKind: accelerate/); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
nit: you can update the fixture here to use the halfSigned shape from sendMany.test.ts
this i think: