|
@@ -29,26 +29,42 @@ import {
|
|
OpeningId,
|
|
OpeningId,
|
|
} from '@joystream/types/hiring'
|
|
} from '@joystream/types/hiring'
|
|
import { FillOpeningParameters, ProposalId } from '@joystream/types/proposals'
|
|
import { FillOpeningParameters, ProposalId } from '@joystream/types/proposals'
|
|
-import { v4 as uuid } from 'uuid'
|
|
|
|
import { ContentId, DataObject } from '@joystream/types/storage'
|
|
import { ContentId, DataObject } from '@joystream/types/storage'
|
|
import { extendDebug } from './Debugger'
|
|
import { extendDebug } from './Debugger'
|
|
import { InvertedPromise } from './InvertedPromise'
|
|
import { InvertedPromise } from './InvertedPromise'
|
|
|
|
+import { VideoId } from '@joystream/types/content'
|
|
|
|
+import { ChannelId } from '@joystream/types/common'
|
|
|
|
+import { ChannelCategoryMetadata, VideoCategoryMetadata } from '@joystream/content-metadata-protobuf'
|
|
|
|
+import { assert } from 'chai'
|
|
|
|
|
|
export enum WorkingGroups {
|
|
export enum WorkingGroups {
|
|
StorageWorkingGroup = 'storageWorkingGroup',
|
|
StorageWorkingGroup = 'storageWorkingGroup',
|
|
ContentDirectoryWorkingGroup = 'contentDirectoryWorkingGroup',
|
|
ContentDirectoryWorkingGroup = 'contentDirectoryWorkingGroup',
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+type AnyMetadata = {
|
|
|
|
+ serializeBinary(): Uint8Array
|
|
|
|
+}
|
|
|
|
+
|
|
export class ApiFactory {
|
|
export class ApiFactory {
|
|
private readonly api: ApiPromise
|
|
private readonly api: ApiPromise
|
|
private readonly keyring: Keyring
|
|
private readonly keyring: Keyring
|
|
|
|
+ // number used as part of key derivation path
|
|
|
|
+ private keyId = 0
|
|
|
|
+ // mapping from account address to key id.
|
|
|
|
+ // To be able to re-derive keypair externally when mini-secret is known.
|
|
|
|
+ readonly addressesToKeyId: Map<string, number> = new Map()
|
|
|
|
+ // mini secret used in SURI key derivation path
|
|
|
|
+ private readonly miniSecret: string
|
|
|
|
+
|
|
// source of funds for all new accounts
|
|
// source of funds for all new accounts
|
|
private readonly treasuryAccount: string
|
|
private readonly treasuryAccount: string
|
|
|
|
|
|
public static async create(
|
|
public static async create(
|
|
provider: WsProvider,
|
|
provider: WsProvider,
|
|
treasuryAccountUri: string,
|
|
treasuryAccountUri: string,
|
|
- sudoAccountUri: string
|
|
|
|
|
|
+ sudoAccountUri: string,
|
|
|
|
+ miniSecret: string
|
|
): Promise<ApiFactory> {
|
|
): Promise<ApiFactory> {
|
|
const debug = extendDebug('api-factory')
|
|
const debug = extendDebug('api-factory')
|
|
let connectAttempts = 0
|
|
let connectAttempts = 0
|
|
@@ -65,7 +81,7 @@ export class ApiFactory {
|
|
// Give it a few seconds to be ready.
|
|
// Give it a few seconds to be ready.
|
|
await Utils.wait(5000)
|
|
await Utils.wait(5000)
|
|
|
|
|
|
- return new ApiFactory(api, treasuryAccountUri, sudoAccountUri)
|
|
|
|
|
|
+ return new ApiFactory(api, treasuryAccountUri, sudoAccountUri, miniSecret)
|
|
} catch (err) {
|
|
} catch (err) {
|
|
if (connectAttempts === 3) {
|
|
if (connectAttempts === 3) {
|
|
throw new Error('Unable to connect to chain')
|
|
throw new Error('Unable to connect to chain')
|
|
@@ -75,32 +91,60 @@ export class ApiFactory {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- constructor(api: ApiPromise, treasuryAccountUri: string, sudoAccountUri: string) {
|
|
|
|
|
|
+ constructor(api: ApiPromise, treasuryAccountUri: string, sudoAccountUri: string, miniSecret: string) {
|
|
this.api = api
|
|
this.api = api
|
|
this.keyring = new Keyring({ type: 'sr25519' })
|
|
this.keyring = new Keyring({ type: 'sr25519' })
|
|
this.treasuryAccount = this.keyring.addFromUri(treasuryAccountUri).address
|
|
this.treasuryAccount = this.keyring.addFromUri(treasuryAccountUri).address
|
|
this.keyring.addFromUri(sudoAccountUri)
|
|
this.keyring.addFromUri(sudoAccountUri)
|
|
|
|
+ this.miniSecret = miniSecret
|
|
|
|
+ this.addressesToKeyId = new Map()
|
|
|
|
+ this.keyId = 0
|
|
}
|
|
}
|
|
|
|
|
|
public getApi(label: string): Api {
|
|
public getApi(label: string): Api {
|
|
- return new Api(this.api, this.treasuryAccount, this.keyring, label)
|
|
|
|
|
|
+ return new Api(this, this.api, this.treasuryAccount, this.keyring, label)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public createKeyPairs(n: number): { key: KeyringPair; id: number }[] {
|
|
|
|
+ const keys: { key: KeyringPair; id: number }[] = []
|
|
|
|
+ for (let i = 0; i < n; i++) {
|
|
|
|
+ const id = this.keyId++
|
|
|
|
+ const key = this.createCustomKeyPair(`${id}`)
|
|
|
|
+ keys.push({ key, id })
|
|
|
|
+ this.addressesToKeyId.set(key.address, id)
|
|
|
|
+ }
|
|
|
|
+ return keys
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public createCustomKeyPair(customPath: string): KeyringPair {
|
|
|
|
+ const uri = `${this.miniSecret}//testing//${customPath}`
|
|
|
|
+ return this.keyring.addFromUri(uri)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public keyGenInfo(): { start: number; final: number } {
|
|
|
|
+ const start = 0
|
|
|
|
+ const final = this.keyId
|
|
|
|
+ return {
|
|
|
|
+ start,
|
|
|
|
+ final,
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- // public close(): void {
|
|
|
|
- // this.api.disconnect()
|
|
|
|
- // }
|
|
|
|
|
|
+ public getAllGeneratedAccounts(): { [k: string]: number } {
|
|
|
|
+ return Object.fromEntries(this.addressesToKeyId)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
export class Api {
|
|
export class Api {
|
|
|
|
+ private readonly factory: ApiFactory
|
|
private readonly api: ApiPromise
|
|
private readonly api: ApiPromise
|
|
private readonly sender: Sender
|
|
private readonly sender: Sender
|
|
- private readonly keyring: Keyring
|
|
|
|
// source of funds for all new accounts
|
|
// source of funds for all new accounts
|
|
private readonly treasuryAccount: string
|
|
private readonly treasuryAccount: string
|
|
|
|
|
|
- constructor(api: ApiPromise, treasuryAccount: string, keyring: Keyring, label: string) {
|
|
|
|
|
|
+ constructor(factory: ApiFactory, api: ApiPromise, treasuryAccount: string, keyring: Keyring, label: string) {
|
|
|
|
+ this.factory = factory
|
|
this.api = api
|
|
this.api = api
|
|
- this.keyring = keyring
|
|
|
|
this.treasuryAccount = treasuryAccount
|
|
this.treasuryAccount = treasuryAccount
|
|
this.sender = new Sender(api, keyring, label)
|
|
this.sender = new Sender(api, keyring, label)
|
|
}
|
|
}
|
|
@@ -113,12 +157,24 @@ export class Api {
|
|
this.sender.setLogLevel(LogLevel.Verbose)
|
|
this.sender.setLogLevel(LogLevel.Verbose)
|
|
}
|
|
}
|
|
|
|
|
|
- public createKeyPairs(n: number): KeyringPair[] {
|
|
|
|
- const nKeyPairs: KeyringPair[] = []
|
|
|
|
- for (let i = 0; i < n; i++) {
|
|
|
|
- nKeyPairs.push(this.keyring.addFromUri(i + uuid().substring(0, 8)))
|
|
|
|
- }
|
|
|
|
- return nKeyPairs
|
|
|
|
|
|
+ public createKeyPairs(n: number): { key: KeyringPair; id: number }[] {
|
|
|
|
+ return this.factory.createKeyPairs(n)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public createCustomKeyPair(path: string): KeyringPair {
|
|
|
|
+ return this.factory.createCustomKeyPair(path)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public keyGenInfo(): { start: number; final: number } {
|
|
|
|
+ return this.factory.keyGenInfo()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public getAllgeneratedAccounts(): { [k: string]: number } {
|
|
|
|
+ return this.factory.getAllGeneratedAccounts()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public encodeMetadata(metadata: AnyMetadata): Bytes {
|
|
|
|
+ return this.api.createType('Bytes', '0x' + Buffer.from(metadata.serializeBinary()).toString('hex'))
|
|
}
|
|
}
|
|
|
|
|
|
// Well known WorkingGroup enum defined in runtime
|
|
// Well known WorkingGroup enum defined in runtime
|
|
@@ -138,6 +194,11 @@ export class Api {
|
|
return this.sender.signAndSend(this.api.tx.sudo.sudo(tx), sudo)
|
|
return this.sender.signAndSend(this.api.tx.sudo.sudo(tx), sudo)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public async makeSudoAsCall(who: string, tx: SubmittableExtrinsic<'promise'>): Promise<ISubmittableResult> {
|
|
|
|
+ const sudo = await this.api.query.sudo.key()
|
|
|
|
+ return this.sender.signAndSend(this.api.tx.sudo.sudoAs(who, tx), sudo)
|
|
|
|
+ }
|
|
|
|
+
|
|
public createPaidTermId(value: BN): PaidTermId {
|
|
public createPaidTermId(value: BN): PaidTermId {
|
|
return this.api.createType('PaidTermId', value)
|
|
return this.api.createType('PaidTermId', value)
|
|
}
|
|
}
|
|
@@ -149,8 +210,18 @@ export class Api {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
- public getMemberIds(address: string): Promise<MemberId[]> {
|
|
|
|
- return this.api.query.members.memberIdsByControllerAccountId<Vec<MemberId>>(address)
|
|
|
|
|
|
+ // Many calls in the testing framework take an account id instead of a member id when an action
|
|
|
|
+ // is intended to be in the context of the member. This function is used to do a reverse lookup.
|
|
|
|
+ // There is an underlying assumption that each member has a unique controller account even
|
|
|
|
+ // though the runtime does not place that constraint. But for the purpose of the tests we throw
|
|
|
|
+ // if that condition is found to be false to esnure the tests do not fail. As long as all memberships
|
|
|
|
+ // are created through the membership fixture this should not happen.
|
|
|
|
+ public async getMemberId(address: string): Promise<MemberId> {
|
|
|
|
+ const ids = await this.api.query.members.memberIdsByControllerAccountId<Vec<MemberId>>(address)
|
|
|
|
+ if (ids.length > 1) {
|
|
|
|
+ throw new Error('More than one member with same controller account was detected')
|
|
|
|
+ }
|
|
|
|
+ return ids[0]
|
|
}
|
|
}
|
|
|
|
|
|
public async getBalance(address: string): Promise<Balance> {
|
|
public async getBalance(address: string): Promise<Balance> {
|
|
@@ -631,7 +702,7 @@ export class Api {
|
|
description: string,
|
|
description: string,
|
|
runtime: Bytes | string
|
|
runtime: Bytes | string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createRuntimeUpgradeProposal(memberId, name, description, stake, runtime),
|
|
this.api.tx.proposalsCodex.createRuntimeUpgradeProposal(memberId, name, description, stake, runtime),
|
|
account
|
|
account
|
|
@@ -645,7 +716,7 @@ export class Api {
|
|
description: string,
|
|
description: string,
|
|
text: string
|
|
text: string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createTextProposal(memberId, name, description, stake, text),
|
|
this.api.tx.proposalsCodex.createTextProposal(memberId, name, description, stake, text),
|
|
account
|
|
account
|
|
@@ -660,7 +731,7 @@ export class Api {
|
|
balance: BN,
|
|
balance: BN,
|
|
destination: string
|
|
destination: string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createSpendingProposal(memberId, title, description, stake, balance, destination),
|
|
this.api.tx.proposalsCodex.createSpendingProposal(memberId, title, description, stake, balance, destination),
|
|
account
|
|
account
|
|
@@ -674,7 +745,7 @@ export class Api {
|
|
stake: BN,
|
|
stake: BN,
|
|
validatorCount: BN
|
|
validatorCount: BN
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createSetValidatorCountProposal(memberId, title, description, stake, validatorCount),
|
|
this.api.tx.proposalsCodex.createSetValidatorCountProposal(memberId, title, description, stake, validatorCount),
|
|
account
|
|
account
|
|
@@ -695,7 +766,7 @@ export class Api {
|
|
minCouncilStake: BN,
|
|
minCouncilStake: BN,
|
|
minVotingStake: BN
|
|
minVotingStake: BN
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createSetElectionParametersProposal(memberId, title, description, stake, {
|
|
this.api.tx.proposalsCodex.createSetElectionParametersProposal(memberId, title, description, stake, {
|
|
announcing_period: announcingPeriod,
|
|
announcing_period: announcingPeriod,
|
|
@@ -719,7 +790,7 @@ export class Api {
|
|
openingId: OpeningId,
|
|
openingId: OpeningId,
|
|
workingGroup: string
|
|
workingGroup: string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createBeginReviewWorkingGroupLeaderApplicationsProposal(
|
|
this.api.tx.proposalsCodex.createBeginReviewWorkingGroupLeaderApplicationsProposal(
|
|
memberId,
|
|
memberId,
|
|
@@ -741,7 +812,7 @@ export class Api {
|
|
const councilAccounts = await this.getCouncilAccounts()
|
|
const councilAccounts = await this.getCouncilAccounts()
|
|
return Promise.all(
|
|
return Promise.all(
|
|
councilAccounts.map(async (account) => {
|
|
councilAccounts.map(async (account) => {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.approveProposal(account, memberId, proposal)
|
|
return this.approveProposal(account, memberId, proposal)
|
|
})
|
|
})
|
|
)
|
|
)
|
|
@@ -1156,7 +1227,7 @@ export class Api {
|
|
),
|
|
),
|
|
})
|
|
})
|
|
|
|
|
|
- const memberId: MemberId = (await this.getMemberIds(leaderOpening.account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(leaderOpening.account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createAddWorkingGroupLeaderOpeningProposal(
|
|
this.api.tx.proposalsCodex.createAddWorkingGroupLeaderOpeningProposal(
|
|
memberId,
|
|
memberId,
|
|
@@ -1186,7 +1257,7 @@ export class Api {
|
|
payoutInterval: BN
|
|
payoutInterval: BN
|
|
workingGroup: string
|
|
workingGroup: string
|
|
}): Promise<ISubmittableResult> {
|
|
}): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(fillOpening.account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(fillOpening.account)
|
|
|
|
|
|
const fillOpeningParameters: FillOpeningParameters = this.api.createType('FillOpeningParameters', {
|
|
const fillOpeningParameters: FillOpeningParameters = this.api.createType('FillOpeningParameters', {
|
|
opening_id: fillOpening.openingId,
|
|
opening_id: fillOpening.openingId,
|
|
@@ -1221,7 +1292,7 @@ export class Api {
|
|
slash: boolean,
|
|
slash: boolean,
|
|
workingGroup: string
|
|
workingGroup: string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createTerminateWorkingGroupLeaderRoleProposal(
|
|
this.api.tx.proposalsCodex.createTerminateWorkingGroupLeaderRoleProposal(
|
|
memberId,
|
|
memberId,
|
|
@@ -1248,7 +1319,7 @@ export class Api {
|
|
rewardAmount: BN,
|
|
rewardAmount: BN,
|
|
workingGroup: string
|
|
workingGroup: string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createSetWorkingGroupLeaderRewardProposal(
|
|
this.api.tx.proposalsCodex.createSetWorkingGroupLeaderRewardProposal(
|
|
memberId,
|
|
memberId,
|
|
@@ -1272,7 +1343,7 @@ export class Api {
|
|
rewardAmount: BN,
|
|
rewardAmount: BN,
|
|
workingGroup: string
|
|
workingGroup: string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createDecreaseWorkingGroupLeaderStakeProposal(
|
|
this.api.tx.proposalsCodex.createDecreaseWorkingGroupLeaderStakeProposal(
|
|
memberId,
|
|
memberId,
|
|
@@ -1296,7 +1367,7 @@ export class Api {
|
|
rewardAmount: BN,
|
|
rewardAmount: BN,
|
|
workingGroup: string
|
|
workingGroup: string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createSlashWorkingGroupLeaderStakeProposal(
|
|
this.api.tx.proposalsCodex.createSlashWorkingGroupLeaderStakeProposal(
|
|
memberId,
|
|
memberId,
|
|
@@ -1319,7 +1390,7 @@ export class Api {
|
|
mintCapacity: BN,
|
|
mintCapacity: BN,
|
|
workingGroup: string
|
|
workingGroup: string
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx.proposalsCodex.createSetWorkingGroupMintCapacityProposal(
|
|
this.api.tx.proposalsCodex.createSetWorkingGroupMintCapacityProposal(
|
|
memberId,
|
|
memberId,
|
|
@@ -1372,7 +1443,7 @@ export class Api {
|
|
text: string,
|
|
text: string,
|
|
module: WorkingGroups
|
|
module: WorkingGroups
|
|
): Promise<ISubmittableResult> {
|
|
): Promise<ISubmittableResult> {
|
|
- const memberId: MemberId = (await this.getMemberIds(account))[0]
|
|
|
|
|
|
+ const memberId: MemberId = await this.getMemberId(account)
|
|
return this.sender.signAndSend(
|
|
return this.sender.signAndSend(
|
|
this.api.tx[module].applyOnOpening(memberId, openingId, roleAccountAddress, roleStake, applicantStake, text),
|
|
this.api.tx[module].applyOnOpening(memberId, openingId, roleAccountAddress, roleStake, applicantStake, text),
|
|
account
|
|
account
|
|
@@ -1703,4 +1774,127 @@ export class Api {
|
|
const dataObject = await this.api.query.dataDirectory.dataByContentId<Option<DataObject>>(contentId)
|
|
const dataObject = await this.api.query.dataDirectory.dataByContentId<Option<DataObject>>(contentId)
|
|
return dataObject.unwrapOr(null)
|
|
return dataObject.unwrapOr(null)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async getMemberControllerAccount(memberId: number): Promise<string | undefined> {
|
|
|
|
+ return (await this.api.query.members.membershipById(memberId))?.controller_account.toString()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async createMockChannel(memberId: number, memberControllerAccount?: string): Promise<ChannelId | null> {
|
|
|
|
+ memberControllerAccount = memberControllerAccount || (await this.getMemberControllerAccount(memberId))
|
|
|
|
+
|
|
|
|
+ if (!memberControllerAccount) {
|
|
|
|
+ throw new Error('invalid member id')
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Create a channel without any assets
|
|
|
|
+ const tx = this.api.tx.content.createChannel(
|
|
|
|
+ { Member: memberId },
|
|
|
|
+ {
|
|
|
|
+ assets: [],
|
|
|
|
+ meta: null,
|
|
|
|
+ reward_account: null,
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ const result = await this.sender.signAndSend(tx, memberControllerAccount)
|
|
|
|
+
|
|
|
|
+ const record = this.findEventRecord(result.events, 'content', 'ChannelCreated')
|
|
|
|
+ if (record) {
|
|
|
|
+ return record.event.data[1] as ChannelId
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async createMockVideo(
|
|
|
|
+ memberId: number,
|
|
|
|
+ channelId: number,
|
|
|
|
+ memberControllerAccount?: string
|
|
|
|
+ ): Promise<VideoId | null> {
|
|
|
|
+ memberControllerAccount = memberControllerAccount || (await this.getMemberControllerAccount(memberId))
|
|
|
|
+
|
|
|
|
+ if (!memberControllerAccount) {
|
|
|
|
+ throw new Error('invalid member id')
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Create a video without any assets
|
|
|
|
+ const tx = this.api.tx.content.createVideo({ Member: memberId }, channelId, {
|
|
|
|
+ assets: [],
|
|
|
|
+ meta: null,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ const result = await this.sender.signAndSend(tx, memberControllerAccount)
|
|
|
|
+
|
|
|
|
+ const record = this.findEventRecord(result.events, 'content', 'VideoCreated')
|
|
|
|
+ if (record) {
|
|
|
|
+ return record.event.data[2] as VideoId
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async createChannelCategoryAsLead(name: string): Promise<ISubmittableResult> {
|
|
|
|
+ const lead = await this.getGroupLead(WorkingGroups.ContentDirectoryWorkingGroup)
|
|
|
|
+
|
|
|
|
+ if (!lead) {
|
|
|
|
+ throw new Error('No Content Lead asigned, cannot create channel category')
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const account = lead?.role_account_id
|
|
|
|
+ const meta = new ChannelCategoryMetadata()
|
|
|
|
+ meta.setName(name)
|
|
|
|
+ return this.sender.signAndSend(
|
|
|
|
+ this.api.tx.content.createChannelCategory({ Lead: null }, { meta: this.encodeMetadata(meta) }),
|
|
|
|
+ account?.toString()
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async createVideoCategoryAsLead(name: string): Promise<ISubmittableResult> {
|
|
|
|
+ const lead = await this.getGroupLead(WorkingGroups.ContentDirectoryWorkingGroup)
|
|
|
|
+
|
|
|
|
+ if (!lead) {
|
|
|
|
+ throw new Error('No Content Lead asigned, cannot create channel category')
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const account = lead?.role_account_id
|
|
|
|
+ const meta = new VideoCategoryMetadata()
|
|
|
|
+ meta.setName(name)
|
|
|
|
+ return this.sender.signAndSend(
|
|
|
|
+ this.api.tx.content.createVideoCategory({ Lead: null }, { meta: this.encodeMetadata(meta) }),
|
|
|
|
+ account?.toString()
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async assignWorkerRoleAccount(
|
|
|
|
+ group: WorkingGroups,
|
|
|
|
+ workerId: WorkerId,
|
|
|
|
+ account: string
|
|
|
|
+ ): Promise<ISubmittableResult> {
|
|
|
|
+ if (!(await this.isWorker(workerId, group))) {
|
|
|
|
+ throw new Error('Worker not found')
|
|
|
|
+ }
|
|
|
|
+ const worker = await this.getWorkerById(workerId, group)
|
|
|
|
+
|
|
|
|
+ const memberController = await this.getMemberControllerAccount(worker.member_id.toNumber())
|
|
|
|
+ // there cannot be a worker associated with member that does not exist
|
|
|
|
+ assert(memberController, 'Member controller not found')
|
|
|
|
+
|
|
|
|
+ // Expect membercontroller key is already added to keyring
|
|
|
|
+ // Is is responsibility of caller to ensure this is the case!
|
|
|
|
+
|
|
|
|
+ const updateRoleAccountCall = this.api.tx[group].updateRoleAccount(workerId, account)
|
|
|
|
+ return this.makeSudoAsCall(memberController!, updateRoleAccountCall)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async assignWorkerWellknownAccount(group: WorkingGroups, workerId: WorkerId): Promise<ISubmittableResult> {
|
|
|
|
+ // path to append to base SURI
|
|
|
|
+ const uri = `worker//${this.getWorkingGroupString(group)}//${workerId.toNumber()}`
|
|
|
|
+ const account = this.createCustomKeyPair(uri).address
|
|
|
|
+ return this.assignWorkerRoleAccount(group, workerId, account)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async assignCouncil(accounts: string[]): Promise<ISubmittableResult> {
|
|
|
|
+ const setCouncilCall = this.api.tx.council.setCouncil(accounts)
|
|
|
|
+ return this.makeSudoCall(setCouncilCall)
|
|
|
|
+ }
|
|
}
|
|
}
|