Skip to content

Commit b7edf3f

Browse files
committed
test(mbe): fix eddsa orchestrator test
Ticket: WP-4760
1 parent 33aa23e commit b7edf3f

File tree

2 files changed

+49
-83
lines changed

2 files changed

+49
-83
lines changed

src/__tests__/api/master/eddsa.test.ts

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import {
99
TxRequestVersion,
1010
Environments,
1111
RequestTracer,
12+
EddsaUtils,
13+
openpgpUtils,
1214
} from '@bitgo/sdk-core';
1315
import { EnclavedExpressClient } from '../../../../src/api/master/clients/enclavedExpressClient';
1416
import { handleEddsaSigning } from '../../../../src/api/master/handlers/eddsa';
1517
import { BitGo } from 'bitgo';
18+
import { readKey } from 'openpgp';
1619

1720
describe('Eddsa Signing Handler', () => {
1821
let bitgo: BitGoBase;
@@ -75,7 +78,11 @@ describe('Eddsa Signing Handler', () => {
7578
};
7679
const userPubKey = 'test-user-pub-key';
7780

78-
const getGPGKeysStub = sinon.stub().resolves([{ pub: 'test-gpg-key' }]);
81+
const bitgoGpgKey = await openpgpUtils.generateGPGKeyPair('ed25519');
82+
const getGPGKeysStub = sinon.stub().resolves([{ pub: bitgoGpgKey.publicKey }]);
83+
84+
const pgpKey = await readKey({ armoredKey: bitgoGpgKey.publicKey });
85+
sinon.stub(EddsaUtils.prototype, 'getBitgoPublicGpgKey').resolves(pgpKey);
7986

8087
// Mock getTxRequest call
8188
const getTxRequestNock = nock(bitgoApiUrl)
@@ -139,13 +146,20 @@ describe('Eddsa Signing Handler', () => {
139146
derivationPath: 'm/0',
140147
signableHex: 'testMessage',
141148
},
142-
},
143-
],
144-
signatureShares: [
145-
{
146-
share: 'bitgo-to-user-r-share',
147-
from: 'bitgo',
148-
to: 'user',
149+
signatureShares: [
150+
{
151+
share: 'bitgo-to-user-r-share',
152+
from: 'bitgo',
153+
to: 'user',
154+
type: 'r',
155+
},
156+
{
157+
share: 'user-to-bitgo-r-share',
158+
from: 'user',
159+
to: 'bitgo',
160+
type: 'r',
161+
},
162+
],
149163
},
150164
],
151165
},
@@ -169,7 +183,14 @@ describe('Eddsa Signing Handler', () => {
169183
.get(`/api/v2/wallet/${walletId}/txrequests`)
170184
.query({ txRequestIds: 'test-tx-request-id', latest: true })
171185
.matchHeader('any', () => true)
172-
.reply(200, txRequest);
186+
.reply(200, {
187+
txRequests: [
188+
{
189+
...txRequest,
190+
state: 'signed',
191+
},
192+
],
193+
});
173194

174195
// Mock MPC commitment signing
175196
const signMpcCommitmentNockEbe = nock(enclavedExpressUrl)
@@ -185,14 +206,27 @@ describe('Eddsa Signing Handler', () => {
185206
const signMpcRShareNockEbe = nock(enclavedExpressUrl)
186207
.post(`/api/${coin}/mpc/sign/r`)
187208
.reply(200, {
188-
rShare: { share: 'r-share' },
209+
rShare: {
210+
rShares: [
211+
{ r: 'r-share', R: 'R-share' },
212+
{ r: 'r-share-2', R: 'R-share-2' },
213+
{ r: 'r-share-3', R: 'R-share-3' },
214+
{ r: 'r-share-4', R: 'R-share-4', i: 3, j: 1 },
215+
],
216+
},
189217
});
190218

191219
// Mock MPC G-share signing
192220
const signMpcGShareNockEbe = nock(enclavedExpressUrl)
193221
.post(`/api/${coin}/mpc/sign/g`)
194222
.reply(200, {
195-
gShare: { share: 'g-share' },
223+
gShare: {
224+
r: 'r',
225+
gamma: 'gamma',
226+
i: 1, // USER position
227+
j: 3, // BITGO position
228+
n: 4,
229+
},
196230
});
197231

198232
(bitgo as any).getGPGKeys = getGPGKeysStub;
@@ -206,9 +240,11 @@ describe('Eddsa Signing Handler', () => {
206240
reqId,
207241
);
208242

209-
result.should.eql(txRequest);
243+
result.should.eql({
244+
...txRequest,
245+
state: 'signed',
246+
});
210247

211-
sinon.assert.calledWith(getGPGKeysStub);
212248
getTxRequestNock.done();
213249
exchangeCommitmentsNock.done();
214250
offerRShareNock.done();

src/__tests__/api/master/sendMany.test.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -223,76 +223,6 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
223223
});
224224
});
225225

226-
// TODO: Fix send many tests
227-
// xdescribe('Send Many MPC:', () => {
228-
// it('should send many transactions by calling the enclaved express service', async () => {
229-
// // Mock wallet get request
230-
// const walletGetNock = nock(bitgoApiUrl)
231-
// .get(`/api/v2/${coin}/wallet/${walletId}`)
232-
// .matchHeader('any', () => true)
233-
// .reply(200, {
234-
// id: walletId,
235-
// type: 'cold',
236-
// subType: 'onPrem',
237-
// keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
238-
// multisigType: 'tss',
239-
// });
240-
//
241-
// // Mock keychain get request
242-
// const keychainGetNock = nock(bitgoApiUrl)
243-
// .get(`/api/v2/${coin}/key/user-key-id`)
244-
// .matchHeader('any', () => true)
245-
// .reply(200, {
246-
// id: 'user-key-id',
247-
// commonKeychain: 'common_keychain_user',
248-
// });
249-
//
250-
// const prebuildStub = sinon.stub(Wallet.prototype, 'prebuildTransaction').resolves({
251-
// txHex: 'prebuilt-tx-hex',
252-
// txInfo: {
253-
// nP2SHInputs: 1,
254-
// nSegwitInputs: 0,
255-
// nOutputs: 2,
256-
// },
257-
// walletId,
258-
// txRequestId: 'test-tx-request-id',
259-
// });
260-
//
261-
// const verifyStub = sinon.stub(Coin.Btc.prototype, 'verifyTransaction').resolves(true);
262-
//
263-
// // const eddsaSigningStub = sinon
264-
//
265-
// const response = await agent
266-
// .post(`/api/${coin}/wallet/${walletId}/sendMany`)
267-
// .set('Authorization', `Bearer ${accessToken}`)
268-
// .send({
269-
// recipients: [
270-
// {
271-
// address: 'tb1qtest1',
272-
// amount: '100000',
273-
// },
274-
// {
275-
// address: 'tb1qtest2',
276-
// amount: '200000',
277-
// },
278-
// ],
279-
// source: 'user',
280-
// commonKeychain: 'common_keychain_user',
281-
// });
282-
//
283-
// response.status.should.equal(200);
284-
// response.body.should.have.property('txid', 'test-tx-id');
285-
// response.body.should.have.property('status', 'signed');
286-
//
287-
// walletGetNock.done();
288-
// sinon.assert.calledOnce(prebuildStub);
289-
// sinon.assert.calledOnce(verifyStub);
290-
// keychainGetNock.done();
291-
// signNock.done();
292-
// submitNock.done();
293-
// });
294-
// });
295-
296226
it('should throw error when provided pubkey does not match wallet keychain', async () => {
297227
// Mock wallet get request
298228
const walletGetNock = nock(bitgoApiUrl)

0 commit comments

Comments
 (0)