0

Would like to test the modifier below

modifier isNotAContract(){
    require (msg.sender == tx.origin, 'Contracts are not allowed to interact.');
    _;
}

How can I invoke a function using this modifier by a contract?

Javascript syntax prefered!

  • Modifiers can only be used in solidity functions, not from an external call directly. – Florian Castelain Jun 18 '18 at 8:29
  • Yes, I know. However, I have a function using the modifier. How can I simulate a call from a contract? Like await a.buy( {value: 5000000, from: contract_two}); without actually writing and deploying a contract? – Senju Jun 18 '18 at 8:32
  • 1
    You can't, you'll need to create a testing or mock contract for that purpose – Henk Jun 18 '18 at 8:54
0

Contracts:

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();
    }
}

In Truffle:

var b = await B.new()
await b.f();    // should fail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.