Truffle
松露測試:如何將乙太幣從合約發送到合約?
想測試下面的修飾符
modifier isNotAContract(){ require (msg.sender == tx.origin, 'Contracts are not allowed to interact.'); _; }
如何通過合約使用此修飾符呼叫函式?
首選 Javascript 語法!
契約:
contract A { modifier isNotAContract(){ require (msg.sender == tx.origin, 'Contracts are not allowed to interact.'); _; } function f() public isNotAContract { // ... } } contract B { A a = new A(); function f() public { a.f(); } }
在松露中:
var b = await B.new() await b.f(); // should fail