Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Fix local mocks #2940

Merged
merged 6 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 72 additions & 77 deletions packages/ui/dev/query-node-mocks/generators/generateBounties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,88 +55,83 @@ const bountyStage = randomFromWeightedSet(
[1, 'Failed']
)

const generateBounty =
(mocks: DependOnMocks): Reducer<BountyData, any> =>
(data, _, bountyIndex) => {
// Generate the bounty
const stage = bountyStage()
const creatorId =
bountyIndex < 3 ? String(bountyIndex % 2) : Math.random() < 0.7 ? randomMember(mocks.members).id : undefined
const oracleId =
bountyIndex < 3 ? String((bountyIndex + 1) % 2) : Math.random() < 0.7 ? randomMember(mocks.members).id : undefined
const bounty = {
id: String(bountyIndex),
createdAt: faker.date.recent(20),
title: lorem.sentence(),
description: randomMarkdown(),
cherry: String(randomFromRange(1, 5) * 1000),
entrantStake: String(randomFromRange(1, 5) * 1000),
creatorId: creatorId,
oracleId: oracleId,
fundingType: generateBountyFundingType(),
entrantWhitelist: datatype.boolean()
? random.arrayElements(mocks.members, randomFromRange(1, 10)).map(({ id }) => id)
: undefined,
workPeriod: randomFromRange(5, 20),
judgingPeriod: randomFromRange(5, 20),
stage,
totalFunding: String(randomFromRange(5, 10) * 1000),
discussionThreadId: random.arrayElement(mocks.forumThreads).id,
createdInEvent: randomRawBlock(),
...(datatype.boolean() ? { maxFundingReachedEvent: randomRawBlock() } : {}),
isTerminated: Math.random() < 0.2 && ['Funding', 'Expired', 'Successful', 'Failed'].includes(stage),
}

// Generate the bounty contributions
const contributions = repeat(generateContribution(mocks, bounty), randomFromRange(0, 5))

// Generate the bounty work entries
const entries = repeat(generateEntry(mocks, bounty), randomFromRange(0, 5))

return {
bounties: [...data.bounties, bounty],
bountyContributions: [...data.bountyContributions, ...contributions],
bountyEntries: [...data.bountyEntries, ...entries],
}
const generateBounty = (mocks: DependOnMocks): Reducer<BountyData, any> => (data, _, bountyIndex) => {
// Generate the bounty
const stage = bountyStage()
const creatorId =
bountyIndex < 3 ? String(bountyIndex % 2) : Math.random() < 0.7 ? randomMember(mocks.members).id : undefined
const oracleId =
bountyIndex < 3 ? String((bountyIndex + 1) % 2) : Math.random() < 0.7 ? randomMember(mocks.members).id : undefined
const bounty = {
id: String(bountyIndex),
createdAt: faker.date.recent(20),
title: lorem.sentence(),
description: randomMarkdown(),
cherry: String(randomFromRange(1, 5) * 1000),
entrantStake: String(randomFromRange(1, 5) * 1000),
creatorId: creatorId,
oracleId: oracleId,
fundingType: generateBountyFundingType(),
entrantWhitelist: datatype.boolean()
? random.arrayElements(mocks.members, randomFromRange(1, 10)).map(({ id }) => id)
: undefined,
workPeriod: randomFromRange(5, 20),
judgingPeriod: randomFromRange(5, 20),
stage,
totalFunding: String(randomFromRange(5, 10) * 1000),
discussionThreadId: random.arrayElement(mocks.forumThreads).id,
createdInEvent: randomRawBlock(),
...(datatype.boolean() ? { maxFundingReachedEvent: randomRawBlock() } : {}),
isTerminated: Math.random() < 0.2 && ['Funding', 'Expired', 'Successful', 'Failed'].includes(stage),
}

const generateContribution =
(mocks: DependOnMocks, bounty: RawBountyMock) =>
(contributionIndex: number): RawBountyContributionMock => {
return {
id: `${bounty.id}:${contributionIndex}`,
bountyId: bounty.id,
...(datatype.boolean() ? { contributorId: randomMember(mocks.members).id } : {}),
amount: String(randomFromRange(1, 5) * 1000),
}
// Generate the bounty contributions
const contributions = repeat(generateContribution(mocks, bounty), randomFromRange(0, 5))

// Generate the bounty work entries
const entries = repeat(generateEntry(mocks, bounty), randomFromRange(0, 5))

return {
bounties: [...data.bounties, bounty],
bountyContributions: [...data.bountyContributions, ...contributions],
bountyEntries: [...data.bountyEntries, ...entries],
}
}

const generateEntry =
(mocks: DependOnMocks, bounty: RawBountyMock) =>
(entryIndex: number): RawBountyEntryMock => {
const randomStatus = randomFromWeightedSet(
[4, { type: 'Working' }],
[1, { type: 'Withdrawn' }],
[1, { type: 'Winner', reward: String(Number(bounty.totalFunding) / randomFromRange(1, 3)) }],
[1, { type: 'Passed' }],
[1, { type: 'Rejected' }],
[1, { type: 'CashedOut' }]
)
const worker = randomMember(mocks.members)
const works = repeat(generateWork, randomFromRange(0, 5))

return {
id: `${bounty.id}:${entryIndex}`,
bountyId: bounty.id,
workerId: worker.id,
stake: bounty.entrantStake,
stakingAccount: worker.controllerAccount,
workSubmitted: works.length > 0,
works: works[0] && works,
status: randomStatus(),
announcedInEvent: randomRawBlock(),
}
const generateContribution = (mocks: DependOnMocks, bounty: RawBountyMock) => (
contributionIndex: number
): RawBountyContributionMock => {
return {
id: `${bounty.id}:${contributionIndex}`,
bountyId: bounty.id,
...(datatype.boolean() ? { contributorId: randomMember(mocks.members).id } : {}),
amount: String(randomFromRange(1, 5) * 1000),
}
}

const generateEntry = (mocks: DependOnMocks, bounty: RawBountyMock) => (entryIndex: number): RawBountyEntryMock => {
const randomStatus = randomFromWeightedSet(
[4, { type: 'Working' }],
[1, { type: 'Withdrawn' }],
[1, { type: 'Winner', reward: String(Number(bounty.totalFunding) / randomFromRange(1, 3)) }],
[1, { type: 'Passed' }],
[1, { type: 'Rejected' }]
)
const worker = randomMember(mocks.members)
const works = repeat(generateWork, randomFromRange(0, 5))

return {
id: `${bounty.id}:${entryIndex}`,
bountyId: bounty.id,
workerId: worker.id,
stake: bounty.entrantStake,
stakingAccount: worker.controllerAccount,
workSubmitted: works.length > 0,
works: works[0] && works,
status: randomStatus(),
announcedInEvent: randomRawBlock(),
}
}

export const generateWork = () => ({ ...randomRawBlock(), title: lorem.sentence(), description: randomMessage() })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { randomMarkdown, randomFromRange } from './utils'
export const WORKING_GROUPS = [
'forumWorkingGroup',
'storageWorkingGroup',
'contentDirectoryWorkingGroup',
'contentWorkingGroup',
'membershipWorkingGroup',
]

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/accounts/model/lockTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const isRivalrous = (lockType: LockType) => RIVALROUS.includes(lockType)
const asLockTypes = (locks: BalanceLock[]): LockType[] => locks.flatMap((lock) => lock.type ?? [])
const isConflictingWith = (lockTypeA: LockType): ((lockTypeB: LockType) => boolean) => {
if (!lockTypeA) {
// Don't block transactions based on unknown locks
// Don't block transactions based on unknown locks
return () => false
}

Expand All @@ -62,7 +62,7 @@ const isConflictingWith = (lockTypeA: LockType): ((lockTypeB: LockType) => boole
// Vote stake should be reusable in next elections
return false
}

return lockTypeA === lockTypeB
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/bounty/types/Bounty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export type BountyEntryStatus =
| 'BountyEntryStatusWinner'
| 'BountyEntryStatusPassed'
| 'BountyEntryStatusRejected'
| 'BountyEntryStatusCashedOut'

export interface Contributor {
hasWithdrawn: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/common/hooks/useNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useNetwork = () => {
const networks = useMemo<NetworkType[]>(
() => [
'local',
'local-mocks',
...(IS_DEVELOPMENT ? ['local-mocks' as const] : []),
...(endpointsAreDefined(autoConfEndpoints) ? ['auto-conf' as const] : []),
...(IS_TESTNET_DEFINED ? ['olympia-testnet' as const] : []),
],
Expand Down
48 changes: 24 additions & 24 deletions packages/ui/src/mocks/data/raw/applicationWithdrawnEvents.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
[
{
"id": "0",
"createdAt": "2022-03-06T16:42:27.806Z",
"applicationId": "forumWorkingGroup-186",
"groupId": "forumWorkingGroup"
"createdAt": "2022-04-18T11:59:50.335Z",
"applicationId": "membershipWorkingGroup-221",
"groupId": "membershipWorkingGroup"
},
{
"id": "1",
"createdAt": "2022-03-11T12:41:51.460Z",
"applicationId": "membershipWorkingGroup-224",
"groupId": "membershipWorkingGroup"
"createdAt": "2022-04-18T11:12:32.143Z",
"applicationId": "storageWorkingGroup-190",
"groupId": "storageWorkingGroup"
},
{
"id": "2",
"createdAt": "2022-03-10T21:33:38.736Z",
"applicationId": "membershipWorkingGroup-231",
"groupId": "membershipWorkingGroup"
"createdAt": "2022-04-26T08:04:31.160Z",
"applicationId": "forumWorkingGroup-164",
"groupId": "forumWorkingGroup"
},
{
"id": "3",
"createdAt": "2022-03-15T10:04:42.987Z",
"applicationId": "storageWorkingGroup-192",
"groupId": "storageWorkingGroup"
"createdAt": "2022-04-17T10:51:01.844Z",
"applicationId": "contentWorkingGroup-199",
"groupId": "contentWorkingGroup"
},
{
"id": "4",
"createdAt": "2022-03-16T11:09:10.041Z",
"applicationId": "membershipWorkingGroup-233",
"groupId": "membershipWorkingGroup"
"createdAt": "2022-04-13T22:46:26.858Z",
"applicationId": "contentWorkingGroup-209",
"groupId": "contentWorkingGroup"
},
{
"id": "5",
"createdAt": "2022-03-04T11:07:33.866Z",
"applicationId": "contentDirectoryWorkingGroup-213",
"groupId": "contentDirectoryWorkingGroup"
"createdAt": "2022-04-26T18:21:45.159Z",
"applicationId": "forumWorkingGroup-164",
"groupId": "forumWorkingGroup"
},
{
"id": "6",
"createdAt": "2022-02-28T20:18:02.083Z",
"applicationId": "storageWorkingGroup-196",
"groupId": "storageWorkingGroup"
"createdAt": "2022-04-27T22:05:17.837Z",
"applicationId": "membershipWorkingGroup-215",
"groupId": "membershipWorkingGroup"
},
{
"id": "7",
"createdAt": "2022-03-09T00:17:22.656Z",
"applicationId": "contentDirectoryWorkingGroup-216",
"groupId": "contentDirectoryWorkingGroup"
"createdAt": "2022-04-15T22:35:05.626Z",
"applicationId": "forumWorkingGroup-169",
"groupId": "forumWorkingGroup"
}
]
Loading