Skip to content

Commit

Permalink
Use L2 devchain (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazarre authored Jul 26, 2024
1 parent def3f2d commit 053d2b1
Show file tree
Hide file tree
Showing 53 changed files with 297 additions and 277 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-icons-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/dev-utils': patch
---

Introduces testWithAnvilL1 and testWithAnvilL2 that replace previously used testWithAnvil to make it explicit in which context given test suite is being run.
4 changes: 2 additions & 2 deletions packages/cli/src/commands/account/authorize.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test'
import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import { addressToPublicKey } from '@celo/utils/lib/signatureUtils'
import Web3 from 'web3'
import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
Expand All @@ -10,7 +10,7 @@ import Register from './register'

process.env.NO_SYNCCHECK = 'true'

testWithAnvil('account:authorize cmd', (web3: Web3) => {
testWithAnvilL1('account:authorize cmd', (web3: Web3) => {
test('can authorize vote signer', async () => {
const accounts = await web3.eth.getAccounts()
const notRegisteredAccount = accounts[0]
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/account/claims.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ContractKit, IdentityMetadataWrapper, newKitFromWeb3 } from '@celo/contractkit'
import { ClaimTypes } from '@celo/contractkit/lib/identity'
import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test'
import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import { readFileSync, writeFileSync } from 'fs'
import { tmpdir } from 'os'
import Web3 from 'web3'
Expand All @@ -12,7 +12,7 @@ import CreateMetadata from './create-metadata'
import RegisterMetadata from './register-metadata'
process.env.NO_SYNCCHECK = 'true'

testWithAnvil('account metadata cmds', (web3: Web3) => {
testWithAnvilL1('account metadata cmds', (web3: Web3) => {
let account: string
let accounts: string[]
let kit: ContractKit
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/account/deauthorize.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test'
import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import { PROOF_OF_POSSESSION_SIGNATURE } from '../../test-utils/constants'
import Authorize from './authorize'
Expand All @@ -7,7 +7,7 @@ import Register from './register'

process.env.NO_SYNCCHECK = 'true'

testWithAnvil('account:deauthorize cmd', (web3) => {
testWithAnvilL1('account:deauthorize cmd', (web3) => {
test('can deauthorize attestation signer', async () => {
const accounts = await web3.eth.getAccounts()
const notRegisteredAccount = accounts[0]
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/account/list.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit'
import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test'
import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import { AddressValidation } from '@celo/wallet-ledger/lib/ledger-wallet'
import { LocalWallet } from '@celo/wallet-local'
import Web3 from 'web3'
Expand All @@ -24,7 +24,7 @@ jest.mock('@celo/wallet-ledger', () => {
}
})

testWithAnvil('account:list', (web3: Web3) => {
testWithAnvilL1('account:list', (web3: Web3) => {
let account: string
let accounts: string[]
let kit: ContractKit
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/account/register.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { newKitFromWeb3 } from '@celo/contractkit'
import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test'
import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import Web3 from 'web3'
import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import Register from './register'

process.env.NO_SYNCCHECK = 'true'

testWithAnvil('account:register cmd', (web3: Web3) => {
testWithAnvilL1('account:register cmd', (web3: Web3) => {
test('can register account', async () => {
const accounts = await web3.eth.getAccounts()

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/account/set-name.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test'
import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import Web3 from 'web3'
import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import Register from '../account/register'
import SetName from './set-name'

process.env.NO_SYNCCHECK = 'true'

testWithAnvil('account:set-name cmd', (web3: Web3) => {
testWithAnvilL1('account:set-name cmd', (web3: Web3) => {
test('can set the name of an account', async () => {
const accounts = await web3.eth.getAccounts()
await testLocallyWithWeb3Node(Register, ['--from', accounts[0]], web3)
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/config/set.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newKitFromWeb3 } from '@celo/contractkit'
import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test'
import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import { ux } from '@oclif/core'
import Web3 from 'web3'
import {
Expand All @@ -17,7 +17,7 @@ afterEach(async () => {
jest.restoreAllMocks()
})

testWithAnvil('config:set cmd', (web3: Web3) => {
testWithAnvilL1('config:set cmd', (web3: Web3) => {
it('shows a warning if gasCurrency is passed', async () => {
const kit = newKitFromWeb3(web3)
const feeCurrencyDirectory = await kit.contracts.getFeeCurrencyDirectory()
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/commands/election/activate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
setupGroupAndAffiliateValidator,
voteForGroupFrom,
} from '../../test-utils/chain-setup'
import { stripAnsiCodes, testLocally } from '../../test-utils/cliUtils'
import { stripAnsiCodesAndTxHashes, testLocally } from '../../test-utils/cliUtils'
import ElectionActivate from './activate'

process.env.NO_SYNCCHECK = 'true'
Expand Down Expand Up @@ -119,7 +119,8 @@ testWithGanache('election:activate', (web3: Web3) => {
}),
])

expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodes))).toMatchInlineSnapshot(`
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes)))
.toMatchInlineSnapshot(`
[
[
"Running Checks:",
Expand All @@ -134,7 +135,7 @@ testWithGanache('election:activate', (web3: Web3) => {
"SendTransaction: activate",
],
[
"txHash: 0xeb8b78386a4a12b607bc7fcd5025f9b831b37eda9b3719a87c7235947a314d49",
"txHash: 0xtxhash",
],
]
`)
Expand Down
17 changes: 12 additions & 5 deletions packages/cli/src/commands/election/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ux } from '@oclif/core'
import BigNumber from 'bignumber.js'
import Web3 from 'web3'
import { setupGroupAndAffiliateValidator } from '../../test-utils/chain-setup'
import { stripAnsiCodes, testLocally } from '../../test-utils/cliUtils'
import { stripAnsiCodesAndTxHashes, testLocally } from '../../test-utils/cliUtils'
import Run from './run'

process.env.NO_SYNCCHECK = 'true'
Expand All @@ -31,8 +31,11 @@ testWithGanache('election:run', (web3: Web3) => {
],
]
`)
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodes))).toMatchInlineSnapshot(`[]`)
expect(warnMock.mock.calls.map((args) => args.map(stripAnsiCodes))).toMatchInlineSnapshot(`
expect(
logMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes))
).toMatchInlineSnapshot(`[]`)
expect(warnMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes)))
.toMatchInlineSnapshot(`
[
[
"Warning: error running actual elections, retrying with minimum validators at 0",
Expand Down Expand Up @@ -104,7 +107,11 @@ testWithGanache('election:run', (web3: Web3) => {
],
]
`)
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodes))).toMatchInlineSnapshot(`[]`)
expect(warnMock.mock.calls.map((args) => args.map(stripAnsiCodes))).toMatchInlineSnapshot(`[]`)
expect(
logMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes))
).toMatchInlineSnapshot(`[]`)
expect(
warnMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes))
).toMatchInlineSnapshot(`[]`)
})
})
12 changes: 7 additions & 5 deletions packages/cli/src/commands/election/show.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ux } from '@oclif/core'
import BigNumber from 'bignumber.js'
import Web3 from 'web3'
import { registerAccount, setupGroup } from '../../test-utils/chain-setup'
import { stripAnsiCodes, testLocally } from '../../test-utils/cliUtils'
import { stripAnsiCodesAndTxHashes, testLocally } from '../../test-utils/cliUtils'
import Show from './show'

process.env.NO_SYNCCHECK = 'true'
Expand Down Expand Up @@ -33,7 +33,7 @@ testWithGanache('election:show', (web3: Web3) => {
await expect(testLocally(Show, [groupAddress, '--group'])).rejects.toThrow(
"Some checks didn't pass!"
)
expect(stripAnsiCodes(logMock.mock.calls[1][0])).toContain(
expect(stripAnsiCodesAndTxHashes(logMock.mock.calls[1][0])).toContain(
`✘ ${groupAddress} is ValidatorGroup`
)
})
Expand All @@ -45,7 +45,7 @@ testWithGanache('election:show', (web3: Web3) => {
await expect(testLocally(Show, [voterAddress, '--voter'])).rejects.toThrow(
"Some checks didn't pass!"
)
expect(stripAnsiCodes(logMock.mock.calls[1][0])).toContain(
expect(stripAnsiCodesAndTxHashes(logMock.mock.calls[1][0])).toContain(
`${voterAddress} is not registered as an account. Try running account:register`
)
})
Expand Down Expand Up @@ -75,7 +75,8 @@ testWithGanache('election:show', (web3: Web3) => {
await testLocally(Show, [groupAddress, '--group'])

expect(writeMock.mock.calls).toMatchInlineSnapshot(`[]`)
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodes))).toMatchInlineSnapshot(`
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes)))
.toMatchInlineSnapshot(`
[
[
"Running Checks:",
Expand Down Expand Up @@ -127,7 +128,8 @@ testWithGanache('election:show', (web3: Web3) => {
await testLocally(Show, [voterAddress, '--voter'])

expect(writeMock.mock.calls).toMatchInlineSnapshot(`[]`)
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodes))).toMatchInlineSnapshot(`
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes)))
.toMatchInlineSnapshot(`
[
[
"Running Checks:",
Expand Down
11 changes: 6 additions & 5 deletions packages/cli/src/commands/election/vote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
registerAccountWithLockedGold,
setupGroupAndAffiliateValidator,
} from '../../test-utils/chain-setup'
import { stripAnsiCodes, testLocally } from '../../test-utils/cliUtils'
import { stripAnsiCodesAndTxHashes, testLocally } from '../../test-utils/cliUtils'
import Vote from './vote'

process.env.NO_SYNCCHECK = 'true'
Expand Down Expand Up @@ -46,7 +46,7 @@ testWithGanache('election:vote', (web3: Web3) => {
testLocally(Vote, ['--from', fromAddress, '--for', groupAddress, '--value', '1'])
).rejects.toThrow()

expect(stripAnsiCodes(logMock.mock.calls[2][0])).toContain(
expect(stripAnsiCodesAndTxHashes(logMock.mock.calls[2][0])).toContain(
`✘ 0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb is ValidatorGroup`
)
})
Expand All @@ -63,7 +63,7 @@ testWithGanache('election:vote', (web3: Web3) => {
testLocally(Vote, ['--from', fromAddress, '--for', groupAddress, '--value', '1'])
).rejects.toThrow()

expect(stripAnsiCodes(logMock.mock.calls[3][0])).toContain(
expect(stripAnsiCodesAndTxHashes(logMock.mock.calls[3][0])).toContain(
`✘ Account has at least 0.000000000000000001 non-voting Locked Gold`
)
})
Expand All @@ -88,7 +88,8 @@ testWithGanache('election:vote', (web3: Web3) => {
).resolves.not.toThrow()

expect(await election.getTotalVotesForGroupByAccount(groupAddress, fromAddress)).toEqual(amount)
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodes))).toMatchInlineSnapshot(`
expect(logMock.mock.calls.map((args) => args.map(stripAnsiCodesAndTxHashes)))
.toMatchInlineSnapshot(`
[
[
"Running Checks:",
Expand All @@ -109,7 +110,7 @@ testWithGanache('election:vote', (web3: Web3) => {
"SendTransaction: vote",
],
[
"txHash: 0x5427ddef3d99512241b5c61b8c0467674c7278ef86a2258676d864430285b1ad",
"txHash: 0xtxhash",
],
]
`)
Expand Down
Loading

0 comments on commit 053d2b1

Please sign in to comment.