-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5123 from thesan/luxor/vested-wg-spending-qn
Add vested budget spending tests and mappings
- Loading branch information
Showing
10 changed files
with
243 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
tests/network-tests/src/fixtures/workingGroups/VestedSpendFromBudgetFixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import BN from 'bn.js' | ||
import { assert } from 'chai' | ||
import { Api } from '../../Api' | ||
import { QueryNodeApi } from '../../QueryNodeApi' | ||
import { EventDetails, WorkingGroupModuleName } from '../../types' | ||
import { BaseWorkingGroupFixture } from './BaseWorkingGroupFixture' | ||
import { SubmittableExtrinsic } from '@polkadot/api/types' | ||
import { ISubmittableResult } from '@polkadot/types/types/' | ||
import { Utils } from '../../utils' | ||
import { VestedBudgetSpendingEventFieldsFragment, WorkingGroupFieldsFragment } from '../../graphql/generated/queries' | ||
|
||
export type VestingSchedule = { | ||
locked: BN | ||
perBlock: BN | ||
startingBlock: number | ||
} | ||
|
||
export class VestedSpendFromBudgetFixture extends BaseWorkingGroupFixture { | ||
protected receivers: string[] | ||
protected vestingSchedules: VestingSchedule[] | ||
protected preExecuteBudget?: BN | ||
|
||
public constructor( | ||
api: Api, | ||
query: QueryNodeApi, | ||
group: WorkingGroupModuleName, | ||
receivers: string[], | ||
vestingSchedules: VestingSchedule[] | ||
) { | ||
super(api, query, group) | ||
this.receivers = receivers | ||
this.vestingSchedules = vestingSchedules | ||
} | ||
|
||
protected async getSignerAccountOrAccounts(): Promise<string> { | ||
return this.api.getLeadRoleKey(this.group) | ||
} | ||
|
||
protected async getExtrinsics(): Promise<SubmittableExtrinsic<'promise'>[]> { | ||
return this.receivers.map((reciever, i) => | ||
this.api.tx[this.group].vestedSpendFromBudget(reciever, this.vestingSchedules[i], this.getRationale(reciever)) | ||
) | ||
} | ||
|
||
protected getEventFromResult(result: ISubmittableResult): Promise<EventDetails> { | ||
return this.api.getEventDetails(result, this.group, 'VestedBudgetSpending') | ||
} | ||
|
||
protected getRationale(receiver: string): string { | ||
return `Vested budget spending to ${receiver} rationale` | ||
} | ||
|
||
public async execute(): Promise<void> { | ||
this.preExecuteBudget = await this.api.query[this.group].budget() | ||
await super.execute() | ||
} | ||
|
||
protected assertQueryNodeEventIsValid(qEvent: VestedBudgetSpendingEventFieldsFragment, i: number): void { | ||
assert.equal(qEvent.group.name, this.group) | ||
assert.equal(qEvent.amount, this.vestingSchedules[i].locked.toString()) | ||
assert.equal(qEvent.perBlock, this.vestingSchedules[i].perBlock.toString()) | ||
assert.equal(qEvent.startingBlock, this.vestingSchedules[i].startingBlock) | ||
assert.equal(qEvent.receiver, this.receivers[i]) | ||
assert.equal(qEvent.rationale, this.getRationale(this.receivers[i])) | ||
} | ||
|
||
protected assertQueriedGroupIsValid(qGroup: WorkingGroupFieldsFragment | null): void { | ||
Utils.assert(qGroup, 'Query node: Working group not found!') | ||
assert.equal( | ||
qGroup.budget, | ||
this.preExecuteBudget!.sub(this.vestingSchedules.reduce((a, b) => a.add(b.locked), new BN(0))) | ||
) | ||
} | ||
|
||
async runQueryNodeChecks(): Promise<void> { | ||
await super.runQueryNodeChecks() | ||
|
||
// Query and check the events | ||
await this.query.tryQueryWithTimeout( | ||
() => this.query.getVestedBudgetSpendingEvents(this.events), | ||
(qEvents) => this.assertQueryNodeEventsAreValid(qEvents) | ||
) | ||
|
||
// Check the group | ||
const qGroup = await this.query.getWorkingGroup(this.group) | ||
this.assertQueriedGroupIsValid(qGroup) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.