Skip to content

Commit

Permalink
Encode and decode contracts in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Oct 23, 2024
1 parent b33aa52 commit 198281b
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ FROM runtimeverificationinc/kframework-k:ubuntu-noble-${K_COMMIT}
RUN apt-get update \
&& apt-get upgrade --yes \
&& apt-get install --yes \
curl
curl \
libcrypto++-dev

ARG USER_ID=1001
ARG GROUP_ID=1001
Expand Down
2 changes: 2 additions & 0 deletions ukm-semantics/main/decoding.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
```k
requires "decoding/impl.md"
requires "decoding/syntax.md"
module UKM-DECODING
imports private UKM-DECODING-IMPL
endmodule
```
16 changes: 16 additions & 0 deletions ukm-semantics/main/decoding/impl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```k
module UKM-DECODING-IMPL
imports private COMMON-K-CELL
imports private UKM-DECODING-SYNTAX
imports private UKM-FULL-PREPROCESSED-CONFIGURATION
syntax UkmFullPreprocessedCell ::= decodeUkmFullPreprocessedCell(Bytes)
[function, hook(ULM.decode)]
rule
<k> ukmDecodePreprocessedCell(B:Bytes) => .K ... </k>
(_:UkmFullPreprocessedCell => decodeUkmFullPreprocessedCell(B))
endmodule
```
2 changes: 2 additions & 0 deletions ukm-semantics/main/encoding.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
```k
requires "encoding/impl.md"
requires "encoding/syntax.md"
module UKM-ENCODING
imports private UKM-ENCODING-IMPL
endmodule
```
22 changes: 22 additions & 0 deletions ukm-semantics/main/encoding/impl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
```k
module UKM-ENCODING-IMPL
imports private COMMON-K-CELL
imports private BYTES-SYNTAX
imports private UKM-ENCODING-SYNTAX
imports private UKM-FULL-PREPROCESSED-CONFIGURATION
syntax Bytes ::= encodeUkmFullPreprocessedCell(UkmFullPreprocessedCell)
[function, hook(ULM.encode)]
rule
<k>
ukmEncodePreprocessedCell
=> ukmEncodedPreprocessedCell(encodeUkmFullPreprocessedCell(Cell))
...
</k>
Cell:UkmFullPreprocessedCell
endmodule
```
1 change: 1 addition & 0 deletions ukm-semantics/main/encoding/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module UKM-ENCODING-SYNTAX
imports BYTES-SYNTAX
syntax UKMInstruction ::= "ukmEncodePreprocessedCell"
| ukmEncodedPreprocessedCell(Bytes)
endmodule
Expand Down
2 changes: 2 additions & 0 deletions ukm-semantics/targets/testing/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ requires "rust-semantics/test/configuration.md"
module COMMON-K-CELL
imports private RUST-EXECUTION-TEST-PARSING-SYNTAX
imports private RUST-PREPROCESSING-SYNTAX
imports private UKM-ENCODING-SYNTAX
imports private UKM-PREPROCESSING-SYNTAX
imports private UKM-TEST-SYNTAX
configuration
<k>
Expand Down
4 changes: 4 additions & 0 deletions ukm-semantics/targets/testing/ukm-target.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
```k
requires "../../main/decoding.md"
requires "../../main/encoding.md"
requires "../../main/execution.md"
requires "../../main/preprocessing.md"
requires "../../test/execution.md"
Expand All @@ -18,6 +20,8 @@ module UKM-TARGET
imports private RUST-COMMON
imports private RUST-FULL-PREPROCESSING
imports private RUST-EXECUTION-TEST
imports private UKM-DECODING
imports private UKM-ENCODING
imports private UKM-EXECUTION
imports private UKM-PREPROCESSING
imports private UKM-TARGET-CONFIGURATION
Expand Down
8 changes: 8 additions & 0 deletions ukm-semantics/test/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module UKM-TEST-SYNTAX
imports RUST-EXECUTION-TEST-PARSING-SYNTAX
imports UKM-HOOKS-UKM-SYNTAX
syntax UkmInstruction ::= "ukmDecodePreprocessedCell"
syntax ExecutionItem ::= "mock" "CallData"
| "mock" "Caller"
| "mock" UkmHook UkmHookResult
Expand All @@ -27,6 +29,8 @@ endmodule
module UKM-TEST-EXECUTION
imports private COMMON-K-CELL
imports private RUST-EXECUTION-TEST-CONFIGURATION
imports private UKM-DECODING-SYNTAX
imports private UKM-ENCODING-SYNTAX
imports private UKM-EXECUTION-SYNTAX
imports private UKM-HOOKS-BYTES-CONFIGURATION
imports private UKM-HOOKS-BYTES-SYNTAX
Expand All @@ -35,6 +39,10 @@ module UKM-TEST-EXECUTION
imports private UKM-HOOKS-UKM-SYNTAX
imports private UKM-TEST-SYNTAX
// Patching the encoding result to decoding for test purposes
rule ukmEncodedPreprocessedCell(B:Bytes) ~> ukmDecodePreprocessedCell
=> ukmDecodePreprocessedCell(B)
syntax Mockable ::= UkmHook
rule
Expand Down

0 comments on commit 198281b

Please sign in to comment.