Truffle

松露測試:如何將乙太幣從合約發送到合約?

  • June 19, 2018

想測試下面的修飾符

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

引用自:https://ethereum.stackexchange.com/questions/51467