forked from aragon/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
votes.test.ts
193 lines (150 loc) · 6.6 KB
/
votes.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import { BigNumber } from 'ethers'
import { App, connect } from '@aragon/connect'
import { VotingConnectorTheGraph, Vote, Cast } from '../../src'
import { Action, VoteStatus } from '../types'
const VOTING_SUBGRAPH_URL =
'https://api.thegraph.com/subgraphs/name/aragon/aragon-voting-rinkeby'
const VOTING_APP_ADDRESS = '0x37187b0f2089b028482809308e776f92eeb7334e'
// For testing action-fetching functionality
const ACTIONS_ORG_ADDRESS = "0x63210F64Ef6F4EBB9727F6c5665CB8bbeDf20480"
const ACTIONS_VOTING_APP_ADDRESS = '0x9943c2f55d91308b8ddbc58b6e70d1774ace125e'
describe('when connecting to a voting app', () => {
let connector: VotingConnectorTheGraph
let votes: Vote[]
beforeAll(() => {
connector = new VotingConnectorTheGraph({
subgraphUrl: VOTING_SUBGRAPH_URL,
})
})
afterAll(async () => {
await connector.disconnect()
})
describe('when querying for all the votes of a voting app', () => {
beforeAll(async () => {
votes = await connector.votesForApp(VOTING_APP_ADDRESS, 1000, 0)
})
test('returns a list of votes', () => {
expect(votes.length).toBeGreaterThan(0)
})
describe('when looking at a vote', () => {
let vote: Vote
beforeAll(() => {
vote = votes[13]
})
test('should not be executed', () => {
expect(vote.executed).toBe(false)
})
test('should have nays', () => {
expect(vote.nay).toBe('18000000000000000000000')
})
test('should have yeas', () => {
expect(vote.yea).toBe('5400000000000000000000')
})
test('has the expected script', () => {
expect(vote.script).toEqual(
'0x0000000138daca8c123145ead833c42590f4e359fd6bfa0c00000124d948d468000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e0000000015616500b003475136ee6b0844896a2e1ccc68140000000c4d948d46800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000080000000018b8fc0e17c2900d669cc883e3b067e413536240200000064b0c8f9dc000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000076e65776e616d6500000000000000000000000000000000000000000000000000'
)
})
test('should have a valid creator', () => {
expect(vote.creator).toEqual(
'0xadb56e6b6a10c8a1b7fe859b1284cfd74a7bcd1f'
)
})
test('should have a valid original creator', () => {
expect(vote.originalCreator).toBe('0x8cff6832174091dae86f0244e3fd92d4ced2fe07')
})
test('should have valid metadata', () => {
expect(vote.metadata).toEqual(``)
})
test('should have a valid minAcceptQuorum', () => {
expect(vote.minAcceptQuorum).toEqual('10000000000000000')
})
test('should have a valid supportRequiredPct', () => {
expect(vote.supportRequiredPct).toEqual('250000000000000000')
})
test('should have a valid votingPower', () => {
expect(vote.votingPower).toEqual('29531000000000000000000')
})
test('should have a valid snapshotBlock', () => {
expect(vote.snapshotBlock).toEqual('7167970')
})
test('should have a valid startDate', () => {
expect(vote.startDate).toEqual('1599675534')
})
test('should have a valid endDate', () => {
expect(vote.endDate).toEqual('1600280334')
})
test('should have not be accepted', () => {
expect(vote.isAccepted).toBe(false)
})
test('should have a valid status', () => {
expect(vote.status).toEqual(VoteStatus.Rejected)
})
describe('when querying for the casts of a vote', () => {
let casts: Cast[]
beforeAll(async () => {
casts = await vote.casts()
})
test('retrieves casts', () => {
expect(casts.length).toBeGreaterThan(0)
})
})
})
})
describe("when looking at the vote's actions of a voting app", () => {
let installedApps: App[]
let signallingVoteActions: Action[]
let onlyCodeExecutionActions: Action[]
let voteActions: Action[]
beforeAll(async () => {
const org = await connect(ACTIONS_ORG_ADDRESS, "thegraph", { network: 4 })
installedApps = await org.apps()
connector = new VotingConnectorTheGraph({
subgraphUrl: VOTING_SUBGRAPH_URL,
})
votes = await connector.votesForApp(ACTIONS_VOTING_APP_ADDRESS, 1000, 0)
onlyCodeExecutionActions = votes[0].getActions(installedApps)
signallingVoteActions = votes[1].getActions(installedApps)
voteActions = votes[4].getActions(installedApps)
})
test("should return a list of actions", () => {
expect(voteActions.length).toBeGreaterThan(0)
})
test("shouldn't return anything when getting actions from a signaling vote", () => {
expect(signallingVoteActions).toEqual([])
})
test("shouldn't return rewards when getting actions from a vote that only executes code", () => {
const action = onlyCodeExecutionActions[0]
expect(action.rewards).toEqual([])
})
describe("when looking at a specific vote's action and reward", () => {
let rewardedAction: Action
beforeAll(() => {
rewardedAction = voteActions[0]
})
test('should have a valid to (target contract address)', () => {
expect(rewardedAction.to).toEqual("0xcaa6526abb106ff5c5f937e3ea9499243df86b7a")
})
test("should have a valid fnData", () => {
const { abi, notice, params, roles, sig } = rewardedAction.fnData!
expect(Object.keys(abi!).length).toBeGreaterThan(0)
expect(notice).toEqual("Create a new payment of `@tokenAmount(_token, _amount)` to `_receiver` for '`_reference`'")
expect(params!).toEqual(['0x0000000000000000000000000000000000000000',
'0x9943c2f55D91308B8DDbc58B6e70d1774AcE125e', BigNumber.from('3000000000000000000'), "\"reference\""])
expect(roles).toEqual([ 'CREATE_PAYMENTS_ROLE' ])
expect(sig).toEqual("newImmediatePayment(address,address,uint256,string)")
})
test("should have a list of rewards", () => {
expect(rewardedAction.rewards.length).toBeGreaterThan(0)
})
test("should have a valid reward", () => {
const reward = rewardedAction.rewards[0]
const { amount, token, receiver } = reward
const ETH = '0x0000000000000000000000000000000000000000'
expect(amount).toEqual('3000000000000000000')
expect(token).toEqual(ETH)
expect(receiver).toEqual('0x9943c2f55D91308B8DDbc58B6e70d1774AcE125e')
})
})
})
})