Skip to content

Commit d9670e2

Browse files
authored
base integration (#10)
* added tests for base sepolia * added vars to github action * added chainId creation for base
1 parent 0c073ca commit d9670e2

5 files changed

Lines changed: 47 additions & 9 deletions

File tree

.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
# filecoin calibnet
12
FILECOIN_PRIVATE_KEY=somehexstringwithoutthe0xprefix
23
FILECOIN_RPC_URL=wss://wss.calibration.node.glif.io/apigw/lotus/rpc/v1
4+
# dcipher furnace
35
FURNACE_PRIVATE_KEY=somehexstringwithoutthe0xprefix
46
FURNACE_RPC_URL=https://furnace.dcipher.network
7+
# base sepolia
8+
BASE_PRIVATE_KEY=somehexstringwithoutthe0xprefix
9+
BASE_RPC_URL=https://sepolia.base.org

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ env:
99
FILECOIN_RPC_URL: ${{ secrets.FILECOIN_RPC_URL }}
1010
FURNACE_PRIVATE_KEY: ${{ secrets.FURNACE_PRIVATE_KEY }}
1111
FURNACE_RPC_URL: ${{ secrets.FURNACE_RPC_URL }}
12+
BASE_PRIVATE_KEY: ${{ secrets.BASE_PRIVATE_KEY }}
13+
BASE_RPC_URL: ${{ secrets.BASE_RPC_URL }}
1214

1315
jobs:
1416
build:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "randomness-js",
3-
"version": "0.0.1-rc8",
3+
"version": "0.0.1-rc9",
44
"description": "A library for consuming, verifying and using randomness from the dcipher network",
55
"source": "src/index.ts",
66
"main": "./dist/cjs/index.cjs",

src/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {RandomnessCallbackSuccessEvent, RandomnessSender} from "./generated/Rand
1717
/* addresses of the deployed contracts */
1818
export const FURNACE_TESTNET_CONTRACT_ADDRESS = "0x8192aF4ce49f473fCa7e3e5a8d819B0763Def048"
1919
export const FILECOIN_CALIBNET_CONTRACT_ADDRESS = "0x9c789bc7F2B5c6619Be1572A39F2C3d6f33001dC"
20+
export const BASE_SEPOLIA_CONTRACT_ADDRESS = "0x31e01BCA94b787D3B4a16C378Bd5D200686dEb99"
2021

2122
/* some cryptographic parameters that are also defined in the contracts, but we duplicate here for performance */
2223
const RANDOMNESS_DST = "randomness:0.0.1:bn254"
@@ -51,16 +52,27 @@ export class Randomness {
5152
return new Randomness(rpc, FURNACE_TESTNET_CONTRACT_ADDRESS)
5253
}
5354

55+
static createBaseSepolia(rpc: Signer | Provider): Randomness {
56+
return new Randomness(rpc, BASE_SEPOLIA_CONTRACT_ADDRESS)
57+
}
58+
5459
static createFromChainId(rpc: Signer | Provider, chainId: BigNumberish): Randomness {
55-
switch (chainId) {
60+
switch (chainId.toString().toLowerCase()) {
5661
case "314159":
57-
case 314159n:
58-
case 314159:
62+
case "314159n":
63+
case "0x4cb2f":
5964
return Randomness.createFilecoinCalibnet(rpc)
65+
6066
case "64630":
61-
case 64630n:
62-
case 64630:
67+
case "64630n":
68+
case "0xfc76":
6369
return Randomness.createFurnace(rpc)
70+
71+
case "84532":
72+
case "84532n":
73+
case "0x14a34":
74+
return Randomness.createBaseSepolia(rpc)
75+
6476
default:
6577
throw new Error("unsupported chainId :(")
6678
}

test/randomness.test.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import * as dotenv from "dotenv"
22
import {describe, it, expect, beforeAll} from "@jest/globals"
33
import {JsonRpcProvider, NonceManager, Wallet, WebSocketProvider} from "ethers"
4-
import {FILECOIN_CALIBNET_CONTRACT_ADDRESS, FURNACE_TESTNET_CONTRACT_ADDRESS, Randomness} from "../src"
4+
import {
5+
BASE_SEPOLIA_CONTRACT_ADDRESS,
6+
FILECOIN_CALIBNET_CONTRACT_ADDRESS,
7+
FURNACE_TESTNET_CONTRACT_ADDRESS,
8+
Randomness
9+
} from "../src"
510

611
// filecoin calibnet might take forever
712
const TEST_TIMEOUT = 200_000
813
describe("randomness", () => {
914
beforeAll(() => {
1015
dotenv.config()
1116
})
12-
13-
it("can be requested from filecoin testnet and verified", async () => {
17+
18+
it("can be requested from filecoin testnet and verified", async () => {
1419
const rpc = createProvider(process.env.FILECOIN_RPC_URL || "")
1520
const wallet = new NonceManager(new Wallet(process.env.FILECOIN_PRIVATE_KEY || "", rpc))
1621

@@ -37,6 +42,20 @@ describe("randomness", () => {
3742
rpc.destroy()
3843
}, TEST_TIMEOUT)
3944

45+
it("can be requested from a base sepolia and verified", async () => {
46+
const rpc = createProvider(process.env.BASE_RPC_URL || "")
47+
const wallet = new NonceManager(new Wallet(process.env.BASE_PRIVATE_KEY || "", rpc))
48+
49+
const randomness = new Randomness(wallet, BASE_SEPOLIA_CONTRACT_ADDRESS)
50+
expect(randomness).not.toEqual(null)
51+
52+
const response = await randomness.requestRandomness(1, TEST_TIMEOUT)
53+
console.log("randomness requested")
54+
await randomness.verify(response)
55+
56+
rpc.destroy()
57+
}, TEST_TIMEOUT)
58+
4059
})
4160

4261
function createProvider(url: string): JsonRpcProvider | WebSocketProvider {

0 commit comments

Comments
 (0)