-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.7; | ||
|
||
import "hardhat/console.sol"; | ||
|
||
contract BuiltInVars { | ||
constructor() {} | ||
|
||
function printGlobals() public { | ||
console.log("gasleft"); | ||
console.log(gasleft()); | ||
console.log("this"); | ||
console.log(address(this)); | ||
console.log("block.timestamp"); | ||
console.log(block.timestamp); | ||
console.log("block.number"); | ||
console.log(block.number); | ||
console.log("block.difficulty"); | ||
console.log(block.difficulty); | ||
console.log("tx.gasprice"); | ||
console.log(tx.gasprice); | ||
} | ||
|
||
function countGas() public view returns (uint256) { | ||
uint256 start = gasleft(); | ||
uint256 j = 1235 * 127396; | ||
uint256 end = gasleft(); | ||
|
||
return start - end; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { expect } = require("chai"); | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
import { BigNumber, Contract } from 'ethers'; | ||
import hre, {ethers} from 'hardhat' | ||
|
||
describe("BuiltInVars", function () { | ||
let contract: Contract; | ||
let signer: SignerWithAddress; | ||
|
||
beforeEach(async () => { | ||
// Deploy contact | ||
const factory = await ethers.getContractFactory("BuiltInVars"); | ||
contract = await factory.deploy(); | ||
await contract.deployed(); | ||
|
||
// Store signer | ||
signer = (await ethers.getSigners())[0] | ||
}); | ||
|
||
describe("function", function () { | ||
it("prints globals", async () => { | ||
await contract.printGlobals() | ||
|
||
console.log(`Test gas consumption: ${await contract.countGas()}`) | ||
}); | ||
}); | ||
}); |