near / near-workspaces-js

Write tests once, run them both on NEAR TestNet and a controlled NEAR Sandbox local environment
https://near.github.io/near-workspaces-js/
GNU General Public License v3.0
42 stars 22 forks source link

RPC Query To Get Access Key Info Broken #210

Open BenKurrek opened 1 year ago

BenKurrek commented 1 year ago

In the following code snippet, I attempt to get the access key information for the root account test.near but an error is thrown. (Full test here).

const network = 'sandbox';
let networkConfig = {
      networkId: 'localnet',
      viewAccountId: 'test.near',
      nodeUrl: rpcPort,
      walletUrl: `https://wallet.${network}.near.org`,
helperUrl: `https://helper.${network}.near.org`,
};

const keyStore =  new InMemoryKeyStore();
const near = new Near({
    ...networkConfig,
    keyStore,
    headers: {}
});

const signerId = "test.near";
const account = new Account(near.connection, signerId);
const { provider } = account.connection;

const key = await root.getKey();

const queryUrl = `access_key/${signerId}/${key!.getPublicKey().toString()}`;

const accessKey: any = await provider.query(
    queryUrl,
    ""
);
console.log(`accessKey: ${JSON.stringify(accessKey)}`)

This should return the access key information but instead, it throws an error:

Error (TypedError) {
    context: undefined,
    type: 'UntypedError',
    message: '[-32700] Parse error: Failed parsing args: invalid type: sequence, expected struct RpcQueryRequest',
  }

To reproduce this issue:

  1. clone https://github.com/keypom/trial-accounts
  2. checkout ben/workspaces-bug
  3. install deps
  4. run the test command yarn test
volovyks commented 1 year ago

@BenKurrek There is a lot of code that is complex and not relevant to the problem. Can you please write a separate 3 lines test that throws the same error?

fospring commented 10 months ago

In the following code snippet, I attempt to get the access key information for the root account test.near but an error is thrown. (Full test here).

const network = 'sandbox';
let networkConfig = {
      networkId: 'localnet',
      viewAccountId: 'test.near',
      nodeUrl: rpcPort,
      walletUrl: `https://wallet.${network}.near.org`,
helperUrl: `https://helper.${network}.near.org`,
};

const keyStore =  new InMemoryKeyStore();
const near = new Near({
    ...networkConfig,
    keyStore,
    headers: {}
});

const signerId = "test.near";
const account = new Account(near.connection, signerId);
const { provider } = account.connection;

const key = await root.getKey();

const queryUrl = `access_key/${signerId}/${key!.getPublicKey().toString()}`;

const accessKey: any = await provider.query(
    queryUrl,
    ""
);
console.log(`accessKey: ${JSON.stringify(accessKey)}`)

This should return the access key information but instead, it throws an error:

Error (TypedError) {
    context: undefined,
    type: 'UntypedError',
    message: '[-32700] Parse error: Failed parsing args: invalid type: sequence, expected struct RpcQueryRequest',
  }

To reproduce this issue:

  1. clone https://github.com/keypom/trial-accounts
  2. checkout ben/workspaces-bug
  3. install deps
  4. run the test command yarn test

@BenKurrek I think you could replace

const accessKey: any = await provider.query(
    queryUrl,
    ""
);

to

    const accessKey: any = await provider.query({
        "request_type": "view_access_key",
            "finality": "final",
            "account_id": signerId,
            "public_key": key!.getPublicKey().toString()
        }
    );

according to the near rpc api of access-keys,which will pass the tests