2

There is a problem i have with a new DAPP tutorial i'm looking at from this YouTube video:

I have an issue from for testing of my contract. when i run the "truffle test": it returns the following error:

Using network 'development'.

Compiling .\contracts\Election.sol...
ReferenceError: artifact is not defined
    at Object.<anonymous> (C:\DAPP\election\test\election.js:1:16)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at C:\Users\User\AppData\Roaming\npm\node_modules\truffle\node_modules\mocha\lib\mocha.js:231:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (C:\Users\User\AppData\Roaming\npm\node_modules\truffle\node_modules\mocha\lib\mocha.js:228:14)
    at Mocha.run (C:\Users\User\AppData\Roaming\npm\node_modules\truffle\node_modules\mocha\lib\mocha.js:536:10)
    at C:\Users\User\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-core\lib\test.js:125:1
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

I'm wondering i can fix the issue and complete the testing. Also, Here are the details EVN detail:

Truffle v4.1.14 (core: 4.1.14) Solidity v0.4.24 (solc-js)

Here is the Election.js

var Election = artifact.require("./Election.sol");

contract ("Election", function(accounts){

    it("Initialize with 2 candidates",function(){
        return Election.deployed().then(function(instance) {
            return instance.candidatesCount();
        }).then(function(count) {
            assert.equal(count,2);      
        });
    });
});
  • What is the code for election.js? – Raghav Sood Aug 20 '18 at 10:49
  • var Election = artifact.require("./Election.sol"); contract ("Election", function(accounts){ it("Initialize with 2 candidates",function(){ return Election.deployed().then(function(instance) { return instance.candidatesCount(); }).then(function(count) { assert.equal(count,2); }); }); }); – David Mood Aug 20 '18 at 10:54
0

It's just a typo: instead of artifact.require, try artifacts.require

1

Should confirm that the path to your smart contract is correct?

var Election = artifact.require("./Election.sol");

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.