Skip to content

Commit

Permalink
test: vote and propose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DuBento committed Jul 19, 2023
1 parent 46ac94c commit 0de8bc8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 13 deletions.
8 changes: 6 additions & 2 deletions blockchain/lib/newMemberViaGovernance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ const getEncodedFunctionCall = async (addr: string) =>
]
);

export async function proposeNewMember(memberAddress: string) {
export async function proposeNewMember(
memberAddress: string,
signerAddress?: string
) {
const encodedFunctionCall = await getEncodedFunctionCall(memberAddress);

const proposalId = await propose(
await utils.getContractAddress("GovernorToken"),
encodedFunctionCall,
USER_REGISTRY_ADD_MEMBER_DESCRIPTION
USER_REGISTRY_ADD_MEMBER_DESCRIPTION,
signerAddress
);

return proposalId;
Expand Down
6 changes: 4 additions & 2 deletions blockchain/lib/propose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { DEVELOPMENT_CHAINS, VOTING_DELAY } from "../properties";
export async function propose(
proposalTarget: string,
encodedCall: string,
proposalDescription: string
proposalDescription: string,
signerAddress?: string
): Promise<bigint> {
const governor = await utils.getContract<GovernorContract>(
"GovernorContract"
"GovernorContract",
{ signerAddress }
);

console.log(`Proposal Description:\n ${proposalDescription}`);
Expand Down
77 changes: 68 additions & 9 deletions blockchain/test/GovernorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
UserRegistry,
} from "../artifacts-frontend/typechain";
import { execute } from "../lib/execute";
import { newMemberViaGovernance } from "../lib/newMemberViaGovernance";
import {
newMemberViaGovernance,
proposeNewMember,
} from "../lib/newMemberViaGovernance";
import { newSupplychainContractViaGovernance } from "../lib/newSupplychainContractViaGovernance";
import { propose } from "../lib/propose";
import * as utils from "../lib/utils";
Expand All @@ -28,6 +31,8 @@ import {
PROPOSAL_VOTE_DESCRIPTION,
} from "./TestConfig";

console.log = () => {};

describe("Governor", function () {
let governorContract: GovernorContract;
let governorToken: GovernorToken;
Expand Down Expand Up @@ -113,40 +118,94 @@ describe("Governor", function () {
});

describe("Proposals", function () {
let actor1: string;
const encodeFunctionCall = async (addr: string, state: string) =>
await utils.encodeFunctionCall(
"UserRegistry",
USER_REGISTRY_UPDATE_MEMBER_STATE_METHOD,
[addr, state]
);

beforeEach(async function () {
actor1 = (await getNamedAccounts()).actor1;
});

it("Propose new member from unregistered account", async function () {
const proposalId = await proposeNewMember(actor1, actor1);

const proposalState = await governorContract.state(proposalId);
expect(proposalState).to.equal(1); // 1 = Active
});

it("Vote proposal with new member succesfully", async function () {
const { actor1 } = await getNamedAccounts();
await newMemberViaGovernance(actor1);
const newMember = actor1;
await newMemberViaGovernance(newMember);

const newState =
await userRegistry.CONFORMITY_STATE_CORRECTIVE_MEASURE_NEEDED();
const encodedCall = await encodeFunctionCall(actor1, newState.toString());
const encodedCall = await encodeFunctionCall(
newMember,
newState.toString()
);

const proposalId = await propose(
await utils.getContractAddress("UserRegistry"),
encodedCall,
USER_REGISTRY_UPDATE_MEMBER_DESCRIPTION
USER_REGISTRY_UPDATE_MEMBER_DESCRIPTION,
newMember
);

let state = await vote(
proposalId.toString(),
1,
PROPOSAL_VOTE_DESCRIPTION,
actor1
newMember
);

expect(state).to.equal(4); // 4 = Succeeded
});

it("Propose with registered actor succesfully", async function () {});
it("Propose with unregistered actor, unsuccesfully", async function () {});
it("Vote with actor, unsuccesfully", async function () {});
it("Propose with registered actor succesfully", async function () {
await userRegistry.addActor(actor1, ACTOR_NAME, ACTOR_INFO_URI);

const newState =
await userRegistry.CONFORMITY_STATE_CORRECTIVE_MEASURE_NEEDED();
const encodedCall = await encodeFunctionCall(actor1, newState.toString());

const proposalId = await propose(
await utils.getContractAddress("UserRegistry"),
encodedCall,
USER_REGISTRY_UPDATE_MEMBER_DESCRIPTION,
actor1
);

const proposalState = await governorContract.state(proposalId);
expect(proposalState).to.equal(1); // 1 = Active
});

it("Vote with actor, unsuccesfully", async function () {
await userRegistry.addActor(actor1, ACTOR_NAME, ACTOR_INFO_URI);

const newState =
await userRegistry.CONFORMITY_STATE_CORRECTIVE_MEASURE_NEEDED();
const encodedCall = await encodeFunctionCall(actor1, newState.toString());

const proposalId = await propose(
await utils.getContractAddress("UserRegistry"),
encodedCall,
USER_REGISTRY_UPDATE_MEMBER_DESCRIPTION,
actor1
);

let state = await vote(
proposalId.toString(),
1,
PROPOSAL_VOTE_DESCRIPTION,
actor1
);

expect(state).to.equal(3); // 3 = Defeated
});
});

describe("Supplychain factory", function () {
Expand Down

0 comments on commit 0de8bc8

Please sign in to comment.