-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cli] validator deregister. Split affliliate/deaffiliate
Also: - Checks on cmds - support use of signer
- Loading branch information
Showing
39 changed files
with
1,014 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
node_modules | ||
oclif.manifest.json | ||
src/generated | ||
.devchain/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Web3 from 'web3' | ||
import { testWithGanache } from '../../test-utils/ganache-test' | ||
import Authorize from './authorize' | ||
import Register from './register' | ||
|
||
process.env.NO_SYNCCHECK = 'true' | ||
|
||
testWithGanache('account:authorize cmd', (web3: Web3) => { | ||
test('can authorize account', async () => { | ||
const accounts = await web3.eth.getAccounts() | ||
await Register.run(['--from', accounts[0]]) | ||
await Authorize.run(['--from', accounts[0], '--role', 'validator', '--to', accounts[1]]) | ||
}) | ||
|
||
test('fails if from is not an account', async () => { | ||
const accounts = await web3.eth.getAccounts() | ||
await expect( | ||
Authorize.run(['--from', accounts[0], '--role', 'validator', '--to', accounts[1]]) | ||
).rejects.toThrow() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Web3 from 'web3' | ||
import { testWithGanache } from '../../test-utils/ganache-test' | ||
import Register from './register' | ||
|
||
process.env.NO_SYNCCHECK = 'true' | ||
|
||
testWithGanache('account:register cmd', (web3: Web3) => { | ||
test('can register account', async () => { | ||
const accounts = await web3.eth.getAccounts() | ||
|
||
await Register.run(['--from', accounts[0]]) | ||
}) | ||
|
||
test('fails if from is missing', async () => { | ||
// const accounts = await web3.eth.getAccounts() | ||
|
||
await expect(Register.run([])).rejects.toThrow('Missing required flag') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { IArg } from '@oclif/parser/lib/args' | ||
import { BaseCommand } from '../../base' | ||
import { newCheckBuilder } from '../../utils/checks' | ||
import { displaySendTx } from '../../utils/cli' | ||
import { Args, Flags } from '../../utils/command' | ||
|
||
export default class ValidatorAffiliate extends BaseCommand { | ||
static description = 'Affiliate to a ValidatorGroup' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
from: Flags.address({ required: true, description: "Signer or Validator's address" }), | ||
} | ||
|
||
static args: IArg[] = [ | ||
Args.address('groupAddress', { description: "ValidatorGroup's address", required: true }), | ||
] | ||
|
||
static examples = [ | ||
'affiliate --from 0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95 0x97f7333c51897469e8d98e7af8653aab468050a3', | ||
] | ||
|
||
async run() { | ||
const res = this.parse(ValidatorAffiliate) | ||
this.kit.defaultAccount = res.flags.from | ||
const validators = await this.kit.contracts.getValidators() | ||
|
||
await newCheckBuilder(this, res.flags.from) | ||
.isSignerOrAccount() | ||
.canSignValidatorTxs() | ||
.signerAccountIsValidator() | ||
.isValidatorGroup(res.args.groupAddress) | ||
.runChecks() | ||
|
||
await displaySendTx('affiliate', validators.affiliate(res.args.groupAddress)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { BaseCommand } from '../../base' | ||
import { newCheckBuilder } from '../../utils/checks' | ||
import { displaySendTx } from '../../utils/cli' | ||
import { Flags } from '../../utils/command' | ||
|
||
export default class ValidatorDeAffiliate extends BaseCommand { | ||
static description = 'DeAffiliate to a ValidatorGroup' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
from: Flags.address({ required: true, description: "Signer or Validator's address" }), | ||
} | ||
|
||
static examples = ['deaffiliate --from 0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95'] | ||
|
||
async run() { | ||
const res = this.parse(ValidatorDeAffiliate) | ||
this.kit.defaultAccount = res.flags.from | ||
const validators = await this.kit.contracts.getValidators() | ||
|
||
await newCheckBuilder(this, res.flags.from) | ||
.isSignerOrAccount() | ||
.canSignValidatorTxs() | ||
.signerAccountIsValidator() | ||
.runChecks() | ||
|
||
await displaySendTx('deaffiliate', validators.deaffiliate()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { BaseCommand } from '../../base' | ||
import { newCheckBuilder } from '../../utils/checks' | ||
import { displaySendTx } from '../../utils/cli' | ||
import { Flags } from '../../utils/command' | ||
|
||
export default class ValidatorDeregister extends BaseCommand { | ||
static description = 'Deregister a Validator' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
from: Flags.address({ required: true, description: "Signer or Validator's address" }), | ||
} | ||
|
||
static examples = ['deregister --from 0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95'] | ||
|
||
async run() { | ||
const res = this.parse(ValidatorDeregister) | ||
|
||
this.kit.defaultAccount = res.flags.from | ||
const validators = await this.kit.contracts.getValidators() | ||
|
||
await newCheckBuilder(this, res.flags.from) | ||
.isSignerOrAccount() | ||
.canSignValidatorTxs() | ||
.signerAccountIsValidator() | ||
.runChecks() | ||
|
||
const validator = await validators.signerToAccount(res.flags.from) | ||
await displaySendTx('deregister', await validators.deregisterValidator(validator)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { BaseCommand } from '../../base' | ||
import { printValueMap } from '../../utils/cli' | ||
|
||
export default class ValidatorRequirements extends BaseCommand { | ||
static description = 'Get Requirements for Validators' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
} | ||
|
||
static examples = ['requirements'] | ||
|
||
async run() { | ||
this.parse(ValidatorRequirements) | ||
|
||
const validators = await this.kit.contracts.getValidators() | ||
|
||
const requirements = await validators.getValidatorLockedGoldRequirements() | ||
|
||
printValueMap(requirements) | ||
} | ||
} |
Oops, something went wrong.