Skip to content

Commit

Permalink
Migrate releasecelo command tests to anvil (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazarre authored Aug 21, 2024
1 parent 2478aa6 commit a3f9a88
Show file tree
Hide file tree
Showing 10 changed files with 682 additions and 370 deletions.
83 changes: 64 additions & 19 deletions packages/cli/src/commands/releasecelo/admin-revoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { newReleaseGold } from '@celo/abis/web3/ReleaseGold'
import { StableToken, StrongAddress } from '@celo/base'
import { serializeSignature } from '@celo/base/lib/signatureUtils'
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit'
import { AccountsWrapper } from '@celo/contractkit/lib/wrappers/Accounts'
import { GovernanceWrapper } from '@celo/contractkit/lib/wrappers/Governance'
import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold'
import { setBalance, testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test'
import {
getContractFromEvent,
NetworkConfig,
testWithGanache,
timeTravel,
} from '@celo/dev-utils/lib/ganache-test'
import BigNumber from 'bignumber.js'
import Web3 from 'web3'
import { testLocally } from '../../test-utils/cliUtils'
import { topUpWithToken } from '../../test-utils/chain-setup'
import { testLocally, testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import { createMultisig } from '../../test-utils/multisigUtils'
import { deployReleaseGoldContract } from '../../test-utils/release-gold'
import Approve from '../governance/approve'
import GovernanceUpvote from '../governance/upvote'
import GovernanceVote from '../governance/vote'
Expand All @@ -22,29 +28,31 @@ import LockedGold from './locked-gold'

process.env.NO_SYNCCHECK = 'true'

testWithGanache('releasegold:admin-revoke cmd', (web3: Web3) => {
testWithAnvilL1('releasegold:admin-revoke cmd', (web3: Web3) => {
let kit: ContractKit
let contractAddress: string
let contractAddress: StrongAddress
let releaseGoldWrapper: ReleaseGoldWrapper
let accounts: string[]
let accounts: StrongAddress[]

beforeEach(async () => {
contractAddress = await getContractFromEvent(
'ReleaseGoldInstanceCreated(address,address)',
accounts = (await web3.eth.getAccounts()) as StrongAddress[]
kit = newKitFromWeb3(web3)
contractAddress = await deployReleaseGoldContract(
web3,
{ index: 1 } // revocable: true
await createMultisig(kit, [accounts[0], accounts[1]] as StrongAddress[], 2, 2),
accounts[1],
accounts[0],
accounts[2]
)
kit = newKitFromWeb3(web3)
releaseGoldWrapper = new ReleaseGoldWrapper(
kit.connection,
newReleaseGold(web3, contractAddress),
kit.contracts
)
accounts = await web3.eth.getAccounts()
})

test('will revoke', async () => {
await testLocally(AdminRevoke, ['--contract', contractAddress, '--yesreally'])
await testLocallyWithWeb3Node(AdminRevoke, ['--contract', contractAddress, '--yesreally'], web3)
const revokedContract = await getContractFromEvent(
'ReleaseScheduleRevoked(uint256,uint256)',
web3
Expand All @@ -53,24 +61,68 @@ testWithGanache('releasegold:admin-revoke cmd', (web3: Web3) => {
})

test('will rescue all cUSD balance', async () => {
await topUpWithToken(kit, StableToken.cUSD, accounts[0], new BigNumber('100'))
const stableToken = await kit.contracts.getStableToken()
await stableToken.transfer(contractAddress, 100).send({
from: accounts[0],
})
await testLocally(AdminRevoke, ['--contract', contractAddress, '--yesreally'])
await testLocallyWithWeb3Node(AdminRevoke, ['--contract', contractAddress, '--yesreally'], web3)
const balance = await stableToken.balanceOf(contractAddress)
expect(balance.isZero()).toBeTruthy()
})

test('will refund and finalize', async () => {
await testLocally(AdminRevoke, ['--contract', contractAddress, '--yesreally'])
await testLocallyWithWeb3Node(AdminRevoke, ['--contract', contractAddress, '--yesreally'], web3)
const destroyedContract = await getContractFromEvent(
'ReleaseGoldInstanceDestroyed(address,address)',
web3
)
expect(destroyedContract).toBe(contractAddress)
})

describe('#when account exists with locked celo', () => {
const value = '10'

beforeEach(async () => {
// Make sure the release gold contract has enough funds
await setBalance(web3, contractAddress, new BigNumber(web3.utils.toWei('10', 'ether')))
await testLocallyWithWeb3Node(CreateAccount, ['--contract', contractAddress], web3)
await testLocallyWithWeb3Node(
LockedGold,
['--contract', contractAddress, '--action', 'lock', '--value', value, '--yes'],
web3
)
})

test('will unlock all gold', async () => {
await testLocallyWithWeb3Node(
AdminRevoke,
['--contract', contractAddress, '--yesreally'],
web3
)
const lockedGold = await kit.contracts.getLockedGold()
const lockedAmount = await lockedGold.getAccountTotalLockedGold(releaseGoldWrapper.address)
expect(lockedAmount.isZero()).toBeTruthy()
})
})
})

// Following tests rely on using personal_* RPC methods which are not supported in anvil
testWithGanache('releasegold:admin-revoke cmd', (web3: Web3) => {
let kit: ContractKit
let contractAddress: string
let accounts: string[]

beforeEach(async () => {
contractAddress = await getContractFromEvent(
'ReleaseGoldInstanceCreated(address,address)',
web3,
{ index: 1 } // revocable: true
)
kit = newKitFromWeb3(web3)
accounts = await web3.eth.getAccounts()
})

describe('#when account exists with locked celo', () => {
const value = '10'

Expand All @@ -87,13 +139,6 @@ testWithGanache('releasegold:admin-revoke cmd', (web3: Web3) => {
])
})

test('will unlock all gold', async () => {
await testLocally(AdminRevoke, ['--contract', contractAddress, '--yesreally'])
const lockedGold = await kit.contracts.getLockedGold()
const lockedAmount = await lockedGold.getAccountTotalLockedGold(releaseGoldWrapper.address)
expect(lockedAmount.isZero()).toBeTruthy()
})

describe('#when account has authorized a vote signer', () => {
let voteSigner: string
let accountsWrapper: AccountsWrapper
Expand Down
Loading

0 comments on commit a3f9a88

Please sign in to comment.