Skip to content

Instantly share code, notes, and snippets.

Created March 29, 2022 10:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save piorot/4bafb0a4b8bff32a52f03926d36c1ec6 to your computer and use it in GitHub Desktop.
Shareholder be able to withdraw resources paid as rent
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Apartment is ERC20 {
uint public balance;
constructor() ERC20("ApartmentContract", "APRTM") {
super._mint(_msgSender(), 100);
console.log("Deploying a Greeter with greeting:");
function withdraw() public {
require(this.balanceOf(msg.sender) > 0, "XXX");
receive() external payable {
balance += msg.value;
it("Shareholder be able to withdraw resources paid as rent", async () => {
const Apartment = await ethers.getContractFactory("Apartment");
const apartment = await Apartment.deploy();
[owner, Alice, Bob] = await ethers.getSigners();
await apartment.deployed();
await apartment.transfer(Alice.address, 20);
await Bob.sendTransaction({
to: apartment.address,
value: ethers.utils.parseEther("1")
const aliceBalanceBeforeWithdrawal = await Alice.getBalance();
await apartment.connect(Alice).withdraw();
expect(await (await Alice.getBalance()).gt(aliceBalanceBeforeWithdrawal));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment