0

I'm currently trying to test run source code from GitHub based on a 2018 tutorial where solidity was using version 0.5.16. I'm currently using truffle v4.1.14. Appreciate any help. Thanks! In the error list, 1-4 have the same issues and 5 & 6 have the same issue. The error row will be marked with "--> ERROR"

ERROR LIST:

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)

PARTIAL OF THE SOURCE CODE THAT HAS HIGHLIGHTED TO HAVE PROBLEM (1-4):

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');

  });

PARTIAL OF THE SOURCE CODE THAT HAS HIGHLIGHTED TO HAVE PROBLEM (5&6):

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

suspect that 5 & 6 are related to the web browser used, I'm using Google Chrome. full source code (document.test.js): https://github.com/lionel1702/final-project-RumeelHussain/blob/master/test/documents.test.js

full source code (account.test.js):https://github.com/lionel1702/final-project-RumeelHussain/blob/master/test/accounts.test.js

2
  • What is "c" in "countBefore.c" ? – clement Sep 4 '20 at 9:24
  • I also have no idea what it is, I got the code from GitHub and want to have a test run. I later found out that this code is too old to be run. So many errors will pop up at the same time not many people understand the code. Thank you for trying to help – Lionel Lim Sep 5 '20 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.