-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] Deploy VoteERC20 extension (#4264)
## 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
Showing
6 changed files
with
647 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"thirdweb": patch | ||
--- | ||
|
||
Add extension for deploying VoteERC20 contract |
3 changes: 3 additions & 0 deletions
3
packages/thirdweb/scripts/generate/abis/prebuilts/VoteERC20.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
] |
230 changes: 230 additions & 0 deletions
230
packages/thirdweb/src/extensions/prebuilts/__generated__/VoteERC20/write/initialize.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
packages/thirdweb/src/extensions/prebuilts/deploy-vote.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
); | ||
}); | ||
}); |
Oops, something went wrong.