Skip to content

Commit

Permalink
Add handle command.
Browse files Browse the repository at this point in the history
  • Loading branch information
montera82 committed Sep 5, 2023
1 parent 967f2a8 commit 5a76a5b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/cli/src/commands/feehandler/distribute.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
26 changes: 26 additions & 0 deletions packages/cli/src/commands/feehandler/distribute.ts
Original file line number Diff line number Diff line change
@@ -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')
}
}
26 changes: 26 additions & 0 deletions packages/cli/src/commands/feehandler/handle.ts
Original file line number Diff line number Diff line change
@@ -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')
}
}

0 comments on commit 5a76a5b

Please sign in to comment.