mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 19:01:02 +00:00
[contracts] API host functions: remove seal_ name prefix + enable aliasing (#12126)
* works but ugly * refactored + renamed host fns * fixed tests * fix benchmarks * updated marco docs * Update frame/contracts/proc-macro/src/lib.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * fix for the duplicated prefixed alias bug + test * refactored a bit * fix warnings + try to make macro rustdoc compile * fmt after clearing * examples update + nocompile * add seal_ prefixes to unstable host functions * updated after a review Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
@@ -929,7 +929,7 @@ mod tests {
|
||||
(module
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "__unstable__" "seal_contains_storage" (func $seal_contains_storage (param i32 i32) (result i32)))
|
||||
(import "__unstable__" "contains_storage" (func $contains_storage (param i32 i32) (result i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
|
||||
@@ -947,7 +947,7 @@ mod tests {
|
||||
)
|
||||
;; Call seal_clear_storage and save what it returns at 0
|
||||
(i32.store (i32.const 0)
|
||||
(call $seal_contains_storage
|
||||
(call $contains_storage
|
||||
(i32.const 8) ;; key_ptr
|
||||
(i32.load (i32.const 4)) ;; key_len
|
||||
)
|
||||
@@ -1678,11 +1678,53 @@ mod tests {
|
||||
)
|
||||
(func (export "deploy"))
|
||||
)
|
||||
"#;
|
||||
|
||||
const CODE_TIMESTAMP_NOW_UNPREFIXED: &str = r#"
|
||||
(module
|
||||
(import "seal0" "now" (func $now (param i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; size of our buffer is 32 bytes
|
||||
(data (i32.const 32) "\20")
|
||||
|
||||
(func $assert (param i32)
|
||||
(block $ok
|
||||
(br_if $ok
|
||||
(get_local 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "call")
|
||||
;; This stores the block timestamp in the buffer
|
||||
(call $now (i32.const 0) (i32.const 32))
|
||||
|
||||
;; assert len == 8
|
||||
(call $assert
|
||||
(i32.eq
|
||||
(i32.load (i32.const 32))
|
||||
(i32.const 8)
|
||||
)
|
||||
)
|
||||
|
||||
;; assert that contents of the buffer is equal to the i64 value of 1111.
|
||||
(call $assert
|
||||
(i64.eq
|
||||
(i64.load (i32.const 0))
|
||||
(i64.const 1111)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "deploy"))
|
||||
)
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
fn now() {
|
||||
assert_ok!(execute(CODE_TIMESTAMP_NOW, vec![], MockExt::default()));
|
||||
assert_ok!(execute(CODE_TIMESTAMP_NOW_UNPREFIXED, vec![], MockExt::default()));
|
||||
}
|
||||
|
||||
const CODE_MINIMUM_BALANCE: &str = r#"
|
||||
@@ -2221,7 +2263,7 @@ mod tests {
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
const CODE_CALL_RUNTIME: &str = r#"
|
||||
(module
|
||||
(import "__unstable__" "seal_call_runtime" (func $seal_call_runtime (param i32 i32) (result i32)))
|
||||
(import "__unstable__" "call_runtime" (func $call_runtime (param i32 i32) (result i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
@@ -2238,7 +2280,7 @@ mod tests {
|
||||
)
|
||||
;; Just use the call passed as input and store result to memory
|
||||
(i32.store (i32.const 0)
|
||||
(call $seal_call_runtime
|
||||
(call $call_runtime
|
||||
(i32.const 4) ;; Pointer where the call is stored
|
||||
(i32.load (i32.const 0)) ;; Size of the call
|
||||
)
|
||||
@@ -2350,7 +2392,7 @@ mod tests {
|
||||
(module
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "__unstable__" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32 i32) (result i32)))
|
||||
(import "__unstable__" "set_storage" (func $set_storage (param i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 4) size of input buffer
|
||||
@@ -2367,7 +2409,7 @@ mod tests {
|
||||
)
|
||||
;; Store the passed value to the passed key and store result to memory
|
||||
(i32.store (i32.const 168)
|
||||
(call $seal_set_storage
|
||||
(call $set_storage
|
||||
(i32.const 8) ;; key_ptr
|
||||
(i32.load (i32.const 4)) ;; key_len
|
||||
(i32.add ;; value_ptr = 8 + key_len
|
||||
@@ -2421,7 +2463,7 @@ mod tests {
|
||||
(module
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "__unstable__" "seal_get_storage" (func $seal_get_storage (param i32 i32 i32 i32) (result i32)))
|
||||
(import "__unstable__" "get_storage" (func $get_storage (param i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 4) size of input buffer (160 bytes as we copy the key+len here)
|
||||
@@ -2442,7 +2484,7 @@ mod tests {
|
||||
)
|
||||
;; Load a storage value and result of this call into the output buffer
|
||||
(i32.store (i32.const 168)
|
||||
(call $seal_get_storage
|
||||
(call $get_storage
|
||||
(i32.const 12) ;; key_ptr
|
||||
(i32.load (i32.const 8)) ;; key_len
|
||||
(i32.const 172) ;; Pointer to the output buffer
|
||||
@@ -2515,7 +2557,7 @@ mod tests {
|
||||
(module
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "__unstable__" "seal_clear_storage" (func $seal_clear_storage (param i32 i32) (result i32)))
|
||||
(import "__unstable__" "clear_storage" (func $clear_storage (param i32 i32) (result i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; size of input buffer
|
||||
@@ -2532,7 +2574,7 @@ mod tests {
|
||||
)
|
||||
;; Call seal_clear_storage and save what it returns at 0
|
||||
(i32.store (i32.const 0)
|
||||
(call $seal_clear_storage
|
||||
(call $clear_storage
|
||||
(i32.const 8) ;; key_ptr
|
||||
(i32.load (i32.const 4)) ;; key_len
|
||||
)
|
||||
@@ -2601,7 +2643,7 @@ mod tests {
|
||||
(module
|
||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "__unstable__" "seal_take_storage" (func $seal_take_storage (param i32 i32 i32 i32) (result i32)))
|
||||
(import "__unstable__" "take_storage" (func $take_storage (param i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
;; [0, 4) size of input buffer (160 bytes as we copy the key+len here)
|
||||
@@ -2623,7 +2665,7 @@ mod tests {
|
||||
|
||||
;; Load a storage value and result of this call into the output buffer
|
||||
(i32.store (i32.const 168)
|
||||
(call $seal_take_storage
|
||||
(call $take_storage
|
||||
(i32.const 12) ;; key_ptr
|
||||
(i32.load (i32.const 8)) ;; key_len
|
||||
(i32.const 172) ;; Pointer to the output buffer
|
||||
|
||||
Reference in New Issue
Block a user