Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ux } from '@oclif/core'

import { BaseCommand } from '../../base'
import { displaySendTx } from '../../utils/cli'
import { displayViemTx } from '../../utils/cli'
import { CustomFlags } from '../../utils/command'

export default class AttestationRewardsWithdraw extends BaseCommand {
Expand All @@ -21,6 +21,7 @@ export default class AttestationRewardsWithdraw extends BaseCommand {

async run() {
const kit = await this.getKit()
const publicClient = await this.getPublicClient()
const { flags } = await this.parse(AttestationRewardsWithdraw)
const [accounts, attestations] = await Promise.all([
kit.contracts.getAccounts(),
Expand All @@ -43,7 +44,11 @@ export default class AttestationRewardsWithdraw extends BaseCommand {
}

ux.action.start(`Withdrawing ${pendingWithdrawals.toString()} rewards to ${accountAddress}`)
await displaySendTx('withdraw', attestations.withdraw(tokenAddress), { from: flags.from })
await displayViemTx(
'withdraw',
attestations.withdraw(tokenAddress, { from: flags.from }),
publicClient
)
ux.action.stop()
}
}
21 changes: 11 additions & 10 deletions packages/cli/src/commands/lockedcelo/delegate-info.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { newKitFromProvider } from '@celo/contractkit'
import { testWithAnvilL2 } from '@celo/dev-utils/anvil-test'
import Web3 from 'web3'
import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import { testLocallyWithNode } from '../../test-utils/cliUtils'
import Register from '../account/register'
import Delegate from './delegate'
import DelegateInfo from './delegate-info'
import Lock from './lock'

process.env.NO_SYNCCHECK = 'true'

testWithAnvilL2('lockedgold:delegate-info cmd', (web3: Web3) => {
testWithAnvilL2('lockedgold:delegate-info cmd', (provider) => {
test('gets the info', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const account = accounts[0]
const account2 = accounts[1]
await testLocallyWithWeb3Node(Register, ['--from', account], web3)
await testLocallyWithWeb3Node(Register, ['--from', account2], web3)
await testLocallyWithWeb3Node(Lock, ['--from', account, '--value', '200'], web3)
await testLocallyWithNode(Register, ['--from', account], provider)
await testLocallyWithNode(Register, ['--from', account2], provider)
await testLocallyWithNode(Lock, ['--from', account, '--value', '200'], provider)

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Delegate,
['--from', account, '--to', account2, '--percent', '100'],
web3
provider
)

await testLocallyWithWeb3Node(DelegateInfo, ['--account', account], web3)
await testLocallyWithNode(DelegateInfo, ['--account', account], provider)
})
})
53 changes: 26 additions & 27 deletions packages/cli/src/commands/lockedcelo/delegate.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { serializeSignature, StrongAddress } from '@celo/base'
import { newKitFromWeb3 } from '@celo/contractkit'
import { newKitFromProvider } from '@celo/contractkit'
import { testWithAnvilL2 } from '@celo/dev-utils/anvil-test'
import Web3 from 'web3'
import { stripAnsiCodesFromNestedArray, testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import { stripAnsiCodesFromNestedArray, testLocallyWithNode } from '../../test-utils/cliUtils'
import { deployReleaseGoldContract } from '../../test-utils/release-gold'
import Register from '../account/register'
import Authorize from '../releasecelo/authorize'
Expand All @@ -12,13 +11,13 @@ import Lock from './lock'

process.env.NO_SYNCCHECK = 'true'

testWithAnvilL2('lockedgold:delegate cmd', (web3: Web3) => {
testWithAnvilL2('lockedgold:delegate cmd', (provider) => {
it('can not delegate when not an account or a vote signer', async () => {
const [delegator, delegatee] = await web3.eth.getAccounts()
const kit = newKitFromWeb3(web3)
const kit = newKitFromProvider(provider)
const [delegator, delegatee] = await kit.connection.getAccounts()
const lockedGold = await kit.contracts.getLockedGold()

await testLocallyWithWeb3Node(Register, ['--from', delegatee], web3)
await testLocallyWithNode(Register, ['--from', delegatee], provider)

const delegateeVotingPower = await lockedGold.getAccountTotalGovernanceVotingPower(delegatee)

Expand All @@ -28,10 +27,10 @@ testWithAnvilL2('lockedgold:delegate cmd', (web3: Web3) => {
const logMock = jest.spyOn(console, 'log')

await expect(
testLocallyWithWeb3Node(
testLocallyWithNode(
Delegate,
['--from', delegator, '--to', delegatee, '--percent', '45'],
web3
provider
)
).rejects.toMatchInlineSnapshot(`[Error: Some checks didn't pass!]`)

Expand All @@ -58,44 +57,44 @@ testWithAnvilL2('lockedgold:delegate cmd', (web3: Web3) => {
})

test('can delegate', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const account = accounts[0]
const account2 = accounts[1]
const kit = newKitFromWeb3(web3)
const lockedGold = await kit.contracts.getLockedGold()
await testLocallyWithWeb3Node(Register, ['--from', account], web3)
await testLocallyWithWeb3Node(Register, ['--from', account2], web3)
await testLocallyWithWeb3Node(Lock, ['--from', account, '--value', '200'], web3)
await testLocallyWithNode(Register, ['--from', account], provider)
await testLocallyWithNode(Register, ['--from', account2], provider)
await testLocallyWithNode(Lock, ['--from', account, '--value', '200'], provider)

const account2OriginalVotingPower =
await lockedGold.getAccountTotalGovernanceVotingPower(account2)
expect(account2OriginalVotingPower.toFixed()).toBe('0')

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Delegate,
['--from', account, '--to', account2, '--percent', '100'],
web3
provider
)

const account2VotingPower = await lockedGold.getAccountTotalGovernanceVotingPower(account2)
expect(account2VotingPower.toFixed()).toBe('200')
})

it('can delegate as a vote signer for releasecelo contract', async () => {
const kit = newKitFromProvider(provider)
const [beneficiary, owner, voteSigner, refundAddress, delegateeAddress] =
(await web3.eth.getAccounts()) as StrongAddress[]
const kit = newKitFromWeb3(web3)
(await kit.connection.getAccounts()) as StrongAddress[]
const accountsWrapper = await kit.contracts.getAccounts()
const releaseGoldContractAddress = await deployReleaseGoldContract(
web3,
provider,
owner,
beneficiary,
owner,
refundAddress
)

await testLocallyWithWeb3Node(CreateAccount, ['--contract', releaseGoldContractAddress], web3)
await testLocallyWithWeb3Node(
await testLocallyWithNode(CreateAccount, ['--contract', releaseGoldContractAddress], provider)
await testLocallyWithNode(
Authorize,
[
'--contract',
Expand All @@ -109,17 +108,17 @@ testWithAnvilL2('lockedgold:delegate cmd', (web3: Web3) => {
await accountsWrapper.generateProofOfKeyPossession(releaseGoldContractAddress, voteSigner)
),
],
web3
provider
)
await testLocallyWithWeb3Node(Lock, ['--from', beneficiary, '--value', '100'], web3)
await testLocallyWithNode(Lock, ['--from', beneficiary, '--value', '100'], provider)

const createAccountTx = await accountsWrapper.createAccount().send({ from: delegateeAddress })
await createAccountTx.waitReceipt()
const createHash = await accountsWrapper.createAccount({ from: delegateeAddress })
await kit.connection.viemClient.waitForTransactionReceipt({ hash: createHash as `0x${string}` })

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Delegate,
['--from', voteSigner, '--to', delegateeAddress, '--percent', '100'],
web3
provider
)

const lockedGold = await kit.contracts.getLockedGold()
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/commands/lockedcelo/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Flags } from '@oclif/core'
import BigNumber from 'bignumber.js'
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
import { displaySendTx } from '../../utils/cli'
import { displayViemTx } from '../../utils/cli'
import { CustomFlags } from '../../utils/command'
import { LockedGoldArgs } from '../../utils/lockedgold'

Expand Down Expand Up @@ -31,6 +31,7 @@ export default class Delegate extends BaseCommand {

async run() {
const kit = await this.getKit()
const publicClient = await this.getPublicClient()
const res = await this.parse(Delegate)
const address = res.flags.from
const to = res.flags.to
Expand All @@ -50,10 +51,7 @@ export default class Delegate extends BaseCommand {

const lockedGold = await kit.contracts.getLockedGold()

console.log('value', percent.toString())
console.log('valueFixed', percentFixed.toFixed())

const tx = lockedGold.delegate(to, percentFixed.toFixed())
await displaySendTx('delegate', tx)
await displayViemTx('delegate', tx, publicClient)
}
}
29 changes: 14 additions & 15 deletions packages/cli/src/commands/lockedcelo/lock.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
import { newKitFromWeb3 } from '@celo/contractkit'
import { newKitFromProvider } from '@celo/contractkit'
import { testWithAnvilL2 } from '@celo/dev-utils/anvil-test'
import { ux } from '@oclif/core'
import BigNumber from 'bignumber.js'
import Web3 from 'web3'
import {
LONG_TIMEOUT_MS,
stripAnsiCodesFromNestedArray,
testLocallyWithWeb3Node,
testLocallyWithNode,
} from '../../test-utils/cliUtils'
import Register from '../account/register'
import Lock from './lock'
import Unlock from './unlock'

process.env.NO_SYNCCHECK = 'true'

testWithAnvilL2('lockedgold:lock cmd', (web3: Web3) => {
testWithAnvilL2('lockedgold:lock cmd', (provider) => {
test(
'can lock with pending withdrawals',
async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const account = accounts[0]
const kit = newKitFromWeb3(web3)
const lockedGold = await kit.contracts.getLockedGold()
await testLocallyWithWeb3Node(Register, ['--from', account], web3)
await testLocallyWithWeb3Node(Lock, ['--from', account, '--value', '100'], web3)
await testLocallyWithWeb3Node(Unlock, ['--from', account, '--value', '50'], web3)
await testLocallyWithWeb3Node(Lock, ['--from', account, '--value', '75'], web3)
await testLocallyWithWeb3Node(Unlock, ['--from', account, '--value', '50'], web3)
await testLocallyWithWeb3Node(Lock, ['--from', account, '--value', '50'], web3)
await testLocallyWithNode(Register, ['--from', account], provider)
await testLocallyWithNode(Lock, ['--from', account, '--value', '100'], provider)
await testLocallyWithNode(Unlock, ['--from', account, '--value', '50'], provider)
await testLocallyWithNode(Lock, ['--from', account, '--value', '75'], provider)
await testLocallyWithNode(Unlock, ['--from', account, '--value', '50'], provider)
await testLocallyWithNode(Lock, ['--from', account, '--value', '50'], provider)
const pendingWithdrawalsTotalValue = await lockedGold.getPendingWithdrawalsTotalValue(account)
expect(pendingWithdrawalsTotalValue.toFixed()).toBe('0')
},
LONG_TIMEOUT_MS
)
describe('when EOA is not yet an account', () => {
it('performs the registration and locks the value', async () => {
const eoaAddresses = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const eoaAddresses = await kit.connection.getAccounts()
const eoa = eoaAddresses[1]
const kit = newKitFromWeb3(web3)
const accountsContract = await kit.contracts.getAccounts()
const lockedGoldContract = await kit.contracts.getLockedGold()

Expand All @@ -47,7 +46,7 @@ testWithAnvilL2('lockedgold:lock cmd', (web3: Web3) => {
// pre check
expect(await accountsContract.isAccount(eoa)).toBe(false)

await testLocallyWithWeb3Node(Lock, ['--from', eoa, '--value', '100'], web3)
await testLocallyWithNode(Lock, ['--from', eoa, '--value', '100'], provider)

expect(stripAnsiCodesFromNestedArray(logSpy.mock.calls)).toMatchInlineSnapshot(`
[
Expand Down
15 changes: 8 additions & 7 deletions packages/cli/src/commands/lockedcelo/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Flags } from '@oclif/core'
import BigNumber from 'bignumber.js'
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
import { displaySendTx } from '../../utils/cli'
import { displayViemTx } from '../../utils/cli'
import { CustomFlags } from '../../utils/command'
import { LockedGoldArgs } from '../../utils/lockedgold'

Expand All @@ -26,6 +26,7 @@ export default class Lock extends BaseCommand {

async run() {
const kit = await this.getKit()
const publicClient = await this.getPublicClient()
const res = await this.parse(Lock)
const address = res.flags.from as StrongAddress

Expand All @@ -45,7 +46,7 @@ export default class Lock extends BaseCommand {

if (!isAccount) {
console.log('Address will be registered with Account contract to enable locking.')
await displaySendTx('register', accountsContract.createAccount())
await displayViemTx('register', accountsContract.createAccount(), publicClient)
}

const pendingWithdrawalsValue = await lockedGold.getPendingWithdrawalsTotalValue(address)
Expand All @@ -54,13 +55,13 @@ export default class Lock extends BaseCommand {

await newCheckBuilder(this).hasEnoughCelo(address, lockValue).runChecks()

const txos = await lockedGold.relock(address, relockValue)
for (const txo of txos) {
await displaySendTx('relock', txo, { from: address })
const hashes = await lockedGold.relock(address, relockValue, { from: address })
for (const hash of hashes) {
await displayViemTx('relock', Promise.resolve(hash), publicClient)
}
if (lockValue.gt(new BigNumber(0))) {
const tx = lockedGold.lock()
await displaySendTx('lock', tx, { value: lockValue.toFixed() })
const tx = lockedGold.lock({ value: lockValue.toFixed() })
await displayViemTx('lock', tx, publicClient)
}
}
}
25 changes: 12 additions & 13 deletions packages/cli/src/commands/lockedcelo/revoke-delegate.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
import { newKitFromWeb3 } from '@celo/contractkit'
import { newKitFromProvider } from '@celo/contractkit'
import { testWithAnvilL2 } from '@celo/dev-utils/anvil-test'
import Web3 from 'web3'
import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import { testLocallyWithNode } from '../../test-utils/cliUtils'
import Register from '../account/register'
import Delegate from './delegate'
import Lock from './lock'
import RevokeDelegate from './revoke-delegate'

process.env.NO_SYNCCHECK = 'true'

testWithAnvilL2('lockedgold:revoke-delegate cmd', (web3: Web3) => {
testWithAnvilL2('lockedgold:revoke-delegate cmd', (provider) => {
test('can revoke delegate', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const account = accounts[0]
const account2 = accounts[1]
const kit = newKitFromWeb3(web3)
const lockedGold = await kit.contracts.getLockedGold()
await testLocallyWithWeb3Node(Register, ['--from', account], web3)
await testLocallyWithWeb3Node(Register, ['--from', account2], web3)
await testLocallyWithWeb3Node(Lock, ['--from', account, '--value', '200'], web3)
await testLocallyWithNode(Register, ['--from', account], provider)
await testLocallyWithNode(Register, ['--from', account2], provider)
await testLocallyWithNode(Lock, ['--from', account, '--value', '200'], provider)

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Delegate,
['--from', account, '--to', account2, '--percent', '100'],
web3
provider
)

const account2VotingPower = await lockedGold.getAccountTotalGovernanceVotingPower(account2)
expect(account2VotingPower.toFixed()).toBe('200')

await testLocallyWithWeb3Node(
await testLocallyWithNode(
RevokeDelegate,
['--from', account, '--to', account2, '--percent', '100'],
web3
provider
)

const account2VotingPowerAfterRevoke =
Expand Down
Loading
Loading