From a2c732640e9007b0a6c142aa65cd1998cf230334 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Fri, 19 May 2023 12:51:39 -0300 Subject: [PATCH] make constructor always payable --- CHANGELOG.md | 4 ++ contracts/Test.sol | 8 ---- src/core.test.ts.md | 104 +++++++++++++++++------------------------- src/core.test.ts.snap | Bin 1987 -> 1968 bytes src/core.ts | 4 +- 5 files changed, 48 insertions(+), 72 deletions(-) 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 4625dc1be4080447d7f1b4d7a689f59e56d1a16e..85063b07245f7329a7168f286bcc4f20d7c5f84a 100644 GIT binary patch literal 1968 zcmV;h2T%AxRzVqhgc>b-+TPMA3sIr^L0lx zl#kY*|3Hke3VW6g`c}`t$a}E<`rPdT3@#ooef8++Bj@w@>qp-{`R?)Rs?>V7fBy0i zDNwiI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74vReS(8Hx_QE2DM4L}lym{o$#O7@Vy+s< zJtpkZ*z7)r*z5*l(~gCZ3Ae?u*%iemjbg4^jEP6braEO){V}kq?!q05oF|i@go8GP zI$pZu`s{N3oO1nq8eF$?aorYzc^-_79Sb27w#BhI7sV!xVy>EqLy#8#Ub4N_&v2Aibsf*bg*k9&Qb+*31HAJd%Lm4@!fdlAJ2xa3-JM!rjY z73)}C1y;A!jPxe*IFnY$pqh@RIn>j7NhVJB&QAC)CnY`!r8P1>0p$;`fJslU$X7Xq zl~Y(bg$4T~=@<7ig;7Q2WLZv@kx$M=yaEC&F^Alq#=$CMDh*;sAFfOCeF^j z9W#ohw?oz3`=F8De$ElYqg_OA2|3|XlJ|m@aBleewtOk5p=hdm6wlImLECaWFZb~O z8Yu2Ve|j-15BnoL-Dz9&u|N5m6)(95m4>d6C_(ovGXKZyIx6#y&f?3tC&M130e3G7 zo@pYAymfbQ4q}2WcGv&T{J!tL-q)O_RcQOF&QA#@P1$}W7{A%?Y?DYaGR+B%H{i;1-L zJ;L2HVA4s;zn*wo2f)mAe&*B@4Ep4joT&2hN_>*&C=lzer9V%69j&|;d!R@JVvg6m zNLAfEKx`vK$8F@+%hVPUfO;vmv6&92EG^nhLhe<-=Caf_4Ar?@zZdhbT=UM~^%y5! z-_?l(%wG%L$k_cGY^8Y2{9q%&c=3G>3W38APbW1%a*u+4@LWL+h&;^;F1k3p8fg$B+D4&ve!kMu`h=)??-f zWzoC$upn!9q>n*_MIC>1X5=F;_H;}oRTb^3fD;+~^e?2?G2T^^kGLmszpr{ ctor.stateMutability === 'payable'); - return [ [ `constructor(${[...missingArguments].map(([name, type]) => `${type} ${name}`).join(', ')})`, ...parentConstructorCalls, ...(parentInitializerCalls.length ? ['initializer'] : []), - ...(shouldBePayable ? ['payable'] : []), + 'payable', '{', ].join(' '), parentInitializerCalls.map(e => `${e};`),