dimanche 26 juillet 2020

Error During 'npm run test': Invalid number of parameters for "undefined". Got 1 expected 0

I get this error message when doing an npm run test. I am running an assertion test for deploying a test lottery app for a smart contract. I have declared the required libraries and provider, and tried similar code with other tests. They worked fine until I tried this test just running to make sure the deployment works, but failed.

Here is my code:

const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const { interface, bytecode } = require('../compile');

let lottery;
let accounts;

beforeEach(async () => {
  accounts = await web3.eth.getAccounts();

  lottery = await new web3.eth.Contract(JSON.parse(interface))
  .deploy({ data: bytecode })
  .send({ from: accounts[0], gas: '1000000'});
});

describe('Lottery', () => {
  it('deploys a contract', () => {
    assert.ok(lottery.options.address);
  });
});

I get this result:

$ npm run test

> Lottery@1.0.0 test /Volumes/Seagate Backup Plus Drive/Development/Udemy/EthereumSolidity/lottery
> mocha



  Inbox
    1) "before each" hook for "deploys a contract"


  0 passing (137ms)
  1 failing

  1) "before each" hook for "deploys a contract":
     Error: Invalid number of parameters for "undefined". Got 1 expected 0!
      at Object.InvalidNumberOfParams (node_modules/web3-core-helpers/src/errors.js:32:16)
      at Object._createTxObject (node_modules/web3-eth-contract/src/index.js:813:22)
      at Contract.deploy (node_modules/web3-eth-contract/src/index.js:611:33)
      at Context.beforeEach (test/inbox.test copy 2.js:16:6)
      at process.internalTickCallback (internal/process/next_tick.js:77:7)



npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Lottery@1.0.0 test: `mocha`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the Lottery@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I am not sure what I am doing wrong during the assertion. Appreciate any thoughts that can help out, thank you.

Aucun commentaire:

Enregistrer un commentaire