Skip to content

Commit

Permalink
MX getBlockTimestamp hook
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Aug 28, 2024
1 parent 6ba7fc2 commit f842671
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mx-semantics/main/blocks/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```k
module MX-BLOCKS-CONFIGURATION
imports INT-SYNTAX
configuration
<mx-blocks>
<mx-current-block>
<mx-current-block-timestamp> 0 </mx-current-block-timestamp>
</mx-current-block>
</mx-blocks>
endmodule
```
14 changes: 14 additions & 0 deletions mx-semantics/main/blocks/hooks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```k
module MX-BLOCKS-HOOKS
imports private COMMON-K-CELL
imports private MX-BLOCKS-CONFIGURATION
imports private MX-COMMON-SYNTAX
rule
<k> MX#getBlockTimestamp ( .MxHookArgs ) => mxIntValue(T) ... </k>
<mx-current-block-timestamp> T </mx-current-block-timestamp>
endmodule
```
3 changes: 3 additions & 0 deletions mx-semantics/main/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
requires "accounts/configuration.md"
requires "biguint/configuration.md"
requires "blocks/configuration.md"
requires "calls/configuration.md"
module MX-COMMON-CONFIGURATION
imports MX-ACCOUNTS-CONFIGURATION
imports MX-BIGUINT-CONFIGURATION
imports MX-BLOCKS-CONFIGURATION
imports MX-CALL-CONFIGURATION
configuration
<mx-common>
<mx-call-data/>
<mx-biguint/>
<mx-blocks/>
<mx-accounts/>
</mx-common>
endmodule
Expand Down
2 changes: 2 additions & 0 deletions mx-semantics/main/mx-common.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
requires "accounts/hooks.md"
requires "biguint/hooks.md"
requires "blocks/hooks.md"
requires "calls/hooks.md"
module MX-COMMON
imports private MX-ACCOUNTS-HOOKS
imports private MX-BIGUINT-HOOKS
imports private MX-BLOCKS-HOOKS
imports private MX-CALLS-HOOKS
endmodule
Expand Down
13 changes: 13 additions & 0 deletions mx-semantics/test/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module MX-TEST-EXECUTION-PARSING-SYNTAX
| setCaller(String)
| addAccount(String)
| setBalance(account:String, token:String, nonce:Int, value:Int)
| setBlockTimestamp(Int)
syntax MxTest ::= NeList{TestInstruction, ";"}
Expand All @@ -24,6 +25,7 @@ module MX-TEST-EXECUTION
imports private INT
imports private MX-ACCOUNTS-TEST
imports private MX-BIGUINT-TEST
imports private MX-BLOCKS-TEST
imports private MX-CALL-TEST
imports private MX-TEST-CONFIGURATION
imports private MX-TEST-EXECUTION-PARSING-SYNTAX
Expand Down Expand Up @@ -151,4 +153,15 @@ module MX-ACCOUNTS-TEST
endmodule
module MX-BLOCKS-TEST
imports private COMMON-K-CELL
imports private MX-BLOCKS-CONFIGURATION
imports private MX-TEST-EXECUTION-PARSING-SYNTAX
rule
<k> setBlockTimestamp(T:Int) => .K ... </k>
<mx-current-block-timestamp> _ => T </mx-current-block-timestamp>
endmodule
```
3 changes: 3 additions & 0 deletions tests/mx/blockchain/get-block-timestamp.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setBlockTimestamp(1234);
call 0 MX#getBlockTimestamp;
check_eq mxIntValue(1234)

0 comments on commit f842671

Please sign in to comment.