Skip to content

Commit

Permalink
🔧 Fix local mocks (#2940)
Browse files Browse the repository at this point in the history
* Making local-mocks invisible in production

* Fix on seeding error

* Fix contentWorkingGroup name in mocks and regenerate mocks

* Fix ContentWorkingGroup page test

* Show the `local-mocks` option in development mode

* Fix tests

Co-authored-by: WRadoslaw <r.wyszynski00@gmail.com>
Co-authored-by: Theophile Sandoz <theophile.sandoz@gmail.com>
  • Loading branch information
3 people authored Apr 29, 2022
1 parent 7c8f606 commit 6cfb9a9
Show file tree
Hide file tree
Showing 41 changed files with 19,069 additions and 11,209 deletions.
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
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
4 changes: 3 additions & 1 deletion packages/ui/src/common/hooks/useNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { useLocalStorage } from './useLocalStorage'
export const useNetwork = () => {
const [network = DEFAULT_NETWORK.type, setNetwork] = useLocalStorage<NetworkType>('network')

const showMocks = typeof IS_DEVELOPMENT === 'boolean' && IS_DEVELOPMENT
const [autoConfEndpoints] = useLocalStorage<NetworkEndpoints>('auto_network_config')

const networks = useMemo<NetworkType[]>(
() => [
'local',
'local-mocks',
...(showMocks ? ['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

1 comment on commit 6cfb9a9

@vercel
Copy link

@vercel vercel bot commented on 6cfb9a9 Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pioneer-2 – ./

pioneer-2-git-dev-joystream.vercel.app
pioneer-2-joystream.vercel.app
pioneer-2.vercel.app

Please sign in to comment.