From 5a76a5be9fb39583f4c82917066e1bd7bb5eb978 Mon Sep 17 00:00:00 2001 From: Edwin Tops Date: Tue, 5 Sep 2023 20:25:56 +0200 Subject: [PATCH] Add handle command. --- .../commands/feehandler/distribute.test.ts | 21 +++++++++++++++ .../cli/src/commands/feehandler/distribute.ts | 26 +++++++++++++++++++ .../cli/src/commands/feehandler/handle.ts | 26 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 packages/cli/src/commands/feehandler/distribute.test.ts create mode 100644 packages/cli/src/commands/feehandler/distribute.ts create mode 100644 packages/cli/src/commands/feehandler/handle.ts diff --git a/packages/cli/src/commands/feehandler/distribute.test.ts b/packages/cli/src/commands/feehandler/distribute.test.ts new file mode 100644 index 00000000000..dfbd09ea04d --- /dev/null +++ b/packages/cli/src/commands/feehandler/distribute.test.ts @@ -0,0 +1,21 @@ +import { newKitFromWeb3 } from '@celo/contractkit' +import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import BigNumber from 'bignumber.js' +import Web3 from 'web3' +import { testLocally } from '../../test-utils/cliUtils' +import Distribute from './distribute' + +process.env.NO_SYNCCHECK = 'true' + +testWithGanache('feehandler:distribute cmd', (web3: Web3) => { + const kit = newKitFromWeb3(web3) + + test('can distribute token', async () => { + const accounts = await web3.eth.getAccounts() + const initialBalanceRecipient = new BigNumber(await kit.connection.getBalance(accounts[1])) + await testLocally(Distribute, ['--from', accounts[0], '--to', accounts[1]]) + + const finalBalanceRecipient = new BigNumber(await kit.connection.getBalance(accounts[1])) + expect(finalBalanceRecipient.isGreaterThan(initialBalanceRecipient)).toBe(true) + }) +}) diff --git a/packages/cli/src/commands/feehandler/distribute.ts b/packages/cli/src/commands/feehandler/distribute.ts new file mode 100644 index 00000000000..ab8a1a2bdb7 --- /dev/null +++ b/packages/cli/src/commands/feehandler/distribute.ts @@ -0,0 +1,26 @@ +import { BaseCommand } from '../../base' +import { displaySendTx } from '../../utils/cli' +import { Flags } from '../../utils/command' + +export default class Distribute extends BaseCommand { + static description = 'Distributes the the token to the beneficiary' + + static flags = { + ...BaseCommand.flags, + from: Flags.address({ required: true, description: "Initiator's address" }), + to: Flags.address({ required: true, description: 'The address to receive the token' }), + } + + static examples = [ + 'distribute --from 0x5409ed021d9299bf6814279a6a1411a7e866a631 --to 0x5409ed021d9299bf6814279a6a1411a7e866a631', + ] + + async run() { + const res = this.parse(Distribute) + const from: string = res.flags.from + this.kit.defaultAccount = from + const to: string = res.flags.to + const feeHandler = await this.kit.contracts.getFeeHandler() + await displaySendTx('distribute', await feeHandler.distribute(to), {}, 'TokensDistributed') + } +} diff --git a/packages/cli/src/commands/feehandler/handle.ts b/packages/cli/src/commands/feehandler/handle.ts new file mode 100644 index 00000000000..b6a784beeac --- /dev/null +++ b/packages/cli/src/commands/feehandler/handle.ts @@ -0,0 +1,26 @@ +import { BaseCommand } from '../../base' +import { displaySendTx } from '../../utils/cli' +import { Flags } from '../../utils/command' + +export default class Handle extends BaseCommand { + static description = 'Distributes the the token to the beneficiary' + + static flags = { + ...BaseCommand.flags, + from: Flags.address({ required: true, description: "Initiator's address" }), + to: Flags.address({ required: true, description: 'The address to receive the token' }), + } + + static examples = [ + 'handle --from 0x5409ed021d9299bf6814279a6a1411a7e866a631 --to 0x5409ed021d9299bf6814279a6a1411a7e866a631', + ] + + async run() { + const res = this.parse(Handle) + const from: string = res.flags.from + this.kit.defaultAccount = from + const to: string = res.flags.to + const feeHandler = await this.kit.contracts.getFeeHandler() + await displaySendTx('handle', await feeHandler.handle(to), {}, 'TokensDistributed') + } +}