|
1 | 1 | import { expect } from "chai";
|
2 | 2 | import { ethers, network } from "hardhat";
|
3 |
| -import { BigNumber } from "ethers"; |
| 3 | +import { toBigInt } from "ethers"; |
4 | 4 | import { IncrementalNG, BlockHashRNG } from "../../typechain-types";
|
5 | 5 |
|
6 | 6 | let rng, rngFactory;
|
7 | 7 | const initialNg = 424242;
|
| 8 | +const abiCoder = ethers.AbiCoder.defaultAbiCoder(); |
8 | 9 |
|
9 | 10 | describe("IncrementalNG", async () => {
|
10 | 11 | beforeEach("Setup", async () => {
|
11 | 12 | rngFactory = await ethers.getContractFactory("IncrementalNG");
|
12 | 13 | rng = (await rngFactory.deploy(initialNg)) as IncrementalNG;
|
13 |
| - await rng.deployed(); |
14 | 14 | });
|
15 | 15 |
|
16 | 16 | it("Should return a number incrementing each time", async () => {
|
17 |
| - expect(await rng.callStatic.receiveRandomness(689376)).to.equal(initialNg); |
| 17 | + expect(await rng.receiveRandomness.staticCall(689376)).to.equal(initialNg); |
18 | 18 | await rng.receiveRandomness(29543);
|
19 |
| - expect(await rng.callStatic.receiveRandomness(5894382)).to.equal(initialNg + 1); |
| 19 | + expect(await rng.receiveRandomness.staticCall(5894382)).to.equal(initialNg + 1); |
20 | 20 | await rng.receiveRandomness(0);
|
21 |
| - expect(await rng.callStatic.receiveRandomness(3465)).to.equal(initialNg + 2); |
22 |
| - await rng.receiveRandomness(BigNumber.from(2).pow(255)); |
23 |
| - expect(await rng.callStatic.receiveRandomness(0)).to.equal(initialNg + 3); |
| 21 | + expect(await rng.receiveRandomness.staticCall(3465)).to.equal(initialNg + 2); |
| 22 | + await rng.receiveRandomness(toBigInt(2) ** toBigInt(255)); |
| 23 | + expect(await rng.receiveRandomness.staticCall(0)).to.equal(initialNg + 3); |
24 | 24 | });
|
25 | 25 | });
|
26 | 26 |
|
27 | 27 | describe("BlockHashRNG", async () => {
|
28 | 28 | beforeEach("Setup", async () => {
|
29 | 29 | rngFactory = await ethers.getContractFactory("BlockHashRNG");
|
30 | 30 | rng = (await rngFactory.deploy()) as BlockHashRNG;
|
31 |
| - await rng.deployed(); |
32 | 31 | });
|
33 | 32 |
|
34 | 33 | it("Should return a non-zero number for a block number in the past", async () => {
|
35 | 34 | const tx = await rng.receiveRandomness(9876543210);
|
36 | 35 | const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);
|
37 |
| - const [rn] = ethers.utils.defaultAbiCoder.decode(["uint"], `0x${trace.returnValue}`); |
| 36 | + const [rn] = abiCoder.decode(["uint"], `0x${trace.returnValue}`); |
38 | 37 | expect(rn).to.equal(0);
|
39 | 38 | });
|
40 | 39 |
|
41 | 40 | it("Should return zero for a block number in the future", async () => {
|
42 | 41 | const tx = await rng.receiveRandomness(5);
|
43 | 42 | const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);
|
44 |
| - const [rn] = ethers.utils.defaultAbiCoder.decode(["uint"], `0x${trace.returnValue}`); |
| 43 | + const [rn] = abiCoder.decode(["uint"], `0x${trace.returnValue}`); |
45 | 44 | expect(rn).to.not.equal(0);
|
46 | 45 | });
|
47 | 46 | });
|
0 commit comments