Skip to content

Commit

Permalink
[SDK] Deploy VoteERC20 extension (#4264)
Browse files Browse the repository at this point in the history
## Problem solved

Short description of the bug fixed or feature added

<!-- start pr-codex -->

---

## PR-Codex overview
This PR adds an extension for deploying the `VoteERC20` contract and includes related test cases and contract initialization improvements.

### Detailed summary
- Added extension for deploying `VoteERC20` contract
- Implemented test cases for contract deployment and functionality testing
- Enhanced contract initialization process with better error handling

> The following files were skipped due to too many changes: `packages/thirdweb/src/extensions/prebuilts/deploy-vote.ts`, `packages/thirdweb/src/extensions/prebuilts/__generated__/VoteERC20/write/initialize.ts`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
kien-ngo committed Aug 26, 2024
1 parent 17ca1b9 commit b661ce7
Show file tree
Hide file tree
Showing 6 changed files with 647 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-deers-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Add extension for deploying VoteERC20 contract
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"function initialize(string memory _name, string memory _contractURI, address[] memory _trustedForwarders, address _token, uint256 _initialVotingDelay, uint256 _initialVotingPeriod, uint256 _initialProposalThreshold, uint256 _initialVoteQuorumFraction)"
]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions packages/thirdweb/src/extensions/prebuilts/deploy-vote.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { describe, expect, it } from "vitest";
import { ANVIL_CHAIN } from "~test/chains.js";
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js";
import { TEST_CLIENT } from "~test/test-clients.js";
import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
import { isAddress } from "../../utils/address.js";
import { deployERC20Contract } from "./deploy-erc20.js";
import { deployVoteContract } from "./deploy-vote.js";

describe.runIf(process.env.TW_SECRET_KEY)("deploy-voteERC20 contract", () => {
it("should deploy Vote contract", async () => {
const tokenAddress = await deployERC20Contract({
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
account: TEST_ACCOUNT_A,
type: "TokenERC20",
params: {
name: "Token",
contractURI: TEST_CONTRACT_URI,
},
});
const address = await deployVoteContract({
account: TEST_ACCOUNT_A,
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
params: {
name: "",
contractURI: TEST_CONTRACT_URI,
tokenAddress: tokenAddress,
// user needs 0.5 <token> to create proposal
initialProposalThreshold: "0.5",
// vote expires 10 blocks later
initialVotingPeriod: 10,
// Requires 51% of users who voted, voted "For", for this proposal to pass
minVoteQuorumRequiredPercent: 51,
},
});
expect(address).toBeDefined();
expect(isAddress(address)).toBe(true);
// Further tests to verify the functionality of this contract
// are done in other Vote tests
});

it("should throw if passed an non-integer-like value to minVoteQuorumRequiredPercent", async () => {
const tokenAddress = await deployERC20Contract({
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
account: TEST_ACCOUNT_A,
type: "TokenERC20",
params: {
name: "Token",
contractURI: TEST_CONTRACT_URI,
},
});
await expect(() =>
deployVoteContract({
account: TEST_ACCOUNT_A,
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
params: {
name: "",
contractURI: TEST_CONTRACT_URI,
tokenAddress: tokenAddress,
initialProposalThreshold: "0.5",
initialVotingPeriod: 10,
minVoteQuorumRequiredPercent: 51.12,
},
}),
).rejects.toThrowError(
"51.12 is an invalid value. Only integer-like values accepted",
);
});
});
Loading

0 comments on commit b661ce7

Please sign in to comment.