OverviewFilesCommitsIssuesDocsReleasesPeers

hyperswarm-peer / test / debug_testnet.js

38 lines · javascript ref:
#!/usr/bin/env node
// Creates a JS testnet and prints bootstrap address, then waits.
// Usage: node debug_testnet.js
// Then manually run: ./test_crossystem_client immutable_put <bootstrap> <value_hex>

const DHT = require('hyperdht')
const createTestnet = require('hyperdht/testnet')

async function main() {
  console.log('Creating JS testnet (3 nodes)...')
  const testnet = await createTestnet(3, { teardown: () => {} })
  const bootstrap = testnet.bootstrap.map(b => `${b.host}:${b.port}`).join(',')
  console.log(`BOOTSTRAP=${bootstrap}`)

  // Also put a value so we can test immutable_get
  const client = testnet.createNode()
  const value = Buffer.from('test value for debug')
  const putResult = await client.immutablePut(value)
  console.log(`IMMUTABLE_KEY=${putResult.hash.toString('hex')}`)
  console.log(`VALUE_HEX=${value.toString('hex')}`)

  // Also put a mutable value
  const sodium = require('sodium-native')
  const pk = Buffer.alloc(32)
  const sk = Buffer.alloc(64)
  sodium.crypto_sign_keypair(pk, sk)
  await client.mutablePut({ publicKey: pk, secretKey: sk }, Buffer.from('mutable test'), { seq: 1 })
  console.log(`MUTABLE_PK=${pk.toString('hex')}`)

  console.log('\nTestnet ready. Press Ctrl+C to stop.')
  console.log('Example: ./test_crossystem_client immutable_put ' + bootstrap + ' ' + value.toString('hex'))

  // Keep alive
  await new Promise(() => {})
}

main().catch(console.error)