Skip to content

Commit

Permalink
Show validator group affiliates in CLI (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asa Oines authored and celo-ci-bot-user committed Nov 9, 2019
1 parent 0c00b3f commit f1b7e0d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/commands/validatorgroup/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export default class ValidatorGroupShow extends BaseCommand {
static examples = ['show 0x97f7333c51897469E8D98E7af8653aAb468050a3']

async run() {
const { args } = this.parse(ValidatorGroupShow)
const res = this.parse(ValidatorGroupShow)
const validators = await this.kit.contracts.getValidators()

await newCheckBuilder(this)
.isValidatorGroup(args.groupAddress)
.isValidatorGroup(res.args.groupAddress)
.runChecks()

const validatorGroup = await validators.getValidatorGroup(args.groupAddress)
const validatorGroup = await validators.getValidatorGroup(res.args.groupAddress)
printValueMap(validatorGroup)
}
}
10 changes: 10 additions & 0 deletions packages/contractkit/src/wrappers/Validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ testWithGanache('Validators Wrapper', (web3) => {
expect(members).toContain(validatorAccount)
})

test('SBAT get group affiliates', async () => {
const groupAccount = accounts[0]
const validatorAccount = accounts[1]
await setupGroup(groupAccount)
await setupValidator(validatorAccount)
await validators.affiliate(groupAccount).sendAndWaitForReceipt({ from: validatorAccount })
const group = await validators.getValidatorGroup(groupAccount)
expect(group.affiliates).toContain(validatorAccount)
})

describe('SBAT reorderMember', () => {
let groupAccount: string, validator1: string, validator2: string

Expand Down
6 changes: 6 additions & 0 deletions packages/contractkit/src/wrappers/Validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Validator {
export interface ValidatorGroup {
address: Address
members: Address[]
affiliates: Address[]
commission: BigNumber
}

Expand Down Expand Up @@ -148,10 +149,15 @@ export class ValidatorsWrapper extends BaseWrapper<Validators> {
/** Get ValidatorGroup information */
async getValidatorGroup(address: Address): Promise<ValidatorGroup> {
const res = await this.contract.methods.getValidatorGroup(address).call()
const validators = await this.getRegisteredValidators()
const affiliates = validators
.filter((v) => v.affiliation === address)
.filter((v) => !res[0].includes(v.address))
return {
address,
members: res[0],
commission: fromFixed(new BigNumber(res[1])),
affiliates: affiliates.map((v) => v.address),
}
}

Expand Down

0 comments on commit f1b7e0d

Please sign in to comment.