defiforyou / NFT-Marketplace-Smart-Contract

2 stars 2 forks source link

i can't run the test with hardhat, can you help me ? #1

Open kypanz opened 2 years ago

kypanz commented 2 years ago

Hello i have a question, i clone this repository "master" to test in my localhost, all goes fine in the compile, but when i do : npx hardhat test , say this error :

C:\Users\pepap\Desktop\NFT-Marketplace-Smart-Contract-Live-4.1.0\test\sellNFTTest.js:5
const artifactDFYToken = "DFY";
      ^

SyntaxError: Identifier 'artifactDFYToken' has already been declared
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at C:\Users\pepap\Desktop\NFT-Marketplace-Smart-Contract-Live-4.1.0\node_modules\mocha\lib\mocha.js:414:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (C:\Users\pepap\Desktop\NFT-Marketplace-Smart-Contract-Live-4.1.0\node_modules\mocha\lib\mocha.js:411:14)
    at Mocha.run (C:\Users\pepap\Desktop\NFT-Marketplace-Smart-Contract-Live-4.1.0\node_modules\mocha\lib\mocha.js:969:10)
    at testFailures (C:\Users\pepap\Desktop\NFT-Marketplace-Smart-Contract-Live-4.1.0\node_modules\hardhat\src\builtin-tasks\test.ts:99:15)
    at new Promise (<anonymous>)
    at SimpleTaskDefinition.action (C:\Users\pepap\Desktop\NFT-Marketplace-Smart-Contract-Live-4.1.0\node_modules\hardhat\src\builtin-tasks\test.ts:98:34)
    at Environment._runTaskDefinition (C:\Users\pepap\Desktop\NFT-Marketplace-Smart-Contract-Live-4.1.0\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
PS C:\Users\pepap\Desktop\NFT-Marketplace-Smart-Contract-Live-4.1.0>

and when i comment that line, the next error comes :


·············|··········|·············|·············|·············|·············|················
|  Contract  ·  Method  ·  Min        ·  Max        ·  Avg        ·  # calls    ·  usd (avg)    │
·------------|----------|-------------|-------------|-------------|-------------|---------------·

  0 passing (17s)
  6 failing

  1) Deploy DFY Factory
       "before all" hook in "Deploy DFY Factory":
     HardhatError: HH700: Artifact for contract "DFY" not found. Did you mean "Hub"?
      at Artifacts._handleWrongArtifactForContractName (node_modules\hardhat\src\internal\artifacts.ts:478:11)
      at Artifacts._getArtifactPathFromFiles (node_modules\hardhat\src\internal\artifacts.ts:593:19)
      at Artifacts._getArtifactPath (node_modules\hardhat\src\internal\artifacts.ts:275:17)
      at Artifacts.readArtifact (node_modules\hardhat\src\internal\artifacts.ts:58:26)
      at getContractFactory (node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:99:22)
      at Context.<anonymous> (test\AuctionNFT.test.js:58:33)

where i can get the BEP20 for test this Marketplace ?

Thanks for read ❤️

kypanz commented 2 years ago

Solved, i create a BEP20 smart contract called DFY and uncomment the const artifactDFYToken = "DFY"; line, now i am trying to solve this errors :


  1) Deploy DFY Factory
       unit test DFY
         RRRRR => Case 1 :To test Time origin creator put on auction , check bidder bit use BNB to bid and finish with no royalty fee : :
     Error: VM Exception while processing transaction: reverted with reason string 'ERC20: transfer amount exceeds balance'
      at DFY.decreaseAllowance (@openzeppelin/contracts/token/ERC20/ERC20.sol:204)
      at DFY.transfer (@openzeppelin/contracts/token/ERC20/ERC20.sol:115)
      at HardhatNode._mineBlockWithPendingTxs (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:1773:23)
      at HardhatNode.mineBlock (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:466:16)
      at EthModule._sendTransactionAndReturnHash (node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:1504:18)
      at HardhatNetworkProvider.request (node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:118:18)
      at EthersProviderWrapper.send (node_modules\@nomiclabs\hardhat-ethers\src\internal\ethers-provider-wrapper.ts:13:20)

so i am trying to print in console what is the actual balance of the token, i am not sure but the problem can be there

kypanz commented 2 years ago

Solved too, i forget premint in the BEP smart contract, now solving :


 1) Deploy DFY Factory
       unit test DFY
         RRRRR => Case 1 :To test Time origin creator put on auction , check bidder bit use BNB to bid and finish with no royalty fee : :
     Error: VM Exception while processing transaction: reverted with reason string 'startTime'
      at AuctionNFT.onlyProxy (@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:39)
      at <UnrecognizedContract>.<unknown> (0x0dcd1bf9a1b36ce34237eeafef220932846bcd82)
      at HardhatNode._mineBlockWithPendingTxs (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:1773:23)
      at HardhatNode.mineBlock (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:466:16)
      at EthModule._sendTransactionAndReturnHash (node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:1504:18)
      at HardhatNetworkProvider.request (node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:118:18) 
      at EthersProviderWrapper.send (node_modules\@nomiclabs\hardhat-ethers\src\internal\ethers-provider-wrapper.ts:13:20)
kypanz commented 2 years ago

Solved, the error "startTime" is because in your AcutionNFT.test.js, you need to re-defining the next lines :

// success
let _startTime = Math.floor(Date.now() / 1000) + 172800; // 2d
let _endTime = _startTime + 604800; // 7d

here are what do you have in the code :

let _startTime = Math.floor(Date.now() / 1000) + 260; // 2d
let _endTime = _startTime + 70; // 7d