Skip to content

Commit

Permalink
Always subscribe to network changes for EnsController
Browse files Browse the repository at this point in the history
  • Loading branch information
whymarrh committed Oct 31, 2019
1 parent cf548b3 commit 14d2b89
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
15 changes: 7 additions & 8 deletions app/scripts/controllers/ens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ class EnsController {
provider,
})
}

networkStore.subscribe((network) => {
this.store.putState(initState)
this._ens = new Ens({
network,
provider,
})
})
}

this.store = new ObservableStore(initState)
networkStore.subscribe((network) => {
this.store.putState(initState)
this._ens = new Ens({
network,
provider,
})
})
}

reverseResolveAddress (address) {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/app/controllers/ens-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ describe('EnsController', function () {
})

it('should construct the controller given an existing ENS instance', async () => {
const networkStore = {
subscribe: sinon.spy(),
}
const ens = new EnsController({
ens: {},
networkStore,
})

assert.ok(ens._ens)
Expand All @@ -33,11 +37,15 @@ describe('EnsController', function () {
describe('#reverseResolveName', function () {
it('should resolve to an ENS name', async () => {
const address = '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'
const networkStore = {
subscribe: sinon.spy(),
}
const ens = new EnsController({
ens: {
reverse: sinon.stub().withArgs(address).returns('peaksignal.eth'),
lookup: sinon.stub().withArgs('peaksignal.eth').returns(address),
},
networkStore,
})

const name = await ens.reverseResolveAddress(address)
Expand All @@ -48,11 +56,15 @@ describe('EnsController', function () {
const address = '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'
const reverse = sinon.stub().withArgs(address).returns('peaksignal.eth')
const lookup = sinon.stub().withArgs('peaksignal.eth').returns(address)
const networkStore = {
subscribe: sinon.spy(),
}
const ens = new EnsController({
ens: {
reverse,
lookup,
},
networkStore,
})

assert.equal(await ens.reverseResolveAddress(address), 'peaksignal.eth')
Expand All @@ -63,11 +75,15 @@ describe('EnsController', function () {

it('should fail if the name is registered to a different address than the reverse-resolved', async () => {
const address = '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'
const networkStore = {
subscribe: sinon.spy(),
}
const ens = new EnsController({
ens: {
reverse: sinon.stub().withArgs(address).returns('peaksignal.eth'),
lookup: sinon.stub().withArgs('peaksignal.eth').returns('0xfoo'),
},
networkStore,
})

const name = await ens.reverseResolveAddress(address)
Expand All @@ -76,11 +92,15 @@ describe('EnsController', function () {

it('should throw an error when the lookup resolves to the zero address', async () => {
const address = '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'
const networkStore = {
subscribe: sinon.spy(),
}
const ens = new EnsController({
ens: {
reverse: sinon.stub().withArgs(address).returns('peaksignal.eth'),
lookup: sinon.stub().withArgs('peaksignal.eth').returns(ZERO_ADDRESS),
},
networkStore,
})

try {
Expand All @@ -93,11 +113,15 @@ describe('EnsController', function () {

it('should throw an error the lookup resolves to the zero x address', async () => {
const address = '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5'
const networkStore = {
subscribe: sinon.spy(),
}
const ens = new EnsController({
ens: {
reverse: sinon.stub().withArgs(address).returns('peaksignal.eth'),
lookup: sinon.stub().withArgs('peaksignal.eth').returns(ZERO_X_ERROR_ADDRESS),
},
networkStore,
})

try {
Expand Down

0 comments on commit 14d2b89

Please sign in to comment.