mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10558 from ethereum/magictype-tests
Adds more tests for state access (block/tx/msg)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (address payable) {
|
||||
return block.coinbase;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x7878787878787878787878787878787878787878
|
||||
// f() -> 0x7878787878787878787878787878787878787878
|
||||
// f() -> 0x7878787878787878787878787878787878787878
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint) {
|
||||
return block.difficulty;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 200000000
|
||||
// f() -> 200000000
|
||||
// f() -> 200000000
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint) {
|
||||
return block.gaslimit;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 20000000
|
||||
// f() -> 20000000
|
||||
// f() -> 20000000
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
constructor() {}
|
||||
function f() public returns (uint) {
|
||||
return block.number;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// constructor()
|
||||
// f() -> 2
|
||||
// f() -> 3
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
constructor() {}
|
||||
function f() public returns (uint) {
|
||||
return block.timestamp;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// constructor() # This is the 1st block #
|
||||
// f() -> 0x1e # This is the 2nd block (each block is "15 seconds") #
|
||||
// f() -> 0x2d # This is the 3rd block #
|
||||
@@ -0,0 +1,23 @@
|
||||
contract C {
|
||||
bytes32 public genesisHash;
|
||||
bytes32 public currentHash;
|
||||
constructor() {
|
||||
require(block.number == 1);
|
||||
genesisHash = blockhash(0);
|
||||
currentHash = blockhash(1);
|
||||
}
|
||||
function f(uint blockNumber) public returns (bytes32) {
|
||||
return blockhash(blockNumber);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// constructor()
|
||||
// genesisHash() -> 0x3737373737373737373737373737373737373737373737373737373737373737
|
||||
// currentHash() -> 0
|
||||
// f(uint256): 0 -> 0x3737373737373737373737373737373737373737373737373737373737373737
|
||||
// f(uint256): 1 -> 0x3737373737373737373737373737373737373737373737373737373737373738
|
||||
// f(uint256): 255 -> 0x00
|
||||
// f(uint256): 256 -> 0x00
|
||||
// f(uint256): 257 -> 0x00
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (bool) {
|
||||
return gasleft() > 0;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> true
|
||||
// f() -> true
|
||||
// f() -> true
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public returns (bytes calldata) {
|
||||
return msg.data;
|
||||
}
|
||||
function g(uint,bool) public returns (bytes calldata) {
|
||||
return msg.data;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x20, 4, 17219911917854084299749778639755835327755045716242581057573779540915269926912
|
||||
// g(uint256,bool): 1234, true -> 0x20, 0x44, 35691323728519381642872894128098848782337736632589179916067422734266033766400, 33268574187263889506619096617382224251268236217415066441681855047532544, 26959946667150639794667015087019630673637144422540572481103610249216
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public returns (address payable) {
|
||||
return msg.sender;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x1212121212121212121212121212120000000012
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public returns (bytes4) {
|
||||
return msg.sig;
|
||||
}
|
||||
function g() public returns (bytes4) {
|
||||
return msg.sig;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x26121ff000000000000000000000000000000000000000000000000000000000
|
||||
// g() -> 0xe2179b8e00000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,10 @@
|
||||
contract C {
|
||||
function f() public payable returns (uint) {
|
||||
return msg.value;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0
|
||||
// f(), 12 ether -> 12000000000000000000
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (uint) {
|
||||
return tx.gasprice;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 3000000000
|
||||
// f() -> 3000000000
|
||||
// f() -> 3000000000
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public returns (address payable) {
|
||||
return tx.origin;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x9292929292929292929292929292929292929292
|
||||
// f() -> 0x9292929292929292929292929292929292929292
|
||||
// f() -> 0x9292929292929292929292929292929292929292
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public returns (bytes32) {
|
||||
return (blockhash)(block.number - 1);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x3737373737373737373737373737373737373737373737373737373737373738
|
||||
Reference in New Issue
Block a user