-
Notifications
You must be signed in to change notification settings - Fork 7
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 #112 from peanutprotocol/moreRandomness
feat: more randomness
- Loading branch information
Showing
2 changed files
with
41 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { generateAmountsDistribution } from '../../src/raffle' | ||
import { BigNumber } from 'ethersv5' | ||
|
||
describe('Amounts Distribution Functionality', () => { | ||
test('should generate a distribution for 250 slots with a total of 125 Amount', async () => { | ||
const totalAmount = BigNumber.from(125000) | ||
const numberOfSlots = 250 | ||
const distribution = generateAmountsDistribution(totalAmount, numberOfSlots) | ||
|
||
// Print out the amounts distribution | ||
console.log( | ||
'Amounts Distribution:', | ||
distribution.map((amount) => amount.toString()) | ||
) | ||
|
||
// Rank by size | ||
const rankedDistribution = distribution.sort((a, b) => b.sub(a).toNumber()) | ||
console.log( | ||
'Ranked Distribution:', | ||
rankedDistribution.map((amount) => amount.toString()) | ||
) | ||
|
||
// Expectations | ||
expect(distribution.length).toBe(numberOfSlots) | ||
|
||
// Assert that the sum of the distribution equals the total amount | ||
const sumOfDistribution = distribution.reduce((acc, val) => acc.add(val), BigNumber.from(0)) | ||
expect(sumOfDistribution.toString()).toBe(totalAmount.toString()) | ||
|
||
// Optionally, print the sum for verification | ||
console.log('Sum of Distribution:', sumOfDistribution.toString()) | ||
}, 30000) | ||
}) |