-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 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
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) | ||
}) | ||
}) |
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,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') | ||
} | ||
} |
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,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') | ||
} | ||
} |