|
@@ -1,21 +1,29 @@
|
|
|
import { Api } from '../Api'
|
|
|
import BN from 'bn.js'
|
|
|
import { assert } from 'chai'
|
|
|
-import { Fixture } from '../IFixture'
|
|
|
-import { PaidTermId } from '@joystream/types/members'
|
|
|
+import { Fixture, BaseFixture } from '../Fixture'
|
|
|
+import { PaidTermId, MemberId } from '@joystream/types/members'
|
|
|
+import Debugger from 'debug'
|
|
|
|
|
|
-export class BuyMembershipHappyCaseFixture implements Fixture {
|
|
|
- private api: Api
|
|
|
+export class BuyMembershipHappyCaseFixture extends BaseFixture {
|
|
|
private accounts: string[]
|
|
|
private paidTerms: PaidTermId
|
|
|
+ private debug: Debugger.Debugger
|
|
|
+ private memberIds: MemberId[] = []
|
|
|
|
|
|
public constructor(api: Api, accounts: string[], paidTerms: PaidTermId) {
|
|
|
- this.api = api
|
|
|
+ super(api)
|
|
|
this.accounts = accounts
|
|
|
this.paidTerms = paidTerms
|
|
|
+ this.debug = Debugger('fixture:BuyMembershipHappyCaseFixture')
|
|
|
}
|
|
|
|
|
|
- public async runner(expectFailure: boolean): Promise<void> {
|
|
|
+ public getCreatedMembers(): MemberId[] {
|
|
|
+ return this.memberIds.slice()
|
|
|
+ }
|
|
|
+
|
|
|
+ public async execute(expectFailure: boolean): Promise<void> {
|
|
|
+ this.debug(`Registering ${this.accounts.length} new members`)
|
|
|
// Fee estimation and transfer
|
|
|
const membershipFee: BN = await this.api.getMembershipFee(this.paidTerms)
|
|
|
const membershipTransactionFee: BN = this.api.estimateBuyMembershipFee(
|
|
@@ -25,20 +33,15 @@ export class BuyMembershipHappyCaseFixture implements Fixture {
|
|
|
)
|
|
|
this.api.treasuryTransferBalanceToAccounts(this.accounts, membershipTransactionFee.add(new BN(membershipFee)))
|
|
|
|
|
|
- // Buying membership
|
|
|
- await Promise.all(
|
|
|
- this.accounts.map(async (account) => {
|
|
|
- await this.api.buyMembership(account, this.paidTerms, `member${account.substring(0, 14)}`)
|
|
|
- })
|
|
|
- )
|
|
|
-
|
|
|
- // Assertions
|
|
|
- this.accounts.forEach((account) =>
|
|
|
- this.api
|
|
|
- .getMemberIds(account)
|
|
|
- .then((membership) => assert(membership.length > 0, `Account ${account} is not a member`))
|
|
|
- )
|
|
|
+ this.memberIds = (
|
|
|
+ await Promise.all(
|
|
|
+ this.accounts.map((account) =>
|
|
|
+ this.api.buyMembership(account, this.paidTerms, `member${account.substring(0, 14)}`)
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ).map(({ events }) => this.api.expectMemberRegisteredEvent(events))
|
|
|
|
|
|
+ this.debug(`New member ids: ${this.memberIds}`)
|
|
|
if (expectFailure) {
|
|
|
throw new Error('Successful fixture run while expecting failure')
|
|
|
}
|