Skip to content

Commit

Permalink
add e2e test for flatten task
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDedominici committed Nov 27, 2023
1 parent 6c0c01c commit 10c3e9e
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 0 deletions.
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# All e2e test temporary folders
projects-initialization-tests-*
fixture-projects-run-*
18 changes: 18 additions & 0 deletions e2e/fixture-projects/flatten/contracts/A.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: MIT */

pragma abicoder v2;
pragma solidity ^0.8.19;

import "./B.sol";

contract A {
uint256 private storedData;

function set(uint256 value) public {
storedData = value;
}

function get() public view returns (uint256) {
return storedData;
}
}
13 changes: 13 additions & 0 deletions e2e/fixture-projects/flatten/contracts/B.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.19;

import "./C.sol";

contract B {
uint public x;

function inc() public {
x++;
}
}
3 changes: 3 additions & 0 deletions e2e/fixture-projects/flatten/contracts/C.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pragma solidity ^0.8.19;

contract C {}
34 changes: 34 additions & 0 deletions e2e/fixture-projects/flatten/contracts/Lock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

// Uncomment this line to use console.log
// import "hardhat/console.sol";

contract Lock {
uint public unlockTime;
address payable public owner;

event Withdrawal(uint amount, uint when);

constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);

unlockTime = _unlockTime;
owner = payable(msg.sender);
}

function withdraw() public {
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);

require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");

emit Withdrawal(address(this).balance, block.timestamp);

owner.transfer(address(this).balance);
}
}
84 changes: 84 additions & 0 deletions e2e/fixture-projects/flatten/flatten_all_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Sources flattened with hardhat v2.19.2 https://hardhat.org

// SPDX-License-Identifier: MIT AND MPL-2.0 AND UNLICENSED

pragma abicoder v2;

// File contracts/C.sol

pragma solidity ^0.8.19;

contract C {}


// File contracts/B.sol

// Original license: SPDX_License_Identifier: MPL-2.0

pragma solidity ^0.8.19;

contract B {
uint public x;

function inc() public {
x++;
}
}


// File contracts/A.sol

// Original license: SPDX_License_Identifier: MIT

// Original pragma directive: pragma abicoder v2
pragma solidity ^0.8.19;

contract A {
uint256 private storedData;

function set(uint256 value) public {
storedData = value;
}

function get() public view returns (uint256) {
return storedData;
}
}


// File contracts/Lock.sol

// Original license: SPDX_License_Identifier: UNLICENSED
pragma solidity ^0.8.19;

// Uncomment this line to use console.log
// import "hardhat/console.sol";

contract Lock {
uint public unlockTime;
address payable public owner;

event Withdrawal(uint amount, uint when);

constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);

unlockTime = _unlockTime;
owner = payable(msg.sender);
}

function withdraw() public {
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);

require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");

emit Withdrawal(address(this).balance, block.timestamp);

owner.transfer(address(this).balance);
}
}
40 changes: 40 additions & 0 deletions e2e/fixture-projects/flatten/flatten_lock_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Sources flattened with hardhat v2.19.2 https://hardhat.org

// SPDX-License-Identifier: UNLICENSED

// File contracts/Lock.sol

// Original license: SPDX_License_Identifier: UNLICENSED
pragma solidity ^0.8.19;

// Uncomment this line to use console.log
// import "hardhat/console.sol";

contract Lock {
uint public unlockTime;
address payable public owner;

event Withdrawal(uint amount, uint when);

constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);

unlockTime = _unlockTime;
owner = payable(msg.sender);
}

function withdraw() public {
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);

require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");

emit Withdrawal(address(this).balance, block.timestamp);

owner.transfer(address(this).balance);
}
}
3 changes: 3 additions & 0 deletions e2e/fixture-projects/flatten/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
solidity: "0.8.19",
};
6 changes: 6 additions & 0 deletions e2e/fixture-projects/flatten/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "minimal",
"dependencies": {
"hardhat": "file:../../../packages/hardhat-core/hardhat-2.19.1.tgz"
}
}
19 changes: 19 additions & 0 deletions e2e/fixture-projects/flatten/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env sh

# it should flatten all the files in the folder because no file names are passed
if ! npx hardhat flatten | diff - flatten_all_files.txt; then
echo "The flatten file is different from the flatten_all_files.txt"
exit 1
fi

# it should flatten only the 'Lock.sol' file because it is passed as an argument
if ! npx hardhat flatten contracts/Lock.sol | diff - flatten_lock_file.txt; then
echo "The flatten file is different from the flatten_lock_file.txt"
exit 1
fi






0 comments on commit 10c3e9e

Please sign in to comment.