0

Is there any way I can automatically test who can withdraw ether from a smart contract? I need to perform this test automatically. So I cannot manually inspect the instructions.

Can I design a smart contract in such a way that it becomes easy to test? I want to ensure that only the creator of the smart contract can withdraw ether through one specific function. I can easily test that this function exists, but how do I automatically test that no other function exists through which the creator (or any other person) of the smart contract can withdraw ether?

Update:

I am aware how to design a smart contract such that only the creator can withdraw ether. However, I need to automatically test who can withdraw ether from a smart contract that is given to me.

0

Create a private address variable owner. In your constructor assign your address as owner. Create a modifier called isOwner. Use this modifier on the withdraw function, this will check automatically if the person withdrawing the amount is owner or not.

This should be easy to test in truffle.

how do I automatically test that no other function exists through which the creator (or any other person) of the smart contract can withdraw ether?

Just don't make any such function. If you have then use the modifier.

Hope it helps.

  • Thanks. To clarify: I am not always the creator of the contract. So I must test if such other withdraw methods exist. Simply not creating such a function does not solve the problem. Hence, your answer unfortunately does not answer my question. – NoMorePen Dec 30 '17 at 18:32

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.