-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_std_builtins.ora
More file actions
63 lines (52 loc) · 1.67 KB
/
test_std_builtins.ora
File metadata and controls
63 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Test contract for standard library builtins
contract StdBuiltinsTest {
storage lastCaller: address;
storage lastTimestamp: u256;
// test basic builtin usage
pub fn recordInfo() -> bool {
var caller: address = std.msg.sender(); // sender should be called caller()?
var txOrigin: address = std.transaction.sender(); // origin should be called origin()?
var time: u256 = std.block.timestamp();
var value: u256 = std.msg.value();
var blockNum: u256 = std.block.number();
var coinbase: address = std.block.coinbase();
var zeroAddr: address = std.constants.ZERO_ADDRESS;
var maxU256: u256 = std.constants.U256_MAX;
// ...
lastCaller = caller;
lastTimestamp = time;
return true;
}
// Test block.timestamp
pub fn getTimestamp() -> u256 {
return std.block.timestamp();
}
// Test block.number
pub fn getBlockNumber() -> u256 {
return std.block.number();
}
// Test block.coinbase
pub fn getCoinbase() -> address {
return std.block.coinbase();
}
// Test transaction.sender
pub fn getOrigin() -> address {
return std.transaction.sender();
}
// Test msg.sender
pub fn getSender() -> address {
return std.msg.sender();
}
// Test msg.value
pub fn getValue() -> u256 {
return std.msg.value();
}
// Test constant ZERO_ADDRESS
pub fn getZeroAddress() -> address {
return std.constants.ZERO_ADDRESS;
}
// Test constant U256_MAX
pub fn getMaxU256() -> u256 {
return std.constants.U256_MAX;
}
}