pull/334/head
Trevor Porter 3 years ago
parent b59c63d69f
commit 9d9431d7ed
  1. 27
      typescript/infra/src/core/check.ts
  2. 9
      typescript/infra/src/core/govern.ts
  3. 4
      typescript/infra/src/utils/utils.ts
  4. 5
      typescript/sdk/src/core/app.ts

@ -60,7 +60,9 @@ export class AbacusCoreChecker extends AbacusAppChecker<
]; ];
this.app.remoteDomainNumbers(domain).map((remote) => { this.app.remoteDomainNumbers(domain).map((remote) => {
owners.push(this.app.mustGetInbox(remote, domain).owner()); owners.push(this.app.mustGetInbox(remote, domain).owner());
owners.push(this.app.mustGetInboxMultisigValidatorManager(remote, domain).owner()); owners.push(
this.app.mustGetInboxMultisigValidatorManager(remote, domain).owner(),
);
}); });
const actual = await Promise.all(owners); const actual = await Promise.all(owners);
actual.map((_) => expect(_).to.equal(owner)); actual.map((_) => expect(_).to.equal(owner));
@ -90,10 +92,12 @@ export class AbacusCoreChecker extends AbacusAppChecker<
let multisigValidatorManager: MultisigValidatorManager; let multisigValidatorManager: MultisigValidatorManager;
// Check the outboxMultisigValidatorManager // Check the outboxMultisigValidatorManager
if (domain === outboxDomain) { if (domain === outboxDomain) {
multisigValidatorManager = this.app.mustGetContracts(domain).outboxMultisigValidatorManager; multisigValidatorManager =
this.app.mustGetContracts(domain).outboxMultisigValidatorManager;
} else { } else {
// Check an inboxMultisigValidatorManager // Check an inboxMultisigValidatorManager
multisigValidatorManager = this.app.mustGetInboxMultisigValidatorManager(outboxDomain, domain); multisigValidatorManager =
this.app.mustGetInboxMultisigValidatorManager(outboxDomain, domain);
} }
return this.checkMultisigValidatorManager( return this.checkMultisigValidatorManager(
domain, domain,
@ -115,7 +119,8 @@ export class AbacusCoreChecker extends AbacusAppChecker<
multisigValidatorManager: MultisigValidatorManager, multisigValidatorManager: MultisigValidatorManager,
): Promise<void> { ): Promise<void> {
const outboxDomainName = this.app.mustResolveDomainName(outboxDomain); const outboxDomainName = this.app.mustResolveDomainName(outboxDomain);
const expected = this.config.multisigValidatorManagers[outboxDomainName]?.validatorSet; const expected =
this.config.multisigValidatorManagers[outboxDomainName]?.validatorSet;
expect(expected).to.not.be.undefined; expect(expected).to.not.be.undefined;
const actual = await multisigValidatorManager.validatorSet(); const actual = await multisigValidatorManager.validatorSet();
@ -124,17 +129,11 @@ export class AbacusCoreChecker extends AbacusAppChecker<
const expectedSet = new Set<string>(expected); const expectedSet = new Set<string>(expected);
const actualSet = new Set<string>(actual); const actualSet = new Set<string>(actual);
const toEnroll = setDifference( const toEnroll = setDifference(expectedSet, actualSet);
expectedSet, const toUnenroll = setDifference(actualSet, expectedSet);
actualSet,
);
const toUnenroll = setDifference(
actualSet,
expectedSet,
);
// Validators that should be enrolled // Validators that should be enrolled
for (const [validatorToEnroll] of toEnroll.entries()) { for (const validatorToEnroll of toEnroll) {
const violation: ValidatorViolation = { const violation: ValidatorViolation = {
domain: localDomain, domain: localDomain,
type: CoreViolationType.Validator, type: CoreViolationType.Validator,
@ -148,7 +147,7 @@ export class AbacusCoreChecker extends AbacusAppChecker<
} }
// Validators that should be unenrolled // Validators that should be unenrolled
for (const [validatorToUnenroll] of toUnenroll.entries()) { for (const validatorToUnenroll of toUnenroll) {
const violation: ValidatorViolation = { const violation: ValidatorViolation = {
domain: localDomain, domain: localDomain,
type: CoreViolationType.Validator, type: CoreViolationType.Validator,

@ -84,14 +84,19 @@ export class AbacusCoreGovernor extends AbacusCoreChecker {
tx = await multisigValidatorManager.populateTransaction.enrollValidator( tx = await multisigValidatorManager.populateTransaction.enrollValidator(
violation.expected, violation.expected,
); );
} else if (violation.actual !== undefined && violation.expected === undefined) { } else if (
violation.actual !== undefined &&
violation.expected === undefined
) {
// Unenrolling an existing validator // Unenrolling an existing validator
tx = await multisigValidatorManager.populateTransaction.unenrollValidator( tx = await multisigValidatorManager.populateTransaction.unenrollValidator(
violation.actual, violation.actual,
); );
} else { } else {
// Invalid state // Invalid state
throw new Error(`Expected exactly one of actual ${violation.actual} or expected ${violation.expected} to be undefined`); throw new Error(
`Expected exactly one of actual ${violation.actual} or expected ${violation.expected} to be undefined`,
);
} }
if (tx.to === undefined) throw new Error('undefined tx.to'); if (tx.to === undefined) throw new Error('undefined tx.to');

@ -161,8 +161,8 @@ export function writeJSON(directory: string, filename: string, obj: any) {
// Returns a \ b // Returns a \ b
export function setDifference<T>(a: Set<T>, b: Set<T>) { export function setDifference<T>(a: Set<T>, b: Set<T>) {
let diff = new Set(a); let diff = new Set(a);
for (const elem of diff) { for (const element of b) {
diff.delete(elem); diff.delete(element);
} }
return diff; return diff;
} }

@ -26,7 +26,10 @@ export class AbacusCore extends AbacusApp<
return contracts.inbox(srcName); return contracts.inbox(srcName);
} }
mustGetInboxMultisigValidatorManager(src: NameOrDomain, dest: NameOrDomain): InboxMultisigValidatorManager { mustGetInboxMultisigValidatorManager(
src: NameOrDomain,
dest: NameOrDomain,
): InboxMultisigValidatorManager {
const contracts = this.mustGetContracts(dest); const contracts = this.mustGetContracts(dest);
const srcName = this.mustGetDomain(src).name; const srcName = this.mustGetDomain(src).name;
return contracts.inboxMultisigValidatorManager(srcName); return contracts.inboxMultisigValidatorManager(srcName);

Loading…
Cancel
Save