-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement storage * Remove comment * Remove redundant priority
- Loading branch information
1 parent
efc4633
commit 0fd8ca7
Showing
18 changed files
with
421 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -463,6 +463,12 @@ $(UKM_WITH_CONTRACT_TESTING_OUTPUT_DIR)/%.run.executed.kore: \ | |
cat $(UKM_CONTRACTS_TESTING_INPUT_DIR)/state_hooks.rs >> [email protected] | ||
echo ">)>" >> [email protected] | ||
|
||
echo "<(<" >> [email protected] | ||
echo "::single_value_mapper" >> [email protected] | ||
echo "<|>" >> [email protected] | ||
cat $(UKM_CONTRACTS_TESTING_INPUT_DIR)/single_value_mapper.rs >> [email protected] | ||
echo ">)>" >> [email protected] | ||
|
||
echo "<(<" >> [email protected] | ||
echo "::ukm" >> [email protected] | ||
echo "<|>" >> [email protected] | ||
|
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
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
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,7 @@ | ||
#![no_std] | ||
|
||
struct SingleValueMapper { key: u64, value_type: () } | ||
|
||
fn new(key:u64) -> :: single_value_mapper :: SingleValueMapper { | ||
:: single_value_mapper :: SingleValueMapper { key: key, value_type: () } | ||
} |
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,47 @@ | ||
mock SetAccountStorageHook ( 7010817630605304703 , 123 ) ukmNoResult(); | ||
mock GetAccountStorageHook ( 7010817630605304703 ) ukmInt64Result(123); | ||
|
||
call :: bytes_hooks :: empty; | ||
return_value_to_arg; | ||
push "setMyDataKey(Uint64,Uint64)"; | ||
call :: bytes_hooks :: append_str; | ||
return_value_to_arg; | ||
push 555_u64; | ||
call :: bytes_hooks :: append_u64; | ||
return_value_to_arg; | ||
push 123_u64; | ||
call :: bytes_hooks :: append_u64; | ||
return_value; | ||
mock CallData; | ||
|
||
call_contract 12345; | ||
return_value; | ||
check_eq (); | ||
|
||
push_status; | ||
check_eq 2; | ||
|
||
|
||
call :: bytes_hooks :: empty; | ||
return_value_to_arg; | ||
push "getMyDataKey(Uint64)"; | ||
call :: bytes_hooks :: append_str; | ||
return_value_to_arg; | ||
push 555_u64; | ||
call :: bytes_hooks :: append_u64; | ||
return_value; | ||
mock CallData; | ||
|
||
call_contract 12345; | ||
return_value; | ||
check_eq (); | ||
|
||
push_status; | ||
check_eq 2; | ||
|
||
output_to_arg; | ||
call :: test_helpers :: decode_single_u64; | ||
return_value; | ||
|
||
check_eq 123_u64 | ||
|
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,36 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use ukm::*; | ||
|
||
#[ukm::contract] | ||
pub trait Storage { | ||
#[storage_mapper("myData")] | ||
fn my_data(&self) -> ::single_value_mapper::SingleValueMapper<u64>; | ||
|
||
#[storage_mapper("myDataKey")] | ||
fn my_data_key(&self, key: u64) -> ::single_value_mapper::SingleValueMapper<u64>; | ||
|
||
#[init] | ||
fn init(&self) {} | ||
|
||
#[endpoint(setMyData)] | ||
fn set(&self, value: u64) { | ||
self.my_data().set(value) | ||
} | ||
|
||
#[endpoint(getMyData)] | ||
fn get(&self) -> u64 { | ||
self.my_data().get() | ||
} | ||
|
||
#[endpoint(setMyDataKey)] | ||
fn set_key(&self, key: u64, value: u64) { | ||
self.my_data_key(key).set(value) | ||
} | ||
|
||
#[endpoint(getMyDataKey)] | ||
fn get_key(&self, key: u64) -> u64 { | ||
self.my_data_key(key).get() | ||
} | ||
} |
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,41 @@ | ||
mock SetAccountStorageHook ( 1809217465971809 , 123 ) ukmNoResult(); | ||
mock GetAccountStorageHook ( 1809217465971809 ) ukmInt64Result(123); | ||
|
||
call :: bytes_hooks :: empty; | ||
return_value_to_arg; | ||
push "setMyData(Uint64)"; | ||
call :: bytes_hooks :: append_str; | ||
return_value_to_arg; | ||
push 123_u64; | ||
call :: bytes_hooks :: append_u64; | ||
return_value; | ||
mock CallData; | ||
|
||
call_contract 12345; | ||
return_value; | ||
check_eq (); | ||
|
||
push_status; | ||
check_eq 2; | ||
|
||
|
||
call :: bytes_hooks :: empty; | ||
return_value_to_arg; | ||
push "getMyData()"; | ||
call :: bytes_hooks :: append_str; | ||
return_value; | ||
mock CallData; | ||
|
||
call_contract 12345; | ||
return_value; | ||
check_eq (); | ||
|
||
push_status; | ||
check_eq 2; | ||
|
||
output_to_arg; | ||
call :: test_helpers :: decode_single_u64; | ||
return_value; | ||
|
||
check_eq 123_u64 | ||
|
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
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,16 @@ | ||
```k | ||
module UKM-EXECUTION-CASTS | ||
imports private RUST-REPRESENTATION | ||
imports private RUST-VALUE-SYNTAX | ||
imports private UKM-REPRESENTATION | ||
syntax Expression ::= ukmCastResult(ValueOrError) | ||
rule ukmCast(ptrValue(_, V), ptrValue(_, rustType(T))) => ukmCastResult(implicitCast(V, T)) | ||
rule ukmCastResult(V:Value) => ptrValue(null, V) | ||
endmodule | ||
``` |
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,38 @@ | ||
```k | ||
module UKM-EXECUTION-STORAGE | ||
imports private RUST-REPRESENTATION | ||
imports private RUST-SHARED-SYNTAX | ||
imports private UKM-REPRESENTATION | ||
syntax Identifier ::= "get" [token] | ||
| "GetAccountStorage" [token] | ||
| "key" [token] | ||
| "set" [token] | ||
| "SetAccountStorage" [token] | ||
| "single_value_mapper" [token] | ||
| "SingleValueMapper" [token] | ||
| "ukm" [token] | ||
rule normalizedFunctionCall | ||
( :: single_value_mapper :: SingleValueMapper :: set :: .PathExprSegments | ||
, (SelfPtr:Ptr , ValuePtr:Ptr , .PtrList) | ||
) | ||
=> :: ukm :: SetAccountStorage :: .PathExprSegments | ||
( SelfPtr . key | ||
, ukmCast(ValuePtr, ptrValue(null, rustType(u64))) | ||
, .CallParamsList | ||
) | ||
rule normalizedFunctionCall | ||
( :: single_value_mapper :: SingleValueMapper :: get :: .PathExprSegments | ||
, (SelfPtr:Ptr , .PtrList) | ||
) | ||
=> :: ukm :: GetAccountStorage :: .PathExprSegments | ||
( SelfPtr . key | ||
, .CallParamsList | ||
) | ||
endmodule | ||
``` |
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
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
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
Oops, something went wrong.