Skip to content

Commit

Permalink
chore: update tests (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchuah authored Nov 20, 2023
1 parent f5c02fc commit 6fc24ec
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 50 deletions.
4 changes: 3 additions & 1 deletion contracts/mocks/MockVRFConsumerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {GelatoVRFConsumerBase} from "../GelatoVRFConsumerBase.sol";
contract MockVRFConsumerBase is GelatoVRFConsumerBase {
uint256 public latestRandomness;
uint64 public latestRequestId;
bytes public latestExtraData;
address private immutable _operatorAddr;

constructor(address operator) {
Expand All @@ -23,9 +24,10 @@ contract MockVRFConsumerBase is GelatoVRFConsumerBase {
function _fulfillRandomness(
uint256 randomness,
uint64 requestId,
bytes memory
bytes memory extraData
) internal override {
latestRandomness = randomness;
latestRequestId = requestId;
latestExtraData = extraData;
}
}
6 changes: 0 additions & 6 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ const config: HardhatUserConfig = {
url: "http://127.0.0.1:8545",
chainId: 31337,
},
hardhat: {
forking: {
url: `https://eth-goerli.g.alchemy.com/v2/${ALCHEMY_ID}`,
blockNumber: 8664000,
},
},

// Prod
avalanche: {
Expand Down
48 changes: 28 additions & 20 deletions test/base.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import hre from "hardhat";
import { assert, expect } from "chai";
import { Web3FunctionUserArgs } from "@gelatonetwork/automate-sdk";
import { Web3FunctionResultV2 } from "@gelatonetwork/web3-functions-sdk";
import { Web3FunctionHardhat } from "@gelatonetwork/web3-functions-sdk/hardhat-plugin";
import { ContractFactory } from "ethers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { MockVRFConsumerBase } from "../typechain";
import { Web3FunctionUserArgs } from "@gelatonetwork/automate-sdk";
import { Web3FunctionResultV2 } from "@gelatonetwork/web3-functions-sdk/*";
const { deployments, w3f, ethers } = hre;
import { assert, expect } from "chai";
import {
ChainOptions,
fetchBeacon,
HttpCachingChain,
HttpChainClient,
fetchBeacon,
roundAt,
} from "drand-client";
import { ContractFactory } from "ethers";
import hre from "hardhat";
import { quicknet } from "../src/drand_info";
import { MockVRFConsumerBase } from "../typechain";
const { deployments, w3f, ethers } = hre;

import fetch from "node-fetch";
global.fetch = fetch;

const DRAND_OPTIONS: ChainOptions = {
disableBeaconVerification: false,
Expand Down Expand Up @@ -54,7 +57,7 @@ describe("ConsumerBase Test Suite", function () {

// Solidity contracts
mockConsumerFactory = await ethers.getContractFactory(
"contracts/MockVRFConsumerBase.sol:MockVRFConsumerBase"
"contracts/mocks/MockVRFConsumerBase.sol:MockVRFConsumerBase"
);

// Drand testing client
Expand All @@ -72,11 +75,12 @@ describe("ConsumerBase Test Suite", function () {
userArgs = { consumerAddress: mockConsumer.address };
});

const data = []; // TODO; test data
it("Stores the latest round in the mock consumer", async () => {
for (let i = 0; i < 2; i++) {
const expectedExtraData = "0x12345678";

const requestId = i;
await mockConsumer.connect(user).requestRandomness(data);
await mockConsumer.connect(user).requestRandomness(expectedExtraData);

const exec = await vrf.run({ userArgs });
const res = exec.result as Web3FunctionResultV2;
Expand All @@ -92,18 +96,22 @@ describe("ConsumerBase Test Suite", function () {

const abi = ethers.utils.defaultAbiCoder;
expect(await mockConsumer.latestRandomness()).to.equal(
ethers.utils.keccak256(
abi.encode(
["uint256", "address", "uint256", "uint256"],
[
ethers.BigNumber.from(`0x${randomness}`),
mockConsumer.address,
(await ethers.provider.getNetwork()).chainId,
requestId,
]
ethers.BigNumber.from(
ethers.utils.keccak256(
abi.encode(
["uint256", "address", "uint256", "uint64"],
[
ethers.BigNumber.from(`0x${randomness}`),
mockConsumer.address,
(await ethers.provider.getNetwork()).chainId,
requestId,
]
)
)
)
);

expect(await mockConsumer.latestExtraData()).to.equal(expectedExtraData);
}
});

Expand Down
29 changes: 18 additions & 11 deletions test/cl.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import hre from "hardhat";
import { assert, expect } from "chai";
import { Web3FunctionHardhat } from "@gelatonetwork/web3-functions-sdk/hardhat-plugin";
import { ContractFactory } from "ethers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { VRFCoordinatorV2Adapter, MockVRFConsumer } from "../typechain";
import { Web3FunctionUserArgs } from "@gelatonetwork/automate-sdk";
import { Web3FunctionResultV2 } from "@gelatonetwork/web3-functions-sdk/*";
const { deployments, w3f, ethers } = hre;
import { Web3FunctionHardhat } from "@gelatonetwork/web3-functions-sdk/hardhat-plugin";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { assert, expect } from "chai";
import {
ChainOptions,
fetchBeacon,
HttpCachingChain,
HttpChainClient,
fetchBeacon,
roundAt,
} from "drand-client";
import { ContractFactory } from "ethers";
import hre from "hardhat";
import { quicknet } from "../src/drand_info";
import { MockVRFConsumer, VRFCoordinatorV2Adapter } from "../typechain";
const { deployments, w3f, ethers } = hre;

import fetch from "node-fetch";
global.fetch = fetch;

const DRAND_OPTIONS: ChainOptions = {
disableBeaconVerification: false,
Expand Down Expand Up @@ -56,7 +59,7 @@ describe("Chainlink Adapter Test Suite", function () {
// Solidity contracts
adapterFactory = await ethers.getContractFactory("VRFCoordinatorV2Adapter");
mockConsumerFactory = await ethers.getContractFactory(
"contracts/chainlink_compatible/MockVRFConsumer.sol:MockVRFConsumer"
"contracts/chainlink_compatible/mocks/MockVRFConsumer.sol:MockVRFConsumer"
);

// Drand testing client
Expand All @@ -71,11 +74,15 @@ describe("Chainlink Adapter Test Suite", function () {
const operator = deployer.address;
adapter = (await adapterFactory
.connect(deployer)
.deploy(operator)) as VRFCoordinatorV2Adapter;
.deploy(operator, operator, [])) as VRFCoordinatorV2Adapter;
mockConsumer = (await mockConsumerFactory
.connect(deployer)
.deploy(adapter.address)) as MockVRFConsumer;
userArgs = { consumerAddress: adapter.address };

await adapter
.connect(deployer)
.updateRequesterPermissions([mockConsumer.address], true);
});

it("Stores the latest round in the mock consumer", async () => {
Expand All @@ -99,7 +106,7 @@ describe("Chainlink Adapter Test Suite", function () {
const abi = ethers.utils.defaultAbiCoder;
const seed = ethers.utils.keccak256(
abi.encode(
["uint256", "address", "uint256", "uint256"],
["uint256", "address", "uint256", "uint64"],
[
ethers.BigNumber.from(`0x${randomness}`),
adapter.address,
Expand Down
21 changes: 12 additions & 9 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import hre from "hardhat";
import { assert, expect } from "chai";
import { Web3FunctionHardhat } from "@gelatonetwork/web3-functions-sdk/hardhat-plugin";
import { ContractFactory } from "ethers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { MockVRFConsumer } from "../typechain";
import { Web3FunctionUserArgs } from "@gelatonetwork/automate-sdk";
import { Web3FunctionResultV2 } from "@gelatonetwork/web3-functions-sdk/*";
const { deployments, w3f, ethers } = hre;
import { Web3FunctionHardhat } from "@gelatonetwork/web3-functions-sdk/hardhat-plugin";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { assert, expect } from "chai";
import {
ChainOptions,
fetchBeacon,
HttpCachingChain,
HttpChainClient,
fetchBeacon,
roundAt,
} from "drand-client";
import { ContractFactory } from "ethers";
import hre from "hardhat";
import { quicknet } from "../src/drand_info";
import { MockVRFConsumer } from "../typechain/contracts/mocks/MockVRFConsumer";
const { deployments, w3f, ethers } = hre;

import fetch from "node-fetch";
global.fetch = fetch;

const DRAND_OPTIONS: ChainOptions = {
disableBeaconVerification: false,
Expand Down Expand Up @@ -54,7 +57,7 @@ describe("VRF Test Suite", function () {

// Solidity contracts
mockConsumerFactory = await ethers.getContractFactory(
"contracts/MockVRFConsumer.sol:MockVRFConsumer"
"contracts/mocks/MockVRFConsumer.sol:MockVRFConsumer"
);

// Drand testing client
Expand Down
6 changes: 3 additions & 3 deletions test/rnglib.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hre from "hardhat";
import { expect } from "chai";
import hre from "hardhat";
import { RNGLibTestHarness } from "../typechain";
const { ethers } = hre;
const { ethers, deployments } = hre;

describe("RNGLib", function () {
// Contracts
Expand All @@ -17,7 +17,7 @@ describe("RNGLib", function () {

// Solidity contracts
const factory = await ethers.getContractFactory("RNGLibTestHarness");
harness = await factory.deploy();
harness = (await factory.deploy()) as RNGLibTestHarness;
});

it("returns distinct consecutive random numbers", async () => {
Expand Down

0 comments on commit 6fc24ec

Please sign in to comment.