Forráskód Böngészése

mint capacity proposal impelemented

Gleb Urvanov 4 éve
szülő
commit
737c2e9ca1

+ 3 - 1
tests/network-tests/.env

@@ -47,4 +47,6 @@ STORAGE_WORKING_GROUP_UNSTAKING_PERIOD = 1
 # Slash value for manage working group lead testing scenario
 SLASH_AMOUNT = 2
 # Stake decrement amount for manage working group lead testing scenario
-STAKE_DECREMENT = 3
+STAKE_DECREMENT = 3
+# Mint capacity increment value for working gorup mint capacity test
+MINT_CAPACITY_INCREMENT = 11

+ 41 - 0
tests/network-tests/src/nicaea/tests/proposals/contentWorkingGroupMintCapacityProposalTest.ts

@@ -0,0 +1,41 @@
+import { KeyringPair } from '@polkadot/keyring/types';
+import { membershipTest } from '../impl/membershipCreation';
+import { councilTest } from '../impl/electingCouncil';
+import { workingGroupMintCapacityProposalTest } from './impl/workingGroupMintCapacityProposal';
+import { initConfig } from '../../utils/config';
+import { Keyring, WsProvider } from '@polkadot/api';
+import BN from 'bn.js';
+import { setTestTimeout } from '../../utils/setTestTimeout';
+import tap from 'tap';
+import { registerJoystreamTypes } from '@nicaea/types';
+import { closeApi } from '../impl/closeApi';
+import { ApiWrapper } from '../../utils/apiWrapper';
+
+tap.mocha.describe('Validator count proposal scenario', async () => {
+  initConfig();
+  registerJoystreamTypes();
+
+  const m1KeyPairs: KeyringPair[] = new Array();
+  const m2KeyPairs: KeyringPair[] = new Array();
+
+  const keyring = new Keyring({ type: 'sr25519' });
+  const N: number = +process.env.MEMBERSHIP_CREATION_N!;
+  const paidTerms: number = +process.env.MEMBERSHIP_PAID_TERMS!;
+  const nodeUrl: string = process.env.NODE_URL!;
+  const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
+  const K: number = +process.env.COUNCIL_ELECTION_K!;
+  const greaterStake: BN = new BN(+process.env.COUNCIL_STAKE_GREATER_AMOUNT!);
+  const lesserStake: BN = new BN(+process.env.COUNCIL_STAKE_LESSER_AMOUNT!);
+  const mintingCapacityIncrement: BN = new BN(+process.env.MINTING_CAPACITY_INCREMENT!);
+  const durationInBlocks: number = 29;
+
+  const provider = new WsProvider(nodeUrl);
+  const apiWrapper: ApiWrapper = await ApiWrapper.create(provider);
+
+  setTestTimeout(apiWrapper, durationInBlocks);
+  membershipTest(apiWrapper, m1KeyPairs, keyring, N, paidTerms, sudoUri);
+  membershipTest(apiWrapper, m2KeyPairs, keyring, N, paidTerms, sudoUri);
+  councilTest(apiWrapper, m1KeyPairs, m2KeyPairs, keyring, K, sudoUri, greaterStake, lesserStake);
+  workingGroupMintCapacityProposalTest(apiWrapper, m1KeyPairs, m2KeyPairs, keyring, sudoUri, mintingCapacityIncrement);
+  closeApi(apiWrapper);
+});

+ 31 - 0
tests/network-tests/src/nicaea/tests/proposals/impl/proposalsModule.ts

@@ -268,6 +268,37 @@ export async function slashLeaderProposal(
   return proposalNumber;
 }
 
+export async function workingGroupMintCapacityProposal(
+  apiWrapper: ApiWrapper,
+  m1KeyPairs: KeyringPair[],
+  sudo: KeyringPair,
+  mintCapacity: BN,
+  workingGroup: WorkingGroups
+): Promise<BN> {
+  // Setup
+  const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8);
+  const description: string = 'Testing working group mint capacity proposal ' + uuid().substring(0, 8);
+  const workingGroupString: string = apiWrapper.getWorkingGroupString(workingGroup);
+
+  // Proposal stake calculation
+  const proposalStake: BN = new BN(50000);
+  const proposalFee: BN = apiWrapper.estimateProposeWorkingGroupMintCapacityFee();
+  await apiWrapper.transferBalance(sudo, m1KeyPairs[0].address, proposalFee.add(proposalStake));
+
+  // Proposal creation
+  const proposalPromise = apiWrapper.expectProposalCreated();
+  await apiWrapper.proposeWorkingGroupMintCapacity(
+    m1KeyPairs[0],
+    proposalTitle,
+    description,
+    proposalStake,
+    mintCapacity,
+    workingGroupString
+  );
+  const proposalNumber: BN = await proposalPromise;
+  return proposalNumber;
+}
+
 export async function voteForProposal(
   apiWrapper: ApiWrapper,
   m2KeyPairs: KeyringPair[],

+ 4 - 4
tests/network-tests/src/nicaea/tests/proposals/impl/workingGroupMintCapacityProposal.ts

@@ -21,11 +21,11 @@ export function workingGroupMintCapacityProposalTest(
     sudo = keyring.addFromUri(sudoUri);
     const description: string = 'spending proposal which is used for API network testing';
     const runtimeVoteFee: BN = apiWrapper.estimateVoteForProposalFee();
-    const initialMintingCapacity: BN = await apiWrapper.getWorkingGroupMintCapacity();
+    const initialMintingCapacity: BN = await apiWrapper.getContentWorkingGroupMintCapacity();
 
     // Topping the balances
     const proposalStake: BN = new BN(50000);
-    const runtimeProposalFee: BN = apiWrapper.estimateProposeWorkingGroupMintCapacityFee(
+    const runtimeProposalFee: BN = apiWrapper.estimateProposeContentWorkingGroupMintCapacityFee(
       description,
       description,
       proposalStake,
@@ -37,7 +37,7 @@ export function workingGroupMintCapacityProposalTest(
     // Proposal creation
     const proposedMintingCapacity: BN = initialMintingCapacity.add(mintingCapacityIncrement);
     const proposalPromise = apiWrapper.expectProposalCreated();
-    await apiWrapper.proposeWorkingGroupMintCapacity(
+    await apiWrapper.proposeContentWorkingGroupMintCapacity(
       m1KeyPairs[0],
       'testing mint capacity' + uuid().substring(0, 8),
       'mint capacity to test proposal functionality' + uuid().substring(0, 8),
@@ -50,7 +50,7 @@ export function workingGroupMintCapacityProposalTest(
     const mintCapacityPromise = apiWrapper.expectProposalFinalized();
     await apiWrapper.batchApproveProposal(m2KeyPairs, proposalNumber);
     await mintCapacityPromise;
-    const newMintingCapacity: BN = await apiWrapper.getWorkingGroupMintCapacity();
+    const newMintingCapacity: BN = await apiWrapper.getContentWorkingGroupMintCapacity();
     assert(
       proposedMintingCapacity.eq(newMintingCapacity),
       `Content working group has unexpected minting capacity ${newMintingCapacity}, expected ${proposedMintingCapacity}`

+ 0 - 150
tests/network-tests/src/nicaea/tests/proposals/leaderHiringHappyCase.ts

@@ -1,150 +0,0 @@
-import { KeyringPair } from '@polkadot/keyring/types';
-import { membershipTest } from '../impl/membershipCreation';
-import { councilTest } from '../impl/electingCouncil';
-import { initConfig } from '../../utils/config';
-import { Keyring, WsProvider } from '@polkadot/api';
-import BN from 'bn.js';
-import { setTestTimeout } from '../../utils/setTestTimeout';
-import tap from 'tap';
-import { registerJoystreamTypes } from '@nicaea/types';
-import { closeApi } from '../impl/closeApi';
-import { ApiWrapper, WorkingGroups } from '../../utils/apiWrapper';
-import {
-  createWorkingGroupLeaderOpening,
-  voteForProposal,
-  beginWorkingGroupLeaderApplicationReview,
-  fillLeaderOpeningProposal,
-  terminateLeaderRoleProposal,
-} from './impl/proposalsModule';
-import {
-  applyForOpening,
-  expectLeadOpeningAdded,
-  expectLeaderSet,
-  expectBeganApplicationReview,
-  expectLeaderRoleTerminated,
-} from '../workingGroup/impl/workingGroupModule';
-
-tap.mocha.describe('Set lead proposal scenario', async () => {
-  initConfig();
-  registerJoystreamTypes();
-
-  const m1KeyPairs: KeyringPair[] = new Array();
-  const m2KeyPairs: KeyringPair[] = new Array();
-  const leadKeyPair: KeyringPair[] = new Array();
-
-  const keyring = new Keyring({ type: 'sr25519' });
-  const N: number = +process.env.MEMBERSHIP_CREATION_N!;
-  const paidTerms: number = +process.env.MEMBERSHIP_PAID_TERMS!;
-  const nodeUrl: string = process.env.NODE_URL!;
-  const sudoUri: string = process.env.SUDO_ACCOUNT_URI!;
-  const K: number = +process.env.COUNCIL_ELECTION_K!;
-  const greaterStake: BN = new BN(+process.env.COUNCIL_STAKE_GREATER_AMOUNT!);
-  const lesserStake: BN = new BN(+process.env.COUNCIL_STAKE_LESSER_AMOUNT!);
-  const applicationStake: BN = new BN(process.env.WORKING_GROUP_APPLICATION_STAKE!);
-  const roleStake: BN = new BN(process.env.WORKING_GROUP_ROLE_STAKE!);
-  const firstRewardInterval: BN = new BN(process.env.LONG_REWARD_INTERVAL!);
-  const rewardInterval: BN = new BN(process.env.LONG_REWARD_INTERVAL!);
-  const payoutAmount: BN = new BN(process.env.PAYOUT_AMOUNT!);
-  const durationInBlocks: number = 60;
-
-  const provider = new WsProvider(nodeUrl);
-  const apiWrapper: ApiWrapper = await ApiWrapper.create(provider);
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri);
-
-  setTestTimeout(apiWrapper, durationInBlocks);
-  membershipTest(apiWrapper, m1KeyPairs, keyring, N, paidTerms, sudoUri);
-  membershipTest(apiWrapper, m2KeyPairs, keyring, N, paidTerms, sudoUri);
-  membershipTest(apiWrapper, leadKeyPair, keyring, 1, paidTerms, sudoUri);
-  councilTest(apiWrapper, m1KeyPairs, m2KeyPairs, keyring, K, sudoUri, greaterStake, lesserStake);
-
-  let createOpeningProposalId: BN;
-  let openingId: BN;
-  tap.test(
-    'Propose create leader opening',
-    async () =>
-      (createOpeningProposalId = await createWorkingGroupLeaderOpening(
-        apiWrapper,
-        m1KeyPairs,
-        sudo,
-        applicationStake,
-        roleStake,
-        'Storage'
-      ))
-  );
-  tap.test('Approve add opening proposal', async () => {
-    voteForProposal(apiWrapper, m2KeyPairs, sudo, createOpeningProposalId);
-    openingId = await expectLeadOpeningAdded(apiWrapper);
-  });
-
-  tap.test(
-    'Apply for lead opening',
-    async () =>
-      await applyForOpening(
-        apiWrapper,
-        leadKeyPair,
-        sudo,
-        applicationStake,
-        roleStake,
-        new BN(openingId),
-        WorkingGroups.storageWorkingGroup,
-        false
-      )
-  );
-  let beginReviewProposalId: BN;
-  tap.test(
-    'Propose begin leader application review',
-    async () =>
-      (beginReviewProposalId = await beginWorkingGroupLeaderApplicationReview(
-        apiWrapper,
-        m1KeyPairs,
-        sudo,
-        new BN(openingId),
-        'Storage'
-      ))
-  );
-  tap.test('Approve begin review proposal', async () => {
-    voteForProposal(apiWrapper, m2KeyPairs, sudo, beginReviewProposalId);
-    expectBeganApplicationReview(apiWrapper);
-  });
-
-  let fillLeaderOpeningProposalId: BN;
-  tap.test(
-    'Propose fill leader opening',
-    async () =>
-      (fillLeaderOpeningProposalId = await fillLeaderOpeningProposal(
-        apiWrapper,
-        m1KeyPairs,
-        leadKeyPair[0].address,
-        sudo,
-        firstRewardInterval,
-        rewardInterval,
-        payoutAmount,
-        new BN(openingId),
-        WorkingGroups.storageWorkingGroup
-      ))
-  );
-  tap.test('Approve fill leader opening', async () => {
-    voteForProposal(apiWrapper, m2KeyPairs, sudo, fillLeaderOpeningProposalId);
-    await expectLeaderSet(apiWrapper, leadKeyPair[0].address, WorkingGroups.storageWorkingGroup);
-  });
-
-  let terminateLeaderRoleProposalId: BN;
-  tap.test(
-    'Propose terminate leader role',
-    async () =>
-      (terminateLeaderRoleProposalId = await terminateLeaderRoleProposal(
-        apiWrapper,
-        m1KeyPairs,
-        leadKeyPair[0].address,
-        sudo,
-        false,
-        WorkingGroups.storageWorkingGroup
-      ))
-  );
-  tap.test('Approve leader role termination', async () => {
-    voteForProposal(apiWrapper, m2KeyPairs, sudo, terminateLeaderRoleProposalId);
-    await expectLeaderRoleTerminated(apiWrapper, WorkingGroups.storageWorkingGroup);
-  });
-
-  closeApi(apiWrapper);
-});

+ 28 - 6
tests/network-tests/src/nicaea/tests/proposals/workingGroupMintCapacityProposalTest.ts

@@ -1,7 +1,6 @@
 import { KeyringPair } from '@polkadot/keyring/types';
 import { membershipTest } from '../impl/membershipCreation';
 import { councilTest } from '../impl/electingCouncil';
-import { workingGroupMintCapacityProposalTest } from './impl/workingGroupMintCapacityProposal';
 import { initConfig } from '../../utils/config';
 import { Keyring, WsProvider } from '@polkadot/api';
 import BN from 'bn.js';
@@ -9,9 +8,11 @@ import { setTestTimeout } from '../../utils/setTestTimeout';
 import tap from 'tap';
 import { registerJoystreamTypes } from '@nicaea/types';
 import { closeApi } from '../impl/closeApi';
-import { ApiWrapper } from '../../utils/apiWrapper';
+import { ApiWrapper, WorkingGroups } from '../../utils/apiWrapper';
+import { voteForProposal, workingGroupMintCapacityProposal } from './impl/proposalsModule';
+import { expectMintCapacityChanged } from '../workingGroup/impl/workingGroupModule';
 
-tap.mocha.describe('Validator count proposal scenario', async () => {
+tap.mocha.describe('Set storage working group mint capacity scenario', async () => {
   initConfig();
   registerJoystreamTypes();
 
@@ -26,16 +27,37 @@ tap.mocha.describe('Validator count proposal scenario', async () => {
   const K: number = +process.env.COUNCIL_ELECTION_K!;
   const greaterStake: BN = new BN(+process.env.COUNCIL_STAKE_GREATER_AMOUNT!);
   const lesserStake: BN = new BN(+process.env.COUNCIL_STAKE_LESSER_AMOUNT!);
-  const mintingCapacityIncrement: BN = new BN(+process.env.MINTING_CAPACITY_INCREMENT!);
-  const durationInBlocks: number = 29;
+  const mintCapacityIncrement: BN = new BN(process.env.MINT_CAPACITY_INCREMENT!);
+  const durationInBlocks: number = 30;
 
   const provider = new WsProvider(nodeUrl);
   const apiWrapper: ApiWrapper = await ApiWrapper.create(provider);
+  const sudo: KeyringPair = keyring.addFromUri(sudoUri);
 
   setTestTimeout(apiWrapper, durationInBlocks);
   membershipTest(apiWrapper, m1KeyPairs, keyring, N, paidTerms, sudoUri);
   membershipTest(apiWrapper, m2KeyPairs, keyring, N, paidTerms, sudoUri);
   councilTest(apiWrapper, m1KeyPairs, m2KeyPairs, keyring, K, sudoUri, greaterStake, lesserStake);
-  workingGroupMintCapacityProposalTest(apiWrapper, m1KeyPairs, m2KeyPairs, keyring, sudoUri, mintingCapacityIncrement);
+
+  let mintCapacityProposalId: BN;
+  const newMintCapacity: BN = (await apiWrapper.getWorkingGroupMintCapacity(WorkingGroups.storageWorkingGroup)).add(
+    mintCapacityIncrement
+  );
+  tap.test(
+    'Propose mint capacity',
+    async () =>
+      (mintCapacityProposalId = await workingGroupMintCapacityProposal(
+        apiWrapper,
+        m1KeyPairs,
+        sudo,
+        newMintCapacity,
+        WorkingGroups.storageWorkingGroup
+      ))
+  );
+  tap.test('Approve mint capacity', async () => {
+    voteForProposal(apiWrapper, m2KeyPairs, sudo, mintCapacityProposalId);
+    await expectMintCapacityChanged(apiWrapper, newMintCapacity);
+  });
+
   closeApi(apiWrapper);
 });

+ 9 - 0
tests/network-tests/src/nicaea/tests/workingGroup/impl/workingGroupModule.ts

@@ -582,3 +582,12 @@ export async function expectLeaderSlashed(
   );
   return;
 }
+
+export async function expectMintCapacityChanged(apiWrapper: ApiWrapper, expectedMintCapacity: BN): Promise<void> {
+  const receivedMintCapacity = await apiWrapper.expectMintCapacityChanged();
+  assert(
+    receivedMintCapacity.eq(expectedMintCapacity),
+    `Unexpected mint capacity: ${receivedMintCapacity}, expected ${expectedMintCapacity}`
+  );
+  return;
+}

+ 63 - 3
tests/network-tests/src/nicaea/utils/apiWrapper.ts

@@ -144,7 +144,12 @@ export class ApiWrapper {
     );
   }
 
-  public estimateProposeWorkingGroupMintCapacityFee(title: string, description: string, stake: BN, balance: BN): BN {
+  public estimateProposeContentWorkingGroupMintCapacityFee(
+    title: string,
+    description: string,
+    stake: BN,
+    balance: BN
+  ): BN {
     return this.estimateTxFee(
       this.api.tx.proposalsCodex.createSetContentWorkingGroupMintCapacityProposal(
         stake,
@@ -457,6 +462,19 @@ export class ApiWrapper {
     );
   }
 
+  public estimateProposeWorkingGroupMintCapacityFee(): BN {
+    return this.estimateTxFee(
+      this.api.tx.proposalsCodex.createSetWorkingGroupMintCapacityProposal(
+        0,
+        'Some testing text used for estimation purposes which is longer than text expected during the test',
+        'Some testing text used for estimation purposes which is longer than text expected during the test',
+        0,
+        0,
+        'Storage'
+      )
+    );
+  }
+
   private applyForCouncilElection(account: KeyringPair, amount: BN): Promise<void> {
     return this.sender.signAndSend(this.api.tx.councilElection.apply(amount), account, false);
   }
@@ -605,7 +623,7 @@ export class ApiWrapper {
     );
   }
 
-  public async proposeWorkingGroupMintCapacity(
+  public async proposeContentWorkingGroupMintCapacity(
     account: KeyringPair,
     title: string,
     description: string,
@@ -924,6 +942,18 @@ export class ApiWrapper {
     });
   }
 
+  public expectMintCapacityChanged(): Promise<BN> {
+    return new Promise(async resolve => {
+      await this.api.query.system.events<Vec<EventRecord>>(events => {
+        events.forEach(record => {
+          if (record.event.method && record.event.method.toString() === 'MintCapacityChanged') {
+            resolve((record.event.data[1] as unknown) as BN);
+          }
+        });
+      });
+    });
+  }
+
   public getTotalIssuance(): Promise<BN> {
     return this.api.query.balances.totalIssuance<Balance>();
   }
@@ -938,13 +968,20 @@ export class ApiWrapper {
     return this.api.query.proposalsEngine.proposalCount<u32>();
   }
 
-  public async getWorkingGroupMintCapacity(): Promise<BN> {
+  public async getContentWorkingGroupMintCapacity(): Promise<BN> {
     const mintId: MintId = await this.api.query.contentWorkingGroup.mint<MintId>();
     const mintCodec = await this.api.query.minting.mints<Codec[]>(mintId);
     const mint: Mint = (mintCodec[0] as unknown) as Mint;
     return mint.getField<Balance>('capacity');
   }
 
+  public async getWorkingGroupMintCapacity(module: WorkingGroups): Promise<BN> {
+    const mintId: MintId = await this.api.query[module].mint<MintId>();
+    const mintCodec = await this.api.query.minting.mints<Codec[]>(mintId);
+    const mint: Mint = (mintCodec[0] as unknown) as Mint;
+    return mint.getField<Balance>('capacity');
+  }
+
   public getValidatorCount(): Promise<BN> {
     return this.api.query.staking.validatorCount<u32>();
   }
@@ -1140,6 +1177,29 @@ export class ApiWrapper {
     );
   }
 
+  public async proposeWorkingGroupMintCapacity(
+    account: KeyringPair,
+    title: string,
+    description: string,
+    proposalStake: BN,
+    mintCapacity: BN,
+    workingGroup: string
+  ): Promise<void> {
+    const memberId: BN = (await this.getMemberIds(account.address))[0];
+    return this.sender.signAndSend(
+      this.api.tx.proposalsCodex.createSetWorkingGroupMintCapacityProposal(
+        memberId,
+        title,
+        description,
+        proposalStake,
+        mintCapacity,
+        workingGroup
+      ),
+      account,
+      false
+    );
+  }
+
   private createAddOpeningTransaction(
     opening: WorkingGroupOpening,
     module: WorkingGroups