Skip to content
Permalink
Browse files

feat: @aragon/wrapper api cleanup (#279)

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 committed Apr 13, 2019
1 parent 244190f commit c15e02c3ec2108013c7a9fba7fb6daa9302d0031
@@ -582,7 +582,9 @@ export default class Aragon {
address,
providerName,
resolve,
reject
reject (err) {
reject(err || new Error('The identity modification was not completed'))
}
})
})
}
@@ -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'))
}
@@ -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
@@ -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')
@@ -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

@@ -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

@@ -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'

0 comments on commit c15e02c

Please sign in to comment.
You can’t perform that action at this time.