Hi,
As can be read in the docs, Node’s path.resolve()
method resolves a sequence of paths or path segments into an absolute path.
If, after processing all given path segments, an absolute path has not been generated, the current working directory is used.
I guess this is what is happening in your case.
A simple fix would be to make the first path segment absolute:
const contractPath = path.resolve("~/Truffle_programs/search_opcode/", "contracts", "Attack.sol");
// '/home/zulfi/Truffle_programs/search_opcode/contracts/~/Truffle_programs/search_opcode/contracts/Attack.sol'
const contractPath1 = path.resolve("/~/Truffle_programs/search_opcode/", "contracts", "Attack.sol");
// '/~/Truffle_programs/search_opcode/contracts/Attack.sol'
Does that help?
P.S. What is Attack.sol
doing? That sounds a bit sus in the contect of Ethereum