In Truffle, when you write tests, you can use ‘artifacts’ and ‘web3’ objects, without defining these names:
const MyContract = artifacts.require('MyContract'); //artifacts was never defined before !
const web3 = new Web3('http://localhost:8545'); //same thing for Web3!
How is it possible? this is not valid Javascript! Well, this is what Truffle calls “variable injection”, and to understand how this work, watch this video to have the answer and have a peek at Truffle internals:
SolidityTestingTruffle
Leave a Reply