Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

fix: misc examples broken #846

Merged
merged 6 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/.ignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
multisig/basic.ts
multisig/stash.ts
multisig/virtual.ts
ink/deploy.eg.ts
smoldot.eg.ts
xcm/asset_teleportation.ts
2 changes: 1 addition & 1 deletion examples/multisig/virtual.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const call = Balances.transfer({
})

// Fund Billy and Carol's proxy accounts (existential deposits).
await fundAndRatify("billy", carol).run()
await fundAndRatify("billy", billy).run()
await fundAndRatify("carol", carol).run()

// Retrieve David's final balance.
Expand Down
4 changes: 2 additions & 2 deletions examples/paginate.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ console.log("Account keys:", accountKeys)
$.assert($.sizedArray($.uint8Array, 10), accountKeys)

// Reference the first 10 key-value pairs of a statemint dev chain's uniques class map.
tjjfvi marked this conversation as resolved.
Show resolved Hide resolved
const collectionsEntries = Uniques.Class.entryPage(10, null)
const collectionsEntries = await Uniques.Class.entryPage(10, null).run()

// Each entry should be of type `[number, types.pallet_uniques.types.CollectionDetails]`
console.log("Collections entries:", collectionsEntries)
$.assert(
$.sizedArray($.tuple($.u8, types.pallet_uniques.types.$collectionDetails), 10),
$.sizedArray($.tuple($.u16, types.pallet_uniques.types.$collectionDetails), 10),
harrysolovay marked this conversation as resolved.
Show resolved Hide resolved
collectionsEntries,
)
2 changes: 1 addition & 1 deletion examples/read/now.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ const now = await Timestamp.Now.value().run()
console.log("Now:", now)

// Ensure `now` is of the correct shape.
$.assert($.u32, now)
$.assert($.u64, now)
14 changes: 4 additions & 10 deletions examples/sign/ed25519.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import { assert } from "asserts"
import { Rune } from "capi"
import { signature } from "capi/patterns/signature/polkadot.ts"
import * as ed from "npm:@noble/ed25519"
import { sha512 } from "npm:@noble/hashes/sha512"
import * as ed from "https://esm.sh/@noble/ed25519@1.7.3"
import { Balances, createUsers, System, types } from "westend_dev/mod.js"

const { alexa, billy } = await createUsers()
Expand All @@ -22,23 +21,18 @@ const billyFree = System.Account
const billyFreeInitial = await billyFree.run()
console.log("Billy free initial:", billyFreeInitial)

// Bring your own Ed25519 implementation. In this case, we utilize
// [`noble-ed25519`](https://github.com/paulmillr/noble-ed25519), which
// requires us to specify a sync sha512 hasher implementation.
ed.etc.sha512Sync = (...msgs) => sha512(ed.etc.concatBytes(...msgs))

// Initialize a secret with the `crypto.getRandomValues` builtin.
const secret = crypto.getRandomValues(new Uint8Array(32))

// Get a Rune of the secret-corresponding multiaddress.
const address = types.sp_runtime.multiaddress.MultiAddress
.Id(ed.getPublicKey(secret))
.Id(await ed.getPublicKey(secret))

// Define a `sign` function for later use.
function sign(msg: Uint8Array) {
async function sign(msg: Uint8Array) {
return {
type: "Ed25519" as const,
value: ed.sign(msg, secret),
value: await ed.sign(msg, secret),
}
}

Expand Down
32 changes: 18 additions & 14 deletions examples/tx/handle_errors.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
* (and handling) of dispatch errors.
*/

import { assertRejects } from "asserts"
import { assertInstanceOf } from "asserts"
import { alice, bob, ExtrinsicError } from "capi"
import { signature } from "capi/patterns/signature/polkadot.ts"
import { Balances } from "westend_dev/mod.js"
import { Balances } from "contracts_dev/mod.js"

// The following should reject with an `ExtrinsicError`.
assertRejects(() =>
Balances
.transfer({
value: 1_000_000_000_000_000_000_000_000_000_000_000_000n,
dest: bob.address,
})
.signed(signature({ sender: alice }))
.sent()
.dbgStatus("Transfer:")
.finalizedEvents()
.unhandleFailed()
.run(), ExtrinsicError)
const extrinsicError = await Balances
.transfer({
value: 1_000_000_000_000_000_000_000_000_000_000_000_000n,
dest: bob.address,
})
.signed(signature({ sender: alice }))
.sent()
.dbgStatus("Transfer:")
.inBlockEvents()
.unhandleFailed()
.rehandle(ExtrinsicError)
.run()

// Ensure `extrinsicError` is in fact an instance of `ExtrinsicError`
console.log("The unhandled extrinsic error:", extrinsicError)
assertInstanceOf(extrinsicError, ExtrinsicError)
2 changes: 1 addition & 1 deletion examples/watch.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ let i = 0
// gather and yield the `collection`-described data upon new blocks.
for await (const item of now.iter()) {
console.log(item)
$.assert($.u32, item)
$.assert($.u64, item)
if (++i === 3) break
}