it('should correctly disable krs emails when creating backup keychains', co(function *() { const params = { label: 'my_wallet', disableKRSEmail: true, backupXpubProvider: 'test', passphrase: 'test123', userKey: 'xpub123' }; // bitgo key nock(bgUrl) .post('/api/v2/tbtc/key', _.matches({ source: 'bitgo' })) .reply(200); // user key nock(bgUrl) .post('/api/v2/tbtc/key', _.conforms({ pub: (p) => p.startsWith('xpub') })) .reply(200); // backup key nock(bgUrl) .post('/api/v2/tbtc/key', _.matches({ source: 'backup', provider: params.backupXpubProvider, disableKRSEmail: true })) .reply(200); // wallet nock(bgUrl) .post('/api/v2/tbtc/wallet') .reply(200); yield wallets.generateWallet(params); }));
it('should correctly pass through the krsSpecific param when creating backup keychains', co(function *() { const params = { label: 'my_wallet', backupXpubProvider: 'test', passphrase: 'test123', userKey: 'xpub123', krsSpecific: { coverage: 'insurance', expensive: true, howExpensive: 25 } }; // bitgo key nock(bgUrl) .post('/api/v2/tbtc/key', _.matches({ source: 'bitgo' })) .reply(200); // user key nock(bgUrl) .post('/api/v2/tbtc/key', _.conforms({ pub: (p) => p.startsWith('xpub') })) .reply(200); // backup key nock(bgUrl) .post('/api/v2/tbtc/key', _.matches({ source: 'backup', provider: params.backupXpubProvider, krsSpecific: { coverage: 'insurance', expensive: true, howExpensive: 25 } })) .reply(200); // wallet nock(bgUrl) .post('/api/v2/tbtc/wallet') .reply(200); yield wallets.generateWallet(params); }));
export default function findRoutes(routerAst): RouteNode { let routeFn; let isRouteMap = _.matches({ callee: { object: { name: 'Router' }, property: { name: 'map' } } }); recast.visit(routerAst, { visitCallExpression(path) { let node = path.node; if (isRouteMap(node)) { routeFn = node; } return false; } }); let appRoute: RouteNode = { node: routeFn, parent: null, children: null, moduleName: 'application', name: 'application' }; appRoute.children = findChildRoutes(routeFn, appRoute); return appRoute; }
function findChildRoutes(routeFnNode: ESTree.FunctionExpression, parentRoute) { let routeNodes: any[] = []; let isRoute = _.matches({ callee: { object: { type: 'ThisExpression' }, property: { name: 'route' } } }); recast.visit(routeFnNode, { visitCallExpression(path) { if (isRoute(path.node) && path.node !== parentRoute.node) { routeNodes.push(path.node); return false; } else { this.traverse(path); } } }); return routeNodes.map(routeCallNode => { let child: RouteNode = { node: routeCallNode, parent: parentRoute, children: [], moduleName: routeCallNode.arguments[0].value, name: routeCallNode.arguments[0].value }; child.children = findChildRoutes(routeCallNode, child); return child; }); }
it('arguments', co(function *() { const optionalParams = { limit: '25', minValue: '0', maxValue: '9999999999999', minHeight: '0', minConfirms: '2', enforceMinConfirmsForChange: 'false', feeRate: '10000', maxFeeRate: '100000', recipientAddress: '2NCUFDLiUz9CVnmdVqQe9acVonoM89e76df' }; const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/maximumSpendable`; const response = nock(bgUrl) .get(path) .query(_.matches(optionalParams)) // use _.matches to do a partial match on request body object instead of strict matching .reply(200, { coin: 'tbch', maximumSpendable: 65000 }); try { yield wallet.maximumSpendable(optionalParams); } catch (e) { // test is successful if nock is consumed } response.isDone().should.be.true(); }));
it('should accept a string argument for address', co(function *() { const params = { limit: 1, address: 'stringAddress' }; const apiParams = { limit: '1', address: 'stringAddress' }; const scope = nock(bgUrl) .get(`/api/v2/${wallet.coin()}/wallet/${wallet.id()}/transfer`) .query(_.matches(apiParams)) .reply(200); try { yield wallet.transfers(params); } catch (e) { // test is successful if nock is consumed, HMAC errors expected } scope.isDone().should.be.True(); }));
it('should forward all valid parameters', co(function *() { const params = { limit: 1, address: ['address1', 'address2'], dateGte: 'dateString0', dateLt: 'dateString1', valueGte: 0, valueLt: 300000000, allTokens: true, searchLabel: 'abc', includeHex: true, type: 'transfer_type', state: 'transfer_state' }; // The actual api request will only send strings, but the SDK function expects numbers for some values const apiParams = _.mapValues(params, param => Array.isArray(param) ? param : String(param)); const scope = nock(bgUrl) .get(`/api/v2/${wallet.coin()}/wallet/${wallet.id()}/transfer`) .query(_.matches(apiParams)) .reply(200); yield wallet.transfers(params); scope.isDone().should.be.True(); }));
export function valueToUrl( value, { host, type, thumbnail, }: { host?: string; type?: 'image' | 'video' | 'attache' | 'file'; thumbnail?: { width?: number; height?: number }; }, ) { if (value) { const hostPrefix = host || _.cond([ [_.matches('image'), _.constant(Config.get('IMAGE_HOST'))], [_.matches('video'), _.constant(Config.get('VIDEO_HOST'))], [_.matches('attache'), _.constant(Config.get('ATTACHE_HOST'))], [_.matches('file'), _.constant(Config.get('FILE_HOST'))], ])(type) || ''; let url = hostPrefix + `/${value}`.replace('//', '/').slice(1); if (thumbnail) { const template = _.get(AppContext.serverSettings['settings.url-resolver'], 'value.uploads'); try { url = template.replace('{{ url }}', url); } catch (e) { logger.warn('using template error', { template, url }); } // url += `?imageView2/2/w/${thumbnail.width || 1280}/h/${thumbnail.height || // 1280}/format/jpg/interlace/1/ignore-error/1`; } logger.debug('[valueToUrl]', { value, url, host }); return url; } return ''; }
it('should pass maxFeeRate parameter when calling fanout unspents', co(function *() { const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/fanoutUnspents`; const response = nock(bgUrl) .post(path, _.matches({ maxFeeRate })) // use _.matches to do a partial match on request body object instead of strict matching .reply(200); try { yield wallet.fanoutUnspents({ address, maxFeeRate }); } catch (e) { // the fanoutUnspents method will probably throw an exception for not having all of the correct nocks // we only care about /fanoutUnspents and whether maxFeeRate is an allowed parameter } response.isDone().should.be.true(); }));
it('should pass maxFeeRate parameter when building transactions', co(function *() { const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/tx/build`; const response = nock(bgUrl) .post(path, _.matches({ recipients, maxFeeRate })) // use _.matches to do a partial match on request body object instead of strict matching .reply(200); try { yield wallet.prebuildTransaction({ recipients, maxFeeRate }); } catch (e) { // the prebuildTransaction method will probably throw an exception for not having all of the correct nocks // we only care about /tx/build and whether maxFeeRate is an allowed parameter } response.isDone().should.be.true(); }));