diff --git a/packages/governance-sdk/src/governance/serialisation.ts b/packages/governance-sdk/src/governance/serialisation.ts index 48f01f9a..3a3c8f05 100644 --- a/packages/governance-sdk/src/governance/serialisation.ts +++ b/packages/governance-sdk/src/governance/serialisation.ts @@ -111,8 +111,10 @@ import { deserializeBorsh } from '../tools/borsh'; writer.length += 1; if (value.type === VoteTypeKind.MultiChoice) { - writer.buf.writeUInt16LE(value.choiceCount!, writer.length); - writer.length += 2; + writer.buf.writeUInt8(value.choiceCount!, writer.length); + writer.length += 1; + writer.buf.writeUInt8(value.choiceCount!, writer.length); + writer.length += 1; } }; diff --git a/packages/governance-sdk/tests/governance/api.v4.test.ts b/packages/governance-sdk/tests/governance/api.v4.test.ts new file mode 100644 index 00000000..6636fa32 --- /dev/null +++ b/packages/governance-sdk/tests/governance/api.v4.test.ts @@ -0,0 +1,78 @@ +import { Keypair } from '@solana/web3.js'; +import { GoverningTokenConfigAccountArgs, GoverningTokenType } from '../../src'; +import { BenchBuilder } from '../tools/builders'; + +test('setRealmConfig', async () => { + // Arrange + const realm = await BenchBuilder.withConnection() + .then(b => b.withWallet()) + .then(b => b.withRealm()) + .then(b => b.sendTx()); + + const communityTokenConfig = new GoverningTokenConfigAccountArgs({ + voterWeightAddin: Keypair.generate().publicKey, + maxVoterWeightAddin: Keypair.generate().publicKey, + tokenType: GoverningTokenType.Liquid, + }); + + // Act + await realm.setRealmConfig(communityTokenConfig); + + // Assert + const realmConfig = await realm.getRealmConfig(); + + expect(realmConfig.account.realm).toEqual(realm.realmPk); + + // communityTokenConfig + expect(realmConfig.account.communityTokenConfig.tokenType).toEqual( + communityTokenConfig.tokenType, + ); + expect(realmConfig.account.communityTokenConfig.voterWeightAddin).toEqual( + communityTokenConfig.voterWeightAddin, + ); + expect(realmConfig.account.communityTokenConfig.maxVoterWeightAddin).toEqual( + communityTokenConfig.maxVoterWeightAddin, + ); + + // councilTokenConfig + expect(realmConfig.account.councilTokenConfig.tokenType).toEqual( + GoverningTokenType.Liquid, + ); + expect(realmConfig.account.councilTokenConfig.voterWeightAddin).toEqual( + undefined, + ); + expect(realmConfig.account.councilTokenConfig.maxVoterWeightAddin).toEqual( + undefined, + ); +}); + +test('createGovernance', async () => { + // Arrange + const realm = await BenchBuilder.withConnection() + .then(b => b.withWallet()) + .then(b => b.withRealm()) + .then(b => b.withCommunityMember()) + .then(b => b.sendTx()); + + // Act + const governancePk = await realm.createGovernance(); + + // // Assert + const governance = await realm.getGovernance(governancePk); + + expect(governance.account.realm).toEqual(realm.realmPk); +}); + +test('createProposal', async () => { + // Arrange + const realm = await BenchBuilder.withConnection() + .then(b => b.withWallet()) + .then(b => b.withRealm()) + .then(b => b.withCommunityMember()) + .then(b => b.withGovernance()) + .then(b => b.sendTx()); + + // Act + const proposalPk = await realm.createProposal('proposal 1', true); + +}); diff --git a/packages/governance-sdk/tests/tools/builders.ts b/packages/governance-sdk/tests/tools/builders.ts index abc91139..57699f78 100644 --- a/packages/governance-sdk/tests/tools/builders.ts +++ b/packages/governance-sdk/tests/tools/builders.ts @@ -379,17 +379,23 @@ export class RealmBuilder { return this; } - async createProposal(name?: string) { - const proposalPk = await this._createProposal(name); + async createProposal(name?: string, multiple?: boolean) { + const proposalPk = await this._createProposal(name, multiple); await this.sendTx(); return proposalPk; } - async _createProposal(name?: string) { + async _createProposal(name?: string, multiple?: boolean) { // Create single choice Approve/Deny proposal with instruction to mint more governance tokens - const voteType = VoteType.SINGLE_CHOICE; - const options = ['Approve']; - const useDenyOption = true; + let voteType = VoteType.SINGLE_CHOICE; + let options = ['Approve']; + let useDenyOption = true; + + if (multiple) { + voteType = VoteType.MULTI_CHOICE(4); + options = ['One', 'Two', 'Three', 'four'] + useDenyOption = false + } this.proposalPk = await withCreateProposal( this.bench.instructions, @@ -408,7 +414,6 @@ export class RealmBuilder { useDenyOption, this.bench.walletPk, ); - return this.proposalPk; }