-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into nicolasbrugneaux/use-safe
- Loading branch information
Showing
16 changed files
with
667 additions
and
15 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,5 @@ | ||
--- | ||
'@celo/contractkit': patch | ||
--- | ||
|
||
Expose `sendValidatorPayment` methods for `EpochManager` contract wrapper |
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,5 @@ | ||
--- | ||
'@celo/celocli': minor | ||
--- | ||
|
||
Add `epochs:send-validator-payment` command to support sending validator, their group and delegation beneficiary allocated epoch payments |
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,5 @@ | ||
--- | ||
'@celo/celocli': patch | ||
--- | ||
|
||
Fix bug with GovernanceSlasher missing version causing failure. defend against exceptions when printing contracts info |
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
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
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
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
91 changes: 91 additions & 0 deletions
91
packages/cli/src/commands/epochs/send-validator-payment-l2.test.ts
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,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
26
packages/cli/src/commands/epochs/send-validator-payment.test.ts
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 { 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(`[]`) | ||
}) | ||
}) |
Oops, something went wrong.