Created
March 18, 2021 22:01
-
-
Save jstrassburg/d00dd0372256ba6054452e8749d22a20 to your computer and use it in GitHub Desktop.
Smart contract payable constructor failing test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.2; | |
contract Foo { | |
uint public value; | |
constructor() payable { | |
value = msg.value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> truffle test | |
Using network 'development'. | |
Compiling your contracts... | |
=========================== | |
> Compiling .\test\TestFoo.sol | |
> Artifacts written to C:\Users\jstra\AppData\Local\Temp\test--11228-dvwQ6fhl6MiC | |
> Compiled successfully using: | |
- solc: 0.8.2+commit.661d1103.Emscripten.clang | |
TestFoo | |
1) testConstructor | |
> No events were emitted | |
0 passing (27s) | |
1 failing | |
1) TestFoo | |
testConstructor: | |
Error: Returned error: VM Exception while processing transaction: revert | |
at Context.<anonymous> (C:\Users\jstra\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\testing\SolidityTest.js:92:1) | |
at runMicrotasks (<anonymous>) | |
at processTicksAndRejections (node:internal/process/task_queues:94:5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.2; | |
import "truffle/Assert.sol"; | |
import "truffle/DeployedAddresses.sol"; | |
import "../contracts/Foo.sol"; | |
contract TestFoo { | |
function testConstructor() public payable { | |
uint expectedAmount = 233; | |
Foo foo = new Foo{value: expectedAmount}(); | |
Assert.equal(foo.value(), expectedAmount, "Wrong amount."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment