Skip to content

Commit

Permalink
Merge branch 'master' into nicolasbrugneaux/use-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux authored Jan 24, 2025
2 parents f7231a0 + 4a1d9e7 commit dea0a5b
Show file tree
Hide file tree
Showing 16 changed files with 667 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-lobsters-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/contractkit': patch
---

Expose `sendValidatorPayment` methods for `EpochManager` contract wrapper
5 changes: 5 additions & 0 deletions .changeset/slimy-beds-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/celocli': minor
---

Add `epochs:send-validator-payment` command to support sending validator, their group and delegation beneficiary allocated epoch payments
5 changes: 5 additions & 0 deletions .changeset/witty-poems-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/celocli': patch
---

Fix bug with GovernanceSlasher missing version causing failure. defend against exceptions when printing contracts info
67 changes: 67 additions & 0 deletions docs/command-line-interface/epochs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Finishes next epoch process.

* [`celocli epochs:finish`](#celocli-epochsfinish)
* [`celocli epochs:send-validator-payment`](#celocli-epochssend-validator-payment)
* [`celocli epochs:start`](#celocli-epochsstart)
* [`celocli epochs:switch`](#celocli-epochsswitch)

Expand Down Expand Up @@ -66,6 +67,72 @@ FLAG DESCRIPTIONS

_See code: [src/commands/epochs/finish.ts](https://github.com/celo-org/developer-tooling/tree/master/packages/cli/src/commands/epochs/finish.ts)_

## `celocli epochs:send-validator-payment`

Sends the allocated epoch payment to a validator, their group, and delegation beneficiary.

```
USAGE
$ celocli epochs:send-validator-payment --from 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d --for
0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d [-k <value> | --useLedger | ] [-n
<value>] [--gasCurrency 0x1234567890123456789012345678901234567890]
[--ledgerAddresses <value> ] [--ledgerLiveMode ] [--globalHelp]
FLAGS
-k, --privateKey=<value>
Use a private key to sign local transactions with
-n, --node=<value>
URL of the node to run commands against or an alias
--for=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d
(required) Address of the validator to send the payment to
--from=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d
(required) Address of the sender
--gasCurrency=0x1234567890123456789012345678901234567890
Use a specific gas currency for transaction fees (defaults to CELO if no gas
currency is supplied). It must be a whitelisted token.
--globalHelp
View all available global flags
--ledgerAddresses=<value>
[default: 1] If --useLedger is set, this will get the first N addresses for local
signing
--ledgerLiveMode
When set, the 4th postion of the derivation path will be iterated over instead of
the 5th. This is useful to use same address on you Ledger with celocli as you do on
Ledger Live
--useLedger
Set it to use a ledger wallet
DESCRIPTION
Sends the allocated epoch payment to a validator, their group, and delegation
beneficiary.
ALIASES
$ celocli validator:send-payment
EXAMPLES
send-validator-payment --for 0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95
FLAG DESCRIPTIONS
-n, --node=<value> URL of the node to run commands against or an alias
Can be a full url like https://forno.celo.org or an alias. default:
http://localhost:8545
Alias options:
local, localhost => 'http://localhost:8545'
alfajores => Celo Alfajores Testnet,
mainnet, celo, forno => Celo Mainnet chain',
```

_See code: [src/commands/epochs/send-validator-payment.ts](https://github.com/celo-org/developer-tooling/tree/master/packages/cli/src/commands/epochs/send-validator-payment.ts)_

## `celocli epochs:start`

Starts next epoch process.
Expand Down
65 changes: 65 additions & 0 deletions docs/command-line-interface/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ View and manage Validators
* [`celocli validator:register`](#celocli-validatorregister)
* [`celocli validator:requirements`](#celocli-validatorrequirements)
* [`celocli validator:rpc-urls`](#celocli-validatorrpc-urls)
* [`celocli validator:send-payment`](#celocli-validatorsend-payment)
* [`celocli validator:set-bitmaps`](#celocli-validatorset-bitmaps)
* [`celocli validator:show ARG1`](#celocli-validatorshow-arg1)
* [`celocli validator:signed-blocks`](#celocli-validatorsigned-blocks)
Expand Down Expand Up @@ -553,6 +554,70 @@ FLAG DESCRIPTIONS
mainnet, celo, forno => Celo Mainnet chain',
```

## `celocli validator:send-payment`

Sends the allocated epoch payment to a validator, their group, and delegation beneficiary.

```
USAGE
$ celocli validator:send-payment --from 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d --for
0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d [-k <value> | --useLedger | ] [-n
<value>] [--gasCurrency 0x1234567890123456789012345678901234567890]
[--ledgerAddresses <value> ] [--ledgerLiveMode ] [--globalHelp]
FLAGS
-k, --privateKey=<value>
Use a private key to sign local transactions with
-n, --node=<value>
URL of the node to run commands against or an alias
--for=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d
(required) Address of the validator to send the payment to
--from=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d
(required) Address of the sender
--gasCurrency=0x1234567890123456789012345678901234567890
Use a specific gas currency for transaction fees (defaults to CELO if no gas
currency is supplied). It must be a whitelisted token.
--globalHelp
View all available global flags
--ledgerAddresses=<value>
[default: 1] If --useLedger is set, this will get the first N addresses for local
signing
--ledgerLiveMode
When set, the 4th postion of the derivation path will be iterated over instead of
the 5th. This is useful to use same address on you Ledger with celocli as you do on
Ledger Live
--useLedger
Set it to use a ledger wallet
DESCRIPTION
Sends the allocated epoch payment to a validator, their group, and delegation
beneficiary.
ALIASES
$ celocli validator:send-payment
EXAMPLES
send-validator-payment --for 0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95
FLAG DESCRIPTIONS
-n, --node=<value> URL of the node to run commands against or an alias
Can be a full url like https://forno.celo.org or an alias. default:
http://localhost:8545
Alias options:
local, localhost => 'http://localhost:8545'
alfajores => Celo Alfajores Testnet,
mainnet, celo, forno => Celo Mainnet chain',
```

## `celocli validator:set-bitmaps`

Set validator signature bitmaps for provided intervals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Contract handling epoch management.
- [isOnEpochProcess](wrappers_EpochManager.EpochManagerWrapper.md#isonepochprocess)
- [isTimeForNextEpoch](wrappers_EpochManager.EpochManagerWrapper.md#istimefornextepoch)
- [methodIds](wrappers_EpochManager.EpochManagerWrapper.md#methodids)
- [sendValidatorPayment](wrappers_EpochManager.EpochManagerWrapper.md#sendvalidatorpayment)
- [startNextEpochProcess](wrappers_EpochManager.EpochManagerWrapper.md#startnextepochprocess)

### Accessors
Expand Down Expand Up @@ -422,6 +423,30 @@ ___

___

### sendValidatorPayment

**sendValidatorPayment**: (...`args`: [validator: string]) => `CeloTransactionObject`\<`void`\>

#### Type declaration

▸ (`...args`): `CeloTransactionObject`\<`void`\>

##### Parameters

| Name | Type |
| :------ | :------ |
| `...args` | [validator: string] |

##### Returns

`CeloTransactionObject`\<`void`\>

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:68](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L68)

___

### startNextEpochProcess

**startNextEpochProcess**: (...`args`: []) => `CeloTransactionObject`\<`void`\>
Expand Down Expand Up @@ -476,7 +501,7 @@ BaseWrapperForGoverning.address

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:69](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L69)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:70](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L70)

___

Expand All @@ -490,7 +515,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:131](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L131)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:132](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L132)

___

Expand All @@ -510,7 +535,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:82](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L82)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:83](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L83)

___

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/contractkit/modules/wrappers_EpochManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:144](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L144)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:145](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L145)
91 changes: 91 additions & 0 deletions packages/cli/src/commands/epochs/send-validator-payment-l2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { newKitFromWeb3 } from '@celo/contractkit'
import { testWithAnvilL2 } from '@celo/dev-utils/lib/anvil-test'
import { activateAllValidatorGroupsVotes } from '../../test-utils/chain-setup'
import { stripAnsiCodesFromNestedArray, testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import SendValidatorPayment from './send-validator-payment'

process.env.NO_SYNCCHECK = 'true'

testWithAnvilL2('epochs:send-validator-payment cmd', (web3) => {
let logMock = jest.spyOn(console, 'log')
let errorMock = jest.spyOn(console, 'error')

beforeEach(async () => {
logMock.mockClear()
errorMock.mockClear()

await activateAllValidatorGroupsVotes(newKitFromWeb3(web3))
})

it('successfuly sends the payments', async () => {
const kit = newKitFromWeb3(web3)
const [sender] = await web3.eth.getAccounts()
const epochManagerWrapper = await kit.contracts.getEpochManager()
const validatorsWrapper = await kit.contracts.getValidators()
const electedValidators = await epochManagerWrapper.getElectedAccounts()
const validatorAddress = electedValidators[0]
const groupAddress = await validatorsWrapper.getValidatorsGroup(validatorAddress)
const validatorBalanceBefore = (await kit.getTotalBalance(validatorAddress)).cUSD!
const groupBalanceBefore = (await kit.getTotalBalance(groupAddress)).cUSD!

await testLocallyWithWeb3Node(
SendValidatorPayment,
['--for', validatorAddress, '--from', sender],
web3
)

// TODO as the numbers are not deterministic, we can't assert the exact values, so it's tested separately
expect(stripAnsiCodesFromNestedArray(logMock.mock.calls.slice(0, -1))).toMatchInlineSnapshot(`
[
[
"Running Checks:",
],
[
" ✔ 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 is Validator ",
],
[
"All checks passed",
],
[
"SendTransaction: sendValidatorPayment",
],
[
"txHash: 0xtxhash",
],
[
"ValidatorEpochPaymentDistributed:",
],
]
`)

const validatorBalanceAfter = (await kit.getTotalBalance(validatorAddress)).cUSD!
const groupBalanceAfter = (await kit.getTotalBalance(groupAddress)).cUSD!

expect(validatorBalanceAfter.gt(validatorBalanceBefore)).toBe(true)
expect(groupBalanceAfter.gt(groupBalanceBefore)).toBe(true)
})

it('fails if not a validator', async () => {
const [nonValidatorAccount, sender] = await web3.eth.getAccounts()

await expect(
testLocallyWithWeb3Node(
SendValidatorPayment,
['--for', nonValidatorAccount, '--from', sender],
web3
)
).rejects.toMatchInlineSnapshot(`[Error: Some checks didn't pass!]`)

expect(stripAnsiCodesFromNestedArray(logMock.mock.calls)).toMatchInlineSnapshot(`
[
[
"Running Checks:",
],
[
" ✘ 0x5409ED021D9299bf6814279A6A1411A7e866A631 is Validator ",
],
]
`)
expect(stripAnsiCodesFromNestedArray(errorMock.mock.calls)).toMatchInlineSnapshot(`[]`)
})
})
26 changes: 26 additions & 0 deletions packages/cli/src/commands/epochs/send-validator-payment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import { stripAnsiCodesFromNestedArray, testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import SendValidatorPayment from './send-validator-payment'

process.env.NO_SYNCCHECK = 'true'

testWithAnvilL1('epochs:send-validator-payment cmd', (web3) => {
let logMock = jest.spyOn(console, 'log')
let errorMock = jest.spyOn(console, 'error')

beforeEach(() => {
logMock.mockClear().mockImplementation()
errorMock.mockClear().mockImplementation()
})

it('fails if not on L2', async () => {
const [sender, validator] = await web3.eth.getAccounts()

await expect(
testLocallyWithWeb3Node(SendValidatorPayment, ['--for', validator, '--from', sender], web3)
).rejects.toMatchInlineSnapshot(`[Error: This command is only available on L2]`)

expect(stripAnsiCodesFromNestedArray(logMock.mock.calls)).toMatchInlineSnapshot(`[]`)
expect(stripAnsiCodesFromNestedArray(errorMock.mock.calls)).toMatchInlineSnapshot(`[]`)
})
})
Loading

0 comments on commit dea0a5b

Please sign in to comment.