Stop voting with 0 tokens (#65)
This commit is contained in:
parent
26cb1823d9
commit
8575e7de55
|
@ -79,6 +79,7 @@ contract VotingContract {
|
||||||
string calldata description,
|
string calldata description,
|
||||||
uint256 voteAmount
|
uint256 voteAmount
|
||||||
) public {
|
) public {
|
||||||
|
require(voteAmount > 0, 'token amount must not be 0');
|
||||||
require(token.balanceOf(msg.sender) >= voteAmount, 'not enough token');
|
require(token.balanceOf(msg.sender) >= voteAmount, 'not enough token');
|
||||||
VotingRoom memory newVotingRoom;
|
VotingRoom memory newVotingRoom;
|
||||||
newVotingRoom.startBlock = block.number;
|
newVotingRoom.startBlock = block.number;
|
||||||
|
|
|
@ -81,12 +81,12 @@ const getSignedMessages = async (
|
||||||
return { messages, signedMessages }
|
return { messages, signedMessages }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fixture([alice, firstAddress, secondAddress]: any[], provider: JsonRpcProvider) {
|
async function fixture([alice, firstAddress, secondAddress, noTokensAddress]: any[], provider: JsonRpcProvider) {
|
||||||
const erc20 = await deployContract(alice, ERC20Mock, ['MSNT', 'Mock SNT', alice.address, 100000])
|
const erc20 = await deployContract(alice, ERC20Mock, ['MSNT', 'Mock SNT', alice.address, 100000])
|
||||||
await erc20.transfer(firstAddress.address, 10000)
|
await erc20.transfer(firstAddress.address, 10000)
|
||||||
await erc20.transfer(secondAddress.address, 10000)
|
await erc20.transfer(secondAddress.address, 10000)
|
||||||
const contract = await deployContract(alice, VotingContract, [erc20.address, 1000])
|
const contract = await deployContract(alice, VotingContract, [erc20.address, 1000])
|
||||||
return { contract, alice, firstAddress, secondAddress, provider }
|
return { contract, alice, firstAddress, secondAddress, provider, noTokensAddress }
|
||||||
}
|
}
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
|
@ -116,6 +116,22 @@ describe('Contract', () => {
|
||||||
contract.initializeVotingRoom('test', 'short desc', BigNumber.from(10000000000000))
|
contract.initializeVotingRoom('test', 'short desc', BigNumber.from(10000000000000))
|
||||||
).to.be.revertedWith('not enough token')
|
).to.be.revertedWith('not enough token')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('no tokens address', async () => {
|
||||||
|
const { contract, noTokensAddress } = await loadFixture(fixture)
|
||||||
|
const noTokensContract = contract.connect(noTokensAddress)
|
||||||
|
await expect(
|
||||||
|
noTokensContract.initializeVotingRoom('test', 'short desc', BigNumber.from(10))
|
||||||
|
).to.be.revertedWith('not enough token')
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can't start voting with 0 tokens", async () => {
|
||||||
|
const { contract, noTokensAddress } = await loadFixture(fixture)
|
||||||
|
const noTokensContract = contract.connect(noTokensAddress)
|
||||||
|
await expect(noTokensContract.initializeVotingRoom('test', 'short desc', BigNumber.from(0))).to.be.revertedWith(
|
||||||
|
'token amount must not be 0'
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('gets', async () => {
|
it('gets', async () => {
|
||||||
|
|
Loading…
Reference in New Issue