Skip to content

Commit a37e234

Browse files
committed
[SDK] Improve Vote contract tests
1 parent 39ea040 commit a37e234

File tree

2 files changed

+21
-86
lines changed

2 files changed

+21
-86
lines changed

packages/thirdweb/src/extensions/prebuilts/deploy-vote.test.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,12 @@ import { ANVIL_CHAIN } from "~test/chains.js";
33
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js";
44
import { TEST_CLIENT } from "~test/test-clients.js";
55
import { TEST_ACCOUNT_B } from "~test/test-wallets.js";
6-
import { isAddress } from "../../utils/address.js";
76
import { deployERC20Contract } from "./deploy-erc20.js";
87
import { deployVoteContract } from "./deploy-vote.js";
98

109
const account = TEST_ACCOUNT_B;
1110

1211
describe.runIf(process.env.TW_SECRET_KEY)("deploy-voteERC20 contract", () => {
13-
it("should deploy Vote contract", async () => {
14-
const tokenAddress = await deployERC20Contract({
15-
client: TEST_CLIENT,
16-
chain: ANVIL_CHAIN,
17-
account,
18-
type: "TokenERC20",
19-
params: {
20-
name: "Token",
21-
contractURI: TEST_CONTRACT_URI,
22-
},
23-
});
24-
const address = await deployVoteContract({
25-
account,
26-
client: TEST_CLIENT,
27-
chain: ANVIL_CHAIN,
28-
params: {
29-
name: "",
30-
contractURI: TEST_CONTRACT_URI,
31-
tokenAddress: tokenAddress,
32-
// user needs 0.5 <token> to create proposal
33-
initialProposalThreshold: "0.5",
34-
// vote expires 10 blocks later
35-
initialVotingPeriod: 10,
36-
// Requires 51% of users who voted, voted "For", for this proposal to pass
37-
minVoteQuorumRequiredPercent: 51,
38-
},
39-
});
40-
expect(address).toBeDefined();
41-
expect(isAddress(address)).toBe(true);
42-
// Further tests to verify the functionality of this contract
43-
// are done in other Vote tests
44-
});
45-
4612
it("should throw if passed an non-integer-like value to minVoteQuorumRequiredPercent", async () => {
4713
const tokenAddress = await deployERC20Contract({
4814
client: TEST_CLIENT,

packages/thirdweb/src/extensions/vote/read/proposalExists.test.ts renamed to packages/thirdweb/src/extensions/vote/vote.test.ts

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import { ANVIL_CHAIN } from "~test/chains.js";
33
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js";
44
import { TEST_CLIENT } from "~test/test-clients.js";
55
import { TEST_ACCOUNT_C } from "~test/test-wallets.js";
6-
import { getContract } from "../../../contract/contract.js";
7-
import { delegate } from "../../../extensions/erc20/__generated__/IVotes/write/delegate.js";
8-
import { mintTo } from "../../../extensions/erc20/write/mintTo.js";
9-
import { deployERC20Contract } from "../../../extensions/prebuilts/deploy-erc20.js";
10-
import { deployVoteContract } from "../../../extensions/prebuilts/deploy-vote.js";
11-
import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js";
12-
import { propose } from "../__generated__/Vote/write/propose.js";
13-
import { getAll } from "./getAll.js";
14-
import { proposalExists } from "./proposalExists.js";
6+
import { getContract } from "../../contract/contract.js";
7+
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
8+
import { delegate } from "../erc20/__generated__/IVotes/write/delegate.js";
9+
import { mintTo } from "../erc20/write/mintTo.js";
10+
import { deployERC20Contract } from "../prebuilts/deploy-erc20.js";
11+
import { deployVoteContract } from "../prebuilts/deploy-vote.js";
12+
import { propose } from "./__generated__/Vote/write/propose.js";
13+
import { getAll } from "./read/getAll.js";
14+
import { proposalExists } from "./read/proposalExists.js";
1515

1616
const account = TEST_ACCOUNT_C;
1717
const client = TEST_CLIENT;
1818
const chain = ANVIL_CHAIN;
1919

2020
describe.runIf(process.env.TW_SECRET_KEY)("proposal exists", () => {
21-
it("should return false if Vote doesn't have any proposal", async () => {
21+
it("`proposalExists` and `propose` should work", async () => {
2222
const tokenAddress = await deployERC20Contract({
2323
client: TEST_CLIENT,
2424
chain: ANVIL_CHAIN,
@@ -42,47 +42,16 @@ describe.runIf(process.env.TW_SECRET_KEY)("proposal exists", () => {
4242
minVoteQuorumRequiredPercent: 51,
4343
},
4444
});
45-
46-
const contract = getContract({
45+
const voteContract = getContract({
4746
address,
4847
chain,
4948
client,
5049
});
51-
52-
const result = await proposalExists({ contract, proposalId: 0n });
53-
expect(result).toBe(false);
54-
});
55-
56-
it("should return true if Vote has the proposal (id)", async () => {
57-
const tokenAddress = await deployERC20Contract({
58-
client: TEST_CLIENT,
59-
chain: ANVIL_CHAIN,
60-
account,
61-
type: "TokenERC20",
62-
params: {
63-
name: "Token",
64-
contractURI: TEST_CONTRACT_URI,
65-
},
66-
});
67-
const address = await deployVoteContract({
68-
account,
69-
client: TEST_CLIENT,
70-
chain: ANVIL_CHAIN,
71-
params: {
72-
name: "",
73-
contractURI: TEST_CONTRACT_URI,
74-
tokenAddress: tokenAddress,
75-
initialProposalThreshold: "0.5",
76-
initialVotingPeriod: 10,
77-
minVoteQuorumRequiredPercent: 51,
78-
},
79-
});
80-
81-
const contract = getContract({
82-
address,
83-
chain,
84-
client,
50+
const result = await proposalExists({
51+
contract: voteContract,
52+
proposalId: 0n,
8553
});
54+
expect(result).toBe(false);
8655

8756
const tokenContract = getContract({
8857
address: tokenAddress,
@@ -105,19 +74,19 @@ describe.runIf(process.env.TW_SECRET_KEY)("proposal exists", () => {
10574

10675
// step 3: create a proposal
10776
const transaction = propose({
108-
contract,
77+
contract: voteContract,
10978
description: "first proposal",
110-
targets: [contract.address],
79+
targets: [voteContract.address],
11180
values: [0n],
11281
calldatas: ["0x"],
11382
});
11483
await sendAndConfirmTransaction({ transaction, account });
115-
const allProposals = await getAll({ contract });
84+
const allProposals = await getAll({ contract: voteContract });
11685
expect(allProposals.length).toBe(1);
117-
const result = await proposalExists({
118-
contract,
86+
const exists = await proposalExists({
87+
contract: voteContract,
11988
proposalId: allProposals[0]?.proposalId || -1n,
12089
});
121-
expect(result).toBe(true);
90+
expect(exists).toBe(true);
12291
});
12392
});

0 commit comments

Comments
 (0)