-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a verbose flag for outputting more draw info
- refactored things to accomodate for it - added some more tests
- Loading branch information
1 parent
efb0fee
commit 6829716
Showing
6 changed files
with
124 additions
and
34 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
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 |
---|---|---|
@@ -1,11 +1,77 @@ | ||
import {test} from "@jest/globals" | ||
import {main} from "../src/main" | ||
import {describe, it, expect} from "@jest/globals" | ||
import {draw, main} from "../src/main" | ||
|
||
test("make sure it doesn't blow up", async () => { | ||
const params = { | ||
count: 1, | ||
values: ["a", "b", "c"], | ||
drandURL: "https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971" | ||
} | ||
await main(params) | ||
}) | ||
describe("draws", () => { | ||
describe("main function", () => { | ||
it("verbose shouldn't blow up", async () => { | ||
const params = { | ||
count: 1, | ||
values: ["a", "b", "c"], | ||
drandURL: "https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971", | ||
verbose: false, | ||
} | ||
await main(params) | ||
}) | ||
it("non-verbose shouldn't blow up", async () => { | ||
const params = { | ||
count: 1, | ||
values: ["a", "b", "c"], | ||
drandURL: "https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971", | ||
verbose: false, | ||
} | ||
await main(params) | ||
}) | ||
}) | ||
describe("draw function", () => { | ||
it("should return no values for 0 count", async () => { | ||
const params = { | ||
count: 0, | ||
values: ["a", "b", "c"], | ||
drandURL: "https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971", | ||
verbose: true, | ||
} | ||
const result = await draw(params) | ||
expect(result.round).toEqual(0) | ||
expect(result.winners).toEqual([]) | ||
expect(result.randomness).toEqual("") | ||
}) | ||
it("should return all the values for a count less than the number of values", async () => { | ||
const params = { | ||
count: 5, | ||
values: ["a", "b", "c"], | ||
drandURL: "https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971", | ||
verbose: true, | ||
} | ||
const result = await draw(params) | ||
expect(result.round).toEqual(0) | ||
expect(result.winners).toEqual(params.values) | ||
expect(result.randomness).toEqual("") | ||
}) | ||
it("should return the same result each time for custom randomness", async () => { | ||
const params = { | ||
count: 1, | ||
values: ["a", "b", "c"], | ||
randomness: "5af934e9a82fcbc0f7d9cb7be197f6a9f74e10a49227f3dc72ed0686f7ab85f2", | ||
drandURL: "https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971", | ||
verbose: true, | ||
} | ||
const result = await draw(params) | ||
expect(result.round).toEqual(0) | ||
expect(result.randomness).toEqual(params.randomness) | ||
|
||
const result2 = await draw(params) | ||
expect(result).toEqual(result2) | ||
}) | ||
it("should return a non-zero round for real randomness", async () => { | ||
const params = { | ||
count: 1, | ||
values: ["a", "b", "c"], | ||
drandURL: "https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971", | ||
verbose: true, | ||
} | ||
const result = await draw(params) | ||
expect(result.round).toBeGreaterThan(1) | ||
expect(result.winners).toHaveLength(params.count) | ||
}) | ||
}) | ||
}) |