Skip to content

Commit

Permalink
fix OR logic in settings builder (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
solanamonk authored Jun 17, 2024
1 parent 3283c82 commit 8e1037b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/state-controller-sdk/src/settingsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class SettingsBuilder {

or(left: SettingsBuilder, right: SettingsBuilder): SettingsBuilder {
this.nodes = this.nodes.concat(...left.build(), ...right.build(), {
and: {},
or: {},
});
return this;
}
Expand Down
72 changes: 66 additions & 6 deletions tests/state-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import {
PROGRAM_ID as PROPOSAL_PID,
init as initProposal,
} from "@helium/proposal-sdk";
import {
PROGRAM_ID,
SettingsBuilder,
init,
settings,
} from "@helium/state-controller-sdk";
import { PROGRAM_ID, init, settings } from "@helium/state-controller-sdk";
import { expect } from "chai";
import { ensureIdls, makeid } from "./utils";

Expand Down Expand Up @@ -307,6 +302,71 @@ describe("state-controller", () => {
});
});

describe("resolved by choice vote weight or offset", () => {
before(async () => {
nodes = settings()
.and(
settings().choiceVoteWeight(new anchor.BN(5)),
settings().or(
settings().numResolved(1),
settings().offsetFromStartTs(new anchor.BN(5))
)
)
.build();
});

it("resolves to the max choice when there is enough weight", async () => {
await proposalProgram.methods
.voteV0({
choice: 0,
weight: new anchor.BN(3),
removeVote: false,
})
.accounts({ proposal, voter: me })
.rpc({ skipPreflight: true });

await program.methods.resolveV0().accounts({ proposal }).rpc();

let acct = await proposalProgram.account.proposalV0.fetch(proposal!);
expect(Boolean(acct.state.voting)).to.be.true;

await proposalProgram.methods
.voteV0({
choice: 1,
weight: new anchor.BN(5),
removeVote: false,
})
.accounts({ proposal, voter: me })
.rpc({ skipPreflight: true });

acct = await proposalProgram.account.proposalV0.fetch(proposal!);
expect(acct.state.resolved?.choices).to.deep.eq([1]);
});

it("resolves to no choices after offset", async () => {
await proposalProgram.methods
.voteV0({
choice: 0,
weight: new anchor.BN(3),
removeVote: false,
})
.accounts({ proposal, voter: me })
.rpc({ skipPreflight: true });

await program.methods.resolveV0().accounts({ proposal }).rpc();

let acct = await proposalProgram.account.proposalV0.fetch(proposal!);
expect(Boolean(acct.state.voting)).to.be.true;

await sleep(6000);

await program.methods.resolveV0().accounts({ proposal }).rpc();

acct = await proposalProgram.account.proposalV0.fetch(proposal!);
expect(acct.state.resolved?.choices).to.deep.eq([]);
});
});

describe("helium flavor governance", () => {
before(async () => {
nodes = settings()
Expand Down

0 comments on commit 8e1037b

Please sign in to comment.