Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix tests for new account id type
Browse files Browse the repository at this point in the history
Because of the new bounds on the trait tests can't get away by using
u64 as accound id. Replacing the 8 byte value by a 32 byte value
creates out quite a bit of code churn.
  • Loading branch information
athei committed Nov 10, 2020
1 parent ce134d9 commit ee418fd
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 433 deletions.
36 changes: 17 additions & 19 deletions frame/contracts/fixtures/call_return_code.wat
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
;; This calls Django (4) and transfers 100 balance during this call and copies the return code
;; of this call to the output buffer.
;; This calls the supplied dest and transfers 100 balance during this call and copies
;; the return code of this call to the output buffer.
;; It also forwards its input to the callee.
(module
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))

;; [0, 8) address of django
(data (i32.const 0) "\04\00\00\00\00\00\00\00")
;; [0, 8) 100 balance
(data (i32.const 0) "\64\00\00\00\00\00\00\00")

;; [8, 16) 100 balance
(data (i32.const 8) "\64\00\00\00\00\00\00\00")
;; [8, 12) here we store the return code of the transfer

;; [16, 20) here we store the return code of the transfer
;; [12, 16) size of the input data
(data (i32.const 12) "\24")

;; [20, 24) here we store the input data

;; [24, 28) size of the input data
(data (i32.const 24) "\04")
;; [16, inf) here we store the input data
;; 32 byte dest + 4 byte forward

(func (export "deploy"))

(func (export "call")
(call $seal_input (i32.const 20) (i32.const 24))
(call $seal_input (i32.const 16) (i32.const 12))
(i32.store
(i32.const 16)
(i32.const 8)
(call $seal_call
(i32.const 0) ;; Pointer to "callee" address.
(i32.const 8) ;; Length of "callee" address.
(i32.const 16) ;; Pointer to "callee" address.
(i32.const 32) ;; Length of "callee" address.
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 8) ;; Pointer to the buffer with value to transfer
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
(i32.const 20) ;; Pointer to input data buffer address
(i32.load (i32.const 24)) ;; Length of input data buffer
(i32.const 48) ;; Pointer to input data buffer address
(i32.const 4) ;; Length of input data buffer
(i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Ptr to output buffer len
)
)
;; exit with success and take transfer return code to the output buffer
(call $seal_return (i32.const 0) (i32.const 16) (i32.const 4))
(call $seal_return (i32.const 0) (i32.const 8) (i32.const 4))
)
)
21 changes: 15 additions & 6 deletions frame/contracts/fixtures/caller_contract.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_balance" (func $seal_balance (param i32 i32)))
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_instantiate" (func $seal_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_instantiate" (func $seal_instantiate
(param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)
))
(import "seal0" "seal_println" (func $seal_println (param i32 i32)))
(import "env" "memory" (memory 1 1))

Expand Down Expand Up @@ -71,6 +73,8 @@
(i32.const 0) ;; Length is ignored in this case
(i32.const 4294967295) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
(i32.const 0) ;; salt_ptr
(i32.const 0) ;; salt_le
)
)

Expand Down Expand Up @@ -98,6 +102,9 @@
(i32.const 0) ;; Length is ignored in this case
(i32.const 4294967295) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
(i32.const 0) ;; salt_ptr
(i32.const 0) ;; salt_le

)
)

Expand All @@ -114,7 +121,7 @@
;; Length of the output buffer
(i32.store
(i32.sub (get_local $sp) (i32.const 4))
(i32.const 8)
(i32.const 256)
)

;; Deploy the contract successfully.
Expand All @@ -131,6 +138,8 @@
(i32.sub (get_local $sp) (i32.const 4)) ;; Pointer to the address buffer length
(i32.const 4294967295) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
(i32.const 0) ;; salt_ptr
(i32.const 0) ;; salt_le

)
)
Expand All @@ -142,7 +151,7 @@

;; Check that address has the expected length
(call $assert
(i32.eq (i32.load (i32.sub (get_local $sp) (i32.const 4))) (i32.const 8))
(i32.eq (i32.load (i32.sub (get_local $sp) (i32.const 4))) (i32.const 32))
)

;; Check that balance has been deducted.
Expand All @@ -169,7 +178,7 @@
(set_local $exit_code
(call $seal_call
(i32.const 16) ;; Pointer to "callee" address.
(i32.const 8) ;; Length of "callee" address.
(i32.const 32) ;; Length of "callee" address.
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
Expand Down Expand Up @@ -205,7 +214,7 @@
(set_local $exit_code
(call $seal_call
(i32.const 16) ;; Pointer to "callee" address.
(i32.const 8) ;; Length of "callee" address.
(i32.const 32) ;; Length of "callee" address.
(i64.const 1) ;; Supply too little gas
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
Expand Down Expand Up @@ -242,7 +251,7 @@
(set_local $exit_code
(call $seal_call
(i32.const 16) ;; Pointer to "callee" address.
(i32.const 8) ;; Length of "callee" address.
(i32.const 32) ;; Length of "callee" address.
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
Expand Down
42 changes: 25 additions & 17 deletions frame/contracts/fixtures/destroy_and_transfer.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
(import "seal0" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_transfer" (func $seal_transfer (param i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_instantiate" (func $seal_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_instantiate" (func $seal_instantiate
(param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)
))
(import "env" "memory" (memory 1 1))

;; [0, 8) Endowment to send when creating contract.
Expand All @@ -16,14 +18,18 @@

;; [48, 80) Buffer where to store the input to the contract

;; [80, 88) Buffer where to store the address of the instantiated contract

;; [88, 96) Size of the buffer
(data (i32.const 88) "\08")
(data (i32.const 88) "\FF")

;; [96, 100) Size of the input buffer
(data (i32.const 96) "\20")

;; [100, 132) Buffer where to store the address of the instantiated contract

;; [132, 134) Salt
(data (i32.const 132) "\47\11")


(func $assert (param i32)
(block $ok
(br_if $ok
Expand Down Expand Up @@ -54,10 +60,12 @@
(i32.const 8) ;; Length of the buffer with value to transfer.
(i32.const 0) ;; Pointer to input data buffer address
(i32.const 0) ;; Length of input data buffer
(i32.const 80) ;; Buffer where to store address of new contract
(i32.const 100) ;; Buffer where to store address of new contract
(i32.const 88) ;; Pointer to the length of the buffer
(i32.const 4294967295) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this cas
(i32.const 0) ;; Length is ignored in this case
(i32.const 132) ;; salt_ptr
(i32.const 2) ;; salt_len
)
(i32.const 0)
)
Expand All @@ -67,15 +75,15 @@
(call $assert
(i32.eq
(i32.load (i32.const 88))
(i32.const 8)
(i32.const 32)
)
)

;; Store the return address.
(call $seal_set_storage
(i32.const 16) ;; Pointer to the key
(i32.const 80) ;; Pointer to the value
(i32.const 8) ;; Length of the value
(i32.const 100) ;; Pointer to the value
(i32.const 32) ;; Length of the value
)
)

Expand All @@ -85,7 +93,7 @@
(i32.eq
(call $seal_get_storage
(i32.const 16) ;; Pointer to the key
(i32.const 80) ;; Pointer to the value
(i32.const 100) ;; Pointer to the value
(i32.const 88) ;; Pointer to the len of the value
)
(i32.const 0)
Expand All @@ -94,16 +102,16 @@
(call $assert
(i32.eq
(i32.load (i32.const 88))
(i32.const 8)
(i32.const 32)
)
)

;; Calling the destination contract with non-empty input data should fail.
(call $assert
(i32.eq
(call $seal_call
(i32.const 80) ;; Pointer to destination address
(i32.const 8) ;; Length of destination address
(i32.const 100) ;; Pointer to destination address
(i32.const 32) ;; Length of destination address
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
Expand All @@ -121,8 +129,8 @@
(call $assert
(i32.eq
(call $seal_call
(i32.const 80) ;; Pointer to destination address
(i32.const 8) ;; Length of destination address
(i32.const 100) ;; Pointer to destination address
(i32.const 32) ;; Length of destination address
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 8) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
Expand All @@ -141,8 +149,8 @@
(call $assert
(i32.eq
(call $seal_transfer
(i32.const 80) ;; Pointer to destination address
(i32.const 8) ;; Length of destination address
(i32.const 100) ;; Pointer to destination address
(i32.const 32) ;; Length of destination address
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
)
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/fixtures/drain.wat
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
(i32.eq
(call $seal_transfer
(i32.const 16) ;; Pointer to destination address
(i32.const 8) ;; Length of destination address
(i32.const 32) ;; Length of destination address
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
)
Expand Down
38 changes: 20 additions & 18 deletions frame/contracts/fixtures/instantiate_return_code.wat
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
;; This instantiats Charlie (3) and transfers 100 balance during this call and copies the return code
;; This instantiats a contract and transfers 100 balance during this call and copies the return code
;; of this call to the output buffer.
;; The first 32 byte of input is the code hash to instantiate
;; The rest of the input is forwarded to the constructor of the callee
(module
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_instantiate" (func $seal_instantiate (param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
(import "seal0" "seal_instantiate" (func $seal_instantiate
(param i32 i32 i64 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)
))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))

;; [0, 8) address of django
(data (i32.const 0) "\04\00\00\00\00\00\00\00")
;; [0, 8) 100 balance
(data (i32.const 0) "\64\00\00\00\00\00\00\00")

;; [8, 16) 100 balance
(data (i32.const 8) "\64\00\00\00\00\00\00\00")
;; [8, 12) here we store the return code of the transfer

;; [16, 20) here we store the return code of the transfer
;; [12, 16) size of the input buffer
(data (i32.const 12) "\24")

;; [20, 24) size of the input buffer
(data (i32.const 20) "\FF")

;; [24, inf) input buffer
;; [16, inf) input buffer
;; 32 bye code hash + 4 byte forward

(func (export "deploy"))

(func (export "call")
(call $seal_input (i32.const 24) (i32.const 20))
(call $seal_input (i32.const 16) (i32.const 12))
(i32.store
(i32.const 16)
(i32.const 8)
(call $seal_instantiate
(i32.const 24) ;; Pointer to the code hash.
(i32.const 16) ;; Pointer to the code hash.
(i32.const 32) ;; Length of the code hash.
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 8) ;; Pointer to the buffer with value to transfer
(i32.const 0) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer.
(i32.const 56) ;; Pointer to input data buffer address
(i32.sub (i32.load (i32.const 20)) (i32.const 32)) ;; Length of input data buffer
(i32.const 48) ;; Pointer to input data buffer address
(i32.const 4) ;; Length of input data buffer
(i32.const 0xffffffff) ;; u32 max sentinel value: do not copy address
(i32.const 0) ;; Length is ignored in this case
(i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
(i32.const 0) ;; salt_ptr
(i32.const 0) ;; salt_len
)
)
;; exit with success and take transfer return code to the output buffer
(call $seal_return (i32.const 0) (i32.const 16) (i32.const 4))
(call $seal_return (i32.const 0) (i32.const 8) (i32.const 4))
)
)
23 changes: 10 additions & 13 deletions frame/contracts/fixtures/restoration.wat
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@

(func (export "call")
;; copy code hash to contract memory
(call $seal_input (i32.const 264) (i32.const 304))
(call $seal_input (i32.const 308) (i32.const 304))
(call $assert
(i32.eq
(i32.load (i32.const 304))
(i32.const 32)
(i32.const 64)
)
)

(call $seal_restore_to
;; Pointer and length of the encoded dest buffer.
(i32.const 256)
(i32.const 8)
(i32.const 340)
(i32.const 32)
;; Pointer and length of the encoded code hash buffer
(i32.const 264)
(i32.const 308)
(i32.const 32)
;; Pointer and length of the encoded rent_allowance buffer
(i32.const 296)
Expand Down Expand Up @@ -65,14 +64,12 @@
;; Buffer that has ACL storage keys.
(data (i32.const 100) "\01")

;; Address of bob
(data (i32.const 256) "\02\00\00\00\00\00\00\00")

;; [264, 296) Code hash of SET_RENT (copied here by seal_input)

;; [296, 304) Rent allowance
(data (i32.const 296) "\32\00\00\00\00\00\00\00")

;; [304, 308) Size of SET_RENT buffer
(data (i32.const 304) "\20")
;; [304, 308) Size of the buffer that holds code_hash + addr
(data (i32.const 304) "\40")

;; [308, 340) code hash of bob (copied by seal_input)
;; [340, 372) addr of bob (copied by seal_input)
)
Loading

0 comments on commit ee418fd

Please sign in to comment.