类PublicKey在模式:PublicKey中缺失



描述bug在测试环境较近的笑话上无法使用合同的更改方法。当尝试使用更改方法

时,我得到这个错误。问候语合同测试›应使用set_greeting方法更改合同中的问候语

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. spects:

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!");
});
});

预期行为使用near-test-environment

中的near配置通过两个测试截图如果可以的话,添加屏幕截图来帮助解释你的问题。

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

OS: Mac OS Monterey版本:蒙特利额外的上下文如果有人知道一个绕过这个的方法也会很酷😄

检查是否重新导入任何内容

https://docs.near.org/tools/near-api-js/faq class-x-is-missing-in-schema-publickey

最新更新