简体   繁体   English

ExecutionError“:”智能合约恐慌:在运行测试时出现“应在使用前初始化”错误时恐慌:部署[NEAR PROTOCOL]

[英]ExecutionError":"Smart contract panicked: panicked at 'Should be initialized before usage' error while running test:deploy [NEAR PROTOCOL]

I am trying to run 'yarn test:deploy' on this repo Coin Flip and getting all the test cases failed.我正在尝试在此 repo Coin Flip上运行“yarn test:deploy”,但所有测试用例都失败了。 I haven't edited the code yet.我还没有编辑代码。 This is the terminal output I am encountering:这是我遇到的终端 output:

yarn run v1.22.17 $ yarn dev:deploy && yarn test $ yarn build:contracts && rm -rf neardev && (near dev-deploy || exit 0) && yarn patch:config $ (cd contracts &&./build.sh) warning: unused imports: Base58PublicKey , Promise , PublicKey --> src/lib.rs:3:44 | yarn run v1.22.17 $ yarn dev:deploy && yarn test $ yarn build:contracts && rm -rf neardev && (near dev-deploy || exit 0) && yarn patch:config $ (cd contracts &&./build.sh)警告:未使用的导入: Base58PublicKeyPromisePublicKey --> src/lib.rs:3:44 | 3 | 3 | env, near_bindgen, AccountId, Balance, PublicKey, Promise, | env, near_bindgen, AccountId, 余额, PublicKey, Promise, |
^^^^^^^^^ ^^^^^^^ 4 | ^^^^^^^^^ ^^^^^^^ 4 | collections::{ UnorderedMap }, 5 | collections::{ UnorderedMap }, 5 |
json_types::{ U128, Base58PublicKey }, | json_types::{ U128, Base58PublicKey }, |
^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^ | = note: #[warn(unused_imports)] on by default = 注意: #[warn(unused_imports)]默认开启

warning: unused import: serde::Serialize --> src/lib.rs:7:5 |警告:未使用的导入: serde::Serialize --> src/lib.rs:7:5 | 7 | 7 | use serde::Serialize;使用 serde::序列化; | | ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^

warning: basic-token (lib) generated 2 warnings Finished release [optimized] target(s) in 0.10s Starting deployment.警告: basic-token (lib) 生成 2 个警告 0.10 秒内完成发布 [优化] 目标 开始部署。 Account id: dev-1643646762507-80701581766916, node: https://rpc.tes.net.near.org , helper: https://helper.tes.net.near.org , file: ./out/main.wasm Transaction Id EgJ3v7HW5oea4aUmWN35E8DBD3DznRz8pKReWaRdiAx1 Done deploying to dev-1643646762507-80701581766916 $ node./utils/patch-config.js Done.帐户 ID:dev-1643646762507-80701581766916,节点: https://rpc.tes.net.near.org ,助手: https://helper.tes.net.near.org ,文件:./out/main.wasm事务 ID EgJ3v7HW5oea4aUmWN35E8DBD3DznRz8pKReWaRdiAx1 完成部署到 dev-1643646762507-80701581766916 $ node./utils/patch-config.js 完成。 $ REACT_APP_ENV=dev jest app.test.js --useStderr console:log Loading Credentials. $ REACT_APP_ENV=dev jest app.test.js --useStderr console:log 加载凭证。 /root/.near-credentials/tes.net/dev-1643646762507-80701581766916.json /root/.near-credentials/tes.net/dev-1643646762507-80701581766916.json

 at Object.<anonymous> (test/near-utils.js:16:9)

console.log Receipts: JCteRULCHjv3xCqUBQrrkGibgNMFPFzp2aryB3tSpB2r, 4yzsCsEX8w13T3S1jnYTnrHwfwh8Va7b5BMCHgALqke7 console.log 收据:JCteRULCHjv3xCqUBQrrkGibgNMPFFzp2aryB3tSpB2r,4yzsCsEX8w13T3S1jnYTnrHwfwh8Va7b5BMCHgALqke7

 at Account.printLogsAndFailures (node_modules/near-api-js/lib/account.js:62:21)

console.warn Failure [test-1643646780358-957084]: Error: {"index":0,"account_id":"test-1643646780358-957084","predecessor_id":"dev-1643646762507-80701581766916","registrar_account_id":"registrar","kind":{"account_id":"test-1643646780358-957084","registrar_account_id":"registrar","predecessor_id":"dev-1643646762507-80701581766916"}} console.warn失败 [test-1643646780358-957084]:错误:{“index”:0,“account_id”:“test-1643646780358-957084”,“predecessor_id”:“dev-1643646762507-80701581766916”,“registrar_account_id”:“注册商”,“种类”:{“account_id”:“test-1643646780358-957084”,“registrar_account_id”:“注册商”,“predecessor_id”:“dev-1643646762507-80701581766916”}}

 30 | const contractAccount = new Account(connection, contractName); 31 | const newKeyPair = KeyPair.fromRandom("ed25519"); > 32 | await contractAccount.createAccount( | ^ 33 | accountId, 34 | newKeyPair.publicKey, 35 | new BN(parseNearAmount(fundingAmount)) at Account.printLogsAndFailures (node_modules/near-api-js/lib/account.js:65:25) at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:144:14) at createAccount (test/test-utils.js:32:3) at getAccount (test/test-utils.js:95:10) at Object.<anonymous> (test/app.test.js:20:11)

console.log Receipts: DbXqegvztxpwYgaAhn5ougLoa6SFCJqK7WVPL2UBfG5H, GWECkQApTXTdNGRPUabuF3grVK451PXBwX5e5qU4NtaF console.log 收据:DbXqegvztxpwYgaAhn5ougLoa6SFCJqK7WVPL2UBfG5H,GWECkQApTXTdNGRPUabuF3grVK451PXBwX5e5qU4NtaF

 at Account.printLogsAndFailures (node_modules/near-api-js/lib/account.js:62:21)

console.warn Failure [dev-1643646762507-80701581766916]: Error: {"index":0,"kind":{"ExecutionError":"Smart contract panicked: panicked at 'Should be initialized before usage', src/lib.rs:25:9"}} console.warn Failure [dev-1643646762507-80701581766916]: Error: {"index":0,"kind":{"ExecutionError":"Smart contract paniced: paniced at 'Should be initialized before usage', src/lib.rs :25:9"}}

 29 | test('check deposit', async () => { 30 | contract = await getContract(alice) > 31 | await contract.deposit({}, GAS, parseNearAmount('19')); | ^ 32 | const credits = await contract.get_credits({ account_id: alice.accountId }) 33 | expect(credits).toEqual(parseNearAmount('19')) 34 | }); at Account.printLogsAndFailures (node_modules/near-api-js/lib/account.js:65:25) at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:144:14) at node_modules/near-api-js/lib/contract.js:49:39 at Object.<anonymous> (test/app.test.js:31:3)

console.log Receipt: CETdj9Wn8idE52xn9pRWVq1MQy3ADWofcxNcg9sYX6Ed console.log 回执:CETdj9Wn8idE52xn9pRWVq1MQy3ADWofcxNcg9sYX6Ed

 at Account.printLogsAndFailures (node_modules/near-api-js/lib/account.js:62:21)

console.warn Failure [dev-1643646762507-80701581766916]: Error: {"index":0,"kind":{"ExecutionError":"Smart contract panicked: panicked at 'Should be initialized before usage', src/lib.rs:25:9"}} console.warn Failure [dev-1643646762507-80701581766916]: Error: {"index":0,"kind":{"ExecutionError":"Smart contract paniced: paniced at 'Should be initialized before usage', src/lib.rs :25:9"}}

 37 | 38 | for (let i = 0; i < 5; i++) { > 39 | const rand = await contract.play({}, GAS); | ^ 40 | console.log(rand) 41 | const credits = await contract.get_credits({ account_id: alice.accountId }) 42 | console.log(credits) at Account.printLogsAndFailures (node_modules/near-api-js/lib/account.js:65:25) at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:144:14) at node_modules/near-api-js/lib/contract.js:49:39 at Object.<anonymous> (test/app.test.js:39:26)

FAIL test/app.test.js (17.076 s) deploy contract dev-1643646762507-80701581766916 ✕ contract hash (3 ms) ✕ check deposit (3837 ms) ✕ check play (2368 ms) FAIL test/app.test.js(17.076 秒)部署合约 dev-1643646762507-80701581766916 ✕ 合约 hash(3 毫秒)✕ 支票存款(3837 毫秒)✕ 支票播放(2368 毫秒)

deploy contract dev-1643646762507-80701581766916 › contract hash 部署合约 dev-1643646762507-80701581766916 › 合约 hash

 {"index":0,"account_id":"test-1643646780358-957084","predecessor_id":"dev-1643646762507-80701581766916","registrar_account_id":"registrar","kind":{"account_id":"test-1643646780358-957084","registrar_account_id":"registrar","predecessor_id":"dev-1643646762507-80701581766916"}} 30 | const contractAccount = new Account(connection, contractName); 31 | const newKeyPair = KeyPair.fromRandom("ed25519"); > 32 | await contractAccount.createAccount( | ^ 33 | accountId, 34 | newKeyPair.publicKey, 35 | new BN(parseNearAmount(fundingAmount)) at Object.parseResultError (node_modules/near-api-js/lib/utils/rpc_errors.js:48:29) at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:151:36) at createAccount (test/test-utils.js:32:3) at getAccount (test/test-utils.js:95:10) at Object.<anonymous> (test/app.test.js:20:11)

deploy contract dev-1643646762507-80701581766916 › check deposit 部署合约 dev-1643646762507-80701581766916 › 支票存款

{"index":0,"account_id":"test-1643646780358-957084","predecessor_id":"dev-1643646762507-80701581766916","registrar_account_id":"registrar","kind":{"account_id":"test-1643646780358-957084","registrar_account_id":"registrar","predecessor_id":"dev-1643646762507-80701581766916"}} 30 | const contractAccount = new Account(connection, contractName); 31 | const newKeyPair = KeyPair.fromRandom("ed25519"); > 32 | await contractAccount.createAccount( | ^ 33 | accountId, 34 | newKeyPair.publicKey, 35 | new BN(parseNearAmount(fundingAmount)) at Object.parseResultError (node_modules/near-api-js/lib/utils/rpc_errors.js:48:29) at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:151:36) at createAccount (test/test-utils.js:32:3) at getAccount (test/test-utils.js:95:10) at Object.<anonymous> (test/app.test.js:20:11)

deploy contract dev-1643646762507-80701581766916 › check deposit 部署合约 dev-1643646762507-80701581766916 › 支票存款

{"index":0,"kind":{"ExecutionError":"Smart contract panicked: panicked at 'Should be initialized before usage', src/lib.rs:25:9"}} 29 | test('check deposit', async () => { 30 | contract = await getContract(alice) > 31 | await contract.deposit({}, GAS, parseNearAmount('19')); | ^ 32 | const credits = await contract.get_credits({ account_id: alice.accountId }) 33 | expect(credits).toEqual(parseNearAmount('19')) 34 | }); at Object.parseResultError (node_modules/near-api-js/lib/utils/rpc_errors.js:48:29) at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:151:36) at node_modules/near-api-js/lib/contract.js:49:39 at Object.<anonymous> (test/app.test.js:31:3)

deploy contract dev-1643646762507-80701581766916 › check play 部署合约 dev-1643646762507-80701581766916 › 检查播放

{"index":0,"account_id":"test-1643646780358-957084","predecessor_id":"dev-1643646762507-80701581766916","registrar_account_id":"registrar","kind":{"account_id":"test-1643646780358-957084","registrar_account_id":"registrar","predecessor_id":"dev-1643646762507-80701581766916"}} 30 | const contractAccount = new Account(connection, contractName); 31 | const newKeyPair = KeyPair.fromRandom("ed25519"); > 32 | await contractAccount.createAccount( | ^ 33 | accountId, 34 | newKeyPair.publicKey, 35 | new BN(parseNearAmount(fundingAmount)) at Object.parseResultError (node_modules/near-api-js/lib/utils/rpc_errors.js:48:29) at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:151:36) at createAccount (test/test-utils.js:32:3) at getAccount (test/test-utils.js:95:10) at Object.<anonymous> (test/app.test.js:20:11)

deploy contract dev-1643646762507-80701581766916 › check play 部署合约 dev-1643646762507-80701581766916 › 检查播放

{"index":0,"kind":{"ExecutionError":"Smart contract panicked: panicked at 'Should be initialized before usage', src/lib.rs:25:9"}} 37 | 38 | for (let i = 0; i < 5; i++) { > 39 | const rand = await contract.play({}, GAS); | ^ 40 | console.log(rand) 41 | const credits = await contract.get_credits({ account_id: alice.accountId }) 42 | console.log(credits) at Object.parseResultError (node_modules/near-api-js/lib/utils/rpc_errors.js:48:29) at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:151:36) at node_modules/near-api-js/lib/contract.js:49:39 at Object.<anonymous> (test/app.test.js:39:26)
> Test Suites: 1 failed, 1 total
> Tests:       3 failed, 3 total
> Snapshots:   0 total
> Time:        17.145 s, estimated 35 s
> Ran all test suites matching /app.test.js/i. error Command failed with exit
> code 1. info Visit https://yarnpkg.com/en/docs/cli/run for
> documentation about this command. error Command failed with exit code
> 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What am I doing wrong?我究竟做错了什么?

This is the state of my machine:这是我机器的 state:

node --version
v16.13.2

npm --version
8.1.2

near --version
3.1.0

rustc --version
rustc 1.58.1 (db9d1b20b 2022-01-20)

yarn --version
1.22.17

Looks like there are a lot of dependencies needed before running the project.看起来在运行项目之前需要很多依赖项。 From the top of the Readme - npm, node (latest versions) and rust lang seem like a requirement.从自述文件的顶部 - npm、节点(最新版本)和 rust lang 似乎是一个要求。 Try following the readme step by step and see if the errors persist.尝试逐步按照自述文件进行操作,看看错误是否仍然存在。

the error you're seeing is because you need to call the init function on the contract.您看到的错误是因为您需要在合同上调用init function。

Please you need to initialize your contract after deployment.请在部署后初始化您的合同。

run: near call mycontract.myaccount.tes.net init --accountId=myaccount.tes.net运行: near call mycontract.myaccount.tes.net init --accountId=myaccount.tes.net

Then call you smartcontract.然后叫你智能合约。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM