dappconnect-vote-poll-sdk/packages/core/test/models/PollInitMsg.test.ts

79 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-08-09 14:00:42 +00:00
import { expect } from 'chai'
2021-08-16 14:11:22 +00:00
import { PollInitMsg } from '../../src/models/PollInitMsg'
2021-08-09 14:00:42 +00:00
import { MockProvider } from 'ethereum-waffle'
import { PollType } from '../../src/types/PollType'
2021-08-12 14:37:21 +00:00
import { BigNumber } from 'ethers'
2021-08-09 14:00:42 +00:00
describe('PollInitMsg', () => {
const provider = new MockProvider()
const [alice] = provider.getWallets()
it('success', async () => {
2021-08-12 14:37:21 +00:00
const poll = await PollInitMsg._createWithSignFunction(
2021-08-16 07:42:22 +00:00
async (e) => new PollInitMsg('0x01', e),
2021-08-12 14:37:21 +00:00
alice,
'test',
['one', 'two', 'three'],
PollType.WEIGHTED
)
2021-08-09 14:00:42 +00:00
expect(poll).to.not.be.undefined
2021-08-12 14:37:21 +00:00
if (poll) {
expect(poll.owner).to.eq(alice.address)
2021-08-13 11:41:08 +00:00
expect(poll.endTime).to.eq(poll.timestamp + 100000000)
2021-08-12 14:37:21 +00:00
expect(poll.answers).to.deep.eq(['one', 'two', 'three'])
expect(poll.minToken).to.be.undefined
expect(poll.pollType).to.eq(PollType.WEIGHTED)
expect(poll.question).to.eq('test')
2021-08-09 14:00:42 +00:00
2021-08-16 07:42:22 +00:00
expect(poll.signature).to.eq('0x01')
2021-08-12 14:37:21 +00:00
}
2021-08-09 14:00:42 +00:00
})
it('success NON_WEIGHTED', async () => {
2021-08-12 14:37:21 +00:00
const poll = await PollInitMsg._createWithSignFunction(
2021-08-16 07:42:22 +00:00
async (e) => new PollInitMsg('0x01', e),
2021-08-10 12:55:47 +00:00
alice,
2021-08-09 14:00:42 +00:00
'test',
['one', 'two', 'three'],
PollType.NON_WEIGHTED,
BigNumber.from(123)
)
2021-08-12 14:37:21 +00:00
expect(poll).to.not.be.undefined
2021-08-09 14:00:42 +00:00
expect(poll?.minToken?.toNumber()).to.eq(123)
2021-08-12 14:37:21 +00:00
if (poll) {
2021-08-16 07:42:22 +00:00
expect(poll.signature).to.eq('0x01')
2021-08-12 14:37:21 +00:00
}
2021-08-09 14:00:42 +00:00
})
it('NON_WEIGHTED no minToken', async () => {
2021-08-12 14:37:21 +00:00
const poll = await PollInitMsg._createWithSignFunction(
2021-08-16 07:42:22 +00:00
async (e) => new PollInitMsg('0x01', e),
2021-08-12 14:37:21 +00:00
alice,
'test',
['one', 'two', 'three'],
PollType.NON_WEIGHTED
)
2021-08-09 14:00:42 +00:00
expect(poll?.minToken?.toNumber()).to.eq(1)
2021-08-12 14:37:21 +00:00
expect(poll).to.not.be.undefined
if (poll) {
2021-08-16 07:42:22 +00:00
expect(poll.signature).to.eq('0x01')
2021-08-12 14:37:21 +00:00
}
2021-08-09 14:00:42 +00:00
})
it('specific end time', async () => {
2021-08-12 14:37:21 +00:00
const poll = await PollInitMsg._createWithSignFunction(
2021-08-16 07:42:22 +00:00
async (e) => new PollInitMsg('0x01', e),
2021-08-12 14:37:21 +00:00
alice,
'test',
['one', 'two', 'three'],
PollType.NON_WEIGHTED,
undefined,
100
)
2021-08-09 14:00:42 +00:00
expect(poll?.endTime).to.eq(100)
})
})