首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模式中缺少类PublicKey : publicKey

模式中缺少类PublicKey : publicKey
EN

Stack Overflow用户
提问于 2022-05-13 20:22:46
回答 1查看 60关注 0票数 0

描述无法在接近测试环境的情况下在jest上使用合同更改方法的错误。当我试图使用变更方法时,我会得到这个错误。

问候语合同测试>应使用set_greeting方法更改合同中的问候语

代码语言:javascript
复制
Class PublicKey is missing in schema: publicKey

  at serializeStruct (../../node_modules/borsh/lib/index.js:308:15)
  at serializeField (../../node_modules/borsh/lib/index.js:291:13)
  at ../../node_modules/borsh/lib/index.js:312:13
      at Array.map (<anonymous>)
  at serializeStruct (../../node_modules/borsh/lib/index.js:311:29)
  at Object.serialize (../../node_modules/borsh/lib/index.js:334:5)
  at signTransactionObject (node_modules/near-api-js/lib/transaction.js:219:29)
  at Object.signTransaction (node_modules/near-api-js/lib/transaction.js:237:16)
  at Account.signTransaction (node_modules/near-api-js/lib/account.js:99:16)
  at node_modules/near-api-js/lib/account.js:118:34

再现再现行为的步骤:

克隆https://github.com/hack-a-chain-software/near.monorepo将其粘贴到greeting.spec.ts中:

代码语言:javascript
复制
import "jest";
import { Account, connect, Contract } from "near-api-js";
import { KeyStore } from "near-api-js/lib/key_stores";
import { NearConfig } from "near-api-js/lib/near";

/**
 * @name GreetingContract
 * @description - This will handle the interactions
 * with the contract with better TS types
 */
export class GreetingContract {
  private contract: any;

  /**
   * @constructor
   * @param contract
   */
  constructor(contract: any) {
    this.contract = contract as any;
  }

  /**
   * @description - This method gets the message on chain to the user account_id
   */
  public async getGreeting(params: { account_id: string }): Promise<string> {
    return await this.contract.get_greeting(params);
  }

  /**
   * @description - This method updates the message for the account on NEAR
   */
  public async updateGreeting(params: { message: string }) {
    return await this.contract.set_greeting(params);
  }
}

describe("Greeting Contract Tests", () => {
  let contract: GreetingContract;
  let account: Account;
  let config: NearConfig & {
    contractName: string;
    accountId: string;
    deps: { keyStore: KeyStore };
    testAccountId: string;
  };

  /** @description - Runs Before Everything and initializes the near instances */
  beforeAll(async () => {
    // @ts-ignore
    config = nearConfig;

    const near = await connect(config);

    account = await near.account(config.accountId as string);

    contract = await new GreetingContract(
      new Contract(account, config.contractName, {
        viewMethods: ["get_greeting"],
        changeMethods: ["set_greeting"],
      })
    );
  });

  /** @description - Gets the current greeting from the smart contract and checks if it goes okay */
  it("should get the greeting from the contract using the `get_greeting` method", async () => {
    // Gets the current message for that account id on the contract
    const message = await contract.getGreeting({
      account_id: account.accountId,
    });

    console.log(message);

    expect(message).toEqual("Hello");
  });

  it("should change the greeting from the contract using the `set_greeting` method", async () => {
    // Gets the current message for that account id on the contract
    await contract.updateGreeting({
      message: "Whats Up Darling!",
    });

    const message = await contract.getGreeting({
      account_id: account.accountId,
    });

    expect(message).toEqual("Whats Up Darling!");
  });
});

预期的行为通过了来自近测试环境的使用近配置的两个测试。

如果适用的话,添加截图来帮助解释你的问题。

桌面(请填写以下信息):

OS: Mac蒙特利版本:蒙特利附加上下文,如果有人知道绕过它的方法,这也很酷

EN

回答 1

Stack Overflow用户

发布于 2022-10-20 04:24:32

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72235066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档