dappconnect-voting-sdk/packages/core/test/models/TimedPollVoteMsg.test.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-08-10 16:04:40 +00:00
import { expect } from 'chai'
import { TimedPollVoteMsg } from '../../src/models/TimedPollVoteMsg'
import { MockProvider } from 'ethereum-waffle'
2021-08-16 07:42:22 +00:00
import { BigNumber } from 'ethers'
2021-08-10 16:04:40 +00:00
describe('TimedPollVoteMsg', () => {
const provider = new MockProvider()
const [alice] = provider.getWallets()
const pollId = '0x14c336ef626274f156d094fc1d7ffad2bbc83cccc9817598dd55e42a86b56b72'
it('success', async () => {
2021-08-16 07:42:22 +00:00
const poll = await TimedPollVoteMsg._createWithSignFunction(
async (e) => new TimedPollVoteMsg('0x01', e),
alice,
pollId,
0
)
2021-08-10 16:04:40 +00:00
expect(poll).to.not.be.undefined
2021-08-16 07:42:22 +00:00
if (poll) {
expect(poll.voter).to.eq(alice.address)
expect(poll.answer).to.eq(0)
expect(poll.id).to.be.eq(pollId)
expect(poll.tokenAmount).to.be.undefined
expect(poll.signature).to.eq('0x01')
}
2021-08-10 16:04:40 +00:00
})
it('success token amount', async () => {
2021-08-16 07:42:22 +00:00
const poll = await TimedPollVoteMsg._createWithSignFunction(
async (e) => new TimedPollVoteMsg('0x01', e),
alice,
pollId,
1,
BigNumber.from(100)
)
2021-08-10 16:04:40 +00:00
expect(poll).to.not.be.undefined
2021-08-16 07:42:22 +00:00
if (poll) {
expect(poll.voter).to.eq(alice.address)
expect(poll.answer).to.eq(1)
expect(poll.id).to.be.eq(pollId)
expect(poll.tokenAmount).to.deep.eq(BigNumber.from(100))
expect(poll.signature).to.eq('0x01')
}
2021-08-10 16:04:40 +00:00
})
})