text: const DigitalGolems = artifacts.require("DigitalGolems")
  const Digibytes = artifacts.require("Digibytes")
  const Rent = artifacts.require("Rent")
  
  const { assert } = require("chai");
  const {
      catchRevert,            
      catchOutOfGas,          
      catchInvalidJump,       
      catchInvalidOpcode,     
      catchStackOverflow,     
      catchStackUnderflow,   
      catchStaticStateChange
  } = require("../utils/catch_error.js")
  
  
  contract('Card rent', async (accounts)=>{
      let rent;
      let DIG;
      let DBT;
      let fedDeposit;
      let feedPrice = web3.utils.toWei("1")
      let maxAbility = '9';
      let secondsInADay = 86400;
      let user = accounts[9];
      let userRenter = accounts[8];
      let owner = accounts[0];
      let someURLOfCombinedPicture = "someURL"
      before(async () => {
          DIG = await DigitalGolems.new()
          DBT = await Digibytes.new()
          rent = await Rent.new()
          await rent.setDBT(DBT.address)
          await rent.setCard(DIG.address)
          await rent.setFeedPrice(feedPrice)
          await DBT.transfer(userRenter, web3.utils.toWei("17"))
          await DIG.setRent(rent.address)
          //adding assets
          await DIG.ownerMint(
                  user,
                  "some uri",
                  {from: owner}
          )
      })
  
      it("Should create market item", async ()=>{
          fedDeposit = parseInt(maxAbility) * feedPrice
          await rent.createOrder(
              "1", // cardID
              web3.utils.toWei("1"), //priceByDay
              "7",//days
              maxAbility,
              {from: user}
          )
          await DBT.approve(rent.address, web3.utils.toWei("7") + fedDeposit, {from: userRenter})
          await rent.rentOrder(0, {from: userRenter})
      })
  
      it("Should cant be transfered because rented", async () => {
          catchRevert(
              DIG.transferFrom(user, owner, 1, {from: user})
          ) 
      })
  
      it("End Rent should be called by renter", async () => {
          let newTime = (Math.trunc(Date.now()/ 1000) - secondsInADay * 8).toString();
          assert.isFalse(
              await rent.isRentEnded(0)
          )
          await rent.mockTime(0, newTime)
          //revert because still rented
          catchRevert(
              rent.closeOrder(0, {from: owner})
          )
          await rent.endRentAndWithdrawFeedDepositRenter(0, 1,{from: userRenter})
          assert.isAtLeast(
              parseInt((await DBT.balanceOf(userRenter)).toString()),
              fedDeposit
              -
              feedPrice,
              "Renter take fed deposit back"
          )
          assert.equal(
              parseInt((await DBT.balanceOf(user, {from: user})).toString()),
              parseInt(web3.utils.toWei("7") * 997 / 1000)
              + //+ means that after session renter didnt fed golem, so we took from his fed deposit 
              parseInt(feedPrice),
              "Really 99,7%"
          )
          let renterItems = await rent.fetchRenterCardOnMarket(userRenter)
          //already not renter
          assert.equal(
              renterItems.length,
              0
          )
          assert.equal(
              (await DBT.balanceOf(rent.address)).toString(),
              web3.utils.toWei("7") * 3 / 1000,
              "Really 0,3%"
          )
          //revert because already ended by renter
          catchRevert(
              rent.endRentAndWithdrawOwner(0, 0,{from: user})
          ) 
      })
  
      it("Should close order", async () => {
          await rent.closeOrder(0, {from: user})
          let marketCards = await rent.fetchCardOnMarket()
          //length equal 0 because we close our order
          assert.equal(
              marketCards.length,
              0,
              "We closed item"
          )
      })
  
  }
  )