gpt4 book ai didi

nearprotocol - 如何针对具有多个契约(Contract)的本地网络运行近 js-api 测试

转载 作者:行者123 更新时间:2023-12-04 01:13:21 25 4
gpt4 key购买 nike

我已经设置了节点:

nearup run localnet --binary-path ~/code/nearcore/target/release
我正在尝试运行一个开玩笑的测试用例:
beforeAll(async function () {
// NOTE: nearlib and nearConfig are made available by near-cli/test_environment
const near = await nearlib.connect(nearConfig)
})
但是,很明显缺少如何在本地节点上创建测试帐户的步骤。这是错误:
 ● Test suite failed to run

Can not sign transactions for account test.near, no matching key pair found in Signer.

at node_modules/near-api-js/lib/account.js:83:23
at Object.exponentialBackoff [as default] (node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24)
at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:80:24)
at Account.createAndDeployContract (node_modules/near-api-js/lib/account.js:176:9)
at LocalTestEnvironment.setup (node_modules/near-cli/test_environment.js:39:9)
也长得像 near-js-api硬编码以仅部署一份合约。我需要测试多个契约(Contract)。如何部署多个合约?来自近 js-api test_environment.js
class LocalTestEnvironment extends NodeEnvironment {
constructor(config) {
super(config);
}

async setup() {
this.global.nearlib = require('near-api-js');
this.global.nearAPI = require('near-api-js');
this.global.window = {};
let config = require('./get-config')();
this.global.testSettings = this.global.nearConfig = config;
const now = Date.now();
// create random number with at least 7 digits
const randomNumber = Math.floor(Math.random() * (9999999 - 1000000) + 1000000);
config = Object.assign(config, {
contractName: 'test-account-' + now + '-' + randomNumber,
accountId: 'test-account-' + now + '-' + randomNumber
});
const keyStore = new nearAPI.keyStores.UnencryptedFileSystemKeyStore(PROJECT_KEY_DIR);
config.deps = Object.assign(config.deps || {}, {
storage: this.createFakeStorage(),
keyStore,
});
const near = await nearAPI.connect(config);

const masterAccount = await near.account(testAccountName);
const randomKey = await nearAPI.KeyPair.fromRandom('ed25519');
const data = [...fs.readFileSync('./out/main.wasm')];
await config.deps.keyStore.setKey(config.networkId, config.contractName, randomKey);
await masterAccount.createAndDeployContract(config.contractName, randomKey.getPublicKey(), data, INITIAL_BALANCE);

await super.setup();
}
Near-js-sdk 本身正在针对神秘的共享测试进行部署
    case 'ci':
return {
networkId: 'shared-test',
nodeUrl: 'https://rpc.ci-testnet.near.org',
masterAccount: 'test.near',
};

最佳答案

How can I deploy multiple contracts?


您可以使用 masterAccount.createAndDeployContracttest_environment.js .除了一些常见的 init 之外,没有什么特别的 - 您可以直接创建测试所需的任何帐户/契约(Contract)。

near-js-sdk itself is deploying against mysterious shared-test


这是可用于运行集成测试的共享网络。除非您想将您的开发工作保密 - 推荐运行测试的方式(因为点击当前可用于测试的最现实的环境)。

However there is obvious step missing how to create test accounts on your local node.


如果您使用 create-near-app 创建项目您可能有相应的 test.near key 在 neardev/项目文件夹已经。这就是为什么上述神秘环境通常开箱即用的原因。
对于您的本地环境,您需要创建 test.near你自己:
NODE_ENV=local near create-account test.near --masterAccount some-existing-account

之后,您可以将 key 复制到本地格式(或仅重新配置 UnencryptedFileSystemKeyStore 以使用 ~/.near-credentials 路径):
cp ~/.near-credentials/local/test.near.json project/dir/neardev/local/test.near.json

关于nearprotocol - 如何针对具有多个契约(Contract)的本地网络运行近 js-api 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64109797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com