From 2478aa6328a0ff846427f9cf7737db78aeb46f9e Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Tue, 20 Aug 2024 14:46:33 +0200 Subject: [PATCH] Migrate CLI validator, validatorgroup and election commands to anvil (#330) --- .../src/commands/election/activate.test.ts | 24 +++-- .../cli/src/commands/election/current.test.ts | 10 +- .../cli/src/commands/election/list.test.ts | 4 +- .../cli/src/commands/election/revoke.test.ts | 46 ++++---- .../cli/src/commands/election/run.test.ts | 10 +- .../cli/src/commands/election/show.test.ts | 20 ++-- .../cli/src/commands/election/vote.test.ts | 32 ++++-- .../src/commands/validator/register.test.ts | 102 +++++++++++------- .../validatorgroup/commission.test.ts | 51 ++++++--- 9 files changed, 183 insertions(+), 116 deletions(-) diff --git a/packages/cli/src/commands/election/activate.test.ts b/packages/cli/src/commands/election/activate.test.ts index baa7d4cf2..4a8ad852f 100644 --- a/packages/cli/src/commands/election/activate.test.ts +++ b/packages/cli/src/commands/election/activate.test.ts @@ -1,5 +1,5 @@ import { newKitFromWeb3 } from '@celo/contractkit' -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import { ux } from '@oclif/core' import BigNumber from 'bignumber.js' import Web3 from 'web3' @@ -10,18 +10,20 @@ import { setupGroupAndAffiliateValidator, voteForGroupFrom, } from '../../test-utils/chain-setup' -import { stripAnsiCodesAndTxHashes, testLocally } from '../../test-utils/cliUtils' +import { stripAnsiCodesAndTxHashes, testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import ElectionActivate from './activate' process.env.NO_SYNCCHECK = 'true' -testWithGanache('election:activate', (web3: Web3) => { +testWithAnvilL1('election:activate', (web3: Web3) => { afterEach(async () => { jest.clearAllMocks() }) it('fails when no flags are provided', async () => { - await expect(testLocally(ElectionActivate, [])).rejects.toThrow('Missing required flag from') + await expect(testLocallyWithWeb3Node(ElectionActivate, [], web3)).rejects.toThrow( + 'Missing required flag from' + ) }) it('shows no pending votes', async () => { @@ -31,7 +33,7 @@ testWithGanache('election:activate', (web3: Web3) => { await registerAccount(kit, userAddress) - await testLocally(ElectionActivate, ['--from', userAddress]) + await testLocallyWithWeb3Node(ElectionActivate, ['--from', userAddress], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(` [ @@ -53,7 +55,7 @@ testWithGanache('election:activate', (web3: Web3) => { await registerAccountWithLockedGold(kit, userAddress) await voteForGroupFrom(kit, userAddress, groupAddress, new BigNumber(10)) - await testLocally(ElectionActivate, ['--from', userAddress]) + await testLocallyWithWeb3Node(ElectionActivate, ['--from', userAddress], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(` [ @@ -83,7 +85,7 @@ testWithGanache('election:activate', (web3: Web3) => { new BigNumber(0) ) - await testLocally(ElectionActivate, ['--from', userAddress]) + await testLocallyWithWeb3Node(ElectionActivate, ['--from', userAddress], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(`[]`) expect((await election.getVotesForGroupByAccount(userAddress, groupAddress)).active).toEqual( @@ -109,7 +111,7 @@ testWithGanache('election:activate', (web3: Web3) => { ) await Promise.all([ - testLocally(ElectionActivate, ['--from', userAddress, '--wait']), + testLocallyWithWeb3Node(ElectionActivate, ['--from', userAddress, '--wait'], web3), new Promise((resolve) => { // at least the amount the --wait flag waits in the check setTimeout(async () => { @@ -167,7 +169,11 @@ testWithGanache('election:activate', (web3: Web3) => { (await election.getVotesForGroupByAccount(otherUserAddress, groupAddress)).active ).toEqual(new BigNumber(0)) - await testLocally(ElectionActivate, ['--from', otherUserAddress, '--for', userAddress]) + await testLocallyWithWeb3Node( + ElectionActivate, + ['--from', otherUserAddress, '--for', userAddress], + web3 + ) expect(writeMock.mock.calls).toMatchInlineSnapshot(`[]`) expect((await election.getVotesForGroupByAccount(userAddress, groupAddress)).active).toEqual( diff --git a/packages/cli/src/commands/election/current.test.ts b/packages/cli/src/commands/election/current.test.ts index 8571ddd40..2f2c9bc4f 100644 --- a/packages/cli/src/commands/election/current.test.ts +++ b/packages/cli/src/commands/election/current.test.ts @@ -2,12 +2,12 @@ import { newKitFromWeb3 } from '@celo/contractkit' import { WrapperCache } from '@celo/contractkit/lib/contract-cache' import { ElectionWrapper } from '@celo/contractkit/lib/wrappers/Election' import { ValidatorsWrapper } from '@celo/contractkit/lib/wrappers/Validators' -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import { ux } from '@oclif/core' import BigNumber from 'bignumber.js' import Web3 from 'web3' import { registerAccount, setupGroupAndAffiliateValidator } from '../../test-utils/chain-setup' -import { testLocally } from '../../test-utils/cliUtils' +import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import Current from './current' process.env.NO_SYNCCHECK = 'true' @@ -17,7 +17,7 @@ afterEach(async () => { jest.restoreAllMocks() }) -testWithGanache('election:current cmd', async (web3: Web3) => { +testWithAnvilL1('election:current cmd', async (web3: Web3) => { it('shows list with no --valset provided', async () => { const kit = newKitFromWeb3(web3) const [ @@ -75,7 +75,7 @@ testWithGanache('election:current cmd', async (web3: Web3) => { const warnMock = jest.spyOn(console, 'warn') const writeMock = jest.spyOn(ux.write, 'stdout') - await testLocally(Current, ['--csv']) + await testLocallyWithWeb3Node(Current, ['--csv'], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(` [ @@ -152,7 +152,7 @@ testWithGanache('election:current cmd', async (web3: Web3) => { const warnMock = jest.spyOn(console, 'warn') const writeMock = jest.spyOn(ux.write, 'stdout') - await testLocally(Current, ['--csv', '--valset']) + await testLocallyWithWeb3Node(Current, ['--csv', '--valset'], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(` [ diff --git a/packages/cli/src/commands/election/list.test.ts b/packages/cli/src/commands/election/list.test.ts index 8cbbb3278..bb4297863 100644 --- a/packages/cli/src/commands/election/list.test.ts +++ b/packages/cli/src/commands/election/list.test.ts @@ -1,5 +1,5 @@ import { ElectionWrapper, ValidatorGroupVote } from '@celo/contractkit/lib/wrappers/Election' -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import { ux } from '@oclif/core' import BigNumber from 'bignumber.js' import Web3 from 'web3' @@ -8,7 +8,7 @@ import ElectionList from './list' process.env.NO_SYNCCHECK = 'true' -testWithGanache('election:list cmd', (web3: Web3) => { +testWithAnvilL1('election:list cmd', (web3: Web3) => { test('shows list when no arguments provided', async () => { const getValidatorGroupsVotesMock = jest.spyOn( ElectionWrapper.prototype, diff --git a/packages/cli/src/commands/election/revoke.test.ts b/packages/cli/src/commands/election/revoke.test.ts index 32e132d09..e4b5ed279 100644 --- a/packages/cli/src/commands/election/revoke.test.ts +++ b/packages/cli/src/commands/election/revoke.test.ts @@ -1,5 +1,5 @@ import { newKitFromWeb3 } from '@celo/contractkit' -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import BigNumber from 'bignumber.js' import Web3 from 'web3' import { @@ -8,18 +8,18 @@ import { setupGroupAndAffiliateValidator, voteForGroupFromAndActivateVotes, } from '../../test-utils/chain-setup' -import { testLocally } from '../../test-utils/cliUtils' +import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import Revoke from './revoke' process.env.NO_SYNCCHECK = 'true' -testWithGanache('election:revoke', (web3: Web3) => { +testWithAnvilL1('election:revoke', (web3: Web3) => { afterEach(async () => { jest.clearAllMocks() }) it('fails when no flags are provided', async () => { - await expect(testLocally(Revoke, [])).rejects.toThrow('Missing required flag') + await expect(testLocallyWithWeb3Node(Revoke, [], web3)).rejects.toThrow('Missing required flag') }) it('fails when address is not an account', async () => { @@ -27,7 +27,11 @@ testWithGanache('election:revoke', (web3: Web3) => { const [fromAddress, groupAddress] = await web3.eth.getAccounts() await expect( - testLocally(Revoke, ['--from', fromAddress, '--for', groupAddress, '--value', '1']) + testLocallyWithWeb3Node( + Revoke, + ['--from', fromAddress, '--for', groupAddress, '--value', '1'], + web3 + ) ).rejects.toThrow() expect(logMock.mock.calls[1][0]).toContain( `${fromAddress} is not a signer or registered as an account` @@ -41,7 +45,11 @@ testWithGanache('election:revoke', (web3: Web3) => { await registerAccount(kit, fromAddress) await expect( - testLocally(Revoke, ['--from', fromAddress, '--for', groupAddress, '--value', '1']) + testLocallyWithWeb3Node( + Revoke, + ['--from', fromAddress, '--for', groupAddress, '--value', '1'], + web3 + ) ).rejects.toThrow( `can't revoke more votes for ${groupAddress} than have been made by ${fromAddress}` ) @@ -61,14 +69,11 @@ testWithGanache('election:revoke', (web3: Web3) => { amount ) - await testLocally(Revoke, [ - '--from', - fromAddress, - '--for', - groupAddress, - '--value', - amount.toFixed(), - ]) + await testLocallyWithWeb3Node( + Revoke, + ['--from', fromAddress, '--for', groupAddress, '--value', amount.toFixed()], + web3 + ) expect((await election.getVotesForGroupByAccount(fromAddress, groupAddress)).active).toEqual( new BigNumber(0) @@ -90,14 +95,11 @@ testWithGanache('election:revoke', (web3: Web3) => { amount ) - await testLocally(Revoke, [ - '--from', - fromAddress, - '--for', - groupAddress, - '--value', - revokeAmount.toFixed(), - ]) + await testLocallyWithWeb3Node( + Revoke, + ['--from', fromAddress, '--for', groupAddress, '--value', revokeAmount.toFixed()], + web3 + ) expect((await election.getVotesForGroupByAccount(fromAddress, groupAddress)).active).toEqual( amount.minus(revokeAmount) diff --git a/packages/cli/src/commands/election/run.test.ts b/packages/cli/src/commands/election/run.test.ts index 96077cb32..6742943b7 100644 --- a/packages/cli/src/commands/election/run.test.ts +++ b/packages/cli/src/commands/election/run.test.ts @@ -1,17 +1,17 @@ import { newKitFromWeb3 } from '@celo/contractkit' import { ElectionWrapper } from '@celo/contractkit/lib/wrappers/Election' import { ValidatorsWrapper } from '@celo/contractkit/lib/wrappers/Validators' -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import { ux } from '@oclif/core' import BigNumber from 'bignumber.js' import Web3 from 'web3' import { setupGroupAndAffiliateValidator } from '../../test-utils/chain-setup' -import { stripAnsiCodesAndTxHashes, testLocally } from '../../test-utils/cliUtils' +import { stripAnsiCodesAndTxHashes, testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import Run from './run' process.env.NO_SYNCCHECK = 'true' -testWithGanache('election:run', (web3: Web3) => { +testWithAnvilL1('election:run', (web3: Web3) => { afterEach(async () => { jest.clearAllMocks() }) @@ -21,7 +21,7 @@ testWithGanache('election:run', (web3: Web3) => { const warnMock = jest.spyOn(console, 'warn') const writeMock = jest.spyOn(ux.write, 'stdout') - await testLocally(Run, ['--csv']) + await testLocallyWithWeb3Node(Run, ['--csv'], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(` [ @@ -89,7 +89,7 @@ testWithGanache('election:run', (web3: Web3) => { signer: anotherSignerAddress, })) - await testLocally(Run, ['--csv']) + await testLocallyWithWeb3Node(Run, ['--csv'], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(` [ diff --git a/packages/cli/src/commands/election/show.test.ts b/packages/cli/src/commands/election/show.test.ts index 78cf06938..f3f1f1486 100644 --- a/packages/cli/src/commands/election/show.test.ts +++ b/packages/cli/src/commands/election/show.test.ts @@ -1,27 +1,29 @@ import { newKitFromWeb3 } from '@celo/contractkit' import { ElectionWrapper, ValidatorGroupVote, Voter } from '@celo/contractkit/lib/wrappers/Election' -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import { ux } from '@oclif/core' import BigNumber from 'bignumber.js' import Web3 from 'web3' import { registerAccount, setupGroup } from '../../test-utils/chain-setup' -import { stripAnsiCodesAndTxHashes, testLocally } from '../../test-utils/cliUtils' +import { stripAnsiCodesAndTxHashes, testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import Show from './show' process.env.NO_SYNCCHECK = 'true' -testWithGanache('election:show', (web3: Web3) => { +testWithAnvilL1('election:show', (web3: Web3) => { afterEach(async () => { jest.clearAllMocks() }) it('fails when no args are provided', async () => { - await expect(testLocally(Show, [])).rejects.toThrow("Voter or Validator Groups's address") + await expect(testLocallyWithWeb3Node(Show, [], web3)).rejects.toThrow( + "Voter or Validator Groups's address" + ) }) it('fails when no flags are provided', async () => { const [groupAddress] = await web3.eth.getAccounts() - await expect(testLocally(Show, [groupAddress])).rejects.toThrow( + await expect(testLocallyWithWeb3Node(Show, [groupAddress], web3)).rejects.toThrow( 'Must select --voter or --group' ) }) @@ -30,7 +32,7 @@ testWithGanache('election:show', (web3: Web3) => { const logMock = jest.spyOn(console, 'log') const [groupAddress] = await web3.eth.getAccounts() - await expect(testLocally(Show, [groupAddress, '--group'])).rejects.toThrow( + await expect(testLocallyWithWeb3Node(Show, [groupAddress, '--group'], web3)).rejects.toThrow( "Some checks didn't pass!" ) expect(stripAnsiCodesAndTxHashes(logMock.mock.calls[1][0])).toContain( @@ -42,7 +44,7 @@ testWithGanache('election:show', (web3: Web3) => { const logMock = jest.spyOn(console, 'log') const [voterAddress] = await web3.eth.getAccounts() - await expect(testLocally(Show, [voterAddress, '--voter'])).rejects.toThrow( + await expect(testLocallyWithWeb3Node(Show, [voterAddress, '--voter'], web3)).rejects.toThrow( "Some checks didn't pass!" ) expect(stripAnsiCodesAndTxHashes(logMock.mock.calls[1][0])).toContain( @@ -72,7 +74,7 @@ testWithGanache('election:show', (web3: Web3) => { } as ValidatorGroupVote }) - await testLocally(Show, [groupAddress, '--group']) + await testLocallyWithWeb3Node(Show, [groupAddress, '--group'], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(`[]`) expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes))) @@ -125,7 +127,7 @@ testWithGanache('election:show', (web3: Web3) => { } as Voter }) - await testLocally(Show, [voterAddress, '--voter']) + await testLocallyWithWeb3Node(Show, [voterAddress, '--voter'], web3) expect(writeMock.mock.calls).toMatchInlineSnapshot(`[]`) expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes))) diff --git a/packages/cli/src/commands/election/vote.test.ts b/packages/cli/src/commands/election/vote.test.ts index 80f061e0b..a59a893ae 100644 --- a/packages/cli/src/commands/election/vote.test.ts +++ b/packages/cli/src/commands/election/vote.test.ts @@ -1,5 +1,5 @@ import { newKitFromWeb3 } from '@celo/contractkit' -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import { ux } from '@oclif/core' import BigNumber from 'bignumber.js' import Web3 from 'web3' @@ -8,18 +8,18 @@ import { registerAccountWithLockedGold, setupGroupAndAffiliateValidator, } from '../../test-utils/chain-setup' -import { stripAnsiCodesAndTxHashes, testLocally } from '../../test-utils/cliUtils' +import { stripAnsiCodesAndTxHashes, testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import Vote from './vote' process.env.NO_SYNCCHECK = 'true' -testWithGanache('election:vote', (web3: Web3) => { +testWithAnvilL1('election:vote', (web3: Web3) => { afterEach(async () => { jest.clearAllMocks() }) it('fails when no flags are provided', async () => { - await expect(testLocally(Vote, [])).rejects.toThrow('Missing required flag') + await expect(testLocallyWithWeb3Node(Vote, [], web3)).rejects.toThrow('Missing required flag') }) it('fails when voter is not an account', async () => { @@ -27,7 +27,11 @@ testWithGanache('election:vote', (web3: Web3) => { const [fromAddress, groupAddress] = await web3.eth.getAccounts() await expect( - testLocally(Vote, ['--from', fromAddress, '--for', groupAddress, '--value', '1']) + testLocallyWithWeb3Node( + Vote, + ['--from', fromAddress, '--for', groupAddress, '--value', '1'], + web3 + ) ).rejects.toThrow() expect(logMock.mock.calls[1][0]).toContain( @@ -43,7 +47,11 @@ testWithGanache('election:vote', (web3: Web3) => { await registerAccount(kit, fromAddress) await expect( - testLocally(Vote, ['--from', fromAddress, '--for', groupAddress, '--value', '1']) + testLocallyWithWeb3Node( + Vote, + ['--from', fromAddress, '--for', groupAddress, '--value', '1'], + web3 + ) ).rejects.toThrow() expect(stripAnsiCodesAndTxHashes(logMock.mock.calls[2][0])).toContain( @@ -60,7 +68,11 @@ testWithGanache('election:vote', (web3: Web3) => { await setupGroupAndAffiliateValidator(kit, groupAddress, validatorAddress) await expect( - testLocally(Vote, ['--from', fromAddress, '--for', groupAddress, '--value', '1']) + testLocallyWithWeb3Node( + Vote, + ['--from', fromAddress, '--for', groupAddress, '--value', '1'], + web3 + ) ).rejects.toThrow() expect(stripAnsiCodesAndTxHashes(logMock.mock.calls[3][0])).toContain( @@ -84,7 +96,11 @@ testWithGanache('election:vote', (web3: Web3) => { ) await expect( - testLocally(Vote, ['--from', fromAddress, '--for', groupAddress, '--value', amount.toFixed()]) + testLocallyWithWeb3Node( + Vote, + ['--from', fromAddress, '--for', groupAddress, '--value', amount.toFixed()], + web3 + ) ).resolves.not.toThrow() expect(await election.getTotalVotesForGroupByAccount(groupAddress, fromAddress)).toEqual(amount) diff --git a/packages/cli/src/commands/validator/register.test.ts b/packages/cli/src/commands/validator/register.test.ts index 17173ac81..f1bffd0c7 100644 --- a/packages/cli/src/commands/validator/register.test.ts +++ b/packages/cli/src/commands/validator/register.test.ts @@ -1,14 +1,14 @@ -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' import { addressToPublicKey } from '@celo/utils/lib/signatureUtils' import Web3 from 'web3' -import { testLocally } from '../../test-utils/cliUtils' +import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import Register from '../account/register' import Lock from '../lockedgold/lock' import ValidatorRegister from './register' process.env.NO_SYNCCHECK = 'true' -testWithGanache('validator:register', (web3: Web3) => { +testWithAnvilL1('validator:register', (web3: Web3) => { let account: string let ecdsaPublicKey: string @@ -16,52 +16,54 @@ testWithGanache('validator:register', (web3: Web3) => { const accounts = await web3.eth.getAccounts() account = accounts[0] ecdsaPublicKey = await addressToPublicKey(account, web3.eth.sign) - await testLocally(Register, ['--from', account]) - await testLocally(Lock, ['--from', account, '--value', '10000000000000000000000']) + await testLocallyWithWeb3Node(Register, ['--from', account], web3) + await testLocallyWithWeb3Node( + Lock, + ['--from', account, '--value', '10000000000000000000000'], + web3 + ) }) test('can register validator with 0x prefix', async () => { - await testLocally(ValidatorRegister, [ - '--from', - account, - '--ecdsaKey', - ecdsaPublicKey, - '--blsKey', - '0x4fa3f67fc913878b068d1fa1cdddc54913d3bf988dbe5a36a20fa888f20d4894c408a6773f3d7bde11154f2a3076b700d345a42fd25a0e5e83f4db5586ac7979ac2053cd95d8f2efd3e959571ceccaa743e02cf4be3f5d7aaddb0b06fc9aff00', - '--blsSignature', - '0xcdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900', - '--yes', - ]) + await testLocallyWithWeb3Node( + ValidatorRegister, + [ + '--from', + account, + '--ecdsaKey', + ecdsaPublicKey, + '--blsKey', + '0x4fa3f67fc913878b068d1fa1cdddc54913d3bf988dbe5a36a20fa888f20d4894c408a6773f3d7bde11154f2a3076b700d345a42fd25a0e5e83f4db5586ac7979ac2053cd95d8f2efd3e959571ceccaa743e02cf4be3f5d7aaddb0b06fc9aff00', + '--blsSignature', + '0xcdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900', + '--yes', + ], + web3 + ) }) test('can register validator without 0x prefix', async () => { - await testLocally(ValidatorRegister, [ - '--from', - account, - '--ecdsaKey', - ecdsaPublicKey, - '--blsKey', - '4fa3f67fc913878b068d1fa1cdddc54913d3bf988dbe5a36a20fa888f20d4894c408a6773f3d7bde11154f2a3076b700d345a42fd25a0e5e83f4db5586ac7979ac2053cd95d8f2efd3e959571ceccaa743e02cf4be3f5d7aaddb0b06fc9aff00', - '--blsSignature', - 'cdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900', - '--yes', - ]) + await testLocallyWithWeb3Node( + ValidatorRegister, + [ + '--from', + account, + '--ecdsaKey', + ecdsaPublicKey, + '--blsKey', + '4fa3f67fc913878b068d1fa1cdddc54913d3bf988dbe5a36a20fa888f20d4894c408a6773f3d7bde11154f2a3076b700d345a42fd25a0e5e83f4db5586ac7979ac2053cd95d8f2efd3e959571ceccaa743e02cf4be3f5d7aaddb0b06fc9aff00', + '--blsSignature', + 'cdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900', + '--yes', + ], + web3 + ) }) test('fails if validator already registered', async () => { - await testLocally(ValidatorRegister, [ - '--from', - account, - '--ecdsaKey', - ecdsaPublicKey, - '--blsKey', - '4fa3f67fc913878b068d1fa1cdddc54913d3bf988dbe5a36a20fa888f20d4894c408a6773f3d7bde11154f2a3076b700d345a42fd25a0e5e83f4db5586ac7979ac2053cd95d8f2efd3e959571ceccaa743e02cf4be3f5d7aaddb0b06fc9aff00', - '--blsSignature', - 'cdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900', - '--yes', - ]) - await expect( - testLocally(ValidatorRegister, [ + await testLocallyWithWeb3Node( + ValidatorRegister, + [ '--from', account, '--ecdsaKey', @@ -71,7 +73,25 @@ testWithGanache('validator:register', (web3: Web3) => { '--blsSignature', 'cdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900', '--yes', - ]) + ], + web3 + ) + await expect( + testLocallyWithWeb3Node( + ValidatorRegister, + [ + '--from', + account, + '--ecdsaKey', + ecdsaPublicKey, + '--blsKey', + '4fa3f67fc913878b068d1fa1cdddc54913d3bf988dbe5a36a20fa888f20d4894c408a6773f3d7bde11154f2a3076b700d345a42fd25a0e5e83f4db5586ac7979ac2053cd95d8f2efd3e959571ceccaa743e02cf4be3f5d7aaddb0b06fc9aff00', + '--blsSignature', + 'cdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900', + '--yes', + ], + web3 + ) ).rejects.toThrow("Some checks didn't pass!") }) }) diff --git a/packages/cli/src/commands/validatorgroup/commission.test.ts b/packages/cli/src/commands/validatorgroup/commission.test.ts index c37eca2be..ee42351a7 100644 --- a/packages/cli/src/commands/validatorgroup/commission.test.ts +++ b/packages/cli/src/commands/validatorgroup/commission.test.ts @@ -1,6 +1,9 @@ -import { mineBlocks, testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { newKitFromWeb3 } from '@celo/contractkit' +import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' +import { setCommissionUpdateDelay } from '@celo/dev-utils/lib/chain-setup' +import { mineBlocks } from '@celo/dev-utils/lib/ganache-test' import Web3 from 'web3' -import { testLocally } from '../../test-utils/cliUtils' +import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils' import AccountRegister from '../account/register' import Lock from '../lockedgold/lock' import Commission from './commission' @@ -8,31 +11,49 @@ import ValidatorGroupRegister from './register' process.env.NO_SYNCCHECK = 'true' -testWithGanache('validatorgroup:comission cmd', (web3: Web3) => { +testWithAnvilL1('validatorgroup:comission cmd', (web3: Web3) => { const registerValidatorGroup = async () => { const accounts = await web3.eth.getAccounts() - await testLocally(AccountRegister, ['--from', accounts[0]]) - await testLocally(Lock, ['--from', accounts[0], '--value', '10000000000000000000000']) - await testLocally(ValidatorGroupRegister, [ - '--from', - accounts[0], - '--commission', - '0.1', - '--yes', - ]) + await testLocallyWithWeb3Node(AccountRegister, ['--from', accounts[0]], web3) + await testLocallyWithWeb3Node( + Lock, + ['--from', accounts[0], '--value', '10000000000000000000000'], + web3 + ) + await testLocallyWithWeb3Node( + ValidatorGroupRegister, + ['--from', accounts[0], '--commission', '0.1', '--yes'], + web3 + ) } test('can queue update', async () => { const accounts = await web3.eth.getAccounts() await registerValidatorGroup() - await testLocally(Commission, ['--from', accounts[0], '--queue-update', '0.2']) + await testLocallyWithWeb3Node( + Commission, + ['--from', accounts[0], '--queue-update', '0.2'], + web3 + ) }) test('can apply update', async () => { const accounts = await web3.eth.getAccounts() + const kit = newKitFromWeb3(web3) + const validatorsWrapper = await kit.contracts.getValidators() + + // Set commission update delay to 3 blocks for backwards compatibility + await setCommissionUpdateDelay(web3, validatorsWrapper.address, 3) + await registerValidatorGroup() - await testLocally(Commission, ['--from', accounts[0], '--queue-update', '0.2']) + await testLocallyWithWeb3Node( + Commission, + ['--from', accounts[0], '--queue-update', '0.2'], + web3 + ) + await mineBlocks(3, web3) - await testLocally(Commission, ['--from', accounts[0], '--apply']) + + await testLocallyWithWeb3Node(Commission, ['--from', accounts[0], '--apply'], web3) }) })