This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify local substrate process management (#138)
- Loading branch information
1 parent
fdf9a56
commit afdb686
Showing
14 changed files
with
135 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import * as C from "../mod.ts"; | ||
|
||
const chain = C.test.chain(); | ||
const node = await C.test.node(); | ||
const chain = C.test.chain(node); | ||
const alice = await chain.address.alice.asPublicKeyBytes(); | ||
const result = await chain | ||
.pallet("System") | ||
.entry("Account", alice) | ||
.read(); | ||
|
||
console.log({ result }); | ||
node.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +0,0 @@ | ||
import { assert } from "../_deps/asserts.ts"; | ||
import { Hashers, Sr25519 } from "../bindings/mod.ts"; | ||
import * as M from "../frame_metadata/mod.ts"; | ||
import * as C from "../mod.ts"; | ||
import * as U from "../util/mod.ts"; | ||
|
||
const client = await C.test.rpcClient(); | ||
assert(!(client instanceof Error)); | ||
|
||
const metadataRaw = await client.call("state_getMetadata", []); | ||
assert(metadataRaw.result); | ||
|
||
const metadata = M.fromPrefixedHex(metadataRaw.result); | ||
const lookup = new M.Lookup(metadata); | ||
const pallet = lookup.getPalletByName("System"); | ||
const storageEntry = lookup.getStorageEntryByPalletAndName(pallet, "Account"); | ||
const deriveCodec = M.DeriveCodec(metadata); | ||
const [sr25519, hashers] = await Promise.all([Sr25519(), Hashers()]); | ||
const $storageMapKey = M.$storageMapKey({ | ||
deriveCodec, | ||
hashers, | ||
pallet, | ||
storageEntry, | ||
}); | ||
const alice = sr25519.TestUser.fromName("alice"); | ||
const key = U.hex.encode($storageMapKey.encode(alice.publicKey)) as U.HexString; | ||
const storageRaw = await client.call("state_getStorage", [key]); | ||
console.log(deriveCodec(storageEntry.value).decode(U.hex.decode(storageRaw.result!))); | ||
|
||
// // console.log({ result }); | ||
await client.close(); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export * from "./Base.ts"; | ||
export * from "./messages.ts"; | ||
export * from "./providers/detect.ts"; | ||
export * from "./providers/local.ts"; | ||
export * from "./providers/proxy.ts"; | ||
export * from "./providers/smoldot.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
import { Beacon } from "../Beacon.ts"; | ||
import { Chain } from "../core/Chain.ts"; | ||
import { KnownRpcMethods } from "../known/mod.ts"; | ||
import { LocalBeacon, LocalClientProps } from "../rpc/mod.ts"; | ||
import { ProxyBeacon } from "../rpc/mod.ts"; | ||
import { SubstrateProcess } from "../util/mod.ts"; | ||
import { TestAddresses } from "./Addresses.ts"; | ||
|
||
export class TestChain extends Chain<Beacon<LocalClientProps, KnownRpcMethods>> { | ||
export class TestChain extends Chain<ProxyBeacon<KnownRpcMethods>> { | ||
override address: TestAddresses<this> = new TestAddresses(this); | ||
} | ||
|
||
export function chain() { | ||
return new TestChain( | ||
new LocalBeacon({ | ||
path: "./node-template", | ||
cwd: new URL(".", import.meta.url).pathname, | ||
dev: true, | ||
}), | ||
); | ||
export function chain(process: SubstrateProcess) { | ||
return new TestChain(new ProxyBeacon(process.url)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./Chain.ts"; | ||
export * from "./rpcClient.ts"; | ||
export * from "./node.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { assert } from "../_deps/asserts.ts"; | ||
import { SubstrateProcess, substrateProcess } from "../util/mod.ts"; | ||
|
||
export async function node(): Promise<SubstrateProcess> { | ||
const process = await substrateProcess({ | ||
path: "./node-template", | ||
cwd: new URL(".", import.meta.url).pathname, | ||
dev: true, | ||
}); | ||
assert(!(process instanceof Error)); | ||
return process; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.