Skip to content

Conversation

@redpanda-f
Copy link
Contributor

@redpanda-f redpanda-f commented Feb 10, 2026

Introduce: foc-devnet-info library

  • Parses and produces synapse type Chain from DevnetInfo exported by foc-devnet
  • e2e test uses this library now, as an example to interface with foc-devnet
  • mocked tests to check for functionality

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 10, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
synapse-dev 80361be Commit Preview URL

Branch Preview URL
Feb 11 2026, 07:24 AM

@redpanda-f
Copy link
Contributor Author

Things to fix (synced with @hugomrdias ) :

  • Instead of returning ViemChain, we need to return Chain from synapse-sdk?
  • Use synapse-core/mocks for JSON-RPC testing

@redpanda-f redpanda-f marked this pull request as draft February 10, 2026 15:51
@redpanda-f
Copy link
Contributor Author

Did more debugging on this, this needs some more work, and a sister PR on the foc-devnet side as well.

@redpanda-f
Copy link
Contributor Author

Works with latest foc-devnet:

Loading devnet info from: /Users/redpanda/.foc-devnet/state/latest/devnet-info.json
Devnet run: 20260211T1206_DitzyPip (started: 2026-02-11T06:43:31.713665+00:00)
Using user: USER_1 (0x47cc9101fd026fc112d7fadf6b3c9df5be7d4a8c)
SPs available: 1
No file paths provided, using default test file: /Users/redpanda/.foc-devnet/state/latest/devnet-info.json
=== Synapse SDK Storage E2E Example ===

Mode: FOC DevNet
Reading file...
  Reading file: /Users/redpanda/.foc-devnet/state/latest/devnet-info.json

--- Initializing Synapse SDK ---
RPC URL: http://localhost:5701/rpc/v1
Chain: FOC DevNet (ID: 31415926)
Warm Storage Address: 0x4A8a81765bFBe09D6fDd167EF954a1D3401340e5
Multicall3 Address: 0x2e1F1424b41ad7b2E34b0a60501edFc82FEf5BE8
USDFC Address: 0xB514FeE11119E0923950C09A181F1fa3aa62C80b
Endorsements Address: 0x583456fB91a637807d480d1B6E37029805C1978E
✓ Synapse instance created
Wallet address: 0x47CC9101fD026fC112D7FADf6B3c9DF5bE7D4A8c

--- Checking Balances ---
FIL balance: 999.9999900506001 FIL
USDFC balance: 99999.000000 USDFC

--- Setting Up Storage Context ---
✓ Selected service provider: 0x446339aE7245e3cd1FeD701b685C196C69af695e
✓ Using existing data set: 1
Data set ID: 1
Data set contains 1 piece CIDs

--- Service Provider Details ---
Provider ID: 1
Provider Address: 0x446339aE7245e3cd1FeD701b685C196C69af695e
Provider Name: PDP_SP_1
Active: undefined
PDP Service URL: http://host.docker.internal:5714

--- Preflight Upload Check ---
Estimated costs:
  Per epoch (30s): 0.000000 USDFC
  Per day: 0.000000 USDFC
  Per month: 0.000000 USDFC
✓ Sufficient allowances available

--- Uploading ---
Uploading file to service provider...

  Upload progress: 2.95 KB / 2.95 KB (100.0%)
✓ Upload complete! PieceCID: bafkzcibdsyeapurw4m5m6mu7kjhyatucbdkkernmau6qpjua7mll7wnc35islyz5
✓ Piece addition transaction: 0xfc1bd442a78d722c79b4bf447da7886b721f4aad0c9cac51510d3d9a679f296c
✓ Piece addition confirmed! ID(s): 1

--- Upload Summary ---
File 1: /Users/redpanda/.foc-devnet/state/latest/devnet-info.json
    PieceCID: bafkzcibdsyeapurw4m5m6mu7kjhyatucbdkkernmau6qpjua7mll7wnc35islyz5
    Size: 2.95 KB
    Piece ID: 1

--- Downloading Files ---
Downloading file...

  Downloading file 1: bafkzcibdsyeapurw4m5m6mu7kjhyatucbdkkernmau6qpjua7mll7wnc35islyz5

✓ Downloaded 1 file successfully

--- Verifying Data ---
File 1 (/Users/redpanda/.foc-devnet/state/latest/devnet-info.json): ✅ MATCH (2.95 KB)

✅ SUCCESS: All downloaded files match originals!

--- Piece Status ---
Data set exists on provider: true
Data set last proven: 1/1/1970, 6:20:30 AM
Data set next proof due: 1/1/1970, 7:25:30 AM
Hours until challenge window: 0.9

--- Storage Information ---
Your 1 file is now stored on the Filecoin network:
- Data set ID: 1
- Service provider: 0x446339aE7245e3cd1FeD701b685C196C69af695e

Uploaded pieces:

  File 1: /Users/redpanda/.foc-devnet/state/latest/devnet-info.json
    PieceCID: bafkzcibdsyeapurw4m5m6mu7kjhyatucbdkkernmau6qpjua7mll7wnc35islyz5
    Piece ID: 1
    Size: 2.95 KB
    Retrieval URL: http://host.docker.internal:5714/piece/bafkzcibdsyeapurw4m5m6mu7kjhyatucbdkkernmau6qpjua7mll7wnc35islyz5

The service provider(s) will periodically prove they still have your data.

Needs the sister PR on foc-devnet for working well: FilOzone/foc-devnet#61

@redpanda-f redpanda-f marked this pull request as ready for review February 11, 2026 06:53
@rjan90 rjan90 moved this from 📌 Triage to 🔎 Awaiting review in FOC Feb 11, 2026
@BigLep
Copy link
Contributor

BigLep commented Feb 11, 2026

This is being done in support of FilOzone/foc-devnet#7, and more specifically I believe it closes #589

@BigLep BigLep linked an issue Feb 11, 2026 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a new foc-devnet-info helper in @filoz/synapse-core to validate foc-devnet’s devnet-info.json and convert it into a Synapse Chain, and updates the utils E2E example to use this new flow.

Changes:

  • Add foc-devnet-info library (Zod schema + toChain converter) and export it from @filoz/synapse-core.
  • Add unit tests covering devnet-info validation and chain conversion.
  • Update utils/example-storage-e2e.js to load config from devnet-info by default and switch from ethers-based usage to viem-based usage.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
utils/package.json Add workspace dependency on @filoz/synapse-core and switch utils to viem.
utils/example-storage-e2e.js Load devnet config from devnet-info by default; update to viem + new foc-devnet-info helpers.
packages/synapse-sdk/src/test/synapse.test.ts Remove unused session-key-related import.
packages/synapse-core/test/foc-devnet-info.test.ts Add tests for devnet-info validation and chain construction.
packages/synapse-core/src/index.ts Export the new focDevnetInfo module from synapse-core.
packages/synapse-core/src/foc-devnet-info/src/schema.ts New Zod schema + validation wrapper for devnet-info.json.
packages/synapse-core/src/foc-devnet-info/src/index.ts New public API: loadDevnetInfo + toChain (+ re-exports).
packages/synapse-core/package.json Add package export + typesVersions mapping for ./foc-devnet-info.
package.json Adjust Node devEngine version constraint.
examples/script-tag/biome.json Update Biome schema reference URL.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +25
* Environment variables:
* - DETAILS_VIA_ENVVARS: Set to "true" to use env vars instead of devnet info (default: false)
* - USE_CALIBRATION: Set to "true" to use calibration network instead of devnet (default: false)
*
* When DETAILS_VIA_ENVVARS=true or USE_CALIBRATION=true:
* - PRIVATE_KEY: Your Ethereum private key (with 0x prefix)
* - RPC_URL: Filecoin RPC endpoint (defaults to calibration)
*
* Optional environment variables (for devnet):
* - WARM_STORAGE_ADDRESS: Warm Storage service contract address (uses default for network)
* - WARM_STORAGE_ADDRESS: Warm Storage service contract address (optional)
* - MULTICALL3_ADDRESS: Multicall3 address (required for devnet)
* - USDFC_ADDRESS: USDFC token address (optional)
* - ENDORSEMENTS_ADDRESS: Endorsements contract address (optional)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header comment/documentation still lists contract address env vars (WARM_STORAGE_ADDRESS, MULTICALL3_ADDRESS, USDFC_ADDRESS, ENDORSEMENTS_ADDRESS) and implies DETAILS_VIA_ENVVARS can be used for devnet, but the script no longer reads those env vars and always builds CHAIN from calibration in the DETAILS_VIA_ENVVARS branch. Either update the docs to match the actual behavior (env vars => calibration only), or implement env-var-based devnet chain construction/contract overrides so the documented variables are actually used.

Copilot uses AI. Check for mistakes.
*
* When DETAILS_VIA_ENVVARS=false (default):
* - DEVNET_INFO_PATH: Path to devnet-info.json (optional, defaults to ~/.foc-devnet/state/latest/devnet-info.json)
* - DEVNET_USER_INDEX: Index of the user to use from devnet info (optional, defaults to 0) *
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s a stray "*" at the end of the DEVNET_USER_INDEX line in the header comment. This reads like an unfinished footnote and should be removed or completed.

Suggested change
* - DEVNET_USER_INDEX: Index of the user to use from devnet info (optional, defaults to 0) *
* - DEVNET_USER_INDEX: Index of the user to use from devnet info (optional, defaults to 0)

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +76
const rawData = JSON.parse(readFileSync(devnetInfoPath, 'utf8'))
const devnetInfo = loadDevnetInfo(rawData)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the default (devnet-info) mode, readFileSync(devnetInfoPath, ...)/JSON.parse will throw and terminate the process before any helpful usage message if the file is missing or invalid. Consider wrapping this block in a try/catch and printing a clear error with guidance (e.g., set DETAILS_VIA_ENVVARS=true or point DEVNET_INFO_PATH to a valid file).

Suggested change
const rawData = JSON.parse(readFileSync(devnetInfoPath, 'utf8'))
const devnetInfo = loadDevnetInfo(rawData)
let devnetInfo
try {
const rawData = JSON.parse(readFileSync(devnetInfoPath, 'utf8'))
devnetInfo = loadDevnetInfo(rawData)
} catch (err) {
console.error('ERROR: Failed to load devnet info.')
console.error(` Path: ${devnetInfoPath}`)
console.error(' Make sure DEVNET_INFO_PATH points to a valid devnet-info.json file,')
console.error(' or run with DETAILS_VIA_ENVVARS=true (and PRIVATE_KEY, RPC_URL, etc.)')
console.error(' or USE_CALIBRATION=true with the appropriate environment variables.')
if (err && err.message) {
console.error(` Underlying error: ${err.message}`)
}
process.exit(1)
}

Copilot uses AI. Check for mistakes.
const sessionKeyAddress = sessionAccount.address

console.log('\n--- SessionKey Login ---')
console.log(`Session Key: ${sessionKeyAddress})`)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra closing parenthesis in the session key log output (${sessionKeyAddress})). This produces a confusing message; remove the trailing ).

Suggested change
console.log(`Session Key: ${sessionKeyAddress})`)
console.log(`Session Key: ${sessionKeyAddress}`)

Copilot uses AI. Check for mistakes.
Comment on lines 233 to +237
// Use login() to reset the expiry of existing permissions to the new value
const loginTx = await sessionKey.login(refresh, permissionsToRefresh)
console.log(` tx: ${loginTx.hash}`)
const loginReceipt = await loginTx.wait()
if (loginReceipt.status === 1) {
console.log('✓ login successful')
} else {
throw new Error('Login failed')
}
console.log(` tx: ${loginTx}`)
// Note: In viem, we get transaction hash directly
console.log('✓ login successful')
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After sessionKey.login(...) you immediately print "✓ login successful" without waiting for the transaction to be mined/confirmed. Since login() returns only a hash, this message can be incorrect if the tx reverts or is dropped. Consider either waiting for a receipt (e.g. via a viem waitForTransactionReceipt using the same chain/transport) or change the message to reflect submission (e.g. "login submitted").

Copilot uses AI. Check for mistakes.
}

/**
* @deprecated Use {@link toChain} instead. This function returns a plain viem Chain without ABIs.
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation notice for toViemChain says it returns a chain "without ABIs", but toViemChain is currently just an alias of toChain, which does include ABIs in contracts.*.abi. Please update the comment to reflect the current behavior, or reintroduce a separate function if you still need an ABI-less variant.

Suggested change
* @deprecated Use {@link toChain} instead. This function returns a plain viem Chain without ABIs.
* @deprecated Use {@link toChain} instead. This is a deprecated alias that returns the same Chain
* object as {@link toChain}, including contract ABIs.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +28
private_key_hex: '0xf0ea8d631d31668a3b26999169037c0b75f505c675522d956e7cf114938d7f81',
},
{
name: 'USER_2',
evm_addr: '0x3a2167cc501e720fc320e4830ef779047c0179a8',
native_addr: 't410fhiqwptcqdzza7qza4sbq553zar6ac6niyd52bmq',
private_key_hex: '0x2d54e0612c1d96431e4de2c76b0d5ab8d9830b39c4f2cc37b950000e83ab68d7',
},
{
name: 'USER_3',
evm_addr: '0x1e0a344acb785694a621ff18ae73284cbbf461dc',
native_addr: 't410fdyfdiswlpbljjjrb74mk44zijs57iyo4tbp5rsq',
private_key_hex: '0xbbbfb618d44e0e059ffa678c865ea6dcff78ef3fe4b187a07e1709ef3e79911d',
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fixture includes full private keys that look realistic. Even if they’re for a local devnet, they can trigger secret scanners or get reused accidentally. Prefer obviously non-sensitive dummy values (e.g., deterministic test keys like 0x111...) or generate them in-test to avoid committing key-like material.

Suggested change
private_key_hex: '0xf0ea8d631d31668a3b26999169037c0b75f505c675522d956e7cf114938d7f81',
},
{
name: 'USER_2',
evm_addr: '0x3a2167cc501e720fc320e4830ef779047c0179a8',
native_addr: 't410fhiqwptcqdzza7qza4sbq553zar6ac6niyd52bmq',
private_key_hex: '0x2d54e0612c1d96431e4de2c76b0d5ab8d9830b39c4f2cc37b950000e83ab68d7',
},
{
name: 'USER_3',
evm_addr: '0x1e0a344acb785694a621ff18ae73284cbbf461dc',
native_addr: 't410fdyfdiswlpbljjjrb74mk44zijs57iyo4tbp5rsq',
private_key_hex: '0xbbbfb618d44e0e059ffa678c865ea6dcff78ef3fe4b187a07e1709ef3e79911d',
private_key_hex: '0x1111111111111111111111111111111111111111111111111111111111111111',
},
{
name: 'USER_2',
evm_addr: '0x3a2167cc501e720fc320e4830ef779047c0179a8',
native_addr: 't410fhiqwptcqdzza7qza4sbq553zar6ac6niyd52bmq',
private_key_hex: '0x2222222222222222222222222222222222222222222222222222222222222222',
},
{
name: 'USER_3',
evm_addr: '0x1e0a344acb785694a621ff18ae73284cbbf461dc',
native_addr: 't410fdyfdiswlpbljjjrb74mk44zijs57iyo4tbp5rsq',
private_key_hex: '0x3333333333333333333333333333333333333333333333333333333333333333',

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +8
* This schema ensures strict type checking and validates that all required
* fields are present with correct types. It's used by the library to
* validate the exported devnet-info.json file.
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module docstring says the schema provides “strict type checking” and validates that “all required fields are present”, but the Zod objects are not marked .strict(). By default, Zod will allow (and strip) unknown keys, so malformed devnet-info with extra/unexpected fields won’t fail validation. Either make the objects strict (e.g., apply .strict() at least on the top-level objects) or adjust the wording so callers don’t assume unknown keys will be rejected.

Suggested change
* This schema ensures strict type checking and validates that all required
* fields are present with correct types. It's used by the library to
* validate the exported devnet-info.json file.
* This schema validates that all required fields are present with correct
* types in a DevNet info export. Additional or unknown fields may be
* ignored according to Zod's default object parsing behavior. It's used by
* the library to validate the exported devnet-info.json file.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting review

Development

Successfully merging this pull request may close these issues.

foc-devnet Chain builder in synpase-core

2 participants