Browse Source

network-test: refactoring fixtures

Mokhtar Naamani 4 years ago
parent
commit
8223697869

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

@@ -3,7 +3,7 @@ NODE_URL = ws://127.0.0.1:9944
 # Path to the database for shared keys and nonce
 DB_PATH = .tmp/db.json
 # Account which is expected to provide sufficient funds to test accounts.
-SUDO_ACCOUNT_URI = //Alice
+TREASURY_ACCOUNT_URI = //Alice
 # Amount of members able to buy membership in membership creation test.
 MEMBERSHIP_CREATION_N = 2
 # ID of the membership paid terms used in membership creation test.

File diff suppressed because it is too large
+ 281 - 234
tests/network-tests/src/Api.ts


+ 7 - 19
tests/network-tests/src/fixtures/councilElectionHappyCase.ts

@@ -1,31 +1,20 @@
 import { Fixture } from '../IFixture'
 import { ElectCouncilFixture } from './councilElectionModule'
 import { Api } from '../Api'
-import { KeyringPair } from '@polkadot/keyring/types'
 import BN from 'bn.js'
 
 export class CouncilElectionHappyCaseFixture implements Fixture {
   private api: Api
-  private sudo: KeyringPair
-  private voterKeyPairs: KeyringPair[]
-  private applicantKeyPairs: KeyringPair[]
+  private voters: string[]
+  private applicants: string[]
   private k: number
   private greaterStake: BN
   private lesserStake: BN
 
-  constructor(
-    api: Api,
-    sudo: KeyringPair,
-    voterKeyPairs: KeyringPair[],
-    applicantKeyPairs: KeyringPair[],
-    k: number,
-    greaterStake: BN,
-    lesserStake: BN
-  ) {
+  constructor(api: Api, voters: string[], applicants: string[], k: number, greaterStake: BN, lesserStake: BN) {
     this.api = api
-    this.sudo = sudo
-    this.voterKeyPairs = voterKeyPairs
-    this.applicantKeyPairs = applicantKeyPairs
+    this.voters = voters
+    this.applicants = applicants
     this.k = k
     this.greaterStake = greaterStake
     this.lesserStake = lesserStake
@@ -34,10 +23,9 @@ export class CouncilElectionHappyCaseFixture implements Fixture {
   public async runner(expectFailure: boolean): Promise<void> {
     const electCouncilFixture: ElectCouncilFixture = new ElectCouncilFixture(
       this.api,
-      this.voterKeyPairs,
-      this.applicantKeyPairs,
+      this.voters,
+      this.applicants,
       this.k,
-      this.sudo,
       this.greaterStake,
       this.lesserStake
     )

+ 31 - 51
tests/network-tests/src/fixtures/councilElectionModule.ts

@@ -1,5 +1,4 @@
 import { Api } from '../Api'
-import { KeyringPair } from '@polkadot/keyring/types'
 import BN from 'bn.js'
 import { assert } from 'chai'
 import { Seat } from '@joystream/types/council'
@@ -9,27 +8,17 @@ import { Fixture } from '../IFixture'
 
 export class ElectCouncilFixture implements Fixture {
   private api: Api
-  private voterKeyPairs: KeyringPair[]
-  private applicantKeyPairs: KeyringPair[]
+  private voters: string[]
+  private applicants: string[]
   private k: number
-  private sudo: KeyringPair
   private greaterStake: BN
   private lesserStake: BN
 
-  public constructor(
-    api: Api,
-    voterKeyPairs: KeyringPair[],
-    applicantKeyPairs: KeyringPair[],
-    k: number,
-    sudo: KeyringPair,
-    greaterStake: BN,
-    lesserStake: BN
-  ) {
+  public constructor(api: Api, voters: string[], applicants: string[], k: number, greaterStake: BN, lesserStake: BN) {
     this.api = api
-    this.voterKeyPairs = voterKeyPairs
-    this.applicantKeyPairs = applicantKeyPairs
+    this.voters = voters
+    this.applicants = applicants
     this.k = k
-    this.sudo = sudo
     this.greaterStake = greaterStake
     this.lesserStake = lesserStake
   }
@@ -41,79 +30,70 @@ export class ElectCouncilFixture implements Fixture {
     let now = await this.api.getBestBlock()
     const applyForCouncilFee: BN = this.api.estimateApplyForCouncilFee(this.greaterStake)
     const voteForCouncilFee: BN = this.api.estimateVoteForCouncilFee(
-      this.sudo.address,
-      this.sudo.address,
+      this.applicants[0],
+      this.applicants[0],
       this.greaterStake
     )
-    const salt: string[] = []
-    this.voterKeyPairs.forEach(() => {
-      salt.push(''.concat(uuid().replace(/-/g, '')))
+    const salt: string[] = this.voters.map(() => {
+      return ''.concat(uuid().replace(/-/g, ''))
     })
-    const revealVoteFee: BN = this.api.estimateRevealVoteFee(this.sudo.address, salt[0])
+    const revealVoteFee: BN = this.api.estimateRevealVoteFee(this.applicants[0], salt[0])
 
     // Topping the balances
-    this.api.transferBalanceToAccounts(this.sudo, this.applicantKeyPairs, applyForCouncilFee.add(this.greaterStake))
-    this.api.transferBalanceToAccounts(
-      this.sudo,
-      this.voterKeyPairs,
-      voteForCouncilFee.add(revealVoteFee).add(this.greaterStake)
-    )
+    this.api.treasuryTransferBalanceToAccounts(this.applicants, applyForCouncilFee.add(this.greaterStake))
+    this.api.treasuryTransferBalanceToAccounts(this.voters, voteForCouncilFee.add(revealVoteFee).add(this.greaterStake))
 
     // First K members stake more
-    await this.api.sudoStartAnnouncingPeriod(this.sudo, now.addn(100))
-    await this.api.batchApplyForCouncilElection(this.applicantKeyPairs.slice(0, this.k), this.greaterStake)
-    this.applicantKeyPairs.slice(0, this.k).forEach((keyPair) =>
-      this.api.getCouncilElectionStake(keyPair.address).then((stake) => {
+    await this.api.sudoStartAnnouncingPeriod(now.addn(100))
+    await this.api.batchApplyForCouncilElection(this.applicants.slice(0, this.k), this.greaterStake)
+    this.applicants.slice(0, this.k).forEach((account) =>
+      this.api.getCouncilElectionStake(account).then((stake) => {
         assert(
           stake.eq(this.greaterStake),
-          `${keyPair.address} not applied correctly for council election with stake ${stake} versus expected ${this.greaterStake}`
+          `${account} not applied correctly for council election with stake ${stake} versus expected ${this.greaterStake}`
         )
       })
     )
 
     // Last members stake less
-    await this.api.batchApplyForCouncilElection(this.applicantKeyPairs.slice(this.k), this.lesserStake)
-    this.applicantKeyPairs.slice(this.k).forEach((keyPair) =>
-      this.api.getCouncilElectionStake(keyPair.address).then((stake) => {
+    await this.api.batchApplyForCouncilElection(this.applicants.slice(this.k), this.lesserStake)
+    this.applicants.slice(this.k).forEach((account) =>
+      this.api.getCouncilElectionStake(account).then((stake) => {
         assert(
           stake.eq(this.lesserStake),
-          `${keyPair.address} not applied correctrly for council election with stake ${stake} versus expected ${this.lesserStake}`
+          `${account} not applied correctrly for council election with stake ${stake} versus expected ${this.lesserStake}`
         )
       })
     )
 
     // Voting
-    await this.api.sudoStartVotingPeriod(this.sudo, now.addn(100))
+    await this.api.sudoStartVotingPeriod(now.addn(100))
     await this.api.batchVoteForCouncilMember(
-      this.voterKeyPairs.slice(0, this.k),
-      this.applicantKeyPairs.slice(0, this.k),
+      this.voters.slice(0, this.k),
+      this.applicants.slice(0, this.k),
       salt.slice(0, this.k),
       this.lesserStake
     )
     await this.api.batchVoteForCouncilMember(
-      this.voterKeyPairs.slice(this.k),
-      this.applicantKeyPairs.slice(this.k),
+      this.voters.slice(this.k),
+      this.applicants.slice(this.k),
       salt.slice(this.k),
       this.greaterStake
     )
 
     // Revealing
-    await this.api.sudoStartRevealingPeriod(this.sudo, now.addn(100))
+    await this.api.sudoStartRevealingPeriod(now.addn(100))
     await this.api.batchRevealVote(
-      this.voterKeyPairs.slice(0, this.k),
-      this.applicantKeyPairs.slice(0, this.k),
+      this.voters.slice(0, this.k),
+      this.applicants.slice(0, this.k),
       salt.slice(0, this.k)
     )
-    await this.api.batchRevealVote(
-      this.voterKeyPairs.slice(this.k),
-      this.applicantKeyPairs.slice(this.k),
-      salt.slice(this.k)
-    )
+    await this.api.batchRevealVote(this.voters.slice(this.k), this.applicants.slice(this.k), salt.slice(this.k))
     now = await this.api.getBestBlock()
 
     // Resolving election
     // 3 is to ensure the revealing block is in future
-    await this.api.sudoStartRevealingPeriod(this.sudo, now.addn(3))
+    await this.api.sudoStartRevealingPeriod(now.addn(3))
     await Utils.wait(this.api.getBlockDuration().muln(2.5).toNumber())
     const seats: Seat[] = await this.api.getCouncil()
 

+ 20 - 37
tests/network-tests/src/fixtures/membershipModule.ts

@@ -1,5 +1,4 @@
 import { Api } from '../Api'
-import { KeyringPair } from '@polkadot/keyring/types'
 import BN from 'bn.js'
 import { assert } from 'chai'
 import { Fixture } from '../IFixture'
@@ -7,14 +6,12 @@ import { PaidTermId } from '@joystream/types/members'
 
 export class BuyMembershipHappyCaseFixture implements Fixture {
   private api: Api
-  private treasury: KeyringPair
-  private keyPairs: KeyringPair[]
+  private accounts: string[]
   private paidTerms: PaidTermId
 
-  public constructor(api: Api, treasury: KeyringPair, keyPairs: KeyringPair[], paidTerms: PaidTermId) {
+  public constructor(api: Api, accounts: string[], paidTerms: PaidTermId) {
     this.api = api
-    this.treasury = treasury
-    this.keyPairs = keyPairs
+    this.accounts = accounts
     this.paidTerms = paidTerms
   }
 
@@ -22,29 +19,26 @@ export class BuyMembershipHappyCaseFixture implements Fixture {
     // Fee estimation and transfer
     const membershipFee: BN = await this.api.getMembershipFee(this.paidTerms)
     const membershipTransactionFee: BN = this.api.estimateBuyMembershipFee(
-      this.treasury,
+      this.accounts[0],
       this.paidTerms,
       'member_name_which_is_longer_than_expected'
     )
-    await this.api.transferBalanceToAccounts(
-      this.treasury,
-      this.keyPairs,
-      membershipTransactionFee.add(new BN(membershipFee))
-    )
+    await this.api.treasuryTransferBalanceToAccounts(this.accounts, membershipTransactionFee.add(new BN(membershipFee)))
 
     // Buying membership
     await Promise.all(
-      this.keyPairs.map(async (keyPair) => {
-        await this.api.buyMembership(keyPair, this.paidTerms, `member${keyPair.address.substring(0, 14)}`)
+      this.accounts.map(async (account) => {
+        await this.api.buyMembership(account, this.paidTerms, `member${account.substring(0, 14)}`)
       })
     )
 
     // Assertions
-    this.keyPairs.forEach((keyPair) =>
+    this.accounts.forEach((account) =>
       this.api
-        .getMemberIds(keyPair.address)
-        .then((membership) => assert(membership.length > 0, `Account ${keyPair.address} is not a member`))
+        .getMemberIds(account)
+        .then((membership) => assert(membership.length > 0, `Account ${account} is not a member`))
     )
+
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }
@@ -53,35 +47,31 @@ export class BuyMembershipHappyCaseFixture implements Fixture {
 
 export class BuyMembershipWithInsufficienFundsFixture implements Fixture {
   private api: Api
-  private treasury: KeyringPair
-  private aKeyPair: KeyringPair
+  private account: string
   private paidTerms: PaidTermId
 
-  public constructor(api: Api, treasury: KeyringPair, aKeyPair: KeyringPair, paidTerms: PaidTermId) {
+  public constructor(api: Api, account: string, paidTerms: PaidTermId) {
     this.api = api
-    this.treasury = treasury
-    this.aKeyPair = aKeyPair
+    this.account = account
     this.paidTerms = paidTerms
   }
 
   public async runner(expectFailure: boolean) {
     // Assertions
-    this.api
-      .getMemberIds(this.aKeyPair.address)
-      .then((membership) => assert(membership.length === 0, 'Account A is a member'))
+    this.api.getMemberIds(this.account).then((membership) => assert(membership.length === 0, 'Account A is a member'))
 
     // Fee estimation and transfer
     const membershipFee: BN = await this.api.getMembershipFee(this.paidTerms)
     const membershipTransactionFee: BN = this.api.estimateBuyMembershipFee(
-      this.treasury,
+      this.account,
       this.paidTerms,
       'member_name_which_is_longer_than_expected'
     )
-    await this.api.transferBalance(this.treasury, this.aKeyPair.address, membershipTransactionFee)
+    await this.api.treasuryTransferBalance(this.account, membershipTransactionFee)
 
     // Balance assertion
     await this.api
-      .getBalance(this.aKeyPair.address)
+      .getBalance(this.account)
       .then((balance) =>
         assert(
           balance.toBn() < membershipFee.add(membershipTransactionFee),
@@ -90,17 +80,10 @@ export class BuyMembershipWithInsufficienFundsFixture implements Fixture {
       )
 
     // Buying memebership
-    await this.api.buyMembership(
-      this.aKeyPair,
-      this.paidTerms,
-      `late_member_${this.aKeyPair.address.substring(0, 8)}`,
-      true
-    )
+    await this.api.buyMembership(this.account, this.paidTerms, `late_member_${this.account.substring(0, 8)}`, true)
 
     // Assertions
-    this.api
-      .getMemberIds(this.aKeyPair.address)
-      .then((membership) => assert(membership.length === 0, 'Account A is a member'))
+    this.api.getMemberIds(this.account).then((membership) => assert(membership.length === 0, 'Account A is a member'))
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }

+ 101 - 209
tests/network-tests/src/fixtures/proposalsModule.ts

@@ -1,4 +1,3 @@
-import { KeyringPair } from '@polkadot/keyring/types'
 import { Api, WorkingGroups } from '../Api'
 import { v4 as uuid } from 'uuid'
 import BN from 'bn.js'
@@ -11,25 +10,16 @@ import { Utils } from '../utils'
 
 export class CreateWorkingGroupLeaderOpeningFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
   private applicationStake: BN
   private roleStake: BN
   private workingGroup: string
 
   private result: ProposalId | undefined
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
-    applicationStake: BN,
-    roleStake: BN,
-    workingGroup: string
-  ) {
+  constructor(api: Api, proposer: string, applicationStake: BN, roleStake: BN, workingGroup: string) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
     this.applicationStake = applicationStake
     this.roleStake = roleStake
     this.workingGroup = workingGroup
@@ -47,16 +37,16 @@ export class CreateWorkingGroupLeaderOpeningFixture implements Fixture {
     // Proposal stake calculation
     const proposalStake: BN = new BN(100000)
     const proposalFee: BN = this.api.estimateProposeCreateWorkingGroupLeaderOpeningFee()
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
 
     // Proposal creation
     const result = await this.api.proposeCreateWorkingGroupLeaderOpening({
-      account: this.membersKeyPairs[0],
+      account: this.proposer,
       title: proposalTitle,
       description: description,
       proposalStake: proposalStake,
       actiavteAt: 'CurrentBlock',
-      maxActiveApplicants: new BN(this.membersKeyPairs.length),
+      maxActiveApplicants: new BN(10),
       maxReviewPeriodLength: new BN(32),
       applicationStakingPolicyAmount: this.applicationStake,
       applicationCrowdedOutUnstakingPeriodLength: new BN(1),
@@ -87,23 +77,15 @@ export class CreateWorkingGroupLeaderOpeningFixture implements Fixture {
 
 export class BeginWorkingGroupLeaderApplicationReviewFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
   private openingId: OpeningId
   private workingGroup: string
 
   private result: ProposalId | undefined
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
-    openingId: OpeningId,
-    workingGroup: string
-  ) {
+  constructor(api: Api, proposer: string, openingId: OpeningId, workingGroup: string) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
     this.openingId = openingId
     this.workingGroup = workingGroup
   }
@@ -120,11 +102,11 @@ export class BeginWorkingGroupLeaderApplicationReviewFixture implements Fixture
     // Proposal stake calculation
     const proposalStake: BN = new BN(25000)
     const proposalFee: BN = this.api.estimateProposeBeginWorkingGroupLeaderApplicationReviewFee()
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
 
     // Proposal creation
     const result = await this.api.proposeBeginWorkingGroupLeaderApplicationReview(
-      this.membersKeyPairs[0],
+      this.proposer,
       proposalTitle,
       description,
       proposalStake,
@@ -141,9 +123,8 @@ export class BeginWorkingGroupLeaderApplicationReviewFixture implements Fixture
 
 export class FillLeaderOpeningProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
+  private proposer: string
   private applicationId: ApplicationId
-  private treasury: KeyringPair
   private firstRewardInterval: BN
   private rewardInterval: BN
   private payoutAmount: BN
@@ -154,9 +135,8 @@ export class FillLeaderOpeningProposalFixture implements Fixture {
 
   constructor(
     api: Api,
-    membersKeyPairs: KeyringPair[],
+    proposer: string,
     applicationId: ApplicationId,
-    treasury: KeyringPair,
     firstRewardInterval: BN,
     rewardInterval: BN,
     payoutAmount: BN,
@@ -164,9 +144,8 @@ export class FillLeaderOpeningProposalFixture implements Fixture {
     workingGroup: WorkingGroups
   ) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
+    this.proposer = proposer
     this.applicationId = applicationId
-    this.treasury = treasury
     this.firstRewardInterval = firstRewardInterval
     this.rewardInterval = rewardInterval
     this.payoutAmount = payoutAmount
@@ -187,13 +166,13 @@ export class FillLeaderOpeningProposalFixture implements Fixture {
     // Proposal stake calculation
     const proposalStake: BN = new BN(50000)
     const proposalFee: BN = this.api.estimateProposeFillLeaderOpeningFee()
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
 
     const now: BN = await this.api.getBestBlock()
 
     // Proposal creation
     const result = await this.api.proposeFillLeaderOpening({
-      account: this.membersKeyPairs[0],
+      account: this.proposer,
       title: proposalTitle,
       description: description,
       proposalStake: proposalStake,
@@ -215,26 +194,15 @@ export class FillLeaderOpeningProposalFixture implements Fixture {
 
 export class TerminateLeaderRoleProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private leaderRoleAccountAddress: string
-  private treasury: KeyringPair
+  private proposer: string
   private slash: boolean
   private workingGroup: WorkingGroups
 
   private result: ProposalId | undefined
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    leaderRoleAccountAddress: string,
-    treasury: KeyringPair,
-    slash: boolean,
-    workingGroup: WorkingGroups
-  ) {
+  constructor(api: Api, proposer: string, slash: boolean, workingGroup: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.leaderRoleAccountAddress = leaderRoleAccountAddress
-    this.treasury = treasury
+    this.proposer = proposer
     this.slash = slash
     this.workingGroup = workingGroup
   }
@@ -255,11 +223,11 @@ export class TerminateLeaderRoleProposalFixture implements Fixture {
     // Proposal stake calculation
     const proposalStake: BN = new BN(100000)
     const proposalFee: BN = this.api.estimateProposeTerminateLeaderRoleFee()
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
 
     // Proposal creation
     const result = await this.api.proposeTerminateLeaderRole(
-      this.membersKeyPairs[0],
+      this.proposer,
       proposalTitle,
       description,
       proposalStake,
@@ -278,23 +246,15 @@ export class TerminateLeaderRoleProposalFixture implements Fixture {
 
 export class SetLeaderRewardProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
   private payoutAmount: BN
   private workingGroup: WorkingGroups
 
   private result: ProposalId | undefined
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
-    payoutAmount: BN,
-    workingGroup: WorkingGroups
-  ) {
+  constructor(api: Api, proposer: string, payoutAmount: BN, workingGroup: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
     this.payoutAmount = payoutAmount
     this.workingGroup = workingGroup
   }
@@ -314,11 +274,11 @@ export class SetLeaderRewardProposalFixture implements Fixture {
     // Proposal stake calculation
     const proposalStake: BN = new BN(50000)
     const proposalFee: BN = this.api.estimateProposeLeaderRewardFee()
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
 
     // Proposal creation
     const result = await this.api.proposeLeaderReward(
-      this.membersKeyPairs[0],
+      this.proposer,
       proposalTitle,
       description,
       proposalStake,
@@ -337,23 +297,15 @@ export class SetLeaderRewardProposalFixture implements Fixture {
 
 export class DecreaseLeaderStakeProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
   private stakeDecrement: BN
   private workingGroup: WorkingGroups
 
   private result: ProposalId | undefined
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
-    stakeDecrement: BN,
-    workingGroup: WorkingGroups
-  ) {
+  constructor(api: Api, proposer: string, stakeDecrement: BN, workingGroup: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
     this.stakeDecrement = stakeDecrement
     this.workingGroup = workingGroup
   }
@@ -373,11 +325,11 @@ export class DecreaseLeaderStakeProposalFixture implements Fixture {
     // Proposal stake calculation
     const proposalStake: BN = new BN(50000)
     const proposalFee: BN = this.api.estimateProposeDecreaseLeaderStakeFee()
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
 
     // Proposal creation
     const result = await this.api.proposeDecreaseLeaderStake(
-      this.membersKeyPairs[0],
+      this.proposer,
       proposalTitle,
       description,
       proposalStake,
@@ -396,23 +348,15 @@ export class DecreaseLeaderStakeProposalFixture implements Fixture {
 
 export class SlashLeaderProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
   private slashAmount: BN
   private workingGroup: WorkingGroups
 
   private result: ProposalId | undefined
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
-    slashAmount: BN,
-    workingGroup: WorkingGroups
-  ) {
+  constructor(api: Api, proposer: string, slashAmount: BN, workingGroup: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
     this.slashAmount = slashAmount
     this.workingGroup = workingGroup
   }
@@ -431,11 +375,11 @@ export class SlashLeaderProposalFixture implements Fixture {
     // Proposal stake calculation
     const proposalStake: BN = new BN(50000)
     const proposalFee: BN = this.api.estimateProposeSlashLeaderStakeFee()
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
 
     // Proposal creation
     const result = await this.api.proposeSlashLeaderStake(
-      this.membersKeyPairs[0],
+      this.proposer,
       proposalTitle,
       description,
       proposalStake,
@@ -452,23 +396,15 @@ export class SlashLeaderProposalFixture implements Fixture {
 
 export class WorkingGroupMintCapacityProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
   private mintCapacity: BN
   private workingGroup: WorkingGroups
 
   private result: ProposalId | undefined
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
-    mintCapacity: BN,
-    workingGroup: WorkingGroups
-  ) {
+  constructor(api: Api, proposer: string, mintCapacity: BN, workingGroup: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
     this.mintCapacity = mintCapacity
     this.workingGroup = workingGroup
   }
@@ -486,11 +422,11 @@ export class WorkingGroupMintCapacityProposalFixture implements Fixture {
     // Proposal stake calculation
     const proposalStake: BN = new BN(50000)
     const proposalFee: BN = this.api.estimateProposeWorkingGroupMintCapacityFee()
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
 
     // Proposal creation
     const result = await this.api.proposeWorkingGroupMintCapacity(
-      this.membersKeyPairs[0],
+      this.proposer,
       proposalTitle,
       description,
       proposalStake,
@@ -506,23 +442,23 @@ export class WorkingGroupMintCapacityProposalFixture implements Fixture {
 
 export class ElectionParametersProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private councilKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposerAccount: string
 
-  constructor(api: Api, membersKeyPairs: KeyringPair[], councilKeyPairs: KeyringPair[], treasury: KeyringPair) {
+  constructor(api: Api, proposerAccount: string) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.councilKeyPairs = councilKeyPairs
-    this.treasury = treasury
+    this.proposerAccount = proposerAccount
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
     // Setup
     const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8)
     const description: string = 'Testing validator count proposal ' + uuid().substring(0, 8)
+
+    // Council accounts enough balance to ensure they can vote
+    const councilAccounts = await this.api.getCouncilAccounts()
     const runtimeVoteFee: BN = this.api.estimateVoteForProposalFee()
-    await this.api.transferBalanceToAccounts(this.treasury, this.councilKeyPairs, runtimeVoteFee)
+    this.api.treasuryTransferBalanceToAccounts(councilAccounts, runtimeVoteFee)
+
     const announcingPeriod: BN = new BN(28800)
     const votingPeriod: BN = new BN(14400)
     const revealingPeriod: BN = new BN(14400)
@@ -533,6 +469,7 @@ export class ElectionParametersProposalFixture implements Fixture {
     const minVotingStake: BN = await this.api.getMinVotingStake()
 
     // Proposal stake calculation
+    // Required stake is hardcoded in runtime-module (but not available as const)
     const proposalStake: BN = new BN(200000)
     const proposalFee: BN = this.api.estimateProposeElectionParametersFee(
       description,
@@ -547,7 +484,8 @@ export class ElectionParametersProposalFixture implements Fixture {
       minCouncilStake,
       minVotingStake
     )
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+
+    await this.api.treasuryTransferBalance(this.proposerAccount, proposalFee.add(proposalStake))
 
     // Proposal creation
     const proposedAnnouncingPeriod: BN = announcingPeriod.subn(1)
@@ -560,7 +498,7 @@ export class ElectionParametersProposalFixture implements Fixture {
     const proposedMinVotingStake: BN = minVotingStake.addn(1)
 
     const proposalCreationResult = await this.api.proposeElectionParameters(
-      this.membersKeyPairs[0],
+      this.proposerAccount,
       proposalTitle,
       description,
       proposalStake,
@@ -576,7 +514,7 @@ export class ElectionParametersProposalFixture implements Fixture {
     const proposalNumber = this.api.expectProposalCreatedEvent(proposalCreationResult.events)
 
     // Approving the proposal
-    this.api.batchApproveProposal(this.councilKeyPairs, proposalNumber)
+    this.api.batchApproveProposal(proposalNumber)
     await this.api.waitForProposalToFinalize(proposalNumber)
 
     // Assertions
@@ -628,24 +566,13 @@ export class ElectionParametersProposalFixture implements Fixture {
 
 export class SpendingProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private councilKeyPairs: KeyringPair[]
-  private sudo: KeyringPair
+  private proposer: string
   private spendingBalance: BN
   private mintCapacity: BN
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    councilKeyPairs: KeyringPair[],
-    sudo: KeyringPair,
-    spendingBalance: BN,
-    mintCapacity: BN
-  ) {
+  constructor(api: Api, proposer: string, spendingBalance: BN, mintCapacity: BN) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.councilKeyPairs = councilKeyPairs
-    this.sudo = sudo
+    this.proposer = proposer
     this.spendingBalance = spendingBalance
     this.mintCapacity = mintCapacity
   }
@@ -662,34 +589,37 @@ export class SpendingProposalFixture implements Fixture {
       description,
       proposalStake,
       this.spendingBalance,
-      this.sudo.address
+      this.proposer
     )
-    await this.api.transferBalance(this.sudo, this.membersKeyPairs[0].address, runtimeProposalFee.add(proposalStake))
-    await this.api.transferBalanceToAccounts(this.sudo, this.councilKeyPairs, runtimeVoteFee)
-    await this.api.sudoSetCouncilMintCapacity(this.sudo, this.mintCapacity)
+    await this.api.treasuryTransferBalance(this.proposer, runtimeProposalFee.add(proposalStake))
+    const councilAccounts = await this.api.getCouncilAccounts()
+    this.api.treasuryTransferBalanceToAccounts(councilAccounts, runtimeVoteFee)
+    await this.api.sudoSetCouncilMintCapacity(this.mintCapacity)
+
+    const fundingRecipient = this.api.createKeyPairs(1)[0].address
 
     // Proposal creation
     const result = await this.api.proposeSpending(
-      this.membersKeyPairs[0],
+      this.proposer,
       'testing spending' + uuid().substring(0, 8),
       'spending to test proposal functionality' + uuid().substring(0, 8),
       proposalStake,
       this.spendingBalance,
-      this.sudo.address
+      fundingRecipient
     )
     const proposalNumber: ProposalId = this.api.expectProposalCreatedEvent(result.events)
 
     // Approving spending proposal
-    const balanceBeforeMinting: BN = await this.api.getBalance(this.sudo.address)
-    this.api.batchApproveProposal(this.councilKeyPairs, proposalNumber)
+    const balanceBeforeMinting: BN = await this.api.getBalance(fundingRecipient)
+    this.api.batchApproveProposal(proposalNumber)
     await this.api.waitForProposalToFinalize(proposalNumber)
 
-    const balanceAfterMinting: BN = await this.api.getBalance(this.sudo.address)
+    const balanceAfterMinting: BN = await this.api.getBalance(fundingRecipient)
     assert(
-      balanceAfterMinting.sub(balanceBeforeMinting).eq(this.spendingBalance),
-      `member ${
-        this.membersKeyPairs[0].address
-      } has unexpected balance ${balanceAfterMinting}, expected ${balanceBeforeMinting.add(this.spendingBalance)}`
+      balanceAfterMinting.eq(balanceBeforeMinting.add(this.spendingBalance)),
+      `member ${fundingRecipient} has unexpected balance ${balanceAfterMinting}, expected ${balanceBeforeMinting.add(
+        this.spendingBalance
+      )}`
     )
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
@@ -699,15 +629,11 @@ export class SpendingProposalFixture implements Fixture {
 
 export class TextProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private councilKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
 
-  constructor(api: Api, membersKeyPairs: KeyringPair[], councilKeyPairs: KeyringPair[], treasury: KeyringPair) {
+  constructor(api: Api, proposer: string) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.councilKeyPairs = councilKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
@@ -716,7 +642,8 @@ export class TextProposalFixture implements Fixture {
     const description: string = 'Testing text proposal ' + uuid().substring(0, 8)
     const proposalText: string = 'Text of the testing proposal ' + uuid().substring(0, 8)
     const runtimeVoteFee: BN = this.api.estimateVoteForProposalFee()
-    await this.api.transferBalanceToAccounts(this.treasury, this.councilKeyPairs, runtimeVoteFee)
+    const councilAccounts = await this.api.getCouncilAccounts()
+    await this.api.treasuryTransferBalanceToAccounts(councilAccounts, runtimeVoteFee)
 
     // Proposal stake calculation
     const proposalStake: BN = new BN(25000)
@@ -726,25 +653,15 @@ export class TextProposalFixture implements Fixture {
       description,
       proposalText
     )
-    await this.api.transferBalance(
-      this.treasury,
-      this.membersKeyPairs[0].address,
-      runtimeProposalFee.add(proposalStake)
-    )
+    await this.api.treasuryTransferBalance(this.proposer, runtimeProposalFee.add(proposalStake))
 
     // Proposal creation
 
-    const result = await this.api.proposeText(
-      this.membersKeyPairs[0],
-      proposalStake,
-      proposalTitle,
-      description,
-      proposalText
-    )
+    const result = await this.api.proposeText(this.proposer, proposalStake, proposalTitle, description, proposalText)
     const proposalNumber: ProposalId = this.api.expectProposalCreatedEvent(result.events)
 
     // Approving text proposal
-    this.api.batchApproveProposal(this.councilKeyPairs, proposalNumber)
+    this.api.batchApproveProposal(proposalNumber)
     await this.api.waitForProposalToFinalize(proposalNumber)
 
     if (expectFailure) {
@@ -755,22 +672,12 @@ export class TextProposalFixture implements Fixture {
 
 export class ValidatorCountProposalFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private councilKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
   private validatorCountIncrement: BN
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    councilKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
-    validatorCountIncrement: BN
-  ) {
+  constructor(api: Api, proposer: string, validatorCountIncrement: BN) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.councilKeyPairs = councilKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
     this.validatorCountIncrement = validatorCountIncrement
   }
 
@@ -779,18 +686,19 @@ export class ValidatorCountProposalFixture implements Fixture {
     const proposalTitle: string = 'Testing proposal ' + uuid().substring(0, 8)
     const description: string = 'Testing validator count proposal ' + uuid().substring(0, 8)
     const runtimeVoteFee: BN = this.api.estimateVoteForProposalFee()
-    await this.api.transferBalanceToAccounts(this.treasury, this.councilKeyPairs, runtimeVoteFee)
+    const councilAccounts = await this.api.getCouncilAccounts()
+    await this.api.treasuryTransferBalanceToAccounts(councilAccounts, runtimeVoteFee)
 
     // Proposal stake calculation
     const proposalStake: BN = new BN(100000)
     const proposalFee: BN = this.api.estimateProposeValidatorCountFee(description, description, proposalStake)
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, proposalFee.add(proposalStake))
+    await this.api.treasuryTransferBalance(this.proposer, proposalFee.add(proposalStake))
     const validatorCount: BN = await this.api.getValidatorCount()
 
     // Proposal creation
     const proposedValidatorCount: BN = validatorCount.add(this.validatorCountIncrement)
     const result = await this.api.proposeValidatorCount(
-      this.membersKeyPairs[0],
+      this.proposer,
       proposalTitle,
       description,
       proposalStake,
@@ -799,7 +707,7 @@ export class ValidatorCountProposalFixture implements Fixture {
     const proposalNumber: ProposalId = this.api.expectProposalCreatedEvent(result.events)
 
     // Approving the proposal
-    this.api.batchApproveProposal(this.councilKeyPairs, proposalNumber)
+    this.api.batchApproveProposal(proposalNumber)
     await this.api.waitForProposalToFinalize(proposalNumber)
 
     const newValidatorCount: BN = await this.api.getValidatorCount()
@@ -815,22 +723,12 @@ export class ValidatorCountProposalFixture implements Fixture {
 
 export class UpdateRuntimeFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private councilKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private proposer: string
   private runtimePath: string
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    councilKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
-    runtimePath: string
-  ) {
+  constructor(api: Api, proposer: string, runtimePath: string) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.councilKeyPairs = councilKeyPairs
-    this.treasury = treasury
+    this.proposer = proposer
     this.runtimePath = runtimePath
   }
 
@@ -848,16 +746,13 @@ export class UpdateRuntimeFixture implements Fixture {
       description,
       runtime
     )
-    await this.api.transferBalance(
-      this.treasury,
-      this.membersKeyPairs[0].address,
-      runtimeProposalFee.add(proposalStake)
-    )
-    await this.api.transferBalanceToAccounts(this.treasury, this.councilKeyPairs, runtimeVoteFee)
+    this.api.treasuryTransferBalance(this.proposer, runtimeProposalFee.add(proposalStake))
+    const councilAccounts = await this.api.getCouncilAccounts()
+    this.api.treasuryTransferBalanceToAccounts(councilAccounts, runtimeVoteFee)
 
     // Proposal creation
     const result = await this.api.proposeRuntime(
-      this.membersKeyPairs[0],
+      this.proposer,
       proposalStake,
       'testing runtime' + uuid().substring(0, 8),
       'runtime to test proposal functionality' + uuid().substring(0, 8),
@@ -866,7 +761,7 @@ export class UpdateRuntimeFixture implements Fixture {
     const proposalNumber: ProposalId = this.api.expectProposalCreatedEvent(result.events)
 
     // Approving runtime update proposal
-    this.api.batchApproveProposal(this.councilKeyPairs, proposalNumber)
+    this.api.batchApproveProposal(proposalNumber)
     await this.api.waitForProposalToFinalize(proposalNumber)
 
     if (expectFailure) {
@@ -877,23 +772,20 @@ export class UpdateRuntimeFixture implements Fixture {
 
 export class VoteForProposalFixture implements Fixture {
   private api: Api
-  private councilKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
   private proposalNumber: ProposalId
 
-  constructor(api: Api, councilKeyPairs: KeyringPair[], treasury: KeyringPair, proposalNumber: ProposalId) {
+  constructor(api: Api, proposalNumber: ProposalId) {
     this.api = api
-    this.councilKeyPairs = councilKeyPairs
-    this.treasury = treasury
     this.proposalNumber = proposalNumber
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
     const proposalVoteFee: BN = this.api.estimateVoteForProposalFee()
-    await this.api.transferBalanceToAccounts(this.treasury, this.councilKeyPairs, proposalVoteFee)
+    const councilAccounts = await this.api.getCouncilAccounts()
+    this.api.treasuryTransferBalanceToAccounts(councilAccounts, proposalVoteFee)
 
     // Approving the proposal
-    this.api.batchApproveProposal(this.councilKeyPairs, this.proposalNumber)
+    this.api.batchApproveProposal(this.proposalNumber)
     await this.api.waitForProposalToFinalize(this.proposalNumber)
 
     if (expectFailure) {

+ 7 - 16
tests/network-tests/src/fixtures/sudoHireLead.ts

@@ -8,14 +8,12 @@ import {
 import { BuyMembershipHappyCaseFixture } from './membershipModule'
 import { Api, WorkingGroups } from '../Api'
 import { OpeningId } from '@joystream/types/hiring'
-import { KeyringPair } from '@polkadot/keyring/types'
 import { PaidTermId } from '@joystream/types/members'
 import BN from 'bn.js'
 
 export class SudoHireLeadFixture implements Fixture {
   private api: Api
-  private sudo: KeyringPair
-  private leadKeyPair: KeyringPair
+  private leadAccount: string
   private paidTerms: PaidTermId
   private applicationStake: BN
   private roleStake: BN
@@ -27,8 +25,7 @@ export class SudoHireLeadFixture implements Fixture {
 
   constructor(
     api: Api,
-    sudo: KeyringPair,
-    leadKeyPair: KeyringPair,
+    leadAccount: string,
     paidTerms: PaidTermId,
     applicationStake: BN,
     roleStake: BN,
@@ -39,8 +36,7 @@ export class SudoHireLeadFixture implements Fixture {
     workingGroup: WorkingGroups
   ) {
     this.api = api
-    this.sudo = sudo
-    this.leadKeyPair = leadKeyPair
+    this.leadAccount = leadAccount
     this.paidTerms = paidTerms
     this.applicationStake = applicationStake
     this.roleStake = roleStake
@@ -54,8 +50,7 @@ export class SudoHireLeadFixture implements Fixture {
   public async runner(expectFailure: boolean): Promise<void> {
     const leaderHappyCaseFixture: BuyMembershipHappyCaseFixture = new BuyMembershipHappyCaseFixture(
       this.api,
-      this.sudo,
-      [this.leadKeyPair],
+      [this.leadAccount],
       this.paidTerms
     )
     // Buying membership for leader account
@@ -63,8 +58,7 @@ export class SudoHireLeadFixture implements Fixture {
 
     const addLeaderOpeningFixture: AddLeaderOpeningFixture = new AddLeaderOpeningFixture(
       this.api,
-      [this.leadKeyPair],
-      this.sudo,
+      [this.leadAccount],
       this.applicationStake,
       this.roleStake,
       this.openingActivationDelay,
@@ -75,8 +69,7 @@ export class SudoHireLeadFixture implements Fixture {
 
     const applyForLeaderOpeningFixture = new ApplyForOpeningFixture(
       this.api,
-      [this.leadKeyPair],
-      this.sudo,
+      [this.leadAccount],
       this.applicationStake,
       this.roleStake,
       addLeaderOpeningFixture.getCreatedOpeningId() as OpeningId,
@@ -86,7 +79,6 @@ export class SudoHireLeadFixture implements Fixture {
 
     const beginLeaderApplicationReviewFixture = new BeginLeaderApplicationReviewFixture(
       this.api,
-      this.sudo,
       addLeaderOpeningFixture.getCreatedOpeningId() as OpeningId,
       this.workingGroup
     )
@@ -94,8 +86,7 @@ export class SudoHireLeadFixture implements Fixture {
 
     const fillLeaderOpeningFixture = new FillLeaderOpeningFixture(
       this.api,
-      [this.leadKeyPair],
-      this.sudo,
+      [this.leadAccount],
       addLeaderOpeningFixture.getCreatedOpeningId() as OpeningId,
       this.firstRewardInterval,
       this.rewardInterval,

+ 201 - 540
tests/network-tests/src/fixtures/workingGroupModule.ts

@@ -2,8 +2,6 @@ import BN from 'bn.js'
 import { assert } from 'chai'
 import { Api, WorkingGroups } from '../Api'
 import { KeyringPair } from '@polkadot/keyring/types'
-// import { Event } from '@polkadot/types/interfaces'
-import { Keyring } from '@polkadot/api'
 import { v4 as uuid } from 'uuid'
 import { RewardRelationship } from '@joystream/types/recurring-rewards'
 import { Application, ApplicationIdToWorkerIdMap, Worker, WorkerId } from '@joystream/types/working-group'
@@ -13,9 +11,6 @@ import { Fixture } from '../IFixture'
 
 export class AddWorkerOpeningFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private lead: KeyringPair
-  private treasury: KeyringPair
   private applicationStake: BN
   private roleStake: BN
   private activationDelay: BN
@@ -30,9 +25,6 @@ export class AddWorkerOpeningFixture implements Fixture {
 
   public constructor(
     api: Api,
-    membersKeyPairs: KeyringPair[],
-    lead: KeyringPair,
-    treasury: KeyringPair,
     applicationStake: BN,
     roleStake: BN,
     activationDelay: BN,
@@ -40,9 +32,6 @@ export class AddWorkerOpeningFixture implements Fixture {
     module: WorkingGroups
   ) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.lead = lead
-    this.treasury = treasury
     this.applicationStake = applicationStake
     this.roleStake = roleStake
     this.activationDelay = activationDelay
@@ -51,36 +40,42 @@ export class AddWorkerOpeningFixture implements Fixture {
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const lead = await this.api.getGroupLead(this.module)
+    if (!lead) {
+      throw new Error('No Lead')
+    }
     // Fee estimation and transfer
     const addOpeningFee: BN = this.api.estimateAddOpeningFee(this.module)
-    await this.api.transferBalance(this.treasury, this.lead.address, addOpeningFee)
+    await this.api.treasuryTransferBalance(lead.role_account_id.toString(), addOpeningFee)
 
     // Worker opening creation
-    const result = await this.api.addOpening({
-      leader: this.lead,
-      activationDelay: this.activationDelay,
-      maxActiveApplicants: new BN(this.membersKeyPairs.length),
-      maxReviewPeriodLength: new BN(32),
-      applicationStakingPolicyAmount: this.applicationStake,
-      applicationCrowdedOutUnstakingPeriodLength: new BN(1),
-      applicationReviewPeriodExpiredUnstakingPeriodLength: new BN(1),
-      roleStakingPolicyAmount: this.roleStake,
-      roleCrowdedOutUnstakingPeriodLength: new BN(1),
-      roleReviewPeriodExpiredUnstakingPeriodLength: new BN(1),
-      slashableMaxCount: new BN(1),
-      slashableMaxPercentPtsPerTime: new BN(100),
-      fillOpeningSuccessfulApplicantApplicationStakeUnstakingPeriod: this.unstakingPeriod,
-      fillOpeningFailedApplicantApplicationStakeUnstakingPeriod: this.unstakingPeriod,
-      fillOpeningFailedApplicantRoleStakeUnstakingPeriod: this.unstakingPeriod,
-      terminateApplicationStakeUnstakingPeriod: this.unstakingPeriod,
-      terminateRoleStakeUnstakingPeriod: this.unstakingPeriod,
-      exitRoleApplicationStakeUnstakingPeriod: this.unstakingPeriod,
-      exitRoleStakeUnstakingPeriod: this.unstakingPeriod,
-      text: uuid().substring(0, 8),
-      type: 'Worker',
-      module: this.module,
-      expectFailure: expectFailure,
-    })
+    const result = await this.api.addOpening(
+      lead.role_account_id.toString(),
+      {
+        activationDelay: this.activationDelay,
+        maxActiveApplicants: new BN(10),
+        maxReviewPeriodLength: new BN(32),
+        applicationStakingPolicyAmount: this.applicationStake,
+        applicationCrowdedOutUnstakingPeriodLength: new BN(1),
+        applicationReviewPeriodExpiredUnstakingPeriodLength: new BN(1),
+        roleStakingPolicyAmount: this.roleStake,
+        roleCrowdedOutUnstakingPeriodLength: new BN(1),
+        roleReviewPeriodExpiredUnstakingPeriodLength: new BN(1),
+        slashableMaxCount: new BN(1),
+        slashableMaxPercentPtsPerTime: new BN(100),
+        fillOpeningSuccessfulApplicantApplicationStakeUnstakingPeriod: this.unstakingPeriod,
+        fillOpeningFailedApplicantApplicationStakeUnstakingPeriod: this.unstakingPeriod,
+        fillOpeningFailedApplicantRoleStakeUnstakingPeriod: this.unstakingPeriod,
+        terminateApplicationStakeUnstakingPeriod: this.unstakingPeriod,
+        terminateRoleStakeUnstakingPeriod: this.unstakingPeriod,
+        exitRoleApplicationStakeUnstakingPeriod: this.unstakingPeriod,
+        exitRoleStakeUnstakingPeriod: this.unstakingPeriod,
+        text: uuid().substring(0, 8),
+        type: 'Worker',
+      },
+      this.module,
+      expectFailure
+    )
 
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
@@ -90,10 +85,8 @@ export class AddWorkerOpeningFixture implements Fixture {
   }
 }
 
-export class AddLeaderOpeningFixture implements Fixture {
+export class SudoAddLeaderOpeningFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private sudo: KeyringPair
   private applicationStake: BN
   private roleStake: BN
   private activationDelay: BN
@@ -105,18 +98,8 @@ export class AddLeaderOpeningFixture implements Fixture {
     return this.result
   }
 
-  public constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    sudo: KeyringPair,
-    applicationStake: BN,
-    roleStake: BN,
-    activationDelay: BN,
-    module: WorkingGroups
-  ) {
+  public constructor(api: Api, applicationStake: BN, roleStake: BN, activationDelay: BN, module: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.sudo = sudo
     this.applicationStake = applicationStake
     this.roleStake = roleStake
     this.activationDelay = activationDelay
@@ -124,30 +107,31 @@ export class AddLeaderOpeningFixture implements Fixture {
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
-    const result = await this.api.sudoAddOpening({
-      sudo: this.sudo,
-      activationDelay: this.activationDelay,
-      maxActiveApplicants: new BN(this.membersKeyPairs.length),
-      maxReviewPeriodLength: new BN(32),
-      applicationStakingPolicyAmount: this.applicationStake,
-      applicationCrowdedOutUnstakingPeriodLength: new BN(1),
-      applicationReviewPeriodExpiredUnstakingPeriodLength: new BN(1),
-      roleStakingPolicyAmount: this.roleStake,
-      roleCrowdedOutUnstakingPeriodLength: new BN(1),
-      roleReviewPeriodExpiredUnstakingPeriodLength: new BN(1),
-      slashableMaxCount: new BN(1),
-      slashableMaxPercentPtsPerTime: new BN(100),
-      fillOpeningSuccessfulApplicantApplicationStakeUnstakingPeriod: new BN(1),
-      fillOpeningFailedApplicantApplicationStakeUnstakingPeriod: new BN(1),
-      fillOpeningFailedApplicantRoleStakeUnstakingPeriod: new BN(1),
-      terminateApplicationStakeUnstakingPeriod: new BN(1),
-      terminateRoleStakeUnstakingPeriod: new BN(1),
-      exitRoleApplicationStakeUnstakingPeriod: new BN(1),
-      exitRoleStakeUnstakingPeriod: new BN(1),
-      text: uuid().substring(0, 8),
-      type: 'Leader',
-      module: this.module,
-    })
+    const result = await this.api.sudoAddOpening(
+      {
+        activationDelay: this.activationDelay,
+        maxActiveApplicants: new BN(10),
+        maxReviewPeriodLength: new BN(32),
+        applicationStakingPolicyAmount: this.applicationStake,
+        applicationCrowdedOutUnstakingPeriodLength: new BN(1),
+        applicationReviewPeriodExpiredUnstakingPeriodLength: new BN(1),
+        roleStakingPolicyAmount: this.roleStake,
+        roleCrowdedOutUnstakingPeriodLength: new BN(1),
+        roleReviewPeriodExpiredUnstakingPeriodLength: new BN(1),
+        slashableMaxCount: new BN(1),
+        slashableMaxPercentPtsPerTime: new BN(100),
+        fillOpeningSuccessfulApplicantApplicationStakeUnstakingPeriod: new BN(1),
+        fillOpeningFailedApplicantApplicationStakeUnstakingPeriod: new BN(1),
+        fillOpeningFailedApplicantRoleStakeUnstakingPeriod: new BN(1),
+        terminateApplicationStakeUnstakingPeriod: new BN(1),
+        terminateRoleStakeUnstakingPeriod: new BN(1),
+        exitRoleApplicationStakeUnstakingPeriod: new BN(1),
+        exitRoleStakeUnstakingPeriod: new BN(1),
+        text: uuid().substring(0, 8),
+        type: 'Leader',
+      },
+      this.module
+    )
 
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
@@ -159,27 +143,27 @@ export class AddLeaderOpeningFixture implements Fixture {
 
 export class AcceptApplicationsFixture implements Fixture {
   private api: Api
-  private lead: KeyringPair
-  private treasury: KeyringPair
   private openingId: OpeningId
   private module: WorkingGroups
 
-  public constructor(api: Api, lead: KeyringPair, treasury: KeyringPair, openingId: OpeningId, module: WorkingGroups) {
+  public constructor(api: Api, openingId: OpeningId, module: WorkingGroups) {
     this.api = api
-    this.lead = lead
-    this.treasury = treasury
     this.openingId = openingId
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const lead = await this.api.getGroupLead(this.module)
+    if (!lead) {
+      throw new Error('No Lead')
+    }
+    const leadAccount = lead.role_account_id.toString()
     // Fee estimation and transfer
     const acceptApplicationsFee: BN = this.api.estimateAcceptApplicationsFee(this.module)
-    await this.api.transferBalance(this.treasury, this.lead.address, acceptApplicationsFee)
+    await this.api.treasuryTransferBalance(leadAccount, acceptApplicationsFee)
 
     // Begin accepting applications
-    await this.api.acceptApplications(this.lead, this.openingId, this.module)
-    // opening id in working group module is not the same as opening id in hiring module!
+    await this.api.acceptApplications(leadAccount, this.openingId, this.module)
     const wgOpening = await this.api.getWorkingGroupOpening(this.openingId, this.module)
     const opening: HiringOpening = await this.api.getHiringOpening(wgOpening.hiring_opening_id)
     assert(opening.is_active, `${this.module} Opening ${this.openingId} is not active`)
@@ -191,8 +175,7 @@ export class AcceptApplicationsFixture implements Fixture {
 
 export class ApplyForOpeningFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private applicants: string[]
   private applicationStake: BN
   private roleStake: BN
   private openingId: OpeningId
@@ -200,16 +183,14 @@ export class ApplyForOpeningFixture implements Fixture {
 
   public constructor(
     api: Api,
-    membersKeyPairs: KeyringPair[],
-    treasury: KeyringPair,
+    applicants: string[],
     applicationStake: BN,
     roleStake: BN,
     openingId: OpeningId,
     module: WorkingGroups
   ) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.treasury = treasury
+    this.applicants = applicants
     this.applicationStake = applicationStake
     this.roleStake = roleStake
     this.openingId = openingId
@@ -219,14 +200,14 @@ export class ApplyForOpeningFixture implements Fixture {
   public async runner(expectFailure: boolean): Promise<void> {
     // Fee estimation and transfer
     const applyOnOpeningFee: BN = this.api
-      .estimateApplyOnOpeningFee(this.treasury, this.module)
+      .estimateApplyOnOpeningFee(this.applicants[0], this.module)
       .add(this.applicationStake)
       .add(this.roleStake)
-    await this.api.transferBalanceToAccounts(this.treasury, this.membersKeyPairs, applyOnOpeningFee)
+    this.api.treasuryTransferBalanceToAccounts(this.applicants, applyOnOpeningFee)
 
     // Applying for created worker opening
     await this.api.batchApplyOnOpening(
-      this.membersKeyPairs,
+      this.applicants,
       this.openingId,
       this.roleStake,
       this.applicationStake,
@@ -240,35 +221,25 @@ export class ApplyForOpeningFixture implements Fixture {
 export class WithdrawApplicationFixture implements Fixture {
   private api: Api
   private applicationIds: ApplicationId[]
-  private treasury: KeyringPair
   private module: WorkingGroups
 
-  constructor(api: Api, applicationIds: ApplicationId[], treasury: KeyringPair, module: WorkingGroups) {
+  constructor(api: Api, applicationIds: ApplicationId[], module: WorkingGroups) {
     this.api = api
     this.applicationIds = applicationIds
-    this.treasury = treasury
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
     // Fee estimation and transfer
     const withdrawApplicaitonFee: BN = this.api.estimateWithdrawApplicationFee(this.module)
-    // FIXME
+
     // get role accounts of applicants
-    // const roleAccountAddress = this.api.getRoleAccountsOfApplicants(this.module)
-    // await this.api.transferBalanceToAccounts(this.treasury, this.membersKeyPairs, withdrawApplicaitonFee)
+    const roleAccounts = await this.api.getApplicantRoleAccounts(this.applicationIds, this.module)
+    this.api.treasuryTransferBalanceToAccounts(roleAccounts, withdrawApplicaitonFee)
 
     // Application withdrawal
-    // await this.api.batchWithdrawApplication(this.membersKeyPairs, this.module)
-
-    // // Assertions
-    // this.membersKeyPairs.forEach(async (keyPair) => {
-    //   const activeApplications: ApplicationId[] = await this.api.getActiveApplicationsIdsByRoleAccount(
-    //     keyPair.address,
-    //     this.module
-    //   )
-    //   assert(activeApplications.length === 0, `Unexpected active application found for ${keyPair.address}`)
-    // })
+    await this.api.batchWithdrawActiveApplications(this.applicationIds, this.module)
+
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }
@@ -277,27 +248,28 @@ export class WithdrawApplicationFixture implements Fixture {
 
 export class BeginApplicationReviewFixture implements Fixture {
   private api: Api
-  private lead: KeyringPair
-  private treasury: KeyringPair
   private openingId: OpeningId
   private module: WorkingGroups
 
-  constructor(api: Api, lead: KeyringPair, treasury: KeyringPair, openingId: OpeningId, module: WorkingGroups) {
+  constructor(api: Api, openingId: OpeningId, module: WorkingGroups) {
     this.api = api
-    this.lead = lead
-    this.treasury = treasury
     this.openingId = openingId
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const lead = await this.api.getGroupLead(this.module)
+    if (!lead) {
+      throw new Error('No Lead')
+    }
+    const leadAccount = lead.role_account_id.toString()
     // Fee estimation and transfer
     const beginReviewFee: BN = this.api.estimateBeginApplicantReviewFee(this.module)
-    await this.api.transferBalance(this.treasury, this.lead.address, beginReviewFee)
+    await this.api.treasuryTransferBalance(leadAccount, beginReviewFee)
 
     // Begin application review
     // const beginApplicantReviewPromise: Promise<ApplicationId> = this.api.expectApplicationReviewBegan()
-    const result = await this.api.beginApplicantReview(this.lead, this.openingId, this.module)
+    const result = await this.api.beginApplicantReview(leadAccount, this.openingId, this.module)
 
     this.api.expectApplicationReviewBeganEvent(result.events)
 
@@ -307,22 +279,20 @@ export class BeginApplicationReviewFixture implements Fixture {
   }
 }
 
-export class BeginLeaderApplicationReviewFixture implements Fixture {
+export class SudoBeginLeaderApplicationReviewFixture implements Fixture {
   private api: Api
-  private sudo: KeyringPair
   private openingId: OpeningId
   private module: WorkingGroups
 
   constructor(api: Api, sudo: KeyringPair, openingId: OpeningId, module: WorkingGroups) {
     this.api = api
-    this.sudo = sudo
     this.openingId = openingId
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
     // Begin application review
-    await this.api.sudoBeginApplicantReview(this.sudo, this.openingId, this.module)
+    await this.api.sudoBeginApplicantReview(this.openingId, this.module)
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }
@@ -332,8 +302,6 @@ export class BeginLeaderApplicationReviewFixture implements Fixture {
 export class FillOpeningFixture implements Fixture {
   private api: Api
   private applicationIds: ApplicationId[]
-  private lead: KeyringPair
-  private treasury: KeyringPair
   private openingId: OpeningId
   private firstPayoutInterval: BN
   private payoutInterval: BN
@@ -343,8 +311,6 @@ export class FillOpeningFixture implements Fixture {
   constructor(
     api: Api,
     applicationIds: ApplicationId[],
-    lead: KeyringPair,
-    treasury: KeyringPair,
     openingId: OpeningId,
     firstPayoutInterval: BN,
     payoutInterval: BN,
@@ -353,8 +319,6 @@ export class FillOpeningFixture implements Fixture {
   ) {
     this.api = api
     this.applicationIds = applicationIds
-    this.lead = lead
-    this.treasury = treasury
     this.openingId = openingId
     this.firstPayoutInterval = firstPayoutInterval
     this.payoutInterval = payoutInterval
@@ -363,9 +327,14 @@ export class FillOpeningFixture implements Fixture {
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const lead = await this.api.getGroupLead(this.module)
+    if (!lead) {
+      throw new Error('No Lead')
+    }
+    const leadAccount = lead.role_account_id.toString()
     // Fee estimation and transfer
     const beginReviewFee: BN = this.api.estimateFillOpeningFee(this.module)
-    await this.api.transferBalance(this.treasury, this.lead.address, beginReviewFee)
+    await this.api.treasuryTransferBalance(leadAccount, beginReviewFee)
 
     // Assert max number of workers is not exceeded
     const activeWorkersCount: BN = await this.api.getActiveWorkersCount(this.module)
@@ -381,7 +350,7 @@ export class FillOpeningFixture implements Fixture {
     const now: BN = await this.api.getBestBlock()
 
     const result = await this.api.fillOpening(
-      this.lead,
+      leadAccount,
       this.openingId,
       this.applicationIds,
       this.amountPerPayout,
@@ -409,8 +378,7 @@ export class FillOpeningFixture implements Fixture {
 
 export class FillLeaderOpeningFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private sudo: KeyringPair
+  private applicationId: ApplicationId
   private openingId: OpeningId
   private firstPayoutInterval: BN
   private payoutInterval: BN
@@ -419,8 +387,7 @@ export class FillLeaderOpeningFixture implements Fixture {
 
   constructor(
     api: Api,
-    membersKeyPairs: KeyringPair[],
-    sudo: KeyringPair,
+    applicationId: ApplicationId,
     openingId: OpeningId,
     firstPayoutInterval: BN,
     payoutInterval: BN,
@@ -428,8 +395,7 @@ export class FillLeaderOpeningFixture implements Fixture {
     module: WorkingGroups
   ) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.sudo = sudo
+    this.applicationId = applicationId
     this.openingId = openingId
     this.firstPayoutInterval = firstPayoutInterval
     this.payoutInterval = payoutInterval
@@ -438,20 +404,11 @@ export class FillLeaderOpeningFixture implements Fixture {
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
-    // const applicationIds: ApplicationId[] = (
-    //   await Promise.all(
-    //     this.membersKeyPairs.map(async (keypair) =>
-    //       this.api.getActiveApplicationsIdsByRoleAccount(keypair.address, this.module)
-    //     )
-    //   )
-    // ).flat()
-
     // Fill leader opening
     const now: BN = await this.api.getBestBlock()
     const result = await this.api.sudoFillOpening(
-      this.sudo,
       this.openingId,
-      [], // applicationIds, // FIXME
+      [this.applicationId],
       this.amountPerPayout,
       now.add(this.firstPayoutInterval),
       this.payoutInterval,
@@ -460,22 +417,21 @@ export class FillLeaderOpeningFixture implements Fixture {
 
     // Assertions
     const applicationIdToWorkerIdMap = this.api.expectOpeningFilledEvent(result.events)
+    assert(applicationIdToWorkerIdMap.size === 1)
     applicationIdToWorkerIdMap.forEach(async (workerId, applicationId) => {
       const worker: Worker = await this.api.getWorkerById(workerId, this.module)
       const application: Application = await this.api.getApplicationById(applicationId, this.module)
+      const leadWorkerId: WorkerId = (await this.api.getLeadWorkerId(this.module))!
       assert(
         worker.role_account_id.toString() === application.role_account_id.toString(),
         `Role account ids does not match, leader account: ${worker.role_account_id}, application account ${application.role_account_id}`
       )
+      assert(
+        leadWorkerId.eq(workerId),
+        `Role account ids does not match, leader account: ${worker.role_account_id}, application account ${application.role_account_id}`
+      )
     })
-    const leadWorkerId: WorkerId = (await this.api.getLeadWorkerId(this.module))!
-    const openingLeaderAccount: string = (
-      await this.api.getWorkerById(leadWorkerId, this.module)
-    ).role_account_id.toString()
-    assert(
-      openingLeaderAccount === this.membersKeyPairs[0].address,
-      `Unexpected leader account ${openingLeaderAccount}, expected ${this.membersKeyPairs[0].address}`
-    )
+
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }
@@ -485,13 +441,11 @@ export class FillLeaderOpeningFixture implements Fixture {
 export class IncreaseStakeFixture implements Fixture {
   private api: Api
   private workerId: WorkerId
-  private treasury: KeyringPair
   private module: WorkingGroups
 
-  constructor(api: Api, workerId: WorkerId, treasury: KeyringPair, module: WorkingGroups) {
+  constructor(api: Api, workerId: WorkerId, module: WorkingGroups) {
     this.api = api
     this.workerId = workerId
-    this.treasury = treasury
     this.module = module
   }
 
@@ -499,13 +453,16 @@ export class IncreaseStakeFixture implements Fixture {
     // Fee estimation and transfer
     const increaseStakeFee: BN = this.api.estimateIncreaseStakeFee(this.module)
     const stakeIncrement: BN = new BN(1)
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, increaseStakeFee.add(stakeIncrement))
-    const workerId: WorkerId = await this.api.getWorkerIdByRoleAccount(this.membersKeyPairs[0].address, this.module)
+    const worker = await this.api.getWorkerById(this.workerId, this.module)
+    const workerRoleAccount = worker.role_account_id.toString()
+    await this.api.treasuryTransferBalance(workerRoleAccount, increaseStakeFee.add(stakeIncrement))
 
     // Increase worker stake
-    const increasedWorkerStake: BN = (await this.api.getWorkerStakeAmount(workerId, this.module)).add(stakeIncrement)
-    await this.api.increaseStake(this.membersKeyPairs[0], workerId, stakeIncrement, this.module)
-    const newWorkerStake: BN = await this.api.getWorkerStakeAmount(workerId, this.module)
+    const increasedWorkerStake: BN = (await this.api.getWorkerStakeAmount(this.workerId, this.module)).add(
+      stakeIncrement
+    )
+    await this.api.increaseStake(workerRoleAccount, this.workerId, stakeIncrement, this.module)
+    const newWorkerStake: BN = await this.api.getWorkerStakeAmount(this.workerId, this.module)
     assert(
       increasedWorkerStake.eq(newWorkerStake),
       `Unexpected worker stake ${newWorkerStake}, expected ${increasedWorkerStake}`
@@ -518,35 +475,26 @@ export class IncreaseStakeFixture implements Fixture {
 
 export class UpdateRewardAccountFixture implements Fixture {
   public api: Api
-  public membersKeyPairs: KeyringPair[]
-  public keyring: Keyring
-  public treasury: KeyringPair
+  public workerId: WorkerId
   public module: WorkingGroups
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    keyring: Keyring,
-    treasury: KeyringPair,
-    module: WorkingGroups
-  ) {
+  constructor(api: Api, workerId: WorkerId, module: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.keyring = keyring
-    this.treasury = treasury
+    this.workerId = workerId
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const worker = await this.api.getWorkerById(this.workerId, this.module)
+    const workerRoleAccount = worker.role_account_id.toString()
     // Fee estimation and transfer
-    const updateRewardAccountFee: BN = this.api.estimateUpdateRewardAccountFee(this.treasury.address, this.module)
-    await this.api.transferBalance(this.treasury, this.membersKeyPairs[0].address, updateRewardAccountFee)
-    const workerId: WorkerId = await this.api.getWorkerIdByRoleAccount(this.membersKeyPairs[0].address, this.module)
+    const updateRewardAccountFee: BN = this.api.estimateUpdateRewardAccountFee(workerRoleAccount, this.module)
+    await this.api.treasuryTransferBalance(workerRoleAccount, updateRewardAccountFee)
 
     // Update reward account
-    const createdAccount: KeyringPair = this.keyring.addFromUri(uuid().substring(0, 8))
-    await this.api.updateRewardAccount(this.membersKeyPairs[0], workerId, createdAccount.address, this.module)
-    const newRewardAccount: string = await this.api.getWorkerRewardAccount(workerId, this.module)
+    const createdAccount: KeyringPair = this.api.createKeyPairs(1)[0]
+    await this.api.updateRewardAccount(workerRoleAccount, this.workerId, createdAccount.address, this.module)
+    const newRewardAccount: string = await this.api.getWorkerRewardAccount(this.workerId, this.module)
     assert(
       newRewardAccount === createdAccount.address,
       `Unexpected role account ${newRewardAccount}, expected ${createdAccount.address}`
@@ -560,28 +508,25 @@ export class UpdateRewardAccountFixture implements Fixture {
 export class UpdateRoleAccountFixture implements Fixture {
   private api: Api
   private workerId: WorkerId
-  private keyring: Keyring
-  private treasury: KeyringPair
   private module: WorkingGroups
 
-  constructor(api: Api, workerId: WorkerId, keyring: Keyring, treasury: KeyringPair, module: WorkingGroups) {
+  constructor(api: Api, workerId: WorkerId, module: WorkingGroups) {
     this.api = api
     this.workerId = workerId
-    this.keyring = keyring
-    this.treasury = treasury
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
-    // Fee estimation and transfer
-    const updateRoleAccountFee: BN = this.api.estimateUpdateRoleAccountFee(this.treasury.address, this.module)
     const worker = await this.api.getWorkerById(this.workerId, this.module)
-    await this.api.transferBalance(this.treasury, worker.role_account_id.toString(), updateRoleAccountFee)
-    const workerKey = this.keyring.getPair(worker.role_account_id.toString())
+    const workerRoleAccount = worker.role_account_id.toString()
+    // Fee estimation and transfer
+    const updateRoleAccountFee: BN = this.api.estimateUpdateRoleAccountFee(workerRoleAccount, this.module)
+
+    await this.api.treasuryTransferBalance(workerRoleAccount, updateRoleAccountFee)
 
     // Update role account
-    const createdAccount: KeyringPair = this.keyring.addFromUri(uuid().substring(0, 8))
-    await this.api.updateRoleAccount(workerKey, this.workerId, createdAccount.address, this.module)
+    const createdAccount: KeyringPair = this.api.createKeyPairs(1)[0]
+    await this.api.updateRoleAccount(workerRoleAccount, this.workerId, createdAccount.address, this.module)
     const newRoleAccount: string = (await this.api.getWorkerById(this.workerId, this.module)).role_account_id.toString()
     assert(
       newRoleAccount === createdAccount.address,
@@ -596,37 +541,29 @@ export class UpdateRoleAccountFixture implements Fixture {
 
 export class TerminateApplicationsFixture implements Fixture {
   private api: Api
-  private workerIds: WorkerId[]
-  private lead: KeyringPair
-  private treasury: KeyringPair
+  private applicationIds: ApplicationId[]
   private module: WorkingGroups
 
-  constructor(api: Api, workerIds: WorkerId[], lead: KeyringPair, treasury: KeyringPair, module: WorkingGroups) {
+  constructor(api: Api, applicationIds: ApplicationId[], module: WorkingGroups) {
     this.api = api
-    this.workerIds = workerIds
-    this.lead = lead
-    this.treasury = treasury
+    this.applicationIds = applicationIds
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const lead = await this.api.getGroupLead(this.module)
+    if (!lead) {
+      throw new Error('No Lead')
+    }
+    const leadAccount = lead.role_account_id.toString()
+
     // Fee estimation and transfer
     const terminateApplicationFee: BN = this.api.estimateTerminateApplicationFee(this.module)
-    await this.api.transferBalance(
-      this.treasury,
-      this.lead.address,
-      terminateApplicationFee.muln(this.membersKeyPairs.length)
-    )
+    await this.api.treasuryTransferBalance(leadAccount, terminateApplicationFee.muln(this.applicationIds.length))
 
     // Terminate worker applications
-    await this.api.batchTerminateApplication(this.lead, this.membersKeyPairs, this.module)
-    this.membersKeyPairs.forEach(async (keyPair) => {
-      const activeApplications: ApplicationId[] = await this.api.getActiveApplicationsIdsByRoleAccount(
-        keyPair.address,
-        this.module
-      )
-      assert(activeApplications.length === 0, `Account ${keyPair.address} has unexpected active applications`)
-    })
+    await this.api.batchTerminateApplication(leadAccount, this.applicationIds, this.module)
+
     if (expectFailure) {
       throw new Error('Successful fixture run while expecting failure')
     }
@@ -635,38 +572,33 @@ export class TerminateApplicationsFixture implements Fixture {
 
 export class DecreaseStakeFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private lead: KeyringPair
-  private treasury: KeyringPair
+  private workerId: WorkerId
   private module: WorkingGroups
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    lead: KeyringPair,
-    treasury: KeyringPair,
-    module: WorkingGroups
-  ) {
+  constructor(api: Api, workerId: WorkerId, module: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.lead = lead
-    this.treasury = treasury
+    this.workerId = workerId
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const lead = await this.api.getGroupLead(this.module)
+    if (!lead) {
+      throw new Error('No Lead')
+    }
+    const leadAccount = lead.role_account_id.toString()
+
     // Fee estimation and transfer
     const decreaseStakeFee: BN = this.api.estimateDecreaseStakeFee(this.module)
-    await this.api.transferBalance(this.treasury, this.lead.address, decreaseStakeFee)
+    await this.api.treasuryTransferBalance(leadAccount, decreaseStakeFee)
     const workerStakeDecrement: BN = new BN(1)
-    const workerId: WorkerId = await this.api.getWorkerIdByRoleAccount(this.membersKeyPairs[0].address, this.module)
 
     // Worker stake decrement
-    const decreasedWorkerStake: BN = (await this.api.getWorkerStakeAmount(workerId, this.module)).sub(
+    const decreasedWorkerStake: BN = (await this.api.getWorkerStakeAmount(this.workerId, this.module)).sub(
       workerStakeDecrement
     )
-    await this.api.decreaseStake(this.lead, workerId, workerStakeDecrement, this.module, expectFailure)
-    const newWorkerStake: BN = await this.api.getWorkerStakeAmount(workerId, this.module)
+    await this.api.decreaseStake(leadAccount, this.workerId, workerStakeDecrement, this.module, expectFailure)
+    const newWorkerStake: BN = await this.api.getWorkerStakeAmount(this.workerId, this.module)
 
     // Assertions
     if (!expectFailure) {
@@ -680,36 +612,31 @@ export class DecreaseStakeFixture implements Fixture {
 
 export class SlashFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private lead: KeyringPair
-  private treasury: KeyringPair
+  private workerId: WorkerId
   private module: WorkingGroups
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    lead: KeyringPair,
-    treasury: KeyringPair,
-    module: WorkingGroups
-  ) {
+  constructor(api: Api, workerId: WorkerId, module: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.lead = lead
-    this.treasury = treasury
+    this.workerId = workerId
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const lead = await this.api.getGroupLead(this.module)
+    if (!lead) {
+      throw new Error('No Lead')
+    }
+    const leadAccount = lead.role_account_id.toString()
+
     // Fee estimation and transfer
     const slashStakeFee: BN = this.api.estimateSlashStakeFee(this.module)
-    await this.api.transferBalance(this.treasury, this.lead.address, slashStakeFee)
+    await this.api.treasuryTransferBalance(leadAccount, slashStakeFee)
     const slashAmount: BN = new BN(1)
-    const workerId: WorkerId = await this.api.getWorkerIdByRoleAccount(this.membersKeyPairs[0].address, this.module)
 
     // Slash worker
-    const slashedStake: BN = (await this.api.getWorkerStakeAmount(workerId, this.module)).sub(slashAmount)
-    await this.api.slashStake(this.lead, workerId, slashAmount, this.module, expectFailure)
-    const newStake: BN = await this.api.getWorkerStakeAmount(workerId, this.module)
+    const slashedStake: BN = (await this.api.getWorkerStakeAmount(this.workerId, this.module)).sub(slashAmount)
+    await this.api.slashStake(leadAccount, this.workerId, slashAmount, this.module, expectFailure)
+    const newStake: BN = await this.api.getWorkerStakeAmount(this.workerId, this.module)
 
     // Assertions
     assert(slashedStake.eq(newStake), `Unexpected worker stake ${newStake}, expected ${slashedStake}`)
@@ -718,82 +645,75 @@ export class SlashFixture implements Fixture {
 
 export class TerminateRoleFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private lead: KeyringPair
-  private treasury: KeyringPair
+  private workerId: WorkerId
   private module: WorkingGroups
 
-  constructor(
-    api: Api,
-    membersKeyPairs: KeyringPair[],
-    lead: KeyringPair,
-    treasury: KeyringPair,
-    module: WorkingGroups
-  ) {
+  constructor(api: Api, workerId: WorkerId, module: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.lead = lead
-    this.treasury = treasury
+    this.workerId = workerId
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const lead = await this.api.getGroupLead(this.module)
+    if (!lead) {
+      throw new Error('No Lead')
+    }
+    const leadAccount = lead.role_account_id.toString()
+
     // Fee estimation and transfer
     const terminateRoleFee: BN = this.api.estimateTerminateRoleFee(this.module)
-    await this.api.transferBalance(this.treasury, this.lead.address, terminateRoleFee)
-    const workerId: WorkerId = await this.api.getWorkerIdByRoleAccount(this.membersKeyPairs[0].address, this.module)
+    await this.api.treasuryTransferBalance(leadAccount, terminateRoleFee)
 
     // Terminate worker role
-    await this.api.terminateRole(this.lead, workerId, uuid().substring(0, 8), this.module, expectFailure)
+    await this.api.terminateRole(leadAccount, this.workerId, uuid().substring(0, 8), this.module, expectFailure)
 
     // Assertions
-    const isWorker: boolean = await this.api.isWorker(this.membersKeyPairs[0].address, this.module)
-    assert(!isWorker, `Worker with account ${this.membersKeyPairs[0].address} is not terminated`)
+    const isWorker: boolean = await this.api.isWorker(this.workerId, this.module)
+    assert(!isWorker, `Worker ${this.workerId} is not terminated`)
   }
 }
 
 export class LeaveRoleFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
-  private treasury: KeyringPair
+  private workerIds: WorkerId[]
   private module: WorkingGroups
 
-  constructor(api: Api, membersKeyPairs: KeyringPair[], treasury: KeyringPair, module: WorkingGroups) {
+  constructor(api: Api, workerIds: WorkerId[], module: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
-    this.treasury = treasury
+    this.workerIds = workerIds
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
+    const roleAccounts = await this.api.getWorkerRoleAccounts(this.workerIds, this.module)
     // Fee estimation and transfer
     const leaveRoleFee: BN = this.api.estimateLeaveRoleFee(this.module)
-    await this.api.transferBalanceToAccounts(this.treasury, this.membersKeyPairs, leaveRoleFee)
+    this.api.treasuryTransferBalanceToAccounts(roleAccounts, leaveRoleFee)
 
-    await this.api.batchLeaveRole(this.membersKeyPairs, uuid().substring(0, 8), expectFailure, this.module)
+    await this.api.batchLeaveRole(this.workerIds, uuid().substring(0, 8), expectFailure, this.module)
 
     // Assertions
-    this.membersKeyPairs.forEach(async (keyPair) => {
-      const isWorker: boolean = await this.api.isWorker(this.membersKeyPairs[0].address, this.module)
-      assert(!isWorker, `Worker with account ${keyPair.address} is not terminated`)
+    this.workerIds.forEach(async (workerId) => {
+      const isWorker: boolean = await this.api.isWorker(workerId, this.module)
+      assert(!isWorker, `Worker${workerId} is not terminated`)
     })
   }
 }
 
 export class AwaitPayoutFixture implements Fixture {
   private api: Api
-  private membersKeyPairs: KeyringPair[]
+  private workerId: WorkerId
   private module: WorkingGroups
 
-  constructor(api: Api, membersKeyPairs: KeyringPair[], module: WorkingGroups) {
+  constructor(api: Api, workerId: WorkerId, module: WorkingGroups) {
     this.api = api
-    this.membersKeyPairs = membersKeyPairs
+    this.workerId = workerId
     this.module = module
   }
 
   public async runner(expectFailure: boolean): Promise<void> {
-    const workerId: WorkerId = await this.api.getWorkerIdByRoleAccount(this.membersKeyPairs[0].address, this.module)
-    const worker: Worker = await this.api.getWorkerById(workerId, this.module)
+    const worker: Worker = await this.api.getWorkerById(this.workerId, this.module)
     const reward: RewardRelationship = await this.api.getRewardRelationship(worker.reward_relationship.unwrap())
     const now: BN = await this.api.getBestBlock()
     const nextPaymentBlock: BN = new BN(reward.getField('next_payment_at_block').toString())
@@ -801,12 +721,12 @@ export class AwaitPayoutFixture implements Fixture {
     const amountPerPayout: BN = new BN(reward.getField('amount_per_payout').toString())
 
     assert(now.lt(nextPaymentBlock), `Payout already happened in block ${nextPaymentBlock} now ${now}`)
-    const balance: BN = await this.api.getBalance(this.membersKeyPairs[0].address)
+    const balance: BN = await this.api.getBalance(reward.account.toString())
 
     const firstPayoutWaitingPeriod: BN = nextPaymentBlock.sub(now).addn(1)
     await Utils.wait(this.api.getBlockDuration().mul(firstPayoutWaitingPeriod).toNumber())
 
-    const balanceAfterFirstPayout: BN = await this.api.getBalance(this.membersKeyPairs[0].address)
+    const balanceAfterFirstPayout: BN = await this.api.getBalance(reward.account.toString())
     const expectedBalanceFirst: BN = balance.add(amountPerPayout)
     assert(
       balanceAfterFirstPayout.eq(expectedBalanceFirst),
@@ -816,7 +736,7 @@ export class AwaitPayoutFixture implements Fixture {
     const secondPayoutWaitingPeriod: BN = payoutInterval.addn(1)
     await Utils.wait(this.api.getBlockDuration().mul(secondPayoutWaitingPeriod).toNumber())
 
-    const balanceAfterSecondPayout: BN = await this.api.getBalance(this.membersKeyPairs[0].address)
+    const balanceAfterSecondPayout: BN = await this.api.getBalance(reward.account.toString())
     const expectedBalanceSecond: BN = expectedBalanceFirst.add(amountPerPayout)
     assert(
       balanceAfterSecondPayout.eq(expectedBalanceSecond),
@@ -827,262 +747,3 @@ export class AwaitPayoutFixture implements Fixture {
     }
   }
 }
-
-/*
-export class ExpectLeadOpeningAddedFixture implements Fixture {
-  private api: Api
-
-  private result: OpeningId | undefined
-  private events: Event[] = []
-
-  constructor(api: Api) {
-    this.api = api
-  }
-
-  public getCreatedOpeningId(): OpeningId | undefined {
-    return this.result
-  }
-
-  public getEvents(): Event[] {
-    return this.events
-  }
-
-  public async runner(expectFailure: boolean): Promise<void> {
-    const event: Event = await this.api.expectEvent('OpeningAdded')
-    this.events.push(event)
-    this.result = (event.data as unknown) as OpeningId
-    if (expectFailure) {
-      throw new Error('Successful fixture run while expecting failure')
-    }
-  }
-}
-
-export class ExpectLeaderSetFixture implements Fixture {
-  private api: Api
-  private leaderAddress: string
-  private module: WorkingGroups
-
-  private result: WorkerId | undefined
-  private events: Event[] = []
-
-  constructor(api: Api, leaderAddress: string, module: WorkingGroups) {
-    this.api = api
-    this.leaderAddress = leaderAddress
-    this.module = module
-  }
-
-  public getLeaderWorkerId(): WorkerId | undefined {
-    return this.result
-  }
-
-  public getEvents(): Event[] {
-    return this.events
-  }
-
-  public async runner(expectFailure: boolean): Promise<void> {
-    const event: Event = await this.api.expectEvent('LeaderSet')
-    this.events.push(event)
-    const leadWorkerId: WorkerId = (event.data as unknown) as WorkerId
-    const worker: Worker = await this.api.getWorkerById(leadWorkerId, this.module)
-    const leaderApplicationId: ApplicationId = (
-      await this.api.getApplicationsIdsByRoleAccount(this.leaderAddress, this.module)
-    )[0]
-    const application: Application = await this.api.getApplicationById(leaderApplicationId, this.module)
-    assert(
-      worker.role_account_id.eq(application.role_account_id),
-      `Role account ids does not match, leader account: ${worker.role_account_id}, application account ${application.role_account_id}`
-    )
-    this.result = leadWorkerId
-    if (expectFailure) {
-      throw new Error('Successful fixture run while expecting failure')
-    }
-  }
-}
-
-export class ExpectBeganApplicationReviewFixture implements Fixture {
-  private api: Api
-
-  private result: ApplicationId | undefined
-  private events: Event[] = []
-
-  constructor(api: Api) {
-    this.api = api
-  }
-
-  public getApplicationId(): ApplicationId | undefined {
-    return this.result
-  }
-
-  public getEvents(): Event[] {
-    return this.events
-  }
-
-  public async runner(expectFailure: boolean): Promise<void> {
-    const event: Event = await this.api.expectEvent('BeganApplicationReview')
-    this.events.push(event)
-    this.result = (event.data as unknown) as ApplicationId
-    if (expectFailure) {
-      throw new Error('Successful fixture run while expecting failure')
-    }
-  }
-}
-
-export class ExpectLeaderRoleTerminatedFixture implements Fixture {
-  private api: Api
-  private module: WorkingGroups
-
-  private events: Event[] = []
-
-  constructor(api: Api, module: WorkingGroups) {
-    this.api = api
-    this.module = module
-  }
-
-  public getEvents(): Event[] {
-    return this.events
-  }
-
-  public async runner(expectFailure: boolean): Promise<void> {
-    const event: Event = await this.api.expectEvent('TerminatedLeader')
-    this.events.push(event)
-    const leadWorkerId: WorkerId | undefined = await this.api.getLeadWorkerId(this.module)
-    assert(leadWorkerId === undefined, `Unexpected lead worker id: ${leadWorkerId}, expected none`)
-    if (expectFailure) {
-      throw new Error('Successful fixture run while expecting failure')
-    }
-  }
-}
-
-export class ExpectLeaderRewardAmountUpdatedFixture implements Fixture {
-  private api: Api
-  private expectedReward: BN
-  private module: WorkingGroups
-
-  private events: Event[] = []
-
-  constructor(api: Api, expectedReward: BN, module: WorkingGroups) {
-    this.api = api
-    this.expectedReward = expectedReward
-    this.module = module
-  }
-
-  public getEvents(): Event[] {
-    return this.events
-  }
-
-  public async runner(expectFailure: boolean): Promise<void> {
-    const event: Event = await this.api.expectEvent('WorkerRewardAmountUpdated')
-    this.events.push(event)
-    const leadWorkerId: WorkerId = (await this.api.getLeadWorkerId(this.module))!
-    const leadWorker: Worker = await this.api.getWorkerById(leadWorkerId, this.module)
-    const receivedReward: BN = (await this.api.getRewardRelationship(leadWorker.reward_relationship.unwrap()))
-      .amount_per_payout
-    assert(
-      receivedReward.eq(this.expectedReward),
-      `Unexpected reward amount for worker with id ${leadWorkerId}: ${receivedReward}, expected ${this.expectedReward}`
-    )
-    if (expectFailure) {
-      throw new Error('Successful fixture run while expecting failure')
-    }
-  }
-}
-
-export class ExpectLeaderStakeDecreasedFixture implements Fixture {
-  private api: Api
-  private expectedStake: BN
-  private module: WorkingGroups
-
-  private events: Event[] = []
-
-  constructor(api: Api, expectedStake: BN, module: WorkingGroups) {
-    this.api = api
-    this.expectedStake = expectedStake
-    this.module = module
-  }
-
-  public getEvents(): Event[] {
-    return this.events
-  }
-
-  public async runner(expectFailure: boolean): Promise<void> {
-    const event: Event = await this.api.expectEvent('StakeDecreased')
-    this.events.push(event)
-    const leadWorkerId: WorkerId = (await this.api.getLeadWorkerId(this.module))!
-    const receivedStake: BN = await this.api.getWorkerStakeAmount(leadWorkerId, this.module)
-    assert(
-      receivedStake.eq(this.expectedStake),
-      `Unexpected stake amount for worker with id ${leadWorkerId}: ${receivedStake}, expected ${this.expectedStake}`
-    )
-    if (expectFailure) {
-      throw new Error('Successful fixture run while expecting failure')
-    }
-  }
-}
-
-export class ExpectLeaderSlashedFixture implements Fixture {
-  private api: Api
-  private expectedStake: BN
-  private module: WorkingGroups
-
-  private events: Event[] = []
-
-  constructor(api: Api, expectedStake: BN, module: WorkingGroups) {
-    this.api = api
-    this.expectedStake = expectedStake
-    this.module = module
-  }
-
-  public getEvents(): Event[] {
-    return this.events
-  }
-
-  public async runner(expectFailure: boolean): Promise<void> {
-    const event: Event = await this.api.expectEvent('StakeSlashed')
-    this.events.push(event)
-    const leadWorkerId: WorkerId = (await this.api.getLeadWorkerId(this.module))!
-    const receivedStake: BN = await this.api.getWorkerStakeAmount(leadWorkerId, this.module)
-    assert(
-      receivedStake.eq(this.expectedStake),
-      `Unexpected stake amount for worker with id after slash ${leadWorkerId}: ${receivedStake}, expected ${this.expectedStake}`
-    )
-    if (expectFailure) {
-      throw new Error('Successful fixture run while expecting failure')
-    }
-  }
-}
-
-export class ExpectMintCapacityChangedFixture implements Fixture {
-  private api: Api
-  private expectedMintCapacity: BN
-
-  private result: BN | undefined
-  private events: Event[] = []
-
-  constructor(api: Api, expectedMintCapacity: BN) {
-    this.api = api
-    this.expectedMintCapacity = expectedMintCapacity
-  }
-
-  public getResult(): BN | undefined {
-    return this.result
-  }
-
-  public getEvents(): Event[] {
-    return this.events
-  }
-
-  public async runner(expectFailure: boolean): Promise<void> {
-    const event: Event = await this.api.expectEvent('MintCapacityChanged')
-    this.events.push(event)
-    const receivedMintCapacity: BN = (event.data[1] as unknown) as BN
-    assert(
-      receivedMintCapacity.eq(this.expectedMintCapacity),
-      `Unexpected mint capacity: ${receivedMintCapacity}, expected ${this.expectedMintCapacity}`
-    )
-    this.result = receivedMintCapacity
-    if (expectFailure) {
-      throw new Error('Successful fixture run while expecting failure')
-    }
-  }
-}
-*/

+ 11 - 18
tests/network-tests/src/flows/councilSetup.ts

@@ -1,31 +1,27 @@
-import { KeyringPair } from '@polkadot/keyring/types'
-import { Keyring } from '@polkadot/api'
 import BN from 'bn.js'
 import { PaidTermId } from '@joystream/types/members'
-import { DbService } from '../DbService'
 
 import { Api } from '../Api'
-import { Utils } from '../utils'
 import { CouncilElectionHappyCaseFixture } from '../fixtures/councilElectionHappyCase'
 import { BuyMembershipHappyCaseFixture } from '../fixtures/membershipModule'
 
 // Electing council scenario
-export default async function councilSetup(api: Api, env: NodeJS.ProcessEnv, db: DbService) {
-  if (db.hasCouncil()) {
+export default async function councilSetup(api: Api, env: NodeJS.ProcessEnv) {
+  // Skip creating council if already elected
+  if ((await api.getCouncil()).length) {
     return
   }
 
-  const sudoUri: string = env.SUDO_ACCOUNT_URI!
-  const keyring = new Keyring({ type: 'sr25519' })
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri)
-  const voters: KeyringPair[] = Utils.createKeyPairs(keyring, 5)
-  const applicants: KeyringPair[] = Utils.createKeyPairs(keyring, 8)
+  const numberOfApplicants = (await api.getCouncilSize()).toNumber() * 2
+  const voters = api.createKeyPairs(5).map((key) => key.address)
+  const applicants = api.createKeyPairs(numberOfApplicants).map((key) => key.address)
+
   const paidTerms: PaidTermId = api.createPaidTermId(new BN(+env.MEMBERSHIP_PAID_TERMS!))
   const K: number = +env.COUNCIL_ELECTION_K!
   const greaterStake: BN = new BN(+env.COUNCIL_STAKE_GREATER_AMOUNT!)
   const lesserStake: BN = new BN(+env.COUNCIL_STAKE_LESSER_AMOUNT!)
 
-  const createMembersFixture = new BuyMembershipHappyCaseFixture(api, sudo, [...voters, ...applicants], paidTerms)
+  const createMembersFixture = new BuyMembershipHappyCaseFixture(api, [...voters, ...applicants], paidTerms)
   await createMembersFixture.runner(false)
 
   // The fixture moves manually with sudo the election stages, so proper processing
@@ -33,18 +29,15 @@ export default async function councilSetup(api: Api, env: NodeJS.ProcessEnv, db:
   // that is smaller than the council size if not enough members apply.
   const councilElectionHappyCaseFixture = new CouncilElectionHappyCaseFixture(
     api,
-    sudo,
     voters,
     applicants,
     K,
     greaterStake,
     lesserStake
   )
-  await councilElectionHappyCaseFixture.runner(false)
 
-  db.setMembers([...voters, ...applicants])
+  await councilElectionHappyCaseFixture.runner(false)
 
-  const councilMemberAddresses = (await api.getCouncil()).map((seat) => seat.member.toString())
-  const councilKeyPairs = applicants.filter((keyPair) => councilMemberAddresses.includes(keyPair.address))
-  db.setCouncil(councilKeyPairs)
+  // Elected council: AccountId[]
+  // const accountIds = (await api.getCouncil()).map((seat) => seat.member)
 }

+ 6 - 13
tests/network-tests/src/flows/membership/creatingMemberships.ts

@@ -1,11 +1,8 @@
-import { KeyringPair } from '@polkadot/keyring/types'
-import { Keyring } from '@polkadot/api'
 import { Api } from '../../Api'
 import {
   BuyMembershipHappyCaseFixture,
   BuyMembershipWithInsufficienFundsFixture,
 } from '../../fixtures/membershipModule'
-import { Utils } from '../../utils'
 import { PaidTermId } from '@joystream/types/members'
 import BN from 'bn.js'
 import Debugger from 'debug'
@@ -14,30 +11,26 @@ const debug = Debugger('flow:memberships')
 
 // Membership creation scenario
 export default async function memberShipCreation(api: Api, env: NodeJS.ProcessEnv) {
-  const sudoUri: string = env.SUDO_ACCOUNT_URI!
-  const keyring = new Keyring({ type: 'sr25519' })
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri)
-
   const N: number = +env.MEMBERSHIP_CREATION_N!
-  const nKeyPairs: KeyringPair[] = Utils.createKeyPairs(keyring, N)
-  const aKeyPair: KeyringPair[] = Utils.createKeyPairs(keyring, 1)
+  const nAccounts = api.createKeyPairs(N).map((key) => key.address)
+  const aAccount = api.createKeyPairs(1)[0].address
   const paidTerms: PaidTermId = api.createPaidTermId(new BN(+env.MEMBERSHIP_PAID_TERMS!))
 
   debug(`creating ${N} new members`)
-  const happyCaseFixture = new BuyMembershipHappyCaseFixture(api, sudo, nKeyPairs, paidTerms)
+  const happyCaseFixture = new BuyMembershipHappyCaseFixture(api, nAccounts, paidTerms)
   // Buy membeship is accepted with sufficient funds
   await happyCaseFixture.runner(false)
 
   const insufficientFundsFixture: BuyMembershipWithInsufficienFundsFixture = new BuyMembershipWithInsufficienFundsFixture(
     api,
-    sudo,
-    aKeyPair[0],
+    aAccount,
     paidTerms
   )
   // Account A can not buy the membership with insufficient funds
   await insufficientFundsFixture.runner(false)
 
-  const buyMembershipAfterAccountTopUp = new BuyMembershipHappyCaseFixture(api, sudo, aKeyPair, paidTerms)
+  const buyMembershipAfterAccountTopUp = new BuyMembershipHappyCaseFixture(api, [aAccount], paidTerms)
+
   // Account A was able to buy the membership with sufficient funds
   await buyMembershipAfterAccountTopUp.runner(false)
 }

+ 6 - 17
tests/network-tests/src/flows/proposals/electionParametersProposal.ts

@@ -1,26 +1,15 @@
-import { KeyringPair } from '@polkadot/keyring/types'
-import { Keyring } from '@polkadot/api'
 import { Api } from '../../Api'
 import { ElectionParametersProposalFixture } from '../../fixtures/proposalsModule'
-import { DbService } from '../../DbService'
 import { assert } from 'chai'
 
 // Election parameters proposal scenario
-export default async function electionParametersProposal(api: Api, env: NodeJS.ProcessEnv, db: DbService) {
-  const sudoUri: string = env.SUDO_ACCOUNT_URI!
-  const keyring = new Keyring({ type: 'sr25519' })
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri)
-
+export default async function electionParametersProposal(api: Api, env: NodeJS.ProcessEnv) {
   // Pre-Conditions: some members and an elected council
-  assert(db.hasCouncil())
-  const m1KeyPairs = db.getMembers()
-  const m2KeyPairs = db.getCouncil()
+  const council = await api.getCouncil()
+  assert(council.length)
+
+  const proposer = council[0].member.toString()
 
-  const electionParametersProposalFixture: ElectionParametersProposalFixture = new ElectionParametersProposalFixture(
-    api,
-    m1KeyPairs,
-    m2KeyPairs,
-    sudo
-  )
+  const electionParametersProposalFixture = new ElectionParametersProposalFixture(api, proposer)
   await electionParametersProposalFixture.runner(false)
 }

+ 7 - 16
tests/network-tests/src/flows/proposals/spendingProposal.ts

@@ -1,30 +1,21 @@
-import { KeyringPair } from '@polkadot/keyring/types'
-import { Keyring } from '@polkadot/api'
 import BN from 'bn.js'
 import { Api } from '../../Api'
 import { SpendingProposalFixture } from '../../fixtures/proposalsModule'
 import { DbService } from '../../DbService'
+import { assert } from 'chai'
 
 export default async function spendingProposal(api: Api, env: NodeJS.ProcessEnv, db: DbService) {
-  const sudoUri: string = env.SUDO_ACCOUNT_URI!
-  const keyring = new Keyring({ type: 'sr25519' })
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri)
-
   const spendingBalance: BN = new BN(+env.SPENDING_BALANCE!)
   const mintCapacity: BN = new BN(+env.COUNCIL_MINTING_CAPACITY!)
 
   // Pre-conditions, members and council
-  const m1KeyPairs = db.getMembers()
-  const m2KeyPairs = db.getCouncil()
+  const council = await api.getCouncil()
+  assert(council.length)
+
+  const proposer = council[0].member.toString()
+
+  const spendingProposalFixture = new SpendingProposalFixture(api, proposer, spendingBalance, mintCapacity)
 
-  const spendingProposalFixture: SpendingProposalFixture = new SpendingProposalFixture(
-    api,
-    m1KeyPairs,
-    m2KeyPairs,
-    sudo,
-    spendingBalance,
-    mintCapacity
-  )
   // Spending proposal test
   await spendingProposalFixture.runner(false)
 }

+ 7 - 11
tests/network-tests/src/flows/proposals/textProposal.ts

@@ -1,18 +1,14 @@
-import { KeyringPair } from '@polkadot/keyring/types'
-import { Keyring } from '@polkadot/api'
 import { Api } from '../../Api'
 import { TextProposalFixture } from '../../fixtures/proposalsModule'
-import { DbService } from '../../DbService'
-
-export default async function textProposal(api: Api, env: NodeJS.ProcessEnv, db: DbService) {
-  const sudoUri: string = env.SUDO_ACCOUNT_URI!
-  const keyring = new Keyring({ type: 'sr25519' })
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri)
+import { assert } from 'chai'
 
+export default async function textProposal(api: Api, env: NodeJS.ProcessEnv) {
   // Pre-conditions: members and council
-  const m1KeyPairs = db.getMembers()
-  const m2KeyPairs = db.getCouncil()
+  const council = await api.getCouncil()
+  assert(council.length)
+
+  const proposer = council[0].member.toString()
 
-  const textProposalFixture: TextProposalFixture = new TextProposalFixture(api, m1KeyPairs, m2KeyPairs, sudo)
+  const textProposalFixture: TextProposalFixture = new TextProposalFixture(api, proposer)
   await textProposalFixture.runner(false)
 }

+ 7 - 18
tests/network-tests/src/flows/proposals/updateRuntime.ts

@@ -1,5 +1,3 @@
-import { KeyringPair } from '@polkadot/keyring/types'
-import { Keyring } from '@polkadot/api'
 import BN from 'bn.js'
 import { Api } from '../../Api'
 import { Utils } from '../../utils'
@@ -7,34 +5,25 @@ import { BuyMembershipHappyCaseFixture } from '../../fixtures/membershipModule'
 import { UpdateRuntimeFixture } from '../../fixtures/proposalsModule'
 import { PaidTermId } from '@joystream/types/members'
 import { DbService } from '../../DbService'
+import { assert } from 'chai'
 
 export default async function updateRuntime(api: Api, env: NodeJS.ProcessEnv, db: DbService) {
-  const sudoUri: string = env.SUDO_ACCOUNT_URI!
-  const keyring = new Keyring({ type: 'sr25519' })
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri)
-
-  const N: number = +env.MEMBERSHIP_CREATION_N!
   const paidTerms: PaidTermId = api.createPaidTermId(new BN(+env.MEMBERSHIP_PAID_TERMS!))
   const runtimePath: string = env.RUNTIME_WASM_PATH!
 
   // Pre-conditions: members and council
-  const m1KeyPairs = db.getMembers()
-  const m2KeyPairs = db.getCouncil()
+  const council = await api.getCouncil()
+  assert(council.length)
 
-  const updateRuntimeFixture: UpdateRuntimeFixture = new UpdateRuntimeFixture(
-    api,
-    m1KeyPairs,
-    m2KeyPairs,
-    sudo,
-    runtimePath
-  )
+  const proposer = council[0].member.toString()
+
+  const updateRuntimeFixture: UpdateRuntimeFixture = new UpdateRuntimeFixture(api, proposer, runtimePath)
   await updateRuntimeFixture.runner(false)
 
   // Some tests after runtime update
   const thirdMemberSetFixture: BuyMembershipHappyCaseFixture = new BuyMembershipHappyCaseFixture(
     api,
-    sudo,
-    Utils.createKeyPairs(keyring, N),
+    api.createKeyPairs(1).map((key) => key.address),
     paidTerms
   )
   await thirdMemberSetFixture.runner(false)

+ 7 - 11
tests/network-tests/src/flows/proposals/validatorCountProposal.ts

@@ -1,25 +1,21 @@
-import { KeyringPair } from '@polkadot/keyring/types'
-import { Keyring } from '@polkadot/api'
 import BN from 'bn.js'
 import { Api } from '../../Api'
 import { ValidatorCountProposalFixture } from '../../fixtures/proposalsModule'
 import { DbService } from '../../DbService'
+import { assert } from 'chai'
 
 export default async function validatorCount(api: Api, env: NodeJS.ProcessEnv, db: DbService) {
-  const sudoUri: string = env.SUDO_ACCOUNT_URI!
-  const keyring = new Keyring({ type: 'sr25519' })
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri)
+  // Pre-conditions: members and council
+  const council = await api.getCouncil()
+  assert(council.length)
 
-  const validatorCountIncrement: BN = new BN(+env.VALIDATOR_COUNT_INCREMENT!)
+  const proposer = council[0].member.toString()
 
-  const m1KeyPairs = db.getMembers()
-  const m2KeyPairs = db.getCouncil()
+  const validatorCountIncrement: BN = new BN(+env.VALIDATOR_COUNT_INCREMENT!)
 
   const validatorCountProposalFixture: ValidatorCountProposalFixture = new ValidatorCountProposalFixture(
     api,
-    m1KeyPairs,
-    m2KeyPairs,
-    sudo,
+    proposer,
     validatorCountIncrement
   )
   await validatorCountProposalFixture.runner(false)

+ 7 - 19
tests/network-tests/src/flows/proposals/workingGroupMintCapacityProposal.ts

@@ -1,32 +1,22 @@
-import { KeyringPair } from '@polkadot/keyring/types'
-import { Keyring } from '@polkadot/api'
 import BN from 'bn.js'
 import { Api, WorkingGroups } from '../../Api'
 import { VoteForProposalFixture, WorkingGroupMintCapacityProposalFixture } from '../../fixtures/proposalsModule'
 import { ExpectMintCapacityChangedFixture } from '../../fixtures/workingGroupModule'
 import { ProposalId } from '@joystream/types/proposals'
-import { DbService } from '../../DbService'
-
-export default async function workingGroupMintCapactiy(
-  api: Api,
-  env: NodeJS.ProcessEnv,
-  db: DbService,
-  group: WorkingGroups
-) {
-  const sudoUri: string = env.SUDO_ACCOUNT_URI!
-  const keyring = new Keyring({ type: 'sr25519' })
-  const sudo: KeyringPair = keyring.addFromUri(sudoUri)
+import { assert } from 'chai'
 
+export default async function workingGroupMintCapactiy(api: Api, env: NodeJS.ProcessEnv, group: WorkingGroups) {
   const mintCapacityIncrement: BN = new BN(env.MINT_CAPACITY_INCREMENT!)
 
-  const m1KeyPairs = db.getMembers()
-  const m2KeyPairs = db.getCouncil()
+  // Pre-conditions: members and council
+  const council = await api.getCouncil()
+  assert(council.length)
 
+  const proposer = council[0].member.toString()
   const newMintCapacity: BN = (await api.getWorkingGroupMintCapacity(group)).add(mintCapacityIncrement)
   const workingGroupMintCapacityProposalFixture: WorkingGroupMintCapacityProposalFixture = new WorkingGroupMintCapacityProposalFixture(
     api,
-    m1KeyPairs,
-    sudo,
+    proposer,
     newMintCapacity,
     group
   )
@@ -35,8 +25,6 @@ export default async function workingGroupMintCapactiy(
 
   const voteForProposalFixture: VoteForProposalFixture = new VoteForProposalFixture(
     api,
-    m2KeyPairs,
-    sudo,
     workingGroupMintCapacityProposalFixture.getCreatedProposalId() as ProposalId
   )
   const expectMintCapacityChanged = new ExpectMintCapacityChangedFixture(api, newMintCapacity)

+ 8 - 11
tests/network-tests/src/scenarios/full.ts

@@ -1,6 +1,5 @@
 import { WsProvider } from '@polkadot/api'
 import { Api, WorkingGroups } from '../Api'
-import { DbService } from '../DbService'
 import { config } from 'dotenv'
 import Debugger from 'debug'
 
@@ -28,12 +27,10 @@ const scenario = async () => {
   const env = process.env
 
   // Connect api to the chain
-  const nodeUrl: string = process.env.NODE_URL!
+  const nodeUrl: string = env.NODE_URL || 'ws://127.0.0.1:9944'
+  const treasuryAccountUri = env.TREASURY_ACCOUNT_URI
   const provider = new WsProvider(nodeUrl)
-  const api: Api = await Api.create(provider)
-
-  // Create shared state instance
-  const db: DbService = DbService.getInstance()
+  const api: Api = await Api.create(provider, treasuryAccountUri || '//Alice', '//Alice')
 
   // Run flows serially passing them a 'context'
 
@@ -41,14 +38,14 @@ const scenario = async () => {
   await creatingMemberships(api, env)
 
   debug('Council')
-  await councilSetup(api, env, db)
+  await councilSetup(api, env)
 
   debug('Basic Proposals')
   await Promise.all([
-    electionParametersProposal(api, env, db),
-    spendingProposal(api, env, db),
-    textProposal(api, env, db),
-    validatorCountProposal(api, env, db),
+    electionParametersProposal(api, env),
+    // spendingProposal(api, env, db),
+    // textProposal(api, env, db),
+    // validatorCountProposal(api, env, db),
     // workingGroupMintCapacityProposal(api, env, db, WorkingGroups.StorageWorkingGroup),
     // workingGroupMintCapacityProposal(api, env, db, WorkingGroups.ContentDirectoryWorkingGroup),
   ])

+ 2 - 1
tests/network-tests/src/sender.ts

@@ -28,7 +28,8 @@ export class Sender {
     account: AccountId | string,
     shouldFail = false
   ): Promise<ISubmittableResult> {
-    const senderKeyPair = this.keyring.getPair(account)
+    const addr = this.keyring.encodeAddress(account)
+    const senderKeyPair: KeyringPair = this.keyring.getPair(addr)
 
     let finalizedResolve: { (result: ISubmittableResult): void }
     let finalizedReject: { (err: Error): void }

+ 1 - 11
tests/network-tests/src/utils.ts

@@ -3,10 +3,8 @@ import { compactToU8a, stringToU8a } from '@polkadot/util'
 import { blake2AsHex } from '@polkadot/util-crypto'
 import BN from 'bn.js'
 import fs from 'fs'
-import Keyring, { decodeAddress } from '@polkadot/keyring'
+import { decodeAddress } from '@polkadot/keyring'
 import { Seat } from '@joystream/types/council'
-import { KeyringPair } from '@polkadot/keyring/types'
-import { v4 as uuid } from 'uuid'
 
 export class Utils {
   private static LENGTH_ADDRESS = 32 + 1 // publicKey + prefix
@@ -52,12 +50,4 @@ export class Utils {
   public static camelToSnakeCase(key: string): string {
     return key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)
   }
-
-  public static createKeyPairs(keyring: Keyring, n: number): KeyringPair[] {
-    const nKeyPairs: KeyringPair[] = []
-    for (let i = 0; i < n; i++) {
-      nKeyPairs.push(keyring.addFromUri(i + uuid().substring(0, 8)))
-    }
-    return nKeyPairs
-  }
 }

Some files were not shown because too many files changed in this diff