Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed Jul 24, 2023
1 parent c011b9b commit 0892ce5
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 80 deletions.
80 changes: 80 additions & 0 deletions modules/client/test/unit/addresslistVoting-client/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
77 changes: 0 additions & 77 deletions modules/client/test/unit/client-common/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { hexToBytes } from "@aragon/sdk-common";
import {
computeProposalStatus,
isFailingProposal,
} from "../../../src";
import { Multisig__factory } from "@aragon/osx-ethers";
Expand Down Expand Up @@ -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 () => {
Expand Down
63 changes: 63 additions & 0 deletions modules/client/test/unit/multisig-client/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
80 changes: 77 additions & 3 deletions modules/client/test/unit/tokenVoting-client  /utils.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 0892ce5

Please sign in to comment.