Skip to content

Commit

Permalink
fix: reverse events to have consistent order (decentralized-identity#87)
Browse files Browse the repository at this point in the history
* fix: reverse events to have consistent order

- parsing through events from latest to earliest
- reverse events as json rpc returns one batch of events from earliest
to latest
- see decentralized-identity#86 (comment) for more details

* test: add/revoke in one block (importance of event order)
  • Loading branch information
nikolockenvitz committed Nov 9, 2020
1 parent cf91144 commit 08b9692
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/__tests__/ethr-did-resolver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,60 @@ describe('ethrResolver', () => {
})
})

describe('attribute revocation event in same block(-batch) as attribute creation', () => {
beforeAll(async () => {
await stopMining()
await Promise.all([
registry.setAttribute(identity, stringToBytes32('did/svc/TestService2'), 'https://test2.uport.me', 10, {
from: controller
}),
sleep(1).then(() =>
registry.revokeAttribute(identity, stringToBytes32('did/svc/TestService2'), 'https://test2.uport.me', {
from: controller
})
),
sleep(2).then(() => startMining())
])
})

it('resolves document', async () => {
expect(await didResolver.resolve(did)).toEqual({
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [
{
id: `${did}#controller`,
type: 'Secp256k1VerificationKey2018',
controller: did,
ethereumAddress: controller
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
controller: did,
ethereumAddress: delegate2
}
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#controller`
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`
}
],
service: [
{
type: 'TestService',
serviceEndpoint: 'https://test.uport.me'
}
]
})
})
})

describe('error handling', () => {
it('rejects promise', () => {
return expect(didResolver.resolve('did:ethr:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX')).rejects.toEqual(
Expand Down
1 change: 1 addition & 0 deletions src/ethr-did-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ function getResolver(conf = {}) {
toBlock: previousChange
})
const events = logDecoder(logs)
events.reverse()
previousChange = undefined
for (const event of events) {
history.unshift(event)
Expand Down

0 comments on commit 08b9692

Please sign in to comment.