|
|
|
@ -366,15 +366,13 @@ describe('preferences controller', function () { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
describe('on watchAsset', function () { |
|
|
|
|
let stubNext, stubEnd, stubHandleWatchAssetERC20, asy, req, res |
|
|
|
|
let stubHandleWatchAssetERC20, asy, req, res |
|
|
|
|
const sandbox = sinon.createSandbox() |
|
|
|
|
|
|
|
|
|
beforeEach(function () { |
|
|
|
|
req = { params: {} } |
|
|
|
|
res = {} |
|
|
|
|
asy = { next: () => undefined, end: () => undefined } |
|
|
|
|
stubNext = sandbox.stub(asy, 'next') |
|
|
|
|
stubEnd = sandbox.stub(asy, 'end').returns(0) |
|
|
|
|
asy = { next: sandbox.spy(), end: sandbox.spy() } |
|
|
|
|
stubHandleWatchAssetERC20 = sandbox.stub(preferencesController, '_handleWatchAssetERC20') |
|
|
|
|
}) |
|
|
|
|
after(function () { |
|
|
|
@ -382,40 +380,33 @@ describe('preferences controller', function () { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('shouldn not do anything if method not corresponds', async function () { |
|
|
|
|
const asy = { next: () => undefined, end: () => undefined } |
|
|
|
|
const stubNext = sandbox.stub(asy, 'next') |
|
|
|
|
const stubEnd = sandbox.stub(asy, 'end').returns(0) |
|
|
|
|
req.method = 'metamask' |
|
|
|
|
await preferencesController.requestWatchAsset(req, res, asy.next, asy.end) |
|
|
|
|
sandbox.assert.notCalled(stubEnd) |
|
|
|
|
sandbox.assert.called(stubNext) |
|
|
|
|
sandbox.assert.notCalled(asy.end) |
|
|
|
|
sandbox.assert.called(asy.next) |
|
|
|
|
}) |
|
|
|
|
it('should do something if method is supported', async function () { |
|
|
|
|
const asy = { next: () => undefined, end: () => undefined } |
|
|
|
|
const stubNext = sandbox.stub(asy, 'next') |
|
|
|
|
const stubEnd = sandbox.stub(asy, 'end').returns(0) |
|
|
|
|
req.method = 'metamask_watchAsset' |
|
|
|
|
req.params.type = 'someasset' |
|
|
|
|
await preferencesController.requestWatchAsset(req, res, asy.next, asy.end) |
|
|
|
|
sandbox.assert.called(stubEnd) |
|
|
|
|
sandbox.assert.notCalled(stubNext) |
|
|
|
|
sandbox.assert.called(asy.end) |
|
|
|
|
sandbox.assert.notCalled(asy.next) |
|
|
|
|
req.method = addInternalMethodPrefix('watchAsset') |
|
|
|
|
req.params.type = 'someasset' |
|
|
|
|
await preferencesController.requestWatchAsset(req, res, asy.next, asy.end) |
|
|
|
|
sandbox.assert.calledTwice(stubEnd) |
|
|
|
|
sandbox.assert.notCalled(stubNext) |
|
|
|
|
sandbox.assert.calledTwice(asy.end) |
|
|
|
|
sandbox.assert.notCalled(asy.next) |
|
|
|
|
}) |
|
|
|
|
it('should through error if method is supported but asset type is not', async function () { |
|
|
|
|
req.method = 'metamask_watchAsset' |
|
|
|
|
req.params.type = 'someasset' |
|
|
|
|
await preferencesController.requestWatchAsset(req, res, asy.next, asy.end) |
|
|
|
|
sandbox.assert.called(stubEnd) |
|
|
|
|
sandbox.assert.called(asy.end) |
|
|
|
|
sandbox.assert.notCalled(stubHandleWatchAssetERC20) |
|
|
|
|
sandbox.assert.notCalled(stubNext) |
|
|
|
|
sandbox.assert.notCalled(asy.next) |
|
|
|
|
assert.deepEqual(res, {}) |
|
|
|
|
}) |
|
|
|
|
it('should trigger handle add asset if type supported', async function () { |
|
|
|
|
const asy = { next: () => undefined, end: () => undefined } |
|
|
|
|
req.method = 'metamask_watchAsset' |
|
|
|
|
req.params.type = 'ERC20' |
|
|
|
|
await preferencesController.requestWatchAsset(req, res, asy.next, asy.end) |
|
|
|
|