diff --git a/modules/client/test/unit/addresslistVoting-client/utils.test.ts b/modules/client/test/unit/addresslistVoting-client/utils.test.ts new file mode 100644 index 000000000..269077ee4 --- /dev/null +++ b/modules/client/test/unit/addresslistVoting-client/utils.test.ts @@ -0,0 +1,80 @@ +import { ProposalStatus } from "@aragon/sdk-client-common"; +import { computeProposalStatus } from "../../../src/addresslistVoting/internal/utils"; +import { SubgraphAddresslistVotingProposal } from "../../../src/addresslistVoting/internal/types"; + +describe("addresslistVoting-client utils", () => { + describe("computeProposalStatus", () => { + it("should return PENDING", () => { + const endDate = Date.now() / 1000; + const startDate = (Date.now() / 1000) + 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + earlyExecutable: false, + } as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.PENDING); + }); + it("should return EXECUTED", () => { + const endDate = Date.now() / 1000; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: true, + earlyExecutable: false, + } as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.EXECUTED); + }); + it("should return ACTIVE", () => { + const endDate = (Date.now() / 1000) + 500; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + earlyExecutable: false, + } as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.ACTIVE); + }); + it("should return SUCCEDED if executable = true", () => { + const endDate = Date.now() / 1000; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: true, + executed: false, + earlyExecutable: false, + } as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.SUCCEEDED); + }); + it("should return SUCCEDED if earlyExecutable = true", () => { + const endDate = (Date.now() / 1000) + 500; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + earlyExecutable: true, + } as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.SUCCEEDED); + }); + it("should return DEFEATED", () => { + const endDate = (Date.now() / 1000) - 200; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + earlyExecutable: false, + } as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.DEFEATED); + }); + }); +}); diff --git a/modules/client/test/unit/client-common/utils.test.ts b/modules/client/test/unit/client-common/utils.test.ts index e26a193d8..64bb5df6b 100644 --- a/modules/client/test/unit/client-common/utils.test.ts +++ b/modules/client/test/unit/client-common/utils.test.ts @@ -1,6 +1,5 @@ import { hexToBytes } from "@aragon/sdk-common"; import { - computeProposalStatus, isFailingProposal, } from "../../../src"; import { Multisig__factory } from "@aragon/osx-ethers"; @@ -56,82 +55,6 @@ const UPGRADE_TO_ACTION = { ), }; -describe("client-common utils", () => { - describe("computeProposalStatus", () => { - it("should return PENDING", () => { - const endDate = Date.now() / 1000; - const startDate = (Date.now() / 1000) + 500; - - expect(computeProposalStatus({ - endDate: endDate.toString(), - startDate: startDate.toString(), - potentiallyExecutable: false, - executed: false, - earlyExecutable: false, - })).toBe(ProposalStatus.PENDING); - }); - it("should return EXECUTED", () => { - const endDate = Date.now() / 1000; - const startDate = (Date.now() / 1000) - 500; - - expect(computeProposalStatus({ - endDate: endDate.toString(), - startDate: startDate.toString(), - potentiallyExecutable: false, - executed: true, - earlyExecutable: false, - })).toBe(ProposalStatus.EXECUTED); - }); - it("should return ACTIVE", () => { - const endDate = (Date.now() / 1000) + 500; - const startDate = (Date.now() / 1000) - 500; - - expect(computeProposalStatus({ - endDate: endDate.toString(), - startDate: startDate.toString(), - potentiallyExecutable: false, - executed: false, - earlyExecutable: false, - })).toBe(ProposalStatus.ACTIVE); - }); - it("should return SUCCEDED if executable = true", () => { - const endDate = Date.now() / 1000; - const startDate = (Date.now() / 1000) - 500; - - expect(computeProposalStatus({ - endDate: endDate.toString(), - startDate: startDate.toString(), - potentiallyExecutable: true, - executed: false, - earlyExecutable: false, - })).toBe(ProposalStatus.SUCCEEDED); - }); - it("should return SUCCEDED if earlyExecutable = true", () => { - const endDate = (Date.now() / 1000) + 500; - const startDate = (Date.now() / 1000) - 500; - - expect(computeProposalStatus({ - endDate: endDate.toString(), - startDate: startDate.toString(), - potentiallyExecutable: false, - executed: false, - earlyExecutable: true, - })).toBe(ProposalStatus.SUCCEEDED); - }); - it("should return DEFEATED", () => { - const endDate = (Date.now() / 1000) - 200; - const startDate = (Date.now() / 1000) - 500; - - expect(computeProposalStatus({ - endDate: endDate.toString(), - startDate: startDate.toString(), - potentiallyExecutable: false, - executed: false, - earlyExecutable: false, - })).toBe(ProposalStatus.DEFEATED); - }); - }); -}); describe("Detect failing proposals", () => { it("isFailingProposal should return true because the proposal changes the min approvals and then updates the addresses", async () => { diff --git a/modules/client/test/unit/multisig-client/utils.test.ts b/modules/client/test/unit/multisig-client/utils.test.ts new file mode 100644 index 000000000..f69fe1283 --- /dev/null +++ b/modules/client/test/unit/multisig-client/utils.test.ts @@ -0,0 +1,63 @@ +import { ProposalStatus } from "@aragon/sdk-client-common"; +import { computeProposalStatus } from "../../../src/multisig/internal/utils"; +import { SubgraphMultisigProposal } from "../../../src/multisig/internal/types"; + +describe("multisig-client utils", () => { + describe("computeProposalStatus", () => { + it("should return PENDING", () => { + const endDate = Date.now() / 1000; + const startDate = (Date.now() / 1000) + 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + } as SubgraphMultisigProposal)).toBe(ProposalStatus.PENDING); + }); + it("should return EXECUTED", () => { + const endDate = Date.now() / 1000; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: true, + } as SubgraphMultisigProposal)).toBe(ProposalStatus.EXECUTED); + }); + it("should return ACTIVE", () => { + const endDate = (Date.now() / 1000) + 500; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + } as SubgraphMultisigProposal)).toBe(ProposalStatus.ACTIVE); + }); + it("should return SUCCEDED if executable = true", () => { + const endDate = (Date.now() / 1000) + 500; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: true, + executed: false, + } as SubgraphMultisigProposal)).toBe(ProposalStatus.SUCCEEDED); + }); + it("should return DEFEATED", () => { + const endDate = (Date.now() / 1000) - 200; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: true, + executed: false, + } as SubgraphMultisigProposal)).toBe(ProposalStatus.DEFEATED); + }); + }); +}); diff --git "a/modules/client/test/unit/tokenVoting-client\302\240 /utils.test.ts" "b/modules/client/test/unit/tokenVoting-client\302\240 /utils.test.ts" index 202958b0b..94d378e9c 100644 --- "a/modules/client/test/unit/tokenVoting-client\302\240 /utils.test.ts" +++ "b/modules/client/test/unit/tokenVoting-client\302\240 /utils.test.ts" @@ -1,6 +1,6 @@ -import { TokenType } from "@aragon/sdk-client-common"; -import { SubgraphContractType } from "../../../src/tokenVoting/internal/types"; -import { parseToken } from "../../../src/tokenVoting/internal/utils"; +import { ProposalStatus, TokenType } from "@aragon/sdk-client-common"; +import { SubgraphContractType, SubgraphTokenVotingProposal } from "../../../src/tokenVoting/internal/types"; +import { computeProposalStatus, parseToken } from "../../../src/tokenVoting/internal/utils"; describe("tokenVoting-client utils", () => { describe("parseToken", () => { @@ -75,4 +75,78 @@ describe("tokenVoting-client utils", () => { expect(token).toEqual(null); }); }); + describe("computeProposalStatus", () => { + it("should return PENDING", () => { + const endDate = Date.now() / 1000; + const startDate = (Date.now() / 1000) + 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + earlyExecutable: false, + } as SubgraphTokenVotingProposal)).toBe(ProposalStatus.PENDING); + }); + it("should return EXECUTED", () => { + const endDate = Date.now() / 1000; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: true, + earlyExecutable: false, + } as SubgraphTokenVotingProposal)).toBe(ProposalStatus.EXECUTED); + }); + it("should return ACTIVE", () => { + const endDate = (Date.now() / 1000) + 500; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + earlyExecutable: false, + } as SubgraphTokenVotingProposal)).toBe(ProposalStatus.ACTIVE); + }); + it("should return SUCCEDED if executable = true", () => { + const endDate = Date.now() / 1000; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: true, + executed: false, + earlyExecutable: false, + } as SubgraphTokenVotingProposal)).toBe(ProposalStatus.SUCCEEDED); + }); + it("should return SUCCEDED if earlyExecutable = true", () => { + const endDate = (Date.now() / 1000) + 500; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + earlyExecutable: true, + } as SubgraphTokenVotingProposal)).toBe(ProposalStatus.SUCCEEDED); + }); + it("should return DEFEATED", () => { + const endDate = (Date.now() / 1000) - 200; + const startDate = (Date.now() / 1000) - 500; + + expect(computeProposalStatus({ + endDate: endDate.toString(), + startDate: startDate.toString(), + potentiallyExecutable: false, + executed: false, + earlyExecutable: false, + } as SubgraphTokenVotingProposal)).toBe(ProposalStatus.DEFEATED); + }); + }); });