4

i have develop a simple smartContract. when i run truffle test it showed the following error:i am new in this so i cant figure it out.

PS F:\pracdap> truffle test

Compiling your contracts...
===========================
√ Fetching solc version list from solc-bin. Attempt #1
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\SimpleSmartContract.sol       
√ Fetching solc version list from solc-bin. Attempt #1
> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "urce file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more informa
--> /F/pracdap/contracts/SimpleSmartContract.sol


> Artifacts written to C:\Users\HP\AppData\Local\Temp\test--1224-GWVOn3NGyps8
> Compiled successfully using:
   - solc: 0.8.3+commit.8d00100c.Emscripten.clang



  Contract: SimpleSmartContract
    1) should be deployed
    > No events were emitted


  0 passing (128ms)
  1 failing

  1) Contract: SimpleSmartContract
       should be deployed:
     Error: SimpleSmartContract has not been deployed to detected network (network/artifact mismatch)
      at Object.checkNetworkArtifactMatch (F:\node\node_modules\truffle\build\webpack:\packages\contract\lib\utils\index.js
      at Function.deployed (F:\node\node_modules\truffle\build\webpack:\packages\contract\lib\contract\constructorMethods.j
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at Context.<anonymous> (test\simpleSmartContract.js:5:33)

Solidity code

pragma solidity >=0.4.22 <0.9.0;

contract SimpleSmartContract {
}

Node js. test code

const SimpleSmartContract = artifacts.require('SimpleSmartContract');

contract('SimpleSmartContract', () => {
    it('should be deployed', async () => {
        const simpleSmartContract = await SimpleSmartContract.deployed();
        assert(simpleSmartContract.address !== '');
    });
});
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
FSO
  • 89
  • 1
  • 7
  • Welcome to StackOverflow. Please edit your question so that it contains a reproducible code that produces the error (in your case, that's probably going to be both Solidity contract and the javascript test/deployer). You can find more tips in the [How to Ask](https://stackoverflow.com/help/how-to-ask) section. – Petr Hejda Apr 03 '21 at 14:41
  • @Pete Hejda solution? – FSO Apr 03 '21 at 16:19

3 Answers3

6

Looks like you have not added a Migration file for your SimpleSmartContract. Create a file named 2_deploy_contracts.js in your Migrations directory. The add the following code in it :


    const SimpleSmartContract = artifacts.require("SimpleSmartContract");
    
    module.exports = function (deployer) {
      deployer.deploy(SimpleSmartContract);
    };

Then try running the test.

Sudipta Basak
  • 179
  • 13
2

try using migration...if is shows any error let me know.

learner
  • 180
  • 10
0
const SimpleSmartContract = artifacts.require("SimpleSmartContract");

module.exports = async function(deployer, _network, accounts) {
  await deployer.deploy(SimpleSmartContract);
};

You should create a new 'migrations file' in the migration folder with a (possible) name of 2_deploy_contracts.js.

async function arguments:

deployer: deployment of the contract
_network: specified network (truffle-config.js)
accounts: to access the truffle accounts when deploying (I.E Solidity constructor arguments)

Ref: https://trufflesuite.com/docs/truffle/getting-started/running-migrations.html

ZygD
  • 22,092
  • 39
  • 79
  • 102
h1c0
  • 1