0

I have some smart contract which has this function:

function someFunction() external returns (uint256) {
        require(msg.sender != address(0), "zero address");
        //some code....
        return 10;
    }

Then I run my test it stopped working

const {constants,expectRevert,BN} = require('@openzeppelin/test-helpers');
//setting up ....
it("Must fail if caller has zero address", async () => {
        await expectRevert(myContract.someFunction({from:constants.ZERO_ADDRESS}),"zero address")
})

and return this error

UnhandledRejections detected Promise { Error: nonce generation function failed or private key is invalid at Transaction.sign (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\transaction.js:292:1) at Transaction.exports.modules.564403.FakeTransaction.hash (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\node_modules\ethereumjs-tx\dist\fake.js:63:1) ature.js:11:1) at Transaction.fakeHash [as hash] (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\transaction.js:18:1) nsaction.js:230:1)
at RuntimeError.combine (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\runtimeerror.js:42:1) at new RuntimeError (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\runtimeerror.js:19:1) \fake.js:63:1) at Function.RuntimeError.fromResults (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\runtimeerror.js:94:1) at C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\blockchain_double.js:568:1 { uncaught: true } } Error: nonce generation function failed or private key is invalid at Object.exports.sign (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\secp256k1\lib\elliptic\index.js:207:1) at Object.sign (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\secp256k1\lib\index.js:192:1) at Object.exports.ecsign (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\node_modules\ethereumjs-tx\node_modules\ethereumjs-util\dist\signature.js:11:1) at Transaction.exports.modules.994857.Transaction.sign (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\node_modules\ethereumjs-tx\dist\transaction.js:230:1) ure.js:11:1) at Transaction.sign (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\transaction.js:292:1) action.js:230:1)
at Transaction.exports.modules.564403.FakeTransaction.hash (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\node_modules\ethereumjs-tx\dist\fake.js:63:1) ake.js:63:1) at Transaction.fakeHash [as hash] (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\transaction.js:18:1) at RuntimeError.combine (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\runtimeerror.js:42:1) at new RuntimeError (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\runtimeerror.js:19:1) at Function.RuntimeError.fromResults (C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\utils\runtimeerror.js:94:1) at C:\Users\Acer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\ganache-core\lib\blockchain_double.js:568:1 { uncaught: true }

I used solidity-coverage for testing.

Is it possible to check sending transaction from zero address?

How I can fix this?

4
  • You need to have the private key of the address to make a transaction, zero address is the public address.
    – trizin
    Sep 18 '21 at 23:59
  • @trizin Yes, I understand this, but I don't know how to add private key for zero address in ganache-cli or truffle( Do you have any suggestions?
    – Arkenstone
    Sep 19 '21 at 8:56
  • No idea. I suggest that you skip this test. Your require statement looks good and will most likely work.
    – trizin
    Sep 21 '21 at 11:28
  • @trizin I agree with you ) After continuous research I can say that easy way for testing sending from zero address doesn't exist
    – Arkenstone
    Sep 22 '21 at 12:23
0

Nobody can have zero address. To be more precise given an address, it is impossible to find the private key correspond to that address. If anybody can do it then the whole world will collapse not just blockchain but the whole modern society as we know it.

So you don't need to check the zero address because nobody can have it. Zero address is just a place people dump their money to it. It is like a whole world garbage dump but the garbage is money

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.