This is my cantract code which I was using in truffle
pragma solidity 0.5.16;
contract Test {
function getAdd() public view returns(address){
address add = address(this);
return add;
}
}
This is my js Test code
const Test = artifacts.require('../contracts/Test.sol');
contract('Test',(accounts)=>{
it('Testing Testing',async()=>{
let ins =await Test.deployed();
let ans =await ins.getAdd.call();
console.log(ans)
})
})
and I am using ganache for my local blockchain
when I run truffle test command it gives me the result 0x4cB6949669C8631fb2f99Bbe890B99B7DbF64685
but in ganache contract section the deployed contract address is 0xc48Cda939749b1Da32E6853184D595a30c5accCf
I don't know what is going wrong here as address(this) should have return my contract address but it is not working as expected
Steps I have done are:-
- truffle init
- wrote the contract
wrote migration file
const Test = artifacts.require("Test");
module.exports = function(deployer) { deployer.deploy(Test); };
truffle compile
5. truffle migrate
6. truffle test
I dont know why I am getting wrong address in that but when i tried it on remix it was working please help!!
await ins.getAdd.call()
, you can simply useins.address
.