AcalaNetwork / chopsticks

Create parallel reality of your Substrate network.
Apache License 2.0
133 stars 80 forks source link

Dry run and further inspect #693

Closed kianenigma closed 6 months ago

kianenigma commented 6 months ago

Somewhat related to what I am hoping to be able to do in https://github.com/polkadot-js/apps/pull/10342

It would be great if I can dry-run, but instead of relying on the html output to inspect the outcome, do that in the PJS Apps.

So I would imagine:

  1. Chopsticks running in one terminal, exposing the RPC
  2. Chopsticks dry-run command in another
  3. Go to Apps to see the outcome

As noted, this would all be possible from the UI once https://github.com/polkadot-js/apps/pull/10342 is done.

I am not sure, but possible if I just run the Chopstick RPC provider, and write a few lines of PJS-API script that does signFake and submit an extrinsic in the normal route, it might all work? not sure.

ermalkaleci commented 6 months ago

Dry-run can be done completely on browser. You can have multiple chains and xcm

qiweiii commented 6 months ago

Don't need to start chopsticks in one terminal before doing a dry-run command, you can just dry-run an extrinsic and see results.

I think what you want is to run chopsticks in a terminal using a custom config file like this: npx @acala-network/chopsticks@latest -c acala.yml

An example config file:

# acala.yml
endpoint: wss://acala-rpc-1.aca-api.network
port: 8000
mock-signature-host: true
block: '4500000'

# Add your account and tokens in import-storage section
import-storage:
  Sudo:
    Key: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
  System:
    Account:
      -
        -
          - 5EkStBVtFxLo7E61FYNVeXMsawW6byg7QCdk42vQMxxB7Gib
        - providers: 1
          data:
            free: 1000000000000000
      -
        -
          - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
        - providers: 1
          data:
            free: 1000000000000000
  Tokens:
    Accounts:
      -
        -
          - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
          - token: AUSD
        - free: 1000000000000000
      -
        -
          - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
          - token: DOT
        - free: 1000000000000000
      -
        -
          - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
          - token: LDOT
        - free: 1000000000000000
      -
        -
          - 5EkStBVtFxLo7E61FYNVeXMsawW6byg7QCdk42vQMxxB7Gib
          - token: AUSD
        - free: 1000000000000000

Then go to pjs app, and set the custom endpoint ws://localhost:8000, click on Switch

image

Now you are using pjs app like normal.


You can also start multiple chain with xcm, using multiple config files: npx @acala-network/chopsticks@latest -- -- xcm -r polkadot.yml -p acala.yml hydradx.yml

Then you can open multiple pjs app tabs and each connect to a different custom endpoint

kianenigma commented 6 months ago

Alright, thanks for the comments. In one experiment, dry-run closed after I executed a single extrinsic, so there was no opportunity to connect a UI to it, but if that works, that is already good enough for a single extrinsic.

For more flexibility, something like this also works well:

export async function fakeSignForChopsticks(api: ApiPromise, sender: string | AccountId, tx: SubmittableExtrinsic<'promise'>): Promise<void> {
    const account = await api.query.system.account(sender)
    console.log(account.toHuman())
    const options = {
        nonce: account.nonce,
        genesisHash: api.genesisHash,
        runtimeVersion: api.runtimeVersion,
        blockHash: api.genesisHash,
    };
    const mockSignature = new Uint8Array(64)
    mockSignature.fill(0xcd)
    mockSignature.set([0xde, 0xad, 0xbe, 0xef])
    tx.signFake(sender, options)
    tx.signature.set(mockSignature)
}

OR you can reuse the methods provided in import { signFakeWithApi, signFake } from '@acala-network/chopsticks-utils', although I got some weird mismatch in the versions of @polkadot/api while using those, so I re-created it.

No action item needed here, so will close.

kianenigma commented 6 months ago

@qiweiii to re-read your answer, and to reply:

  1. Your first suggestion is to give the Chopsticks provider to the UI and use the UI, but then you cannot submit arbitrary stuff from the UI.
  2. You mention use dry-run, but as noted the default dry-run closes the connection once it is done (it is probably dead simple to tweak this)
xlc commented 6 months ago

it is possible to invoke dev rpcs from UI using the js page and it can be used to ask chopsticks to perform various including jumping blocks to future or modify storages directly

another thing that maybe we can do is create a new page in pjs apps to make invoke those dev rpc easier