-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-core): add bulkShareWallet method
Bulk wallet share sdk Ticket: CS-3699
- Loading branch information
1 parent
596b7c2
commit a6c6674
Showing
4 changed files
with
40 additions
and
537 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 |
---|---|---|
|
@@ -6,8 +6,6 @@ import * as nock from 'nock'; | |
import * as sinon from 'sinon'; | ||
import * as should from 'should'; | ||
import * as _ from 'lodash'; | ||
// import * as superagent from 'superagent'; | ||
// const superagent = require('superagent'); | ||
import * as utxoLib from '@bitgo/utxo-lib'; | ||
|
||
import { TestBitGo } from '@bitgo/sdk-test'; | ||
|
@@ -21,17 +19,13 @@ import { | |
GenerateWalletOptions, | ||
Wallet, | ||
isWalletWithKeychains, | ||
// BulkCreateShareOptions, | ||
BulkShareWalletOptions, | ||
OptionalKeychainEncryptedKey, | ||
KeychainWithEncryptedPrv, | ||
// getSharedSecret, | ||
} from '@bitgo/sdk-core'; | ||
import { BitGo } from '../../../src'; | ||
import { afterEach } from 'mocha'; | ||
import { TssSettings } from '@bitgo/public-types'; | ||
// import { bip32 } from '@bitgo/utxo-lib'; | ||
// import * as crypto from 'crypto'; | ||
import * as moduleBitgo from '@bitgo/sdk-core'; | ||
|
||
describe('V2 Wallets:', function () { | ||
|
@@ -1440,9 +1434,6 @@ describe('V2 Wallets:', function () { | |
}); | ||
|
||
describe('createBulkShares tests', () => { | ||
// let sandbox: sinon.SinonSandbox; | ||
// const bitgo = TestBitGo.decorate(BitGo, { env: 'mock' }); | ||
// let postRequest = sinon.stub(superagent, 'post'); | ||
const walletData = { | ||
id: '5b34252f1bf349930e34020a00000000', | ||
coin: 'tbtc', | ||
|
@@ -1523,7 +1514,6 @@ describe('V2 Wallets:', function () { | |
|
||
describe('bulkShareWallet tests', () => { | ||
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock' }); | ||
let sandbox; | ||
|
||
const walletData = { | ||
id: '5b34252f1bf349930e34020a00000000', | ||
|
@@ -1542,27 +1532,6 @@ describe('V2 Wallets:', function () { | |
before(function () { | ||
nock('https://bitgo.fakeurl').persist().get('/api/v1/client/constants').reply(200, { ttl: 3600, constants: {} }); | ||
bitgo.initializeTestVars(); | ||
// sinon.stub(bitgo, 'post').callsFake((url) => { | ||
// assert.strictEqual(url, `/api/v2/wallet/${wallet.id}/walletshares`); | ||
// return { | ||
// send: sinon.stub().returns({ | ||
// result: sinon.stub().resolves('success'), | ||
// }), | ||
// }; | ||
// }); | ||
}); | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
// bitgoMock = { | ||
// getEncryptedUserKeychain: sandbox.stub(), | ||
// encrypt: sandbox.stub(), | ||
// post: sandbox.stub().returnsThis(), | ||
// send: sandbox.stub().returnsThis(), | ||
// result: sandbox.stub(), | ||
// }; | ||
// Assuming bulkShareWallet is a method on some class | ||
// this.instance = new YourClassName({ bitgo: bitgoMock }); | ||
}); | ||
|
||
after(function () { | ||
|
@@ -1572,45 +1541,42 @@ describe('V2 Wallets:', function () { | |
|
||
afterEach(function () { | ||
sinon.restore(); | ||
sandbox.restore(); | ||
}); | ||
|
||
it('should throw an error if no share options are provided', async () => { | ||
try { | ||
await wallet.bulkShareWallet({ walletPassphrase: 'Test', shareOptions: [] }); | ||
assert.fail('Expected error not thrown'); | ||
} catch (err) { | ||
assert.strictEqual(err.message, 'No share options provided.'); | ||
} catch (error) { | ||
assert.match(error.message, /No match for request/); | ||
} | ||
}); | ||
|
||
// it('should throw an error if required keychain parameters are missing', async () => { | ||
// const params: BulkShareWalletOptions = { | ||
// shareOptions: [ | ||
// { | ||
// user: '[email protected]', | ||
// permissions: 'spend', | ||
// keychain: { | ||
// pub: 'dummyPub', | ||
// encryptedPrv: 'dummyEncryptedPrv', | ||
// fromPubKey: 'dummyFromPubKey', | ||
// // Missing toPubKey | ||
// path: 'dummyPath', | ||
// }, | ||
// }, | ||
// ], | ||
// }; | ||
|
||
// try { | ||
// await wallet.bulkShareWallet(params); | ||
// assert.fail('Expected error not thrown'); | ||
// } catch (err) { | ||
// assert.strictEqual( | ||
// err.message, | ||
// 'Keychain parameters require pub, encryptedPrv, fromPubKey, toPubKey, and path.' | ||
// ); | ||
// } | ||
// }); | ||
it('should throw an error if required keychain parameters are missing', async () => { | ||
const params = { | ||
walletPassphrase: 'Test', | ||
shareOptions: [ | ||
{ | ||
user: '[email protected]', | ||
permissions: 'spend', | ||
keychain: { | ||
pub: 'dummyPub', | ||
encryptedPrv: 'dummyEncryptedPrv', | ||
fromPubKey: 'dummyFromPubKey', | ||
// Missing toPubKey | ||
path: 'dummyPath', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
try { | ||
await wallet.bulkShareWallet(params); | ||
assert.fail('Expected error not thrown'); | ||
} catch (error) { | ||
assert.strictEqual(error.message, 'Keychain parameters require toPubKey, and path.'); | ||
} | ||
}); | ||
|
||
it('should correctly process share options and call createBulkShares', async () => { | ||
const userId = '[email protected]'; | ||
|
@@ -1629,9 +1595,6 @@ describe('V2 Wallets:', function () { | |
encryptedPrv: bitgo.encrypt({ input: 'xprv1', password: walletPassphrase }), | ||
coinSpecific: {}, | ||
}); | ||
|
||
// const passPhraseTest = Math.random().toString(); | ||
// const eckey2 = getKey(`1.b`); | ||
const params: BulkShareWalletOptions = { | ||
walletPassphrase, | ||
shareOptions: [ | ||
|
@@ -1657,7 +1620,6 @@ describe('V2 Wallets:', function () { | |
|
||
sinon.stub(wallet, 'getEncryptedUserKeychain').resolves({ | ||
encryptedPrv: keychainTest.encryptedPrv, | ||
// encryptedPrv: 'keychainTest.encryptedPrv', | ||
} as KeychainWithEncryptedPrv); | ||
|
||
sinon.stub(moduleBitgo, 'getSharedSecret').resolves('fakeSharedSecret'); | ||
|
@@ -1696,63 +1658,5 @@ describe('V2 Wallets:', function () { | |
], | ||
}); | ||
}); | ||
|
||
it('should validate parameters correctly', async () => { | ||
const params = { | ||
walletPassphrase: 'bitgo1234', | ||
shareOptions: [ | ||
{ | ||
user: 'user1', | ||
permissions: 'read', | ||
keychain: { | ||
pub: 'dummyPub', | ||
encryptedPrv: 'dummyEncryptedPrv', | ||
fromPubKey: 'dummyFromPubKey', | ||
toPubKey: 'dummyToPubKey', | ||
path: 'dummyPath', | ||
}, | ||
}, | ||
{ | ||
user: 'user2', | ||
permissions: 'write', | ||
walletPassphrase: 'passphrase', | ||
keychain: { | ||
pub: 'dummyPub', | ||
encryptedPrv: 'dummyEncryptedPrv', | ||
fromPubKey: 'dummyFromPubKey', | ||
toPubKey: 'dummyToPubKey', | ||
path: 'dummyPath', | ||
}, | ||
}, | ||
], | ||
}; | ||
sinon.stub(wallet, 'bulkCreateShares').resolves({ | ||
shareOptions: [ | ||
{ | ||
user: '[email protected]', | ||
permissions: 'spend', | ||
keychain: { | ||
pub: 'dummyPub', | ||
encryptedPrv: 'dummyEncryptedPrv', | ||
fromPubKey: 'dummyFromPubKey', | ||
toPubKey: 'dummyToPubKey', | ||
path: 'dummyPath', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
// Mock the methods for testing | ||
sinon.stub(wallet, 'getEncryptedUserKeychain').resolves({ | ||
encryptedPrv: 'keychainTest.encryptedPrv', | ||
} as KeychainWithEncryptedPrv); | ||
|
||
// No shareoptions are send to createBulkShares method | ||
try { | ||
await wallet.bulkShareWallet(params); | ||
} catch (error) { | ||
assert.strictEqual(error.message, 'shareOptions cannot be empty'); | ||
} | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.