diff --git a/packages/DApp/src/components/card/ProposeModal.tsx b/packages/DApp/src/components/card/ProposeModal.tsx index 96ef854..57e8a74 100644 --- a/packages/DApp/src/components/card/ProposeModal.tsx +++ b/packages/DApp/src/components/card/ProposeModal.tsx @@ -12,6 +12,7 @@ import { CommunityDetail } from '../../models/community' import { CommunitySkeleton } from '../skeleton/CommunitySkeleton' import { useCommunityDetails } from '../../hooks/useCommunityDetails' import { ColumnFlexDiv } from '../../constants/styles' +import { BigNumber } from 'ethers' interface PublicKeyInputProps { publicKey: string @@ -93,7 +94,10 @@ export function ProposeModal({ OK, let’s move on! 🤙 ) : ( - send(1, publicKey)}> + send(1, publicKey, BigNumber.from(proposingAmount))} + > Confirm vote to add community )} diff --git a/packages/DApp/src/components/card/RemoveAmountPicker.tsx b/packages/DApp/src/components/card/RemoveAmountPicker.tsx index a4dd211..d8cb7b9 100644 --- a/packages/DApp/src/components/card/RemoveAmountPicker.tsx +++ b/packages/DApp/src/components/card/RemoveAmountPicker.tsx @@ -8,6 +8,7 @@ import { ButtonPrimary } from '../Button' import { VotePropose } from '../votes/VotePropose' import { Warning } from '../votes/VoteWarning' import { ConfirmBtn } from './VoteConfirmModal' +import { BigNumber } from 'ethers' interface RemoveAmountPickerProps { community: CommunityDetail @@ -74,7 +75,7 @@ export function RemoveAmountPicker({ community, availableAmount, setShowConfirmM setProposingAmount={setProposingAmount} proposingAmount={proposingAmount} /> - send(0, community.publicKey)}> + send(0, community.publicKey, BigNumber.from(proposingAmount))}> Confirm vote to remove community diff --git a/packages/DApp/src/providers/config/config.ts b/packages/DApp/src/providers/config/config.ts index 0bcbc53..ca7ddcc 100644 --- a/packages/DApp/src/providers/config/config.ts +++ b/packages/DApp/src/providers/config/config.ts @@ -16,28 +16,28 @@ interface EnvConfigs { const contracts = { 3: { - votingContract: '0xD330F512Ed6DC3F088a8Ebe342e9f817E09938A9', - directoryContract: '0x6a5dc0B148eAa891224D6c0d1679D5954CA1D295', + votingContract: '0xb3bb261Ac080059A46879d3B3f8B5779b9AF26dF', + directoryContract: '0xfEB894511bC1B92EFA4f7fa050fC0BF7697Df6a2', }, 1337: { - votingContract: '0x2ee36F4A0BBf35C8b7bE185D1c5447Fd485f9c12', - directoryContract: '0x689C9049BD7197687959d0b8Dc2344f42e8e4500', + votingContract: '0xd862f2550F37bE4DCb42Ec684b3D2528635d2Bc9', + directoryContract: '0xbb8243e9f5b55C9e7E64e118c99EE78a7080fbf9', }, } export const config: EnvConfigs = { localhost: { - wakuTopic: `/myApp/localhost/${uuidv4()}/0.0.4/votingRoom/`, + wakuTopic: `/myApp/localhost/${uuidv4()}/0.0.5/votingRoom/`, numberPerPage: 2, contracts, }, development: { - wakuTopic: '/myApp/development/0.0.4/votingRoom/', + wakuTopic: '/myApp/development/0.0.5/votingRoom/', numberPerPage: 3, contracts, }, production: { - wakuTopic: '/myApp/production/0.0.4/votingRoom/', + wakuTopic: '/myApp/production/0.0.5/votingRoom/', numberPerPage: 4, contracts, }, diff --git a/packages/contracts/contracts/MockContract.sol b/packages/contracts/contracts/MockContract.sol index 43002fe..52a01a1 100644 --- a/packages/contracts/contracts/MockContract.sol +++ b/packages/contracts/contracts/MockContract.sol @@ -82,7 +82,11 @@ contract MockContract { return votingRoomMap[roomId].voters; } - function initializeVotingRoom(VoteType voteType, address publicKey) public { + function initializeVotingRoom( + VoteType voteType, + address publicKey, + uint256 voteAmount + ) public { require(communityVotingId[publicKey] == 0, 'vote already ongoing'); if (voteType == VoteType.REMOVE) { require(directory.isCommunityInDirectory(publicKey), 'Community not in directory'); @@ -96,6 +100,9 @@ contract MockContract { newVotingRoom.voteType = voteType; newVotingRoom.community = publicKey; newVotingRoom.roomNumber = latestVoting; + newVotingRoom.totalVotesFor = voteAmount; + newVotingRoom.voted[msg.sender] = true; + newVotingRoom.voters.push(msg.sender); communityVotingId[publicKey] = latestVoting; activeVotingRooms.push(latestVoting); diff --git a/packages/contracts/test/1.mockContract.test.ts b/packages/contracts/test/1.mockContract.test.ts index e025409..f4d6e8c 100644 --- a/packages/contracts/test/1.mockContract.test.ts +++ b/packages/contracts/test/1.mockContract.test.ts @@ -94,31 +94,33 @@ describe('Contract', () => { describe('initialization', () => { it('initializes', async () => { const { contract, firstAddress, secondAddress } = await loadFixture(fixture) - expect(await contract.initializeVotingRoom(1, firstAddress.address)) + expect(await contract.initializeVotingRoom(1, firstAddress.address, BigNumber.from(100))) .to.emit(contract, 'VotingRoomStarted') .withArgs(1, firstAddress.address) - expect(await contract.initializeVotingRoom(1, secondAddress.address)) + expect(await contract.initializeVotingRoom(1, secondAddress.address, BigNumber.from(100))) .to.emit(contract, 'VotingRoomStarted') .withArgs(2, secondAddress.address) - await expect(contract.initializeVotingRoom(1, secondAddress.address)).to.be.revertedWith('vote already ongoing') + await expect(contract.initializeVotingRoom(1, secondAddress.address, BigNumber.from(100))).to.be.revertedWith( + 'vote already ongoing' + ) }) describe('directory interaction', () => { it('remove missing', async () => { const { contract } = await loadFixture(fixture) await expect( - contract.initializeVotingRoom(0, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') + contract.initializeVotingRoom(0, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) ).to.be.revertedWith('Community not in directory') }) it('add already in', async () => { const { contract, directory, alice, provider } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') + await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) await voteAndFinalize(1, 1, alice, contract, provider) expect(await directory.getCommunities()).to.deep.eq(['0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b']) await expect( - contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') + contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) ).to.be.revertedWith('Community already in directory') }) }) @@ -126,22 +128,22 @@ describe('Contract', () => { it('gets', async () => { const { contract, firstAddress, secondAddress } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, firstAddress.address) + await contract.initializeVotingRoom(1, firstAddress.address, BigNumber.from(100)) expect((await contract.votingRoomMap(1)).slice(2)).to.deep.eq([ 1, false, firstAddress.address, - BigNumber.from(0), + BigNumber.from(100), BigNumber.from(0), BigNumber.from(1), ]) - await contract.initializeVotingRoom(1, secondAddress.address) + await contract.initializeVotingRoom(1, secondAddress.address, BigNumber.from(100)) expect((await contract.votingRoomMap(2)).slice(2)).to.deep.eq([ 1, false, secondAddress.address, - BigNumber.from(0), + BigNumber.from(100), BigNumber.from(0), BigNumber.from(2), ]) @@ -149,7 +151,7 @@ describe('Contract', () => { 1, false, firstAddress.address, - BigNumber.from(0), + BigNumber.from(100), BigNumber.from(0), BigNumber.from(1), ]) @@ -157,24 +159,24 @@ describe('Contract', () => { describe('finalization', () => { it('finalizes', async () => { const { contract, firstAddress, provider } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, firstAddress.address) + await contract.initializeVotingRoom(1, firstAddress.address, BigNumber.from(100)) expect((await contract.votingRoomMap(1)).slice(2)).to.deep.eq([ 1, false, firstAddress.address, - BigNumber.from(0), + BigNumber.from(100), BigNumber.from(0), BigNumber.from(1), ]) await provider.send('evm_mine', [Math.floor(Date.now() / 1000 + 2000)]) expect(await contract.finalizeVotingRoom(1)) .to.emit(contract, 'VotingRoomFinalized') - .withArgs(1, firstAddress.address, false, 1) + .withArgs(1, firstAddress.address, true, 1) expect((await contract.votingRoomMap(1)).slice(2)).to.deep.eq([ 1, true, firstAddress.address, - BigNumber.from(0), + BigNumber.from(100), BigNumber.from(0), BigNumber.from(1), ]) @@ -182,14 +184,14 @@ describe('Contract', () => { describe('directory interaction', () => { it('add community', async () => { - const { contract, directory, alice, provider } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') - await voteAndFinalize(1, 1, alice, contract, provider) + const { contract, directory, alice, provider, firstAddress } = await loadFixture(fixture) + await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) + await voteAndFinalize(1, 1, firstAddress, contract, provider) expect((await contract.votingRoomMap(1)).slice(2)).to.deep.eq([ 1, true, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', - BigNumber.from(100), + BigNumber.from(200), BigNumber.from(0), BigNumber.from(1), ]) @@ -197,34 +199,34 @@ describe('Contract', () => { }) it('remove community', async () => { - const { contract, directory, alice, provider } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') - await voteAndFinalize(1, 1, alice, contract, provider) + const { contract, directory, alice, provider, firstAddress } = await loadFixture(fixture) + await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) + await voteAndFinalize(1, 1, firstAddress, contract, provider) expect(await directory.getCommunities()).to.deep.eq(['0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b']) - await contract.initializeVotingRoom(0, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') - await voteAndFinalize(2, 1, alice, contract, provider) + await contract.initializeVotingRoom(0, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) + await voteAndFinalize(2, 1, firstAddress, contract, provider) expect(await directory.getCommunities()).to.deep.eq([]) }) it('failed add vote', async () => { - const { contract, directory, alice, provider } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') - await voteAndFinalize(1, 0, alice, contract, provider) + const { contract, directory, alice, provider, firstAddress } = await loadFixture(fixture) + await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) + await voteAndFinalize(1, 0, firstAddress, contract, provider) expect(await directory.getCommunities()).to.deep.eq([]) }) it('failed remove vote', async () => { - const { contract, directory, alice, provider } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') - await voteAndFinalize(1, 1, alice, contract, provider) + const { contract, directory, alice, provider, firstAddress } = await loadFixture(fixture) + await contract.initializeVotingRoom(1, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) + await voteAndFinalize(1, 1, firstAddress, contract, provider) expect(await directory.getCommunities()).to.deep.eq(['0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b']) - await contract.initializeVotingRoom(0, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b') - await voteAndFinalize(2, 0, alice, contract, provider) + await contract.initializeVotingRoom(0, '0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b', BigNumber.from(100)) + await voteAndFinalize(2, 0, firstAddress, contract, provider) expect(await directory.getCommunities()).to.deep.eq(['0xAcdd71e5Ef3Ab3356d62da78A941aAc08a18CF2b']) }) }) @@ -234,23 +236,23 @@ describe('Contract', () => { describe('helpers', () => { it('getCommunityVoting', async () => { const { contract, firstAddress, secondAddress, provider } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, firstAddress.address) + await contract.initializeVotingRoom(1, firstAddress.address, BigNumber.from(100)) expect((await contract.getCommunityVoting(firstAddress.address)).slice(2)).to.deep.eq([ 1, false, firstAddress.address, - BigNumber.from(0), + BigNumber.from(100), BigNumber.from(0), BigNumber.from(1), ]) await provider.send('evm_mine', [Math.floor(Date.now() / 1000 + 10000)]) - await contract.initializeVotingRoom(1, secondAddress.address) + await contract.initializeVotingRoom(1, secondAddress.address, BigNumber.from(100)) expect((await contract.getCommunityVoting(secondAddress.address)).slice(2)).to.deep.eq([ 1, false, secondAddress.address, - BigNumber.from(0), + BigNumber.from(100), BigNumber.from(0), BigNumber.from(2), ]) @@ -258,18 +260,16 @@ describe('Contract', () => { it('get active votes', async () => { const { contract, firstAddress, secondAddress, provider } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, firstAddress.address) + await contract.initializeVotingRoom(1, firstAddress.address, BigNumber.from(100)) expect(await contract.getActiveVotingRooms()).to.deep.eq([BigNumber.from(1)]) - await contract.initializeVotingRoom(1, secondAddress.address) + await contract.initializeVotingRoom(1, secondAddress.address, BigNumber.from(100)) expect(await contract.getActiveVotingRooms()).to.deep.eq([BigNumber.from(1), BigNumber.from(2)]) await provider.send('evm_mine', [Math.floor(Date.now() / 1000 + 2000)]) await contract.finalizeVotingRoom(1) expect(await contract.getActiveVotingRooms()).to.deep.eq([BigNumber.from(2)]) await contract.finalizeVotingRoom(2) expect(await contract.getActiveVotingRooms()).to.deep.eq([]) - await contract.initializeVotingRoom(1, secondAddress.address) - expect(await contract.getActiveVotingRooms()).to.deep.eq([BigNumber.from(3)]) }) }) @@ -277,19 +277,17 @@ describe('Contract', () => { it('check voters', async () => { const { contract, alice, firstAddress, secondAddress } = await loadFixture(fixture) const { signedMessages } = await getSignedMessages(alice, firstAddress, secondAddress) - await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24') + await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24', BigNumber.from(100)) - expect(await contract.listRoomVoters(1)).to.deep.eq([]) + expect(await contract.listRoomVoters(1)).to.deep.eq([alice.address]) await contract.castVotes(signedMessages.slice(2)) - expect(await contract.listRoomVoters(1)).to.deep.eq([secondAddress.address]) - await contract.castVotes(signedMessages.slice(0, 1)) - expect(await contract.listRoomVoters(1)).to.deep.eq([secondAddress.address, alice.address]) + expect(await contract.listRoomVoters(1)).to.deep.eq([alice.address, secondAddress.address]) }) it('success', async () => { const { contract, alice, firstAddress, secondAddress } = await loadFixture(fixture) const { signedMessages } = await getSignedMessages(alice, firstAddress, secondAddress) - await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24') + await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24', BigNumber.from(100)) await contract.castVotes(signedMessages) expect((await contract.votingRoomMap(1)).slice(2)).to.deep.eq([ 1, @@ -304,7 +302,7 @@ describe('Contract', () => { it('double vote', async () => { const { contract, alice, firstAddress, secondAddress } = await loadFixture(fixture) const { signedMessages } = await getSignedMessages(alice, firstAddress, secondAddress) - await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24') + await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24', BigNumber.from(100)) await contract.castVotes(signedMessages) await contract.castVotes(signedMessages) expect((await contract.votingRoomMap(1)).slice(2)).to.deep.eq([ @@ -319,7 +317,7 @@ describe('Contract', () => { it('random bytes', async () => { const { contract } = await loadFixture(fixture) - await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24') + await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24', BigNumber.from(100)) await expect(contract.castVotes([new Uint8Array([12, 12, 12])])).to.be.reverted }) @@ -332,7 +330,7 @@ describe('Contract', () => { it('old room', async () => { const { contract, alice, firstAddress, secondAddress, provider } = await loadFixture(fixture) const { signedMessages } = await getSignedMessages(alice, firstAddress, secondAddress) - await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24') + await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24', BigNumber.from(100)) await provider.send('evm_mine', [Math.floor(Date.now() / 1000 + 2000)]) await expect(contract.castVotes(signedMessages)).to.be.reverted }) @@ -341,7 +339,7 @@ describe('Contract', () => { const { contract, alice, firstAddress, secondAddress, provider } = await loadFixture(fixture) const { messages } = await getSignedMessages(alice, firstAddress, secondAddress) const types = ['address', 'uint256', 'uint256'] - await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24') + await contract.initializeVotingRoom(1, '0xabA1eF51ef4aE360a9e8C9aD2d787330B602eb24', BigNumber.from(100)) await provider.send('evm_mine', [Math.floor(Date.now() / 1000 + 2000)]) const signedMessages = await Promise.all(