Skip to content

Commit 8068375

Browse files
committed
refactor: generalize voter funding with other proposal steps
1 parent 3591b07 commit 8068375

File tree

3 files changed

+20
-66
lines changed

3 files changed

+20
-66
lines changed

tests/dao/extensions/actions/aibtc-action-send-message.test.ts

+2-32
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Cl, cvToValue } from "@stacks/transactions";
22
import { describe, expect, it } from "vitest";
33
import {
44
constructDao,
5+
fundVoters,
56
getDaoTokens,
67
passActionProposal,
78
} from "../../../test-utilities";
@@ -40,38 +41,7 @@ describe(`action extension: ${contractName}`, () => {
4041
it("run() succeeds if called as a DAO action proposal", () => {
4142
const message = "hello world";
4243
// fund accounts for creating and voting on proposals
43-
const getDaoTokensReceipts = [
44-
getDaoTokens(deployer, deployer, 100000000), // 100 STX
45-
getDaoTokens(deployer, address1, 50000000), // 50 STX
46-
getDaoTokens(deployer, address2, 25000000), // 25 STX
47-
];
48-
const getAddressBalances = [
49-
simnet.callReadOnlyFn(
50-
`${deployer}.aibtc-token`,
51-
"get-balance",
52-
[Cl.principal(deployer)],
53-
deployer
54-
),
55-
simnet.callReadOnlyFn(
56-
`${deployer}.aibtc-token`,
57-
"get-balance",
58-
[Cl.principal(address1)],
59-
deployer
60-
),
61-
simnet.callReadOnlyFn(
62-
`${deployer}.aibtc-token`,
63-
"get-balance",
64-
[Cl.principal(address2)],
65-
deployer
66-
),
67-
];
68-
for (let i = 0; i < getDaoTokensReceipts.length; i++) {
69-
const expectedBalance = parseInt(
70-
cvToValue(getAddressBalances[i].result).value
71-
);
72-
// console.log(`expectedBalance: ${expectedBalance}`);
73-
expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance));
74-
}
44+
fundVoters(deployer, [deployer, address1, address2]);
7545

7646
// construct DAO
7747
const constructReceipt = constructDao(deployer);

tests/dao/extensions/aibtc-onchain-messaging.test.ts

+2-33
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Cl, cvToValue } from "@stacks/transactions";
22
import { describe, expect, it } from "vitest";
33
import {
44
constructDao,
5+
fundVoters,
56
getDaoTokens,
67
passCoreProposal,
78
} from "../../test-utilities";
@@ -55,39 +56,7 @@ describe(`extension: ${contractName}`, () => {
5556
const proposalContractAddress = `${deployer}.${proposalContractName}`;
5657

5758
// fund accounts for creating and voting on proposals
58-
// TODO: consolidate as fundVoters()
59-
const getDaoTokensReceipts = [
60-
getDaoTokens(deployer, deployer, 100000000), // 100 STX
61-
getDaoTokens(deployer, address1, 50000000), // 50 STX
62-
getDaoTokens(deployer, address2, 25000000), // 25 STX
63-
];
64-
const getAddressBalances = [
65-
simnet.callReadOnlyFn(
66-
`${deployer}.aibtc-token`,
67-
"get-balance",
68-
[Cl.principal(deployer)],
69-
deployer
70-
),
71-
simnet.callReadOnlyFn(
72-
`${deployer}.aibtc-token`,
73-
"get-balance",
74-
[Cl.principal(address1)],
75-
deployer
76-
),
77-
simnet.callReadOnlyFn(
78-
`${deployer}.aibtc-token`,
79-
"get-balance",
80-
[Cl.principal(address2)],
81-
deployer
82-
),
83-
];
84-
for (let i = 0; i < getDaoTokensReceipts.length; i++) {
85-
const expectedBalance = parseInt(
86-
cvToValue(getAddressBalances[i].result).value
87-
);
88-
// console.log(`expectedBalance: ${expectedBalance}`);
89-
expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance));
90-
}
59+
fundVoters(deployer, [deployer, address1, address2]);
9160

9261
// construct DAO
9362
const constructReceipt = constructDao(deployer);

tests/test-utilities.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cl, ClarityValue } from "@stacks/transactions";
1+
import { Cl, ClarityValue, cvToValue } from "@stacks/transactions";
22
import { expect } from "vitest";
33

44
export const actionProposalsContractName = "aibtc-action-proposals";
@@ -11,6 +11,21 @@ function getPercentageOfSupply(amount: number, totalSupply: number) {
1111
return percentage;
1212
}
1313

14+
export function fundVoters(deployer: string, voters: string[]) {
15+
for (const voter of voters) {
16+
const stxAmount = Math.floor(Math.random() * 500000000) + 1000000;
17+
const getDaoTokensReceipt = getDaoTokens(deployer, voter, stxAmount);
18+
const getAddressBalanceResult = simnet.callReadOnlyFn(
19+
`${deployer}.aibtc-token`,
20+
"get-balance",
21+
[Cl.principal(voter)],
22+
deployer
23+
).result;
24+
const expectedBalance = parseInt(cvToValue(getAddressBalanceResult).value);
25+
expect(getDaoTokensReceipt.result).toBeOk(Cl.uint(expectedBalance));
26+
}
27+
}
28+
1429
export function getDaoTokens(
1530
deployer: string,
1631
address: string,

0 commit comments

Comments
 (0)