-
Notifications
You must be signed in to change notification settings - Fork 9
Conversation
I explored how to get unique tests users doing something like
But, this is a bit challenging given that
There are a few ways to bypass the
|
5e23a1a
to
96c726c
Compare
Yeah, imports probably won't work well. You'll want to add logic to the provider itself (override Then, you'll want to add a custom function to the codegen to call this route. The easiest way will be to override type ArrayOfLength<
T,
L extends number,
A extends T[] = [],
> = number extends L ? T[]
: L extends A["length"] ? A
: ArrayOfLength<T, L, [...A, T]>
export async function getTestUsers<N extends number>(count: N): Promise<ArrayOfLength<C.Sr25519, N>>
export async function getTestUsers(count: number): Promise<C.Sr25519[]> {
const userIds: number[] = await fetch(`.../testUsers?count=${count}`).then(r => r.json())
return userIds.map(C.testUser)
} Then, it can be used like import { getTestUsers } from "polkadot_dev"
const [alex, bill, carol] = await getTestUsers(3) |
@tjjfvi I've just spoke with @harrysolovay and he suggested a similar approach. Thank you both |
Should we model this as a Rune factory instead? import { System, user } from "polkadot_dev/mod.ts"
const alice = user()
const result = await System.Account.value(alice.publicKey).run()
console.log(result) And let's also make sure to include an |
We need it to persist state between runs, so it wouldn't work well as a rune at the moment. |
Ah, I see. Good point. |
6022a28
to
4d177de
Compare
@tjjfvi @harrysolovay Would you give it a quick pass to validate the provider I'd like to get a quick feedback before refactoring them for the |
@tjjfvi @harrysolovay Shall I move these That way the Thoughts? |
@harrysolovay @tjjfvi I just realized that the So adding the overrides to Maybe I need to change the design by extracting the user testing stuff in a new class and then use composition instead of inheritance. Thoughts? |
Perhaps we should just merge the dev and contracts providers |
I've just meet with Harry and decided to add a |
f4e7b6d
to
c140f6b
Compare
…L_FUNDS to FrameBinProvider
Co-authored-by: Harry Solovay <harrysolovay@gmail.com>
7fd3071
to
179e8a7
Compare
providers/frame/common.ts
Outdated
let index = cache.count | ||
const newCount = index + count | ||
if (newCount < DEFAULT_TEST_USER_COUNT) cache.count = newCount | ||
else index = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last thing: per @tjjfvi's recommendation, let's actually return an error response here. Then we can delete the if (index === -1)
check in the client users
fn.
Resolves #515
Update
PolkadotDevProvider
/ContractsDevProvider
providers with a custom chain spec and add the/user_i
endpointsThe custom chain spec add test accounts with an initial balance.
How to test?
Run the following example to validate that a test account has an initial balance.
To test the API