Skip to content

Commit

Permalink
feat: @aragon/wrapper api cleanup (#279)
Browse files Browse the repository at this point in the history
With the breaking change in #267, this is a good chance to consolidate the API a bit 😄.

Also adds a few tests to the observables requiring "callbacks" (e.g. `performTransactionPath()`).
  • Loading branch information
sohkai authored Apr 13, 2019
1 parent 244190f commit c15e02c
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/aragon-wrapper/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,9 @@ export default class Aragon {
address,
providerName,
resolve,
reject
reject (err) {
reject(err || new Error('The identity modification was not completed'))
}
})
})
}
Expand Down Expand Up @@ -886,9 +888,7 @@ export default class Aragon {
this.transactions.next({
transaction: transactionPath[0],
path: transactionPath,
accept (transactionHash) {
resolve(transactionHash)
},
resolve,
reject (err) {
reject(err || new Error('The transaction was not signed'))
}
Expand Down
145 changes: 143 additions & 2 deletions packages/aragon-wrapper/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ test('should init the identity providers correctly', async (t) => {

test('should emit an intent when requesting address identity modification', async (t) => {
const { Aragon } = t.context
const expectedAddress = '0x123'

t.plan(2)
// arrange
Expand All @@ -690,8 +691,6 @@ test('should emit an intent when requesting address identity modification', asyn
// act
await instance.initIdentityProviders()

const expectedAddress = '0x123'

instance.identityIntents.subscribe(intent => {
t.is(intent.address, expectedAddress)
t.is(intent.providerName, 'local')
Expand All @@ -700,6 +699,67 @@ test('should emit an intent when requesting address identity modification', asyn
instance.requestAddressIdentityModification(expectedAddress)
})

test('should be able to resolve intent when requesting address identity modification', async (t) => {
const { Aragon } = t.context
const expectedAddress = '0x123'

t.plan(2)
// arrange
const instance = new Aragon()

// act
await instance.initIdentityProviders()

let counter = 0
instance.identityIntents.subscribe(intent => {
intent.resolve(counter++)
})

return Promise.all([
instance.requestAddressIdentityModification(expectedAddress).then(val => t.is(val, 0)),
instance.requestAddressIdentityModification(expectedAddress).then(val => t.is(val, 1))
])
})

test('should be able to reject intent when requesting address identity modification', async (t) => {
const { Aragon } = t.context
const expectedAddress = '0x123'

t.plan(2)
// arrange
const instance = new Aragon()

// act
await instance.initIdentityProviders()

let counter = 0
instance.identityIntents.subscribe(intent => {
if (counter === 0) {
intent.reject()
} else {
intent.reject(new Error('custom error'))
}
counter++
})

return Promise.all([
t.throwsAsync(
instance.requestAddressIdentityModification(expectedAddress),
{
instanceOf: Error,
message: 'The identity modification was not completed'
}
),
t.throwsAsync(
instance.requestAddressIdentityModification(expectedAddress),
{
instanceOf: Error,
message: 'custom error'
}
)
])
})

test('should init the forwarders correctly', async (t) => {
const { Aragon } = t.context

Expand Down Expand Up @@ -793,6 +853,87 @@ test('should send notifications correctly', async (t) => {
})
})

test('should emit an intent when performing transaction path', async (t) => {
const { Aragon } = t.context
const initialAddress = '0x123'
const targetAddress = '0x456'

t.plan(3)
// arrange
const instance = new Aragon()
instance.transactions = new Subject()

// act
instance.transactions.subscribe(intent => {
t.deepEqual(intent.transaction, { to: initialAddress })
t.true(Array.isArray(intent.path))
t.is(intent.path.length, 2)
})

instance.performTransactionPath([{ to: initialAddress }, { to: targetAddress }])
})

test('should be able to resolve intent when performing transaction path', async (t) => {
const { Aragon } = t.context
const initialAddress = '0x123'
const targetAddress = '0x456'

t.plan(2)
// arrange
const instance = new Aragon()
instance.transactions = new Subject()

// act
let counter = 0
instance.transactions.subscribe(intent => {
intent.resolve(counter++)
})

return Promise.all([
instance.performTransactionPath([{ to: initialAddress }, { to: targetAddress }]).then(val => t.is(val, 0)),
instance.performTransactionPath([{ to: initialAddress }, { to: targetAddress }]).then(val => t.is(val, 1))
])
})

test('should be able to reject intent when perform transaction path', async (t) => {
const { Aragon } = t.context
const initialAddress = '0x123'
const targetAddress = '0x456'

t.plan(2)
// arrange
const instance = new Aragon()
instance.transactions = new Subject()

// act
let counter = 0
instance.transactions.subscribe(intent => {
if (counter === 0) {
intent.reject()
} else {
intent.reject(new Error('custom error'))
}
counter++
})

return Promise.all([
t.throwsAsync(
instance.performTransactionPath([{ to: initialAddress }, { to: targetAddress }]),
{
instanceOf: Error,
message: 'The transaction was not signed'
}
),
t.throwsAsync(
instance.performTransactionPath([{ to: initialAddress }, { to: targetAddress }]),
{
instanceOf: Error,
message: 'custom error'
}
)
])
})

test('should run the app and reply to a request', async (t) => {
const { Aragon, messengerConstructorStub, utilsStub } = t.context

Expand Down
2 changes: 1 addition & 1 deletion packages/aragon-wrapper/src/rpc/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function combineRequestHandlers (...handlers) {

// Export request handlers
export { default as accounts } from './accounts'
export { default as addressIdentity } from './addressIdentity'
export { default as addressIdentity } from './address-identity'
export { default as appIdentifier } from './app-identifier'
export { default as cache } from './cache'
export { default as call } from './call'
Expand Down

0 comments on commit c15e02c

Please sign in to comment.