Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Kusama Asset Hub PreImage > Kusama Asset Hub PreImage > preimage tests > preimage empty test > note empty preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Noted",
"section": "preimage",
},
]
`;

exports[`Kusama Asset Hub PreImage > Kusama Asset Hub PreImage > preimage tests > preimage empty test > unnote empty preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Cleared",
"section": "preimage",
},
]
`;

exports[`Kusama Asset Hub PreImage > Kusama Asset Hub PreImage > preimage tests > preimage ensure updated test (fees due) > ensure updated preimage events 1`] = `[]`;

exports[`Kusama Asset Hub PreImage > Kusama Asset Hub PreImage > preimage tests > preimage ensure updated test (no fees due) > ensure updated preimage events 1`] = `[]`;

exports[`Kusama Asset Hub PreImage > Kusama Asset Hub PreImage > preimage tests > preimage single note and unnote test > note preimage events 1`] = `
[
{
Expand All @@ -23,3 +51,47 @@ exports[`Kusama Asset Hub PreImage > Kusama Asset Hub PreImage > preimage tests
},
]
`;

exports[`Kusama Asset Hub PreImage > failure tests > preimage oversized test > note oversized preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Noted",
"section": "preimage",
},
]
`;

exports[`Kusama Asset Hub PreImage > failure tests > preimage repeated note and unnote test > note preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Noted",
"section": "preimage",
},
]
`;

exports[`Kusama Asset Hub PreImage > failure tests > preimage repeated note and unnote test > repeat note preimage events 1`] = `[]`;

exports[`Kusama Asset Hub PreImage > failure tests > preimage repeated note and unnote test > repeat unnote preimage events 1`] = `[]`;

exports[`Kusama Asset Hub PreImage > failure tests > preimage repeated note and unnote test > unnote preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Cleared",
"section": "preimage",
},
]
`;

exports[`Kusama Asset Hub PreImage > failure tests > preimage single request and unrequest test as non-root > request preimage events 1`] = `[]`;

exports[`Kusama Asset Hub PreImage > failure tests > preimage single request and unrequest test as non-root > unrequest preimage events 1`] = `[]`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Polkadot Asset Hub PreImage > Polkadot Asset Hub PreImage > preimage tests > preimage empty test > note empty preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Noted",
"section": "preimage",
},
]
`;

exports[`Polkadot Asset Hub PreImage > Polkadot Asset Hub PreImage > preimage tests > preimage empty test > unnote empty preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Cleared",
"section": "preimage",
},
]
`;

exports[`Polkadot Asset Hub PreImage > Polkadot Asset Hub PreImage > preimage tests > preimage ensure updated test (fees due) > ensure updated preimage events 1`] = `[]`;

exports[`Polkadot Asset Hub PreImage > Polkadot Asset Hub PreImage > preimage tests > preimage ensure updated test (no fees due) > ensure updated preimage events 1`] = `[]`;

exports[`Polkadot Asset Hub PreImage > Polkadot Asset Hub PreImage > preimage tests > preimage single note and unnote test > note preimage events 1`] = `
[
{
Expand All @@ -23,3 +51,47 @@ exports[`Polkadot Asset Hub PreImage > Polkadot Asset Hub PreImage > preimage te
},
]
`;

exports[`Polkadot Asset Hub PreImage > failure tests > preimage oversized test > note oversized preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Noted",
"section": "preimage",
},
]
`;

exports[`Polkadot Asset Hub PreImage > failure tests > preimage repeated note and unnote test > note preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Noted",
"section": "preimage",
},
]
`;

exports[`Polkadot Asset Hub PreImage > failure tests > preimage repeated note and unnote test > repeat note preimage events 1`] = `[]`;

exports[`Polkadot Asset Hub PreImage > failure tests > preimage repeated note and unnote test > repeat unnote preimage events 1`] = `[]`;

exports[`Polkadot Asset Hub PreImage > failure tests > preimage repeated note and unnote test > unnote preimage events 1`] = `
[
{
"data": {
"hash_": "(hash)",
},
"method": "Cleared",
"section": "preimage",
},
]
`;

exports[`Polkadot Asset Hub PreImage > failure tests > preimage single request and unrequest test as non-root > request preimage events 1`] = `[]`;

exports[`Polkadot Asset Hub PreImage > failure tests > preimage single request and unrequest test as non-root > unrequest preimage events 1`] = `[]`;
114 changes: 91 additions & 23 deletions packages/shared/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { ApiPromise } from '@polkadot/api'
import { decodeAddress, encodeAddress } from '@polkadot/keyring'
import type { KeyringPair } from '@polkadot/keyring/types'
import type { EventRecord } from '@polkadot/types/interfaces'
import type { PalletStakingValidatorPrefs } from '@polkadot/types/lookup'
import type { FrameSystemAccountInfo, PalletStakingValidatorPrefs } from '@polkadot/types/lookup'
import type { IsEvent } from '@polkadot/types/metadata/decorate/types'
import type { AnyTuple, Codec, IEvent } from '@polkadot/types/types'
import type { HexString } from '@polkadot/util/types'
Expand Down Expand Up @@ -107,6 +107,79 @@ export type BlockProvider = 'Local' | 'NonLocal'
/** Whether async backing is enabled or disabled on the querying parachain. */
export type AsyncBacking = 'Enabled' | 'Disabled'

/**
* Given a PJS client and a call, modify the `scheduler` pallet's `agenda` storage to execute the list of extrinsics
* in the next block.
*
* The calls can be either inline calls or lookup calls, which in the latter case *must* have been noted
* in the storage of the chain's `preimage` pallet with a `notePreimage` extrinsic.
*
* @param blockProvider Whether the calls are being scheduled on a chain that uses a local or nonlocal block provider.
* This chain's runtime *must* have the scheduler pallet available.
*/
export async function scheduleCallListWithOrigin(
client: {
api: ApiPromise
dev: {
setStorage: (values: StorageValues, blockHash?: string) => Promise<any>
}
},
calls: {
call:
| { Inline: any }
| {
Lookup: {
hash: any
len: any
}
}
origin: any
}[],
blockProvider: BlockProvider = 'Local',
) {
const scheduledBlock = await match(blockProvider)
.with('Local', async () => (await client.api.rpc.chain.getHeader()).number.toNumber() + 1)
.with('NonLocal', async () =>
((await client.api.query.parachainSystem.lastRelayChainBlockNumber()) as any).toNumber(),
)
.exhaustive()

const agenda = [
[
[scheduledBlock],
calls.map(({ call, origin }) => ({
call,
origin,
})),
],
]

await client.dev.setStorage({
Scheduler: {
agenda: agenda,
},
})
}

/**
* Given a PJS client and a list of inline calls with the same origin, modify the `scheduler`
* pallet's `agenda` storage to execute the extrinsic in the next block.
*/
export async function scheduleInlineCallListWithSameOrigin(
client: {
api: ApiPromise
dev: {
setStorage: (values: StorageValues, blockHash?: string) => Promise<any>
}
},
encodedCall: HexString[],
origin: any,
blockProvider: BlockProvider = 'Local',
) {
const callList = encodedCall.map((call) => ({ call: { Inline: call }, origin }))
await scheduleCallListWithOrigin(client, callList, blockProvider)
}

/**
* Given a PJS client and a call, modify the `scheduler` pallet's `agenda` storage to execute the extrinsic in the next
* block.
Expand Down Expand Up @@ -135,28 +208,7 @@ export async function scheduleCallWithOrigin(
origin: any,
blockProvider: BlockProvider = 'Local',
) {
const scheduledBlock = await match(blockProvider)
.with('Local', async () => (await client.api.rpc.chain.getHeader()).number.toNumber() + 1)
.with('NonLocal', async () =>
((await client.api.query.parachainSystem.lastRelayChainBlockNumber()) as any).toNumber(),
)
.exhaustive()

await client.dev.setStorage({
Scheduler: {
agenda: [
[
[scheduledBlock],
[
{
call,
origin: origin,
},
],
],
],
},
})
await scheduleCallListWithOrigin(client, [{ call, origin }], blockProvider)
}

/**
Expand Down Expand Up @@ -487,6 +539,22 @@ export function sortAddressesByBytes(addresses: string[], addressEncoding: numbe
.map((bytes) => encodeAddress(bytes, addressEncoding))
}

/**
* Get the free funds of an account.
*/
export async function getFreeFunds(client: Client<any, any>, address: any): Promise<number> {
const account = (await client.api.query.system.account(address)) as FrameSystemAccountInfo
return account.data.free.toNumber()
}

/**
* Get the reserved funds of an account.
*/
export async function getReservedFunds(client: Client<any, any>, address: any): Promise<number> {
const account = (await client.api.query.system.account(address)) as FrameSystemAccountInfo
return account.data.reserved.toNumber()
}

/**
* Configuration for relay chain tests.
*/
Expand Down
19 changes: 2 additions & 17 deletions packages/shared/src/multisig.proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { type Client, setupBalances, setupNetworks, verifyPureProxy } from '@e2e

import type { KeyringPair } from '@polkadot/keyring/types'
import type { AccountId32 } from '@polkadot/types/interfaces/runtime'
import type { FrameSystemAccountInfo } from '@polkadot/types/lookup'
import type { U8aFixed } from '@polkadot/types-codec'
import { encodeAddress } from '@polkadot/util-crypto'

Expand All @@ -16,6 +15,8 @@ import {
check,
checkEvents,
getBlockNumber,
getFreeFunds,
getReservedFunds,
sortAddressesByBytes,
type TestConfig,
} from './helpers/index.js'
Expand Down Expand Up @@ -86,22 +87,6 @@ async function getAndVerifyMultisigEventData(
return [multisigAddress, multisigExtrinsicIndex, multisigCallHash]
}

/**
* Get the free funds of an account.
*/
async function getFreeFunds(client: Client<any, any>, address: any): Promise<number> {
const account = (await client.api.query.system.account(address)) as FrameSystemAccountInfo
return account.data.free.toNumber()
}

/**
* Get the reserved funds of an account.
*/
async function getReservedFunds(client: Client<any, any>, address: any): Promise<number> {
const account = (await client.api.query.system.account(address)) as FrameSystemAccountInfo
return account.data.reserved.toNumber()
}

/**
* Get the costs for creating a number of proxies.
*/
Expand Down
Loading