From fa91ead9291f6bffd17caa84bc30da75c83dce20 Mon Sep 17 00:00:00 2001 From: Armando Andini Date: Mon, 20 Sep 2021 22:15:40 -0300 Subject: [PATCH] Deposit example --- misc/contracts/Deposit.sol | 14 ++++++++++++++ misc/test/deposit_test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 misc/contracts/Deposit.sol create mode 100644 misc/test/deposit_test.ts diff --git a/misc/contracts/Deposit.sol b/misc/contracts/Deposit.sol new file mode 100644 index 0000000..2bd98d3 --- /dev/null +++ b/misc/contracts/Deposit.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity ^0.8.7; +import "hardhat/console.sol"; + +contract Deposit { + receive() external payable { + console.log("Calling receive with value", msg.value); + } + + fallback() external payable { + console.log("Calling fallback", msg.value); + } +} diff --git a/misc/test/deposit_test.ts b/misc/test/deposit_test.ts new file mode 100644 index 0000000..8cc737a --- /dev/null +++ b/misc/test/deposit_test.ts @@ -0,0 +1,28 @@ +const { expect } = require("chai"); +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { BigNumber, Contract } from 'ethers'; +import hre, {ethers} from 'hardhat' + +describe("Deposit", function () { + let contract: Contract; + let signer: SignerWithAddress; + + beforeEach(async () => { + // Deploy contact + const factory = await ethers.getContractFactory("Deposit"); + contract = await factory.deploy(); + await contract.deployed(); + + // Store signer + signer = (await ethers.getSigners())[0] + }); + describe("", function () { + it("", async () => { + const tx = await signer.sendTransaction({to: contract.address, value: 1000}) + console.log('gas limit', tx.gasLimit.toString()) + const rec = await tx.wait() + console.log(rec) + console.log('gas used', rec.gasUsed.toString()) + }); + }); +}); \ No newline at end of file