Browse Source

removed fill opening parameters dto

Gleb Urvanov 4 years ago
parent
commit
200416742c

+ 1 - 1
tests/network-tests/package.json

@@ -7,7 +7,7 @@
     "test": "tap --files src/nicaea/tests/proposals/*Test.ts --files src/nicaea/tests/workingGroup/*Test.ts -T",
     "test": "tap --files src/nicaea/tests/proposals/*Test.ts --files src/nicaea/tests/workingGroup/*Test.ts -T",
     "test-migration-constantinople": "tap --files src/rome/tests/romeRuntimeUpgradeTest.ts --files src/constantinople/tests/electingCouncilTest.ts -T",
     "test-migration-constantinople": "tap --files src/rome/tests/romeRuntimeUpgradeTest.ts --files src/constantinople/tests/electingCouncilTest.ts -T",
     "test-migration-nicaea": "tap --files src/constantinople/tests/proposals/updateRuntimeTest.ts --files src/nicaea/tests/electingCouncilTest.ts -T",
     "test-migration-nicaea": "tap --files src/constantinople/tests/proposals/updateRuntimeTest.ts --files src/nicaea/tests/electingCouncilTest.ts -T",
-    "debug": "tap --files src/iznik/tests/workingGroup/*Test.ts -T",
+    "debug": "tap --files src/iznik/tests/proposals/manageLeaderRoleTest.ts -T",
     "lint": "eslint . --quiet --ext .ts",
     "lint": "eslint . --quiet --ext .ts",
     "checks": "yarn lint && tsc --noEmit --pretty && prettier ./ --check",
     "checks": "yarn lint && tsc --noEmit --pretty && prettier ./ --check",
     "format": "prettier ./ --write "
     "format": "prettier ./ --write "

+ 0 - 85
tests/network-tests/src/iznik/dto/fillOpeningParameters.ts

@@ -1,85 +0,0 @@
-import BN from 'bn.js'
-
-export class FillOpeningParameters {
-  private amountPerPayout!: BN
-  private nextPaymentAtBlock!: BN
-  private payoutInterval!: BN
-  private openingId!: BN
-  private successfulApplicationId!: BN
-  private workingGroup!: string
-
-  public getAmountPerPayout(): BN {
-    return this.amountPerPayout
-  }
-
-  public getNextPaymentAtBlock(): BN {
-    return this.nextPaymentAtBlock
-  }
-
-  public getPayoutInterval(): BN {
-    return this.payoutInterval
-  }
-
-  public getOpeningId(): BN {
-    return this.openingId
-  }
-
-  public getSuccessfulApplicationId(): BN {
-    return this.successfulApplicationId
-  }
-
-  public getWorkingGroup(): string {
-    return this.workingGroup
-  }
-
-  public setAmountPerPayout(value: BN): FillOpeningParameters {
-    this.amountPerPayout = value
-    return this
-  }
-
-  public setNextPaymentAtBlock(value: BN): FillOpeningParameters {
-    this.nextPaymentAtBlock = value
-    return this
-  }
-
-  public setPayoutInterval(value: BN): FillOpeningParameters {
-    this.payoutInterval = value
-    return this
-  }
-
-  public setOpeningId(value: BN): FillOpeningParameters {
-    this.openingId = value
-    return this
-  }
-
-  public setSuccessfulApplicationId(value: BN): FillOpeningParameters {
-    this.successfulApplicationId = value
-    return this
-  }
-
-  public setWorkingGroup(value: string): FillOpeningParameters {
-    this.workingGroup = value
-    return this
-  }
-
-  constructor() {
-    return
-  }
-
-  public getRewardPolicy() {
-    return {
-      amount_per_payout: this.amountPerPayout,
-      next_payment_at_block: this.nextPaymentAtBlock,
-      payout_interval: this.payoutInterval,
-    }
-  }
-
-  public getFillOpeningParameters() {
-    return {
-      opening_id: this.openingId,
-      successful_application_id: this.successfulApplicationId,
-      reward_policy: this.getRewardPolicy(),
-      working_group: this.workingGroup,
-    }
-  }
-}

+ 20 - 9
tests/network-tests/src/iznik/tests/fixtures/proposalsModule.ts

@@ -3,10 +3,14 @@ import { ApiWrapper, WorkingGroups } from '../../utils/apiWrapper'
 import { v4 as uuid } from 'uuid'
 import { v4 as uuid } from 'uuid'
 import BN from 'bn.js'
 import BN from 'bn.js'
 import { WorkingGroupOpening } from '../../dto/workingGroupOpening'
 import { WorkingGroupOpening } from '../../dto/workingGroupOpening'
-import { FillOpeningParameters } from '../../dto/fillOpeningParameters'
+import { FillOpeningParameters } from '@nicaea/types/proposals'
 import { Fixture } from './interfaces/fixture'
 import { Fixture } from './interfaces/fixture'
-import { Bytes } from '@polkadot/types'
+import { Bytes, Option, u32 } from '@polkadot/types'
+import { Balance, BlockNumber } from '@polkadot/types/interfaces'
 import { assert } from 'chai'
 import { assert } from 'chai'
+import { ApplicationId, OpeningId } from '@nicaea/types/hiring'
+import { RewardPolicy } from '@nicaea/types/working-group'
+import { WorkingGroup } from '@nicaea/types/common'
 
 
 export class CreateWorkingGroupLeaderOpeningFixture implements Fixture {
 export class CreateWorkingGroupLeaderOpeningFixture implements Fixture {
   private apiWrapper: ApiWrapper
   private apiWrapper: ApiWrapper
@@ -196,13 +200,20 @@ export class FillLeaderOpeningProposalFixture implements Fixture {
       await this.apiWrapper.getActiveApplicationsIdsByRoleAccount(this.applicantRoleAccountAddress, this.workingGroup)
       await this.apiWrapper.getActiveApplicationsIdsByRoleAccount(this.applicantRoleAccountAddress, this.workingGroup)
     )[0]
     )[0]
     const now = await this.apiWrapper.getBestBlock()
     const now = await this.apiWrapper.getBestBlock()
-    const fillOpeningParameters: FillOpeningParameters = new FillOpeningParameters()
-      .setAmountPerPayout(this.payoutAmount)
-      .setNextPaymentAtBlock(now.add(this.firstRewardInterval))
-      .setPayoutInterval(this.rewardInterval)
-      .setOpeningId(this.openingId)
-      .setSuccessfulApplicationId(applicationId)
-      .setWorkingGroup(workingGroupString)
+
+    const fillOpeningParameters: FillOpeningParameters = new FillOpeningParameters({
+      opening_id: this.openingId as OpeningId,
+      successful_application_id: applicationId as ApplicationId,
+      reward_policy: new Option(
+        RewardPolicy,
+        new RewardPolicy({
+          amount_per_payout: this.payoutAmount as Balance,
+          next_payment_at_block: now.add(this.firstRewardInterval) as BlockNumber,
+          payout_interval: new Option(u32, this.rewardInterval as u32),
+        })
+      ),
+      working_group: new WorkingGroup(workingGroupString),
+    })
 
 
     const proposalPromise = this.apiWrapper.expectProposalCreated()
     const proposalPromise = this.apiWrapper.expectProposalCreated()
     await this.apiWrapper.proposeFillLeaderOpening(
     await this.apiWrapper.proposeFillLeaderOpening(

+ 0 - 0
tests/network-tests/src/iznik/tests/proposals/manageLeaderRole.ts → tests/network-tests/src/iznik/tests/proposals/manageLeaderRoleTest.ts


+ 138 - 55
tests/network-tests/src/iznik/utils/apiWrapper.ts

@@ -1,23 +1,40 @@
 import { ApiPromise, WsProvider } from '@polkadot/api'
 import { ApiPromise, WsProvider } from '@polkadot/api'
-import { Option, Vec, Bytes, u32 } from '@polkadot/types'
+import { Bytes, Option, u32, Vec } from '@polkadot/types'
 import { Codec } from '@polkadot/types/types'
 import { Codec } from '@polkadot/types/types'
 import { KeyringPair } from '@polkadot/keyring/types'
 import { KeyringPair } from '@polkadot/keyring/types'
-import { UserInfo, PaidMembershipTerms, MemberId } from '@nicaea/types/members'
+import { MemberId, PaidMembershipTerms, UserInfo } from '@nicaea/types/members'
 import { Mint, MintId } from '@nicaea/types/mint'
 import { Mint, MintId } from '@nicaea/types/mint'
 import { Lead, LeadId } from '@nicaea/types/content-working-group'
 import { Lead, LeadId } from '@nicaea/types/content-working-group'
-import { Application, WorkerId, Worker, ApplicationIdToWorkerIdMap, Opening } from '@nicaea/types/working-group'
+import {
+  Application,
+  ApplicationIdToWorkerIdMap,
+  Opening,
+  OpeningType,
+  RewardPolicy,
+  Worker,
+  WorkerId,
+} from '@nicaea/types/working-group'
 import { RoleParameters } from '@nicaea/types/roles'
 import { RoleParameters } from '@nicaea/types/roles'
 import { Seat } from '@nicaea/types/council'
 import { Seat } from '@nicaea/types/council'
-import { Balance, Event, EventRecord, AccountId, BlockNumber, BalanceOf } from '@polkadot/types/interfaces'
+import { AccountId, Balance, BalanceOf, BlockNumber, Event, EventRecord } from '@polkadot/types/interfaces'
 import BN from 'bn.js'
 import BN from 'bn.js'
 import { SubmittableExtrinsic } from '@polkadot/api/types'
 import { SubmittableExtrinsic } from '@polkadot/api/types'
 import { Sender } from './sender'
 import { Sender } from './sender'
 import { Utils } from './utils'
 import { Utils } from './utils'
 import { Stake, StakedState } from '@nicaea/types/stake'
 import { Stake, StakedState } from '@nicaea/types/stake'
 import { RewardRelationship } from '@nicaea/types/recurring-rewards'
 import { RewardRelationship } from '@nicaea/types/recurring-rewards'
-import { Opening as HiringOpening, Application as HiringApplication, ApplicationId } from '@nicaea/types/hiring'
-import { WorkingGroupOpening } from '../dto/workingGroupOpening'
-import { FillOpeningParameters } from '../dto/fillOpeningParameters'
+import {
+  ActivateOpeningAt,
+  Application as HiringApplication,
+  ApplicationId,
+  ApplicationRationingPolicy,
+  Opening as HiringOpening,
+  OpeningId,
+  StakingPolicy,
+} from '@nicaea/types/hiring'
+import { FillOpeningParameters } from '@nicaea/types/proposals'
+import { WorkingGroup } from '@nicaea/types/common'
+import { SlashingTerms, WorkingGroupOpeningPolicyCommitment } from '../../../../../types/src/working-group'
 
 
 export enum WorkingGroups {
 export enum WorkingGroups {
   StorageWorkingGroup = 'storageWorkingGroup',
   StorageWorkingGroup = 'storageWorkingGroup',
@@ -240,14 +257,41 @@ export class ApiWrapper {
     return this.estimateTxFee(this.api.tx.proposalsEngine.vote(0, 0, 'Approve'))
     return this.estimateTxFee(this.api.tx.proposalsEngine.vote(0, 0, 'Approve'))
   }
   }
 
 
-  public estimateAddOpeningFee(opening: WorkingGroupOpening, module: WorkingGroups): BN {
+  public estimateAddOpeningFee(module: WorkingGroups): BN {
+    const commitment: WorkingGroupOpeningPolicyCommitment = new WorkingGroupOpeningPolicyCommitment({
+      application_rationing_policy: new Option(ApplicationRationingPolicy, {
+        max_active_applicants: new BN(32) as u32,
+      }),
+      max_review_period_length: new BN(32) as u32,
+      application_staking_policy: new Option(StakingPolicy, {
+        amount: new BN(1),
+        amount_mode: 'AtLeast',
+        crowded_out_unstaking_period_length: new BN(1),
+        review_period_expired_unstaking_period_length: new BN(1),
+      }),
+      role_staking_policy: new Option(StakingPolicy, {
+        amount: new BN(1),
+        amount_mode: 'AtLeast',
+        crowded_out_unstaking_period_length: new BN(1),
+        review_period_expired_unstaking_period_length: new BN(1),
+      }),
+      role_slashing_terms: new SlashingTerms({
+        Slashable: {
+          max_count: new BN(0),
+          max_percent_pts_per_time: new BN(0),
+        },
+      }),
+      fill_opening_successful_applicant_application_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      fill_opening_failed_applicant_application_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      fill_opening_failed_applicant_role_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      terminate_application_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      terminate_role_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      exit_role_application_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      exit_role_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+    })
+
     return this.estimateTxFee(
     return this.estimateTxFee(
-      this.api.tx[module].addOpening(
-        opening.getActivateAt(),
-        opening.getCommitment(),
-        opening.getText(),
-        opening.getOpeningType()
-      )
+      this.api.tx[module].addOpening('CurrentBlock', commitment, 'Human readable text', 'Worker')
     )
     )
   }
   }
 
 
@@ -325,25 +369,37 @@ export class ApiWrapper {
   }
   }
 
 
   public estimateProposeCreateWorkingGroupLeaderOpeningFee(): BN {
   public estimateProposeCreateWorkingGroupLeaderOpeningFee(): BN {
-    const opening: WorkingGroupOpening = new WorkingGroupOpening()
-      .setActivateAtBlock(undefined)
-      .setMaxActiveApplicants(new BN(32))
-      .setMaxReviewPeriodLength(new BN(32))
-      .setApplicationStakingPolicyAmount(new BN(1))
-      .setApplicationCrowdedOutUnstakingPeriodLength(new BN(1))
-      .setApplicationExpiredUnstakingPeriodLength(new BN(1))
-      .setRoleStakingPolicyAmount(new BN(1))
-      .setRoleCrowdedOutUnstakingPeriodLength(new BN(1))
-      .setRoleExpiredUnstakingPeriodLength(new BN(1))
-      .setSlashableMaxCount(new BN(0))
-      .setSlashableMaxPercentPtsPerTime(new BN(0))
-      .setSuccessfulApplicantApplicationStakeUnstakingPeriod(new BN(1))
-      .setFailedApplicantApplicationStakeUnstakingPeriod(new BN(1))
-      .setFailedApplicantRoleStakeUnstakingPeriod(new BN(1))
-      .setTerminateApplicationStakeUnstakingPeriod(new BN(1))
-      .setTerminateRoleStakeUnstakingPeriod(new BN(1))
-      .setExitRoleApplicationStakeUnstakingPeriod(new BN(1))
-      .setExitRoleStakeUnstakingPeriod(new BN(1))
+    const commitment: WorkingGroupOpeningPolicyCommitment = new WorkingGroupOpeningPolicyCommitment({
+      application_rationing_policy: new Option(ApplicationRationingPolicy, {
+        max_active_applicants: new BN(32) as u32,
+      }),
+      max_review_period_length: new BN(32) as u32,
+      application_staking_policy: new Option(StakingPolicy, {
+        amount: new BN(1),
+        amount_mode: 'AtLeast',
+        crowded_out_unstaking_period_length: new BN(1),
+        review_period_expired_unstaking_period_length: new BN(1),
+      }),
+      role_staking_policy: new Option(StakingPolicy, {
+        amount: new BN(1),
+        amount_mode: 'AtLeast',
+        crowded_out_unstaking_period_length: new BN(1),
+        review_period_expired_unstaking_period_length: new BN(1),
+      }),
+      role_slashing_terms: new SlashingTerms({
+        Slashable: {
+          max_count: new BN(0),
+          max_percent_pts_per_time: new BN(0),
+        },
+      }),
+      fill_opening_successful_applicant_application_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      fill_opening_failed_applicant_application_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      fill_opening_failed_applicant_role_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      terminate_application_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      terminate_role_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      exit_role_application_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+      exit_role_stake_unstaking_period: new Option(u32, new BN(1) as BlockNumber),
+    })
 
 
     return this.estimateTxFee(
     return this.estimateTxFee(
       this.api.tx.proposalsCodex.createAddWorkingGroupLeaderOpeningProposal(
       this.api.tx.proposalsCodex.createAddWorkingGroupLeaderOpeningProposal(
@@ -352,8 +408,8 @@ export class ApiWrapper {
         'some long description for the purpose of testing',
         'some long description for the purpose of testing',
         0,
         0,
         {
         {
-          'activate_at': opening.getActivateAt(),
-          'commitment': opening.getCommitment(),
+          'activate_at': 'CurrentBlock',
+          'commitment': commitment,
           'human_readable_text': 'Opening readable text',
           'human_readable_text': 'Opening readable text',
           'working_group': 'Storage',
           'working_group': 'Storage',
         }
         }
@@ -375,13 +431,27 @@ export class ApiWrapper {
   }
   }
 
 
   public estimateProposeFillLeaderOpeningFee(): BN {
   public estimateProposeFillLeaderOpeningFee(): BN {
-    const fillOpeningParameters: FillOpeningParameters = new FillOpeningParameters()
-      .setAmountPerPayout(new BN(1))
-      .setNextPaymentAtBlock(new BN(99999))
-      .setPayoutInterval(new BN(99999))
-      .setOpeningId(new BN(0))
-      .setSuccessfulApplicationId(new BN(0))
-      .setWorkingGroup('Storage')
+    // const fillOpeningParameters: FillOpeningParameters = new FillOpeningParameters()
+    //   .setAmountPerPayout(new BN(1))
+    //   .setNextPaymentAtBlock(new BN(99999))
+    //   .setPayoutInterval(new BN(99999))
+    //   .setOpeningId(new BN(0))
+    //   .setSuccessfulApplicationId(new BN(0))
+    //   .setWorkingGroup('Storage')
+
+    const fillOpeningParameters: FillOpeningParameters = new FillOpeningParameters({
+      opening_id: new BN(0) as OpeningId,
+      successful_application_id: new BN(0) as ApplicationId,
+      reward_policy: new Option(
+        RewardPolicy,
+        new RewardPolicy({
+          amount_per_payout: new BN(1) as Balance,
+          next_payment_at_block: new BN(99999) as BlockNumber,
+          payout_interval: new Option(u32, new BN(99999) as u32),
+        })
+      ),
+      working_group: new WorkingGroup('Storage'),
+    })
 
 
     return this.estimateTxFee(
     return this.estimateTxFee(
       this.api.tx.proposalsCodex.createFillWorkingGroupLeaderOpeningProposal(
       this.api.tx.proposalsCodex.createFillWorkingGroupLeaderOpeningProposal(
@@ -389,7 +459,7 @@ export class ApiWrapper {
         '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',
         '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,
-        fillOpeningParameters.getFillOpeningParameters()
+        fillOpeningParameters
       )
       )
     )
     )
   }
   }
@@ -935,16 +1005,30 @@ export class ApiWrapper {
 
 
   public async addOpening(
   public async addOpening(
     leader: KeyringPair,
     leader: KeyringPair,
-    opening: WorkingGroupOpening,
+    actiavteAt: ActivateOpeningAt,
+    commitment: WorkingGroupOpeningPolicyCommitment,
+    text: string,
+    type: string,
     module: WorkingGroups,
     module: WorkingGroups,
     expectFailure: boolean
     expectFailure: boolean
   ): Promise<void> {
   ): Promise<void> {
-    return this.sender.signAndSend(this.createAddOpeningTransaction(opening, module), leader, expectFailure)
+    return this.sender.signAndSend(
+      this.createAddOpeningTransaction(actiavteAt, commitment, text, type, module),
+      leader,
+      expectFailure
+    )
   }
   }
 
 
-  public async sudoAddOpening(sudo: KeyringPair, opening: WorkingGroupOpening, module: WorkingGroups): Promise<void> {
+  public async sudoAddOpening(
+    sudo: KeyringPair,
+    actiavteAt: ActivateOpeningAt,
+    commitment: WorkingGroupOpeningPolicyCommitment,
+    text: string,
+    type: string,
+    module: WorkingGroups
+  ): Promise<void> {
     return this.sender.signAndSend(
     return this.sender.signAndSend(
-      this.api.tx.sudo.sudo(this.createAddOpeningTransaction(opening, module)),
+      this.api.tx.sudo.sudo(this.createAddOpeningTransaction(actiavteAt, commitment, text, type, module)),
       sudo,
       sudo,
       false
       false
     )
     )
@@ -980,13 +1064,14 @@ export class ApiWrapper {
     fillOpeningParameters: FillOpeningParameters
     fillOpeningParameters: FillOpeningParameters
   ): Promise<void> {
   ): Promise<void> {
     const memberId: BN = (await this.getMemberIds(account.address))[0]
     const memberId: BN = (await this.getMemberIds(account.address))[0]
+
     return this.sender.signAndSend(
     return this.sender.signAndSend(
       this.api.tx.proposalsCodex.createFillWorkingGroupLeaderOpeningProposal(
       this.api.tx.proposalsCodex.createFillWorkingGroupLeaderOpeningProposal(
         memberId,
         memberId,
         title,
         title,
         description,
         description,
         proposalStake,
         proposalStake,
-        fillOpeningParameters.getFillOpeningParameters()
+        fillOpeningParameters
       ),
       ),
       account,
       account,
       false
       false
@@ -1121,15 +1206,13 @@ export class ApiWrapper {
   }
   }
 
 
   private createAddOpeningTransaction(
   private createAddOpeningTransaction(
-    opening: WorkingGroupOpening,
+    actiavteAt: ActivateOpeningAt,
+    commitment: WorkingGroupOpeningPolicyCommitment,
+    text: string,
+    type: string,
     module: WorkingGroups
     module: WorkingGroups
   ): SubmittableExtrinsic<'promise'> {
   ): SubmittableExtrinsic<'promise'> {
-    return this.api.tx[module].addOpening(
-      opening.getActivateAt(),
-      opening.getCommitment(),
-      opening.getText(),
-      opening.getOpeningType()
-    )
+    return this.api.tx[module].addOpening(actiavteAt, commitment, text, type)
   }
   }
 
 
   public async acceptApplications(leader: KeyringPair, openingId: BN, module: WorkingGroups): Promise<void> {
   public async acceptApplications(leader: KeyringPair, openingId: BN, module: WorkingGroups): Promise<void> {

+ 1 - 1
types/src/working-group/index.ts

@@ -185,7 +185,7 @@ export type IWorkingGroupOpeningPolicyCommitment = {
 // very fragile atm and any change to this type in working-group module could result in "unsolvable" inconsistencies
 // very fragile atm and any change to this type in working-group module could result in "unsolvable" inconsistencies
 // (this won't be an issue after CWG gets refactored to use the working-grpup module too)
 // (this won't be an issue after CWG gets refactored to use the working-grpup module too)
 export class WorkingGroupOpeningPolicyCommitment extends JoyStruct<IWorkingGroupOpeningPolicyCommitment> {
 export class WorkingGroupOpeningPolicyCommitment extends JoyStruct<IWorkingGroupOpeningPolicyCommitment> {
-  constructor(value?: WorkingGroupOpeningPolicyCommitment) {
+  constructor(value?: IWorkingGroupOpeningPolicyCommitment) {
     super(
     super(
       {
       {
         application_rationing_policy: Option.with(ApplicationRationingPolicy),
         application_rationing_policy: Option.with(ApplicationRationingPolicy),