diff --git a/CHANGELOG.md b/CHANGELOG.md index eafbe9f..63ecf75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.3.6 + +- Emit a payable constructor always. + ## 0.3.5 - Emit a payable constructor if the contract requires it. diff --git a/contracts/Test.sol b/contracts/Test.sol index 329ba0d..1bb16ac 100644 --- a/contracts/Test.sol +++ b/contracts/Test.sol @@ -239,11 +239,3 @@ contract HasReceiveFunction { import { Imported } from './Imported.sol'; contract ImportedChild is Imported {} - -contract HasPayableCtor { - constructor() payable { msg.value; } -} - -contract HasPayableCtorParent is HasPayableCtor { - constructor() {} -} diff --git a/src/core.test.ts.md b/src/core.test.ts.md index 92393f9..8ba5905 100644 --- a/src/core.test.ts.md +++ b/src/core.test.ts.md @@ -17,7 +17,7 @@ Generated by [AVA](https://avajs.dev). contract $Excluded is Excluded {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -36,7 +36,7 @@ Generated by [AVA](https://avajs.dev). contract $NotImported is NotImported {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -45,7 +45,7 @@ Generated by [AVA](https://avajs.dev). contract $Imported is Imported {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $_testNotImported(NotImported ni) external {␊ @@ -67,7 +67,7 @@ Generated by [AVA](https://avajs.dev). contract $NotImported2 is NotImported2 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -76,7 +76,7 @@ Generated by [AVA](https://avajs.dev). contract $Imported2 is Imported2 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $_testNotImported(NotImported2 ni) external {␊ @@ -98,7 +98,7 @@ Generated by [AVA](https://avajs.dev). contract $Parent1 is Parent1 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x) Parent1(x) {␊ + constructor(uint256 x) Parent1(x) payable {␊ }␊ ␊ function $_testParent1() external {␊ @@ -111,7 +111,7 @@ Generated by [AVA](https://avajs.dev). contract $Parent2 is Parent2 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 y) Parent2(y) {␊ + constructor(uint256 y) Parent2(y) payable {␊ }␊ ␊ receive() external payable {}␊ @@ -120,7 +120,7 @@ Generated by [AVA](https://avajs.dev). contract $Parent3 is Parent3 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 z) Parent3(z) {␊ + constructor(uint256 z) Parent3(z) payable {␊ }␊ ␊ receive() external payable {}␊ @@ -129,7 +129,7 @@ Generated by [AVA](https://avajs.dev). contract $Child1 is Child1 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x) Parent1(x) {␊ + constructor(uint256 x) Parent1(x) payable {␊ }␊ ␊ function $_testParent1() external {␊ @@ -142,7 +142,7 @@ Generated by [AVA](https://avajs.dev). contract $Child2 is Child2 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x, uint256 y) Parent1(x) Parent2(y) {␊ + constructor(uint256 x, uint256 y) Parent1(x) Parent2(y) payable {␊ }␊ ␊ function $_testParent1() external {␊ @@ -155,7 +155,7 @@ Generated by [AVA](https://avajs.dev). contract $Child3 is Child3 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x, uint256 y) Parent1(x) Parent2(y) {␊ + constructor(uint256 x, uint256 y) Parent1(x) Parent2(y) payable {␊ }␊ ␊ function $_testParent1() external {␊ @@ -168,7 +168,7 @@ Generated by [AVA](https://avajs.dev). contract $Child4 is Child4 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x, uint256 y, uint256 z, uint256 c) Parent1(x) Parent2(y) Parent3(z) Child4(c) {␊ + constructor(uint256 x, uint256 y, uint256 z, uint256 c) Parent1(x) Parent2(y) Parent3(z) Child4(c) payable {␊ }␊ ␊ function $_testParent1() external {␊ @@ -190,7 +190,7 @@ Generated by [AVA](https://avajs.dev). contract $Initializable is Initializable {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -199,7 +199,7 @@ Generated by [AVA](https://avajs.dev). contract $AU is AU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $$a() external view returns (uint256) {␊ @@ -220,7 +220,7 @@ Generated by [AVA](https://avajs.dev). contract $BU is BU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $$a() external view returns (uint256) {␊ @@ -249,7 +249,7 @@ Generated by [AVA](https://avajs.dev). contract $CU is CU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $$a() external view returns (uint256) {␊ @@ -286,7 +286,7 @@ Generated by [AVA](https://avajs.dev). contract $XU is XU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $$x() external view returns (uint256) {␊ @@ -307,7 +307,7 @@ Generated by [AVA](https://avajs.dev). contract $YU is YU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $$x() external view returns (uint256) {␊ @@ -336,7 +336,7 @@ Generated by [AVA](https://avajs.dev). contract $YUW is YUW {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x) YUW(x) {␊ + constructor(uint256 x) YUW(x) payable {␊ }␊ ␊ function $$x() external view returns (uint256) {␊ @@ -379,7 +379,7 @@ Generated by [AVA](https://avajs.dev). ␊ mapping(uint256 => Foo.Z) internal $v_Foo_Z;␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $s() external view returns (S memory) {␊ @@ -452,7 +452,7 @@ Generated by [AVA](https://avajs.dev). ␊ mapping(uint256 => Foo.Z) internal $v_Foo_Z;␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $s() external view returns (S memory) {␊ @@ -529,7 +529,7 @@ Generated by [AVA](https://avajs.dev). ␊ event return$_testNonView(uint256 value);␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $INTERNAL_VAR() external pure returns (bytes32) {␊ @@ -563,7 +563,7 @@ Generated by [AVA](https://avajs.dev). abstract contract $Iface is Iface {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -572,7 +572,7 @@ Generated by [AVA](https://avajs.dev). abstract contract $Abs is Abs {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -581,7 +581,7 @@ Generated by [AVA](https://avajs.dev). contract $Concrete1 is Concrete1 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -590,7 +590,7 @@ Generated by [AVA](https://avajs.dev). contract $Concrete2 is Concrete2 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -601,7 +601,7 @@ Generated by [AVA](https://avajs.dev). ␊ mapping(uint256 => mapping(uint256 => uint256)) internal $v_mapping_uint256_uint256_;␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $_testEnumType(Types.Enum e) external {␊ @@ -622,7 +622,7 @@ Generated by [AVA](https://avajs.dev). contract $ConstructorStorageLocation is ConstructorStorageLocation {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(string memory name) ConstructorStorageLocation(name) {␊ + constructor(string memory name) ConstructorStorageLocation(name) payable {␊ }␊ ␊ receive() external payable {}␊ @@ -631,7 +631,7 @@ Generated by [AVA](https://avajs.dev). contract $ImplicitConstructor is ImplicitConstructor {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -640,7 +640,7 @@ Generated by [AVA](https://avajs.dev). contract $Chained0 is Chained0 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $_chained() external {␊ @@ -653,7 +653,7 @@ Generated by [AVA](https://avajs.dev). contract $Chained1 is Chained1 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $_chained() external {␊ @@ -666,7 +666,7 @@ Generated by [AVA](https://avajs.dev). contract $Chained2 is Chained2 {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $_chained() external {␊ @@ -679,7 +679,7 @@ Generated by [AVA](https://avajs.dev). contract $WithVars is WithVars {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $var1() external view returns (uint256) {␊ @@ -730,7 +730,7 @@ Generated by [AVA](https://avajs.dev). ␊ event return$multipleReturns(uint256 ret0, bytes32 ret1);␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $incrementInternal() external returns (uint256 ret0) {␊ @@ -764,14 +764,14 @@ Generated by [AVA](https://avajs.dev). contract $HasReceiveFunction is HasReceiveFunction {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ }␊ ␊ contract $ImportedChild is ImportedChild {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ function $_testNotImported(NotImported ni) external {␊ @@ -780,24 +780,6 @@ Generated by [AVA](https://avajs.dev). ␊ receive() external payable {}␊ }␊ - ␊ - contract $HasPayableCtor is HasPayableCtor {␊ - bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ - ␊ - constructor() payable {␊ - }␊ - ␊ - receive() external payable {}␊ - }␊ - ␊ - contract $HasPayableCtorParent is HasPayableCtorParent {␊ - bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ - ␊ - constructor() payable {␊ - }␊ - ␊ - receive() external payable {}␊ - }␊ ` ## snapshot initializers @@ -813,7 +795,7 @@ Generated by [AVA](https://avajs.dev). contract $Initializable is Initializable {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor() {␊ + constructor() payable {␊ }␊ ␊ receive() external payable {}␊ @@ -822,7 +804,7 @@ Generated by [AVA](https://avajs.dev). contract $AU is AU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 a) initializer {␊ + constructor(uint256 a) initializer payable {␊ __A_init(a);␊ }␊ ␊ @@ -844,7 +826,7 @@ Generated by [AVA](https://avajs.dev). contract $BU is BU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 b) initializer {␊ + constructor(uint256 b) initializer payable {␊ __B_init(b);␊ }␊ ␊ @@ -874,7 +856,7 @@ Generated by [AVA](https://avajs.dev). contract $CU is CU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 b) initializer {␊ + constructor(uint256 b) initializer payable {␊ __B_init(b);␊ __C_init();␊ }␊ @@ -913,7 +895,7 @@ Generated by [AVA](https://avajs.dev). contract $XU is XU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x) initializer {␊ + constructor(uint256 x) initializer payable {␊ __X_init(x);␊ }␊ ␊ @@ -935,7 +917,7 @@ Generated by [AVA](https://avajs.dev). contract $YU is YU {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x) initializer {␊ + constructor(uint256 x) initializer payable {␊ __X_init(x);␊ __Y_init();␊ }␊ @@ -966,7 +948,7 @@ Generated by [AVA](https://avajs.dev). contract $YUW is YUW {␊ bytes32 public __hh_exposed_bytecode_marker = "hardhat-exposed";␊ ␊ - constructor(uint256 x) YUW(x) initializer {␊ + constructor(uint256 x) YUW(x) initializer payable {␊ __Y_init();␊ }␊ ␊ diff --git a/src/core.test.ts.snap b/src/core.test.ts.snap index 4625dc1..85063b0 100644 Binary files a/src/core.test.ts.snap and b/src/core.test.ts.snap differ diff --git a/src/core.ts b/src/core.ts index 2f05d0b..ce5661d 100644 --- a/src/core.ts +++ b/src/core.ts @@ -312,14 +312,12 @@ function makeConstructor(contract: ContractDefinition, deref: ASTDereferencer, i } } - const shouldBePayable = [...constructors.values()].some(ctor => ctor.stateMutability === 'payable'); - return [ [ `constructor(${[...missingArguments].map(([name, type]) => `${type} ${name}`).join(', ')})`, ...parentConstructorCalls, ...(parentInitializerCalls.length ? ['initializer'] : []), - ...(shouldBePayable ? ['payable'] : []), + 'payable', '{', ].join(' '), parentInitializerCalls.map(e => `${e};`),