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
97 changes: 52 additions & 45 deletions packages/cli/src/commands/account/authorize.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { newKitFromProvider } from '@celo/contractkit'
import { testWithAnvilL2 } from '@celo/dev-utils/anvil-test'
import { addressToPublicKey } from '@celo/utils/lib/signatureUtils'
import Web3 from 'web3'
import { stripAnsiCodesFromNestedArray, testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import { stripAnsiCodesFromNestedArray, testLocallyWithNode } from '../../test-utils/cliUtils'
import { PROOF_OF_POSSESSION_SIGNATURE } from '../../test-utils/constants'
import Lock from '../lockedcelo/lock'
import ValidatorRegister from '../validator/register'
Expand All @@ -10,7 +10,7 @@ import Register from './register'

process.env.NO_SYNCCHECK = 'true'

testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
testWithAnvilL2('account:authorize cmd', (provider) => {
const logMock = jest.spyOn(console, 'log')
const errorMock = jest.spyOn(console, 'error')

Expand All @@ -22,15 +22,16 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
afterEach(() => jest.clearAllMocks())

test('can authorize vote signer', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const notRegisteredAccount = accounts[0]
const signerNotRegisteredAccount = accounts[1]

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

logMock.mockClear()

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Authorize,
[
'--from',
Expand All @@ -42,7 +43,7 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
'--signature',
PROOF_OF_POSSESSION_SIGNATURE,
],
web3
provider
)

expect(stripAnsiCodesFromNestedArray(logMock.mock.calls)).toMatchInlineSnapshot(`
Expand All @@ -67,15 +68,16 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
})

test('can authorize attestation signer', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const notRegisteredAccount = accounts[0]
const signerNotRegisteredAccount = accounts[1]

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

logMock.mockClear()

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Authorize,
[
'--from',
Expand All @@ -87,7 +89,7 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
'--signature',
PROOF_OF_POSSESSION_SIGNATURE,
],
web3
provider
)

expect(stripAnsiCodesFromNestedArray(logMock.mock.calls)).toMatchInlineSnapshot(`
Expand All @@ -112,15 +114,16 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
})

test('can authorize validator signer before validator is registered', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const notRegisteredAccount = accounts[0]
const signerNotRegisteredAccount = accounts[1]

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

logMock.mockClear()

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Authorize,
[
'--from',
Expand All @@ -132,7 +135,7 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
'--signature',
PROOF_OF_POSSESSION_SIGNATURE,
],
web3
provider
)

expect(stripAnsiCodesFromNestedArray(logMock.mock.calls)).toMatchInlineSnapshot(`
Expand All @@ -158,25 +161,26 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
})

it('can authorize validator signer after validator is registered', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const notRegisteredAccount = accounts[0]
const signerNotRegisteredAccount = accounts[1]
const ecdsaPublicKey = await addressToPublicKey(notRegisteredAccount, web3.eth.sign)
await testLocallyWithWeb3Node(Register, ['--from', notRegisteredAccount], web3)
await testLocallyWithWeb3Node(
const ecdsaPublicKey = await addressToPublicKey(notRegisteredAccount, kit.connection.sign)
await testLocallyWithNode(Register, ['--from', notRegisteredAccount], provider)
await testLocallyWithNode(
Lock,
['--from', notRegisteredAccount, '--value', '10000000000000000000000'],
web3
provider
)
await testLocallyWithWeb3Node(
await testLocallyWithNode(
ValidatorRegister,
['--from', notRegisteredAccount, '--ecdsaKey', ecdsaPublicKey, '--yes'],
web3
provider
)

logMock.mockClear()

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Authorize,
[
'--from',
Expand All @@ -188,7 +192,7 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
'--signature',
PROOF_OF_POSSESSION_SIGNATURE,
],
web3
provider
)

expect(stripAnsiCodesFromNestedArray(logMock.mock.calls)).toMatchInlineSnapshot(`
Expand All @@ -213,26 +217,27 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
})

it('fails when using BLS keys on L2', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const notRegisteredAccount = accounts[0]
const signerNotRegisteredAccount = accounts[1]
const ecdsaPublicKey = await addressToPublicKey(notRegisteredAccount, web3.eth.sign)
await testLocallyWithWeb3Node(Register, ['--from', notRegisteredAccount], web3)
await testLocallyWithWeb3Node(
const ecdsaPublicKey = await addressToPublicKey(notRegisteredAccount, kit.connection.sign)
await testLocallyWithNode(Register, ['--from', notRegisteredAccount], provider)
await testLocallyWithNode(
Lock,
['--from', notRegisteredAccount, '--value', '10000000000000000000000'],
web3
provider
)
await testLocallyWithWeb3Node(
await testLocallyWithNode(
ValidatorRegister,
['--from', notRegisteredAccount, '--ecdsaKey', ecdsaPublicKey, '--yes'],
web3
provider
)

logMock.mockClear()

await expect(
testLocallyWithWeb3Node(
testLocallyWithNode(
Authorize,
[
'--from',
Expand All @@ -249,7 +254,7 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
'0xcdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900',
],

web3
provider
)
).rejects.toMatchInlineSnapshot(`
[Error: Nonexistent flags: --blsKey, --blsPop
Expand All @@ -260,25 +265,26 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
})

test('can force authorize validator signer without BLS after validator is registered', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const notRegisteredAccount = accounts[0]
const signerNotRegisteredAccount = accounts[1]
const ecdsaPublicKey = await addressToPublicKey(notRegisteredAccount, web3.eth.sign)
await testLocallyWithWeb3Node(Register, ['--from', notRegisteredAccount], web3)
await testLocallyWithWeb3Node(
const ecdsaPublicKey = await addressToPublicKey(notRegisteredAccount, kit.connection.sign)
await testLocallyWithNode(Register, ['--from', notRegisteredAccount], provider)
await testLocallyWithNode(
Lock,
['--from', notRegisteredAccount, '--value', '10000000000000000000000'],
web3
provider
)
await testLocallyWithWeb3Node(
await testLocallyWithNode(
ValidatorRegister,
['--from', notRegisteredAccount, '--ecdsaKey', ecdsaPublicKey, '--yes'],
web3
provider
)

logMock.mockClear()

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Authorize,
[
'--from',
Expand All @@ -291,7 +297,7 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
PROOF_OF_POSSESSION_SIGNATURE,
'--force',
],
web3
provider
)
expect(stripAnsiCodesFromNestedArray(errorMock.mock.calls)).toMatchInlineSnapshot(`[]`)
expect(stripAnsiCodesFromNestedArray(logMock.mock.calls)).toMatchInlineSnapshot(`
Expand All @@ -316,14 +322,15 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
})

test('fails if from is not an account', async () => {
const accounts = await web3.eth.getAccounts()
const kit = newKitFromProvider(provider)
const accounts = await kit.connection.getAccounts()
const notRegisteredAccount = accounts[0]
const signerNotRegisteredAccount = accounts[1]

logMock.mockClear()

await expect(
testLocallyWithWeb3Node(
testLocallyWithNode(
Authorize,
[
'--from',
Expand All @@ -336,7 +343,7 @@ testWithAnvilL2('account:authorize cmd', (web3: Web3) => {
PROOF_OF_POSSESSION_SIGNATURE,
],

web3
provider
)
).rejects.toThrowErrorMatchingInlineSnapshot(`"Some checks didn't pass!"`)
expect(stripAnsiCodesFromNestedArray(errorMock.mock.calls)).toMatchInlineSnapshot(`[]`)
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/account/authorize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Flags } from '@oclif/core'
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
import { displaySendTx } from '../../utils/cli'
import { displayViemTx } from '../../utils/cli'
import { CustomFlags } from '../../utils/command'

export default class Authorize extends BaseCommand {
Expand Down Expand Up @@ -41,6 +41,7 @@ export default class Authorize extends BaseCommand {
async run() {
const res = await this.parse(Authorize)
const kit = await this.getKit()
const publicClient = await this.getPublicClient()
const accounts = await kit.contracts.getAccounts()
const sig = accounts.parseSignatureOfAddress(
res.flags.from,
Expand Down Expand Up @@ -69,6 +70,6 @@ export default class Authorize extends BaseCommand {
this.error(`Invalid role provided`)
return
}
await displaySendTx('authorizeTx', tx)
await displayViemTx('authorizeTx', tx, publicClient)
}
}
21 changes: 10 additions & 11 deletions packages/cli/src/commands/account/balance.test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import { ContractKit, newKitFromWeb3, StableToken } from '@celo/contractkit'
import { ContractKit, newKitFromProvider, StableToken } from '@celo/contractkit'
import { testWithAnvilL2 } from '@celo/dev-utils/anvil-test'
import BigNumber from 'bignumber.js'
import Web3 from 'web3'
import { topUpWithToken } from '../../test-utils/chain-setup'
import { stripAnsiCodesFromNestedArray, testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import { stripAnsiCodesFromNestedArray, testLocallyWithNode } from '../../test-utils/cliUtils'
import Lock from '../lockedcelo/lock'
import Unlock from '../lockedcelo/unlock'
import Balance from './balance'

process.env.NO_SYNCCHECK = 'true'

testWithAnvilL2('account:balance cmd', (web3: Web3) => {
testWithAnvilL2('account:balance cmd', (provider) => {
const consoleMock = jest.spyOn(console, 'log')
let accounts: string[] = []
let kit: ContractKit

beforeEach(async () => {
kit = newKitFromWeb3(web3)
accounts = await web3.eth.getAccounts()
kit = newKitFromProvider(provider)
accounts = await kit.connection.getAccounts()
consoleMock.mockClear()
})

it('shows the balance of the account for CELO only', async () => {
await testLocallyWithWeb3Node(Lock, ['--from', accounts[0], '--value', '1234567890'], web3)
await testLocallyWithWeb3Node(Unlock, ['--from', accounts[0], '--value', '890'], web3)
await testLocallyWithNode(Lock, ['--from', accounts[0], '--value', '1234567890'], provider)
await testLocallyWithNode(Unlock, ['--from', accounts[0], '--value', '890'], provider)

consoleMock.mockClear()

await testLocallyWithWeb3Node(Balance, [accounts[0]], web3)
await testLocallyWithNode(Balance, [accounts[0]], provider)

// Instead of exact snapshot matching, let's verify the balance structure and ranges
const calls = stripAnsiCodesFromNestedArray(consoleMock.mock.calls)
Expand All @@ -52,10 +51,10 @@ testWithAnvilL2('account:balance cmd', (web3: Web3) => {
await topUpWithToken(kit, StableToken.EURm, accounts[0], EURmAmount)
await topUpWithToken(kit, StableToken.BRLm, accounts[0], BRLmAmount)

await testLocallyWithWeb3Node(
await testLocallyWithNode(
Balance,
[accounts[0], '--erc20Address', (await kit.contracts.getGoldToken()).address],
web3
provider
)

expect(stripAnsiCodesFromNestedArray(consoleMock.mock.calls)).toMatchInlineSnapshot(`
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/account/claim-keybase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
verifyKeybaseClaim,
} from '@celo/metadata-claims/lib/keybase'
import { sleep } from '@celo/utils/lib/async'
import { toChecksumAddress } from '@ethereumjs/util'
import { getAddress } from 'viem'

import { Flags, ux } from '@oclif/core'
import { writeFileSync } from 'fs'
Expand All @@ -34,7 +34,7 @@ export default class ClaimKeybase extends ClaimCommand {
const res = await this.parse(ClaimKeybase)
const username = res.flags.username
const metadata = await this.readMetadata()
const accountAddress = toChecksumAddress(metadata.data.meta.address)
const accountAddress = getAddress(metadata.data.meta.address)
const claim = createKeybaseClaim(username)
const signer = await this.getSigner()
const signature = await signer.sign(hashOfClaim(claim))
Expand Down
Loading
Loading