Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法读取属性';0';未定义和类型错误:eventAdded.watch不是函数_Javascript_Arrays - Fatal编程技术网

Javascript TypeError:无法读取属性';0';未定义和类型错误:eventAdded.watch不是函数

Javascript TypeError:无法读取属性';0';未定义和类型错误:eventAdded.watch不是函数,javascript,arrays,Javascript,Arrays,我目前正试图基于2018年的教程从GitHub测试源代码,solidity当时使用的是0.5.16版。我目前正在使用块菌v4.1.14。谢谢你的帮助。谢谢在错误列表中,1-4有相同的问题,5&6有相同的问题。错误行将标记为“-->error” 错误列表: 1) Contract: Accounts ...should register a valid verifier information.: TypeError: Cannot read property '0' of

我目前正试图基于2018年的教程从GitHub测试源代码,solidity当时使用的是0.5.16版。我目前正在使用块菌v4.1.14。谢谢你的帮助。谢谢在错误列表中,1-4有相同的问题,5&6有相同的问题。错误行将标记为“-->error”

错误列表:

1) Contract: Accounts
       ...should register a valid verifier information.:
     TypeError: Cannot read property '0' of undefined
      at Context.<anonymous> (test\accounts.test.js:51:32)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  2) Contract: Accounts
       ...should register a another valid verifier information.:
     TypeError: Cannot read property '0' of undefined
      at Context.<anonymous> (test\accounts.test.js:103:32)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  3) Contract: Accounts
       ...should register a valid requester information.:
     TypeError: Cannot read property '0' of undefined
      at Context.<anonymous> (test\accounts.test.js:147:32)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  4) Contract: Accounts
       ...should register another valid requester information.:
     TypeError: Cannot read property '0' of undefined
      at Context.<anonymous> (test\accounts.test.js:186:32)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  5) Contract: Documents
       ...should add a document and mark as verified for requester.:
     TypeError: eventAdded.watch is not a function
      at Context.<anonymous> (test\documents.test.js:32:22)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  6) Contract: Documents
       ...should add another document and mark as rejected from verifier.:
     TypeError: eventAdded.watch is not a function
      at Context.<anonymous> (test\documents.test.js:112:22)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
怀疑5和6与使用的网络浏览器有关,我使用的是谷歌Chrome

完整源代码(document.test.js):

完整源代码(account.test.js):

it('...should register a valid verifier information.', async() => {

    const accounts = await Accounts.deployed();

    let countBefore = await accounts.verifiersCount.call({ from: verifier1 });
    countBefore = countBefore.c[0]; <--ERROR

    let eventEmitted = false;
    const event = accounts.Registered();

    await event.watch((err, res) => {
      if (err) {
        assert.fail('error received on event watch');
      }
      eventEmitted = true;
    });

    await accounts.register(account.name, account.email, account.logo, account.description, account.type, account.verificationPrice, { from: verifier1 });

    const result = await accounts.getAccount.call({ from: verifier1 });

    assert.equal(result[0], account.name, 'the name of the last added item does match the expected value');
    assert.equal(result[1], account.email, 'the email of the last added item does match the expected value');
    assert.equal(result[2], account.logo, 'the logo of the last added item does match the expected value');
    assert.equal(result[3], account.description, 'the description of the last added item does match the expected value');
    assert.equal(result[4].c[0], account.type, 'the type of the last added item does match the expected value');
    assert.equal(result[5].c[0], account.verificationPrice, 'the verificationPrice of the last added item does match the expected value');
    assert.equal(eventEmitted, true, 'adding an item should emit a Registered event');

    let countAfter = await accounts.verifiersCount.call({ from: verifier1 });
    countAfter = countAfter.c[0];

    assert.equal(countAfter, (countBefore + 1), 'verifiers count should be increased');

    const price = await accounts.getPrice.call(verifier1, { from: verifier1 });

    const getVerifier = await accounts.getVerifier.call(countBefore, { from: verifier1 });

    assert.equal(verifier1, getVerifier[0], 'getVerifier should return valid verifier address');

    assert.equal(price.c[0], account.verificationPrice, 'getPrice should return valid verifier price');

  });
it('...should add a document and mark as verified for requester.', async() => {

    const documents = await Documents.deployed();

    let eventAddEmitted = false;
    const eventAdded = documents.DocumentAdded();
    await eventAdded.watch((err, res) => { --> ERROR
      if (err) {
        assert.fail('error received on event watch');
      }
      eventAddEmitted = true;
    });