Skip to content

Commit

Permalink
Add payment delegation unit tests, generate docs
Browse files Browse the repository at this point in the history
* upstream pr #9700
* test for invalid payment delegation fraction greater than 1
* test that fetched delegation values are equal to values set
* test that deleting delegation clears values
* fix up cli example help
* generate docs for account.md

[finishes #182759476]
[Test] y
[Review] m-chrzan

add docs
  • Loading branch information
Daniel Swid committed Aug 13, 2022
1 parent 4387a30 commit a863b5c
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class SetPaymentDelegation extends BaseCommand {
static args = []

static examples = [
'set-payment-delegation --account 0x5409ed021d9299bf6814279a6a1411a7e866a631 --beneficiary 0x5409ed021d9299bf6814279a6a1411a7e866a631 --fraction 0.1',
'set-payment-delegation --account 0x5409ed021d9299bf6814279a6a1411a7e866a631 --beneficiary 0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb --fraction 0.1',
]

async run() {
Expand Down
88 changes: 87 additions & 1 deletion packages/docs/command-line-interface/account.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions packages/sdk/contractkit/src/wrappers/Accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { addressToPublicKey, parseSignature } from '@celo/utils/lib/signatureUti
import Web3 from 'web3'
import { ContractKit, newKitFromWeb3 } from '../kit'
import { AccountsWrapper } from './Accounts'
import { valueToBigNumber, valueToFixidityString } from './BaseWrapper'
import { LockedGoldWrapper } from './LockedGold'
import { ValidatorsWrapper } from './Validators'

Expand Down Expand Up @@ -167,4 +168,53 @@ testWithGanache('Accounts Wrapper', (web3) => {
await accountsInstance.createAccount().sendAndWaitForReceipt({ from: account })
await expect(accountsInstance.setWalletAddress(wallet)).rejects
})

test('DELEGATE fraction greater than 1 should fail', async () => {
const account = accounts[0]
const beneficiary = accounts[1]
const fractionInvalid = valueToFixidityString(valueToBigNumber('2.5'))

kit.defaultAccount = account

await accountsInstance.createAccount().sendAndWaitForReceipt({ from: account })
await expect(
accountsInstance.setPaymentDelegation(beneficiary, fractionInvalid).sendAndWaitForReceipt({})
).rejects.toEqual(
new Error(
'Error: VM Exception while processing transaction: revert Fraction must not be greater than 1'
)
)
})

test('DELEGATE beneficiary and fraction returned from get should equal set value', async () => {
const account = accounts[0]
const beneficiary = accounts[1]
const fractionValid = valueToFixidityString(valueToBigNumber('.25'))
const expectedRetval = { 0: beneficiary, 1: fractionValid }

kit.defaultAccount = account

await accountsInstance.createAccount().sendAndWaitForReceipt({ from: account })
await accountsInstance.setPaymentDelegation(beneficiary, fractionValid).sendAndWaitForReceipt()

const retval = await accountsInstance.getPaymentDelegation(account)
expect(retval).toEqual(expectedRetval)
})

test('DELEGATE delete expected to clear beneficiary and fraction after setting values', async () => {
const account = accounts[0]
const beneficiary = accounts[1]
const fractionValid = valueToFixidityString(valueToBigNumber('.25'))
const expectedRetval = { 0: '0x0000000000000000000000000000000000000000', 1: '0' }

kit.defaultAccount = account

await accountsInstance.createAccount().sendAndWaitForReceipt({ from: account })
await accountsInstance.setPaymentDelegation(beneficiary, fractionValid).sendAndWaitForReceipt()

await accountsInstance.deletePaymentDelegation().sendAndWaitForReceipt()

const retval = await accountsInstance.getPaymentDelegation(account)
expect(retval).toEqual(expectedRetval)
})
})

0 comments on commit a863b5c

Please sign in to comment.