Curious how one should link a library inside of test suite without using migrations.
For example:
let x = await Lib.new();
await ContractZ.link(x.address);
let z = await ContractZ.new()
console.log(z.address)
getting
TypeError: Cannot read property 'replace' of undefined
at node_modules/truffle/build/webpack:/packages/truffle-contract/lib/utils.js:113:1
at Array.forEach (<anonymous>)
at Object.linkBytecode (node_modules/truffle/build/webpack:/packages/truffle-contract/lib/utils.js:109:1)
at Function.binary (node_modules/truffle/build/webpack:/packages/truffle-contract/lib/contract.js:633:1)
at Function.getter (node_modules/truffle/build/webpack:/packages/truffle-contract/lib/contract.js:388:1)
at Function.checkLibraries (node_modules/truffle/build/webpack:/packages/truffle-contract/lib/utils.js:139:1)
at constructor.detectNetwork.then.network (node_modules/truffle/build/webpack:/packages/truffle-contract/lib/contract.js:131:1)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
truffle version): Truffle v5.0.0-next.12 (core: 5.0.0-beta.0)node --version): v9.11.2npm --version): 5.6.0I understand that I can fix it if I simply add a link to migrations:
module.exports = async function (deployer) {
await deployer.deploy(Lib);
await deployer.link(Lib, ContractZ);
};
I was just curious if I can do same thing inside of test suite.
It looks like it might be that ContractZ, after linking, does not reflect the link added. Will look into. Thanks!
Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem.
There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks!
Got the same pb...
I got it working, we need to use the 2nd form of link() since with new() the instance is not at the same address as the expected default with deployed(): https://github.com/trufflesuite/truffle-contract#mycontractlinkname-address
const myLib = await MyLib.new();
await MyContract.link(MyLib, myLib.address);
const mycontract = await MyContract.new();
This only worked for me when I wrote it like:
const myLib = await MyLib.new();
await MyContract.link("MyLib", myLib.address);
const mycontract = await MyContract.new();
Most helpful comment
This only worked for me when I wrote it like: