Skip to content

Commit

Permalink
refactor: generalize voter funding with other proposal steps
Browse files Browse the repository at this point in the history
  • Loading branch information
whoabuddy committed Jan 15, 2025
1 parent 3591b07 commit 8068375
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 66 deletions.
34 changes: 2 additions & 32 deletions tests/dao/extensions/actions/aibtc-action-send-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Cl, cvToValue } from "@stacks/transactions";
import { describe, expect, it } from "vitest";
import {
constructDao,
fundVoters,
getDaoTokens,
passActionProposal,
} from "../../../test-utilities";
Expand Down Expand Up @@ -40,38 +41,7 @@ describe(`action extension: ${contractName}`, () => {
it("run() succeeds if called as a DAO action proposal", () => {
const message = "hello world";
// fund accounts for creating and voting on proposals
const getDaoTokensReceipts = [
getDaoTokens(deployer, deployer, 100000000), // 100 STX
getDaoTokens(deployer, address1, 50000000), // 50 STX
getDaoTokens(deployer, address2, 25000000), // 25 STX
];
const getAddressBalances = [
simnet.callReadOnlyFn(
`${deployer}.aibtc-token`,
"get-balance",
[Cl.principal(deployer)],
deployer
),
simnet.callReadOnlyFn(
`${deployer}.aibtc-token`,
"get-balance",
[Cl.principal(address1)],
deployer
),
simnet.callReadOnlyFn(
`${deployer}.aibtc-token`,
"get-balance",
[Cl.principal(address2)],
deployer
),
];
for (let i = 0; i < getDaoTokensReceipts.length; i++) {
const expectedBalance = parseInt(
cvToValue(getAddressBalances[i].result).value
);
// console.log(`expectedBalance: ${expectedBalance}`);
expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance));
}
fundVoters(deployer, [deployer, address1, address2]);

// construct DAO
const constructReceipt = constructDao(deployer);
Expand Down
35 changes: 2 additions & 33 deletions tests/dao/extensions/aibtc-onchain-messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Cl, cvToValue } from "@stacks/transactions";
import { describe, expect, it } from "vitest";
import {
constructDao,
fundVoters,
getDaoTokens,
passCoreProposal,
} from "../../test-utilities";
Expand Down Expand Up @@ -55,39 +56,7 @@ describe(`extension: ${contractName}`, () => {
const proposalContractAddress = `${deployer}.${proposalContractName}`;

// fund accounts for creating and voting on proposals
// TODO: consolidate as fundVoters()
const getDaoTokensReceipts = [
getDaoTokens(deployer, deployer, 100000000), // 100 STX
getDaoTokens(deployer, address1, 50000000), // 50 STX
getDaoTokens(deployer, address2, 25000000), // 25 STX
];
const getAddressBalances = [
simnet.callReadOnlyFn(
`${deployer}.aibtc-token`,
"get-balance",
[Cl.principal(deployer)],
deployer
),
simnet.callReadOnlyFn(
`${deployer}.aibtc-token`,
"get-balance",
[Cl.principal(address1)],
deployer
),
simnet.callReadOnlyFn(
`${deployer}.aibtc-token`,
"get-balance",
[Cl.principal(address2)],
deployer
),
];
for (let i = 0; i < getDaoTokensReceipts.length; i++) {
const expectedBalance = parseInt(
cvToValue(getAddressBalances[i].result).value
);
// console.log(`expectedBalance: ${expectedBalance}`);
expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance));
}
fundVoters(deployer, [deployer, address1, address2]);

// construct DAO
const constructReceipt = constructDao(deployer);
Expand Down
17 changes: 16 additions & 1 deletion tests/test-utilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cl, ClarityValue } from "@stacks/transactions";
import { Cl, ClarityValue, cvToValue } from "@stacks/transactions";
import { expect } from "vitest";

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

export function fundVoters(deployer: string, voters: string[]) {
for (const voter of voters) {
const stxAmount = Math.floor(Math.random() * 500000000) + 1000000;
const getDaoTokensReceipt = getDaoTokens(deployer, voter, stxAmount);
const getAddressBalanceResult = simnet.callReadOnlyFn(
`${deployer}.aibtc-token`,
"get-balance",
[Cl.principal(voter)],
deployer
).result;
const expectedBalance = parseInt(cvToValue(getAddressBalanceResult).value);
expect(getDaoTokensReceipt.result).toBeOk(Cl.uint(expectedBalance));
}
}

export function getDaoTokens(
deployer: string,
address: string,
Expand Down

0 comments on commit 8068375

Please sign in to comment.