2019-08-08 15:27:09 +02:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const { processValidatorsEvents, parseValidatorEvent } = require('..')
|
2019-05-09 12:03:18 +02:00
|
|
|
|
|
|
|
describe('parseValidatorEvent', () => {
|
|
|
|
it('should parse ValidatorAdded event from v1', () => {
|
|
|
|
// Given
|
|
|
|
const event = {
|
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x000000000000000000000000cfef0c6bb765321529ffe81507f6d099693cd225',
|
|
|
|
topics: ['0xe366c1c0452ed8eec96861e9e54141ebff23c9ec89fe27b996b45f5ec3884987']
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
}
|
|
|
|
// When
|
|
|
|
parseValidatorEvent(event)
|
|
|
|
|
|
|
|
// Then
|
2019-08-08 15:27:09 +02:00
|
|
|
expect(event.event).to.be.equal('ValidatorAdded')
|
|
|
|
expect(event.returnValues.validator).to.be.equal('0xcfef0c6bb765321529ffe81507f6d099693cd225')
|
2019-05-09 12:03:18 +02:00
|
|
|
})
|
|
|
|
it('should parse ValidatorAdded event', () => {
|
|
|
|
// Given
|
|
|
|
const event = {
|
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x',
|
2019-05-09 12:03:18 +02:00
|
|
|
topics: [
|
2019-05-22 16:31:09 +02:00
|
|
|
'0xe366c1c0452ed8eec96861e9e54141ebff23c9ec89fe27b996b45f5ec3884987',
|
|
|
|
'0x000000000000000000000000cfef0c6bb765321529ffe81507f6d099693cd225'
|
|
|
|
]
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
}
|
|
|
|
// When
|
|
|
|
parseValidatorEvent(event)
|
|
|
|
|
|
|
|
// Then
|
2019-08-08 15:27:09 +02:00
|
|
|
expect(event.event).to.be.equal('ValidatorAdded')
|
|
|
|
expect(event.returnValues.validator).to.be.equal('0xcfef0c6bb765321529ffe81507f6d099693cd225')
|
2019-05-09 12:03:18 +02:00
|
|
|
})
|
|
|
|
it('should parse ValidatorAdded event from rewardableValidators', () => {
|
|
|
|
// Given
|
|
|
|
const event = {
|
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x000000000000000000000000cfef0c6bb765321529ffe81507f6d099693cd225',
|
2019-05-09 12:03:18 +02:00
|
|
|
topics: [
|
2019-05-22 16:31:09 +02:00
|
|
|
'0x8064a302796c89446a96d63470b5b036212da26bd2debe5bec73e0170a9a5e83',
|
|
|
|
'0x000000000000000000000000cfef0c6bb765321529ffe81507f6d099693cd225'
|
|
|
|
]
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
}
|
|
|
|
// When
|
|
|
|
parseValidatorEvent(event)
|
|
|
|
|
|
|
|
// Then
|
2019-08-08 15:27:09 +02:00
|
|
|
expect(event.event).to.be.equal('ValidatorAdded')
|
|
|
|
expect(event.returnValues.validator).to.be.equal('0xcfef0c6bb765321529ffe81507f6d099693cd225')
|
2019-05-09 12:03:18 +02:00
|
|
|
})
|
|
|
|
it('should parse ValidatorRemoved event', () => {
|
|
|
|
// Given
|
|
|
|
const event = {
|
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x',
|
2019-05-09 12:03:18 +02:00
|
|
|
topics: [
|
2019-05-22 16:31:09 +02:00
|
|
|
'0xe1434e25d6611e0db941968fdc97811c982ac1602e951637d206f5fdda9dd8f1',
|
|
|
|
'0x000000000000000000000000cfef0c6bb765321529ffe81507f6d099693cd225'
|
|
|
|
]
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
}
|
|
|
|
// When
|
|
|
|
parseValidatorEvent(event)
|
|
|
|
|
|
|
|
// Then
|
2019-08-08 15:27:09 +02:00
|
|
|
expect(event.event).to.be.equal('ValidatorRemoved')
|
|
|
|
expect(event.returnValues.validator).to.be.equal('0xcfef0c6bb765321529ffe81507f6d099693cd225')
|
2019-05-09 12:03:18 +02:00
|
|
|
})
|
|
|
|
it('should parse ValidatorRemoved event from v1', () => {
|
|
|
|
// Given
|
|
|
|
const event = {
|
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x000000000000000000000000cfef0c6bb765321529ffe81507f6d099693cd225',
|
|
|
|
topics: ['0xe1434e25d6611e0db941968fdc97811c982ac1602e951637d206f5fdda9dd8f1']
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
}
|
|
|
|
// When
|
|
|
|
parseValidatorEvent(event)
|
|
|
|
|
|
|
|
// Then
|
2019-08-08 15:27:09 +02:00
|
|
|
expect(event.event).to.be.equal('ValidatorRemoved')
|
|
|
|
expect(event.returnValues.validator).to.be.equal('0xcfef0c6bb765321529ffe81507f6d099693cd225')
|
2019-05-09 12:03:18 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
describe('processValidatorsEvents', () => {
|
|
|
|
it('should return validator list from raw events', () => {
|
|
|
|
// Given
|
|
|
|
const events = [
|
2019-05-22 16:31:09 +02:00
|
|
|
{
|
|
|
|
// Add v1 event
|
2019-05-09 12:03:18 +02:00
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x000000000000000000000000cfef0c6bb765321529ffe81507f6d099693cd225',
|
|
|
|
topics: ['0xe366c1c0452ed8eec96861e9e54141ebff23c9ec89fe27b996b45f5ec3884987']
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
},
|
2019-05-22 16:31:09 +02:00
|
|
|
{
|
|
|
|
// Add v1 event
|
2019-05-09 12:03:18 +02:00
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x000000000000000000000000Cbd25A2a5708051747a052dBB1b291865Fc0e474',
|
|
|
|
topics: ['0xe366c1c0452ed8eec96861e9e54141ebff23c9ec89fe27b996b45f5ec3884987']
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
},
|
2019-05-22 16:31:09 +02:00
|
|
|
{
|
|
|
|
// Remove v1 event
|
2019-05-09 12:03:18 +02:00
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x000000000000000000000000cfef0c6bb765321529ffe81507f6d099693cd225',
|
|
|
|
topics: ['0xe1434e25d6611e0db941968fdc97811c982ac1602e951637d206f5fdda9dd8f1']
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
},
|
2019-05-22 16:31:09 +02:00
|
|
|
{
|
|
|
|
// Add event
|
2019-05-09 12:03:18 +02:00
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x',
|
2019-05-09 12:03:18 +02:00
|
|
|
topics: [
|
2019-05-22 16:31:09 +02:00
|
|
|
'0xe366c1c0452ed8eec96861e9e54141ebff23c9ec89fe27b996b45f5ec3884987',
|
|
|
|
'0x000000000000000000000000FE365A92Bc01425441dE76D8EDA48496B64446FB'
|
|
|
|
]
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
},
|
2019-05-22 16:31:09 +02:00
|
|
|
{
|
|
|
|
// Add event
|
2019-05-09 12:03:18 +02:00
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x',
|
2019-05-09 12:03:18 +02:00
|
|
|
topics: [
|
2019-05-22 16:31:09 +02:00
|
|
|
'0xe366c1c0452ed8eec96861e9e54141ebff23c9ec89fe27b996b45f5ec3884987',
|
|
|
|
'0x000000000000000000000000Bac68A86Cf596E3b124781E0bdbC47bb458bec62'
|
|
|
|
]
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
},
|
2019-05-22 16:31:09 +02:00
|
|
|
{
|
|
|
|
// Remove event
|
2019-05-09 12:03:18 +02:00
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x',
|
2019-05-09 12:03:18 +02:00
|
|
|
topics: [
|
2019-05-22 16:31:09 +02:00
|
|
|
'0xe1434e25d6611e0db941968fdc97811c982ac1602e951637d206f5fdda9dd8f1',
|
|
|
|
'0x000000000000000000000000FE365A92Bc01425441dE76D8EDA48496B64446FB'
|
|
|
|
]
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
},
|
2019-05-22 16:31:09 +02:00
|
|
|
{
|
|
|
|
// Add rewardable event
|
2019-05-09 12:03:18 +02:00
|
|
|
raw: {
|
2019-05-22 16:31:09 +02:00
|
|
|
data: '0x0000000000000000000000000066938BBE9b31D44DFa8e27A1d675A545DF6ed5',
|
2019-05-09 12:03:18 +02:00
|
|
|
topics: [
|
2019-05-22 16:31:09 +02:00
|
|
|
'0x8064a302796c89446a96d63470b5b036212da26bd2debe5bec73e0170a9a5e83',
|
|
|
|
'0x000000000000000000000000f4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
|
|
|
]
|
2019-05-09 12:03:18 +02:00
|
|
|
},
|
|
|
|
returnValues: {}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// When
|
|
|
|
const validatorList = processValidatorsEvents(events)
|
|
|
|
|
|
|
|
// Then
|
2019-08-08 15:27:09 +02:00
|
|
|
expect(validatorList.length).to.be.equal(3)
|
|
|
|
expect(validatorList[0]).to.be.equal('0xCbd25A2a5708051747a052dBB1b291865Fc0e474')
|
|
|
|
expect(validatorList[1]).to.be.equal('0xBac68A86Cf596E3b124781E0bdbC47bb458bec62')
|
|
|
|
expect(validatorList[2]).to.be.equal('0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955')
|
2019-05-09 12:03:18 +02:00
|
|
|
})
|
|
|
|
})
|