New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@substrate/connect

Package Overview
Dependencies
Maintainers
20
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@substrate/connect - npm Package Compare versions

Comparing version 0.7.30 to 0.7.31

6

CHANGELOG.md

@@ -5,2 +5,8 @@ # Changelog

## 0.7.31 - 2023-07-25
### Changed
- Update smoldot@[version 1.0.13](https://github.com/smol-dot/smoldot/blob/main/wasm-node/CHANGELOG.md#1013---2023-07-16)[#1493](https://github.com/paritytech/substrate-connect/pull/1493)
## 0.7.30 - 2023-07-10

@@ -7,0 +13,0 @@

9

package.json
{
"name": "@substrate/connect",
"version": "0.7.30",
"version": "0.7.31",
"description": "Substrate-connect to Smoldot clients. Using either substrate extension with predefined clients or an internal smoldot client based on chainSpecs provided.",

@@ -32,3 +32,3 @@ "author": "Parity Team <admin@parity.io>",

"pretest": "yarn build",
"test": "node --no-warnings --experimental-vm-modules ../../node_modules/jest/bin/jest.js --colors --coverage",
"test": "vitest",
"deep-clean": "yarn clean && rm -rf node_modules",

@@ -43,7 +43,8 @@ "clean": "rm -rf dist tsconfig.tsbuildinfo",

"@substrate/connect-extension-protocol": "^1.0.1",
"smoldot": "1.0.11"
"smoldot": "1.0.13"
},
"devDependencies": {
"eslint": "^8.44.0"
"eslint": "^8.44.0",
"vitest": "^0.33.0"
}
}

@@ -0,1 +1,5 @@

/**
* @vitest-environment jsdom
*/
import { it, describe, expect } from "vitest"
import { randomBytes } from "crypto"

@@ -11,14 +15,17 @@ import {

import { WellKnownChain } from "../WellKnownChain.js"
;(globalThis.crypto as any) = {
getRandomValues: <T extends ArrayBufferView | null>(arr: T) => {
if (!arr) return arr
const tmp = new Uint8Array(arr.byteLength)
const randomBytesBuffer = randomBytes(tmp.length)
tmp.set(randomBytesBuffer)
const test = new DataView(arr.buffer)
for (let i = 0; i < tmp.length; i++) {
test.setUint8(i, tmp[i])
}
return arr
},
if (!globalThis.crypto) {
;(globalThis.crypto as any) = {
getRandomValues: <T extends ArrayBufferView | null>(arr: T) => {
if (!arr) return arr
const tmp = new Uint8Array(arr.byteLength)
const randomBytesBuffer = randomBytes(tmp.length)
tmp.set(randomBytesBuffer)
const test = new DataView(arr.buffer)
for (let i = 0; i < tmp.length; i++) {
test.setUint8(i, tmp[i])
}
return arr
},
}
}

@@ -25,0 +32,0 @@

// eslint-disable-next-line import/no-extraneous-dependencies
import { jest } from "@jest/globals"
import { beforeEach, beforeAll, it, describe, expect, vi } from "vitest"
import type { AddChainOptions, ClientOptions } from "smoldot"
import { WellKnownChain } from "../WellKnownChain"
import { ScClient } from "./types"

@@ -48,4 +47,4 @@ class SdAlreadyDestroyedError extends Error {

) => {
let _remove = jest.fn<() => []>()
let _sendJsonRpc = jest.fn<(rpc: string) => void>()
let _remove = vi.fn()
let _sendJsonRpc = vi.fn()
return {

@@ -74,3 +73,3 @@ _addChainOptions: addChainOptions,

const terminate = jest.fn()
const terminate = vi.fn()

@@ -109,4 +108,4 @@ return {

jest.unstable_mockModule("smoldot", mockSmoldotLightFactory)
jest.unstable_mockModule("./specs/index.js", () => ({
vi.doMock("smoldot", mockSmoldotLightFactory)
vi.doMock("./specs/index.js", () => ({
getSpec: (wellKnownChain: string) => `fake-${wellKnownChain}-spec`,

@@ -118,57 +117,63 @@ }))

let createScClient: () => ScClient
beforeAll(async () => {
;({ createScClient } = await import("./smoldot-light"))
mockedSmoldotLight = (await import("smoldot")) as unknown as MockSmoldotLight
mockedSmoldotLight = mockSmoldotLightFactory as unknown as MockSmoldotLight
})
beforeEach(() => {
vi.resetModules()
})
describe("SmoldotConnect::smoldot", () => {
describe("client", () => {
it("does not eagerly instantiate the client", () => {
createScClient()
expect(mockedSmoldotLight.getLatestClient()).toBeUndefined()
import("./smoldot-light").then((smoldot) => {
smoldot.createScClient()
mockedSmoldotLight =
mockSmoldotLightFactory as unknown as MockSmoldotLight
expect(mockedSmoldotLight.start).toBeUndefined()
})
})
it("terminates the internal client when all the chains, from all clients, have been removed", async () => {
const { addWellKnownChain } = createScClient()
const { addChain } = createScClient()
it("terminates the internal client when all the chains, from all clients, have been removed", () => {
import("./smoldot-light").then(async (smoldot) => {
const { addWellKnownChain, addChain } = smoldot.createScClient()
const chain1 = await addWellKnownChain("" as WellKnownChain)
const client = mockedSmoldotLight.getLatestClient()
let chain1 = await addWellKnownChain("" as WellKnownChain)
const client = mockedSmoldotLight?.getLatestClient()
let chain2 = await addChain("")
expect(client).toBe(mockedSmoldotLight.getLatestClient())
const chain2 = await addChain("")
expect(client).toBe(mockedSmoldotLight.getLatestClient())
chain1.remove()
expect(client.terminate).not.toHaveBeenCalled()
chain1.remove()
expect(client.terminate).not.toHaveBeenCalled()
chain2.remove()
expect(client.terminate).toHaveBeenCalled()
const chain3 = await addWellKnownChain("" as WellKnownChain)
expect(mockedSmoldotLight.getLatestClient()).not.toBe(client)
expect(
mockedSmoldotLight.getLatestClient().terminate,
).not.toHaveBeenCalled()
chain3.remove()
expect(mockedSmoldotLight.getLatestClient().terminate).toHaveBeenCalled()
chain2.remove()
expect(client.terminate).toHaveBeenCalled()
let chain3 = await addWellKnownChain("" as WellKnownChain)
expect(mockedSmoldotLight.getLatestClient()).not.toBe(client)
expect(
mockedSmoldotLight.getLatestClient().terminate,
).not.toHaveBeenCalled()
chain3.remove()
expect(
mockedSmoldotLight.getLatestClient().terminate,
).toHaveBeenCalled()
})
})
it("handles race conditions on the client when adding/removing chains", async () => {
const { addChain } = createScClient()
const { addChain: addChain2 } = createScClient()
it("handles race conditions on the client when adding/removing chains", () => {
import("./smoldot-light").then(async (smoldot) => {
const { addChain } = smoldot.createScClient()
const { addChain: addChain2 } = smoldot.createScClient()
const chain1 = await addChain("")
const client = mockedSmoldotLight.getLatestClient()
let chain1 = await addChain("")
const client = mockedSmoldotLight.getLatestClient()
const chain2Promise = addChain2("")
chain1.remove()
expect(client.terminate).not.toHaveBeenCalled()
const chain2Promise = addChain2("")
chain1.remove()
expect(client.terminate).not.toHaveBeenCalled()
const chain2 = await chain2Promise
chain2.remove()
expect(client.terminate).toHaveBeenCalled()
let chain2 = await chain2Promise
chain2.remove()
expect(client.terminate).toHaveBeenCalled()
})
})

@@ -178,53 +183,52 @@ })

describe("chain", () => {
it("propagates the correct chainSpec to smoldot", async () => {
const { addChain, addWellKnownChain } = createScClient()
const chainSpec = "testChainSpec"
await addChain(chainSpec)
it("propagates the correct chainSpec to smoldot", () => {
import("./smoldot-light").then(async (smoldot) => {
const { addChain, addWellKnownChain } = smoldot.createScClient()
const chainSpec = "testChainSpec"
await addChain(chainSpec)
let mockedChain = mockedSmoldotLight.getLatestClient()._getLatestChain()
expect(mockedChain._addChainOptions.chainSpec).toEqual(chainSpec)
let mockedChain = mockedSmoldotLight.getLatestClient()._getLatestChain()
expect(mockedChain._addChainOptions.chainSpec).toEqual(chainSpec)
await addWellKnownChain(WellKnownChain.polkadot)
mockedChain = mockedSmoldotLight.getLatestClient()._getLatestChain()
expect(mockedChain._addChainOptions.chainSpec).toEqual(
"fake-polkadot-spec",
)
await addWellKnownChain(WellKnownChain.polkadot)
await addWellKnownChain(WellKnownChain.ksmcc3)
mockedChain = mockedSmoldotLight.getLatestClient()._getLatestChain()
expect(mockedChain._addChainOptions.chainSpec).toEqual(
"fake-ksmcc3-spec",
)
mockedChain = mockedSmoldotLight.getLatestClient()._getLatestChain()
expect(mockedChain._addChainOptions.chainSpec).toEqual(
"fake-polkadot-spec",
)
await addWellKnownChain(WellKnownChain.ksmcc3)
mockedChain = mockedSmoldotLight.getLatestClient()._getLatestChain()
expect(mockedChain._addChainOptions.chainSpec).toEqual("fake-ksmcc3-spec")
await addWellKnownChain(WellKnownChain.rococo_v2_2)
mockedChain = mockedSmoldotLight.getLatestClient()._getLatestChain()
expect(mockedChain._addChainOptions.chainSpec).toEqual(
"fake-rococo_v2_2-spec",
)
await addWellKnownChain(WellKnownChain.rococo_v2_2)
mockedChain = mockedSmoldotLight.getLatestClient()._getLatestChain()
expect(mockedChain._addChainOptions.chainSpec).toEqual(
"fake-rococo_v2_2-spec",
)
})
})
it("propagates the correct potentialRelayChainIds to smoldot", async () => {
const { addChain } = createScClient()
const prevChains = await Promise.all(
Array(3)
.fill(null)
.map(() => addChain("")),
)
prevChains[0].remove()
await addChain("")
const mockedChains = mockedSmoldotLight
.getLatestClient()
._getChains()
.slice(-4)
const lastMockedChain = mockedChains[3]
expect(lastMockedChain._addChainOptions.potentialRelayChains).toEqual([
mockedChains[1],
mockedChains[2],
])
it("propagates the correct potentialRelayChainIds to smoldot", () => {
import("./smoldot-light").then(async (smoldot) => {
const { addChain } = smoldot.createScClient()
let prevChains = await Promise.all(
Array(3)
.fill(null)
.map(() => addChain("")),
)
prevChains[0].remove()
await addChain("")
const mockedChains = mockedSmoldotLight
.getLatestClient()
._getChains()
.slice(-4)
const lastMockedChain = mockedChains[3]
expect(lastMockedChain._addChainOptions.potentialRelayChains).toEqual([
mockedChains[1],
mockedChains[2],
])
})
})
})
})

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc