Value printed as [object Object]? #657
-
Hello! uint256 s_SubPrice; //= 0.1 ether;
constructor (uint256 startPrice) {
i_owner = msg.sender;
s_SubPrice = startPrice;
}
modifier onlyOwner{
require(msg.sender==i_owner);
_;
}
function changePrice(uint256 newPrice) public onlyOwner {
s_SubPrice = newPrice;
}
//Getter functions
function getOwner() public view returns(address){
return i_owner;
}
function getPrice() public view returns(uint256) {
return s_SubPrice;
}
const { assert, expect } = require("chai")
const { network, deployments, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../../helper.hardhat")
!developmentChains.includes(network.name)
? describe.skip
: describe("Code Unit Tests", async function () {
let Code //, raffleContract, vrfCoordinatorV2Mock, raffleEntranceFee, interval, player // , deployer
const chainId = network.config.chainId
const NewValue = ethers.utils.parseEther("0.3")
beforeEach(async function () {
const {deployer} = await getNamedAccounts()
accounts = await ethers.getSigners()
await deployments.fixture(["all"])
Code = await ethers.getContract("Code", deployer)
})
describe("constructor", async function () {
it("intitiallizes the Code correctly", async function () {
const startPrice = await Code.getPrice()
assert.equal(startPrice.toString(), ethers.utils.parseEther("0.1"))
})
describe("changePrice", async function () {
it ("Changes the Price correctly", async function () {
const FirstPrice = await Code.getPrice()
console.log(`Value1: ${FirstPrice/1e18}`)
const SetNewPrice = await Code.changePrice(NewValue)//Code breaks here
//await SetNewPrice.wait(1)
console.log(`Value2: ${SetNewPrice}`)
const NewPrice = await Code.getPrice()
assert.equal(NewPrice.toString(), ethers.utils.parseEther("0.3"))
})
})
})
}) The code works fine during the deployment and testing but once I print the variables value, Value2 prints this result
Thank you guys! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
your console.logging this function
it doesn't return anything it sets the value for |
Beta Was this translation helpful? Give feedback.
-
@obc92 The issue I am seeing is that the parseEther function returns the value as string, and changePrice requires an integer, |
Beta Was this translation helpful? Give feedback.
-
Check this link on stack-overflow. It might help your issue... |
Beta Was this translation helpful? Give feedback.
-
Solved this, thanks you everyone! |
Beta Was this translation helpful? Give feedback.
@obc92 The issue I am seeing is that the parseEther function returns the value as string, and changePrice requires an integer,
await Code.changePrice(NewValue)
.