-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1024 from AntelopeIO/find_secondary_test
add unit test for `find_secondary` host functions
- Loading branch information
Showing
7 changed files
with
166 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
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
10 changes: 10 additions & 0 deletions
10
unittests/test-contracts/db_find_secondary_test/CMakeLists.txt
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,10 @@ | ||
if(EOSIO_COMPILE_TEST_CONTRACTS) | ||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/db_find_secondary_test.wasm" | ||
COMMAND "${CDT_ROOT}/bin/eosio-wast2wasm" "${CMAKE_CURRENT_SOURCE_DIR}/db_find_secondary_test.wast" -o "${CMAKE_CURRENT_BINARY_DIR}/db_find_secondary_test.wasm" | ||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/db_find_secondary_test.wast") | ||
|
||
add_custom_target(gen_db_find_secondary_test_wasm ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/db_find_secondary_test.wasm") | ||
else() | ||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/db_find_secondary_test.wasm ${CMAKE_CURRENT_BINARY_DIR}/db_find_secondary_test.wasm COPYONLY ) | ||
endif() | ||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/db_find_secondary_test.abi ${CMAKE_CURRENT_BINARY_DIR}/db_find_secondary_test.abi COPYONLY ) |
23 changes: 23 additions & 0 deletions
23
unittests/test-contracts/db_find_secondary_test/db_find_secondary_test.abi
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,23 @@ | ||
{ | ||
"version": "eosio::abi/1.0", | ||
"types": [], | ||
"structs": [{ | ||
"name": "empty", | ||
"base": "", | ||
"fields": [] | ||
} | ||
], | ||
"actions": [{ | ||
"name": "doit", | ||
"type": "empty", | ||
"ricardian_contract": "" | ||
} | ||
], | ||
"tables": [], | ||
"ricardian_clauses": [], | ||
"error_messages": [], | ||
"abi_extensions": [], | ||
"variants": [], | ||
"action_results": [] | ||
} | ||
|
Binary file added
BIN
+1.42 KB
unittests/test-contracts/db_find_secondary_test/db_find_secondary_test.wasm
Binary file not shown.
120 changes: 120 additions & 0 deletions
120
unittests/test-contracts/db_find_secondary_test/db_find_secondary_test.wast
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,120 @@ | ||
(module | ||
(import "env" "db_idx64_store" (func $db_idx64_store (param i64 i64 i64 i64 i32) (result i32))) | ||
(import "env" "db_idx64_find_secondary" (func $db_idx64_find_secondary (param i64 i64 i64 i32 i32) (result i32))) | ||
(import "env" "db_idx128_store" (func $db_idx128_store (param i64 i64 i64 i64 i32) (result i32))) | ||
(import "env" "db_idx128_find_secondary" (func $db_idx128_find_secondary (param i64 i64 i64 i32 i32) (result i32))) | ||
(import "env" "db_idx256_store" (func $db_idx256_store (param i64 i64 i64 i64 i32 i32) (result i32))) | ||
(import "env" "db_idx256_find_secondary" (func $db_idx256_find_secondary (param i64 i64 i64 i32 i32 i32) (result i32))) | ||
(import "env" "db_idx_double_store" (func $db_idx_double_store (param i64 i64 i64 i64 i32) (result i32))) | ||
(import "env" "db_idx_double_find_secondary" (func $db_idx_double_find_secondary (param i64 i64 i64 i32 i32) (result i32))) | ||
(import "env" "db_idx_long_double_store" (func $db_idx_long_double_store (param i64 i64 i64 i64 i32) (result i32))) | ||
(import "env" "db_idx_long_double_find_secondary" (func $db_idx_long_double_find_secondary (param i64 i64 i64 i32 i32) (result i32))) | ||
|
||
(memory 1) | ||
(export "apply" (func $apply)) | ||
|
||
(func $apply (param $receiver i64) (param $account i64) (param $action_name i64) | ||
;;;;;;;;;;idx64 | ||
;;load 2 items with sec key at 16 | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 7) (i32.const 16))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 14) (i32.const 16))) | ||
;;load items with sec key at 48 -- this is what will be tested against | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 15) (i32.const 48))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 8) (i32.const 48))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 1) (i32.const 48))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 4) (i32.const 48))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 90) (i32.const 48))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 42) (i32.const 48))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 3) (i32.const 48))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 60) (i32.const 48))) | ||
;;load 2 items with sec key at 80 | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 0) (i32.const 80))) | ||
(drop (call $db_idx64_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 88) (i32.const 80))) | ||
|
||
;;;;;;;;;;idx128 | ||
;;load 2 items with sec key at 16 | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 7) (i32.const 16))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 14) (i32.const 16))) | ||
;;load items with sec key at 48 -- this is what will be tested against | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 15) (i32.const 48))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 8) (i32.const 48))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 1) (i32.const 48))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 4) (i32.const 48))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 90) (i32.const 48))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 42) (i32.const 48))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 3) (i32.const 48))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 60) (i32.const 48))) | ||
;;load 2 items with sec key at 80 | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 0) (i32.const 80))) | ||
(drop (call $db_idx128_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 88) (i32.const 80))) | ||
|
||
;;;;;;;;;;idx256 | ||
;;load 2 items with sec key at 16 | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 7) (i32.const 16) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 14) (i32.const 16) (i32.const 2))) | ||
;;load items with sec key at 48 -- this is what will be tested against | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 15) (i32.const 48) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 8) (i32.const 48) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 1) (i32.const 48) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 4) (i32.const 48) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 90) (i32.const 48) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 42) (i32.const 48) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 3) (i32.const 48) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 60) (i32.const 48) (i32.const 2))) | ||
;;load 2 items with sec key at 80 | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 0) (i32.const 80) (i32.const 2))) | ||
(drop (call $db_idx256_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 88) (i32.const 80) (i32.const 2))) | ||
|
||
;;;;;;;;;;double | ||
;;load 2 items with sec key at 16 | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 7) (i32.const 16))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 14) (i32.const 16))) | ||
;;load items with sec key at 48 -- this is what will be tested against | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 15) (i32.const 48))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 8) (i32.const 48))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 1) (i32.const 48))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 4) (i32.const 48))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 90) (i32.const 48))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 42) (i32.const 48))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 3) (i32.const 48))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 60) (i32.const 48))) | ||
;;load 2 items with sec key at 80 | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 0) (i32.const 80))) | ||
(drop (call $db_idx_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 88) (i32.const 80))) | ||
|
||
;;;;;;;;;;long double (f128) | ||
;;load 2 items with sec key at 16 | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 7) (i32.const 16))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 14) (i32.const 16))) | ||
;;load items with sec key at 48 -- this is what will be tested against | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 15) (i32.const 48))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 8) (i32.const 48))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 1) (i32.const 48))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 4) (i32.const 48))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 90) (i32.const 48))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 42) (i32.const 48))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 3) (i32.const 48))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 60) (i32.const 48))) | ||
;;load 2 items with sec key at 80 | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 0) (i32.const 80))) | ||
(drop (call $db_idx_long_double_store (get_local $receiver) (get_local $receiver) (get_local $receiver) (i64.const 88) (i32.const 80))) | ||
|
||
;;test each index type. expect to find primary key of 1 when searching seckey at 48 since 1 was the lowest that was stored for the | ||
;; searched seckey (the primary key will be placed at memory location 1024) | ||
(drop (call $db_idx64_find_secondary (get_local $receiver) (get_local $receiver) (get_local $receiver) (i32.const 48) (i32.const 1024))) | ||
(if (i64.ne (i64.load (i32.const 1024)) (i64.const 1)) (then unreachable)) | ||
(drop (call $db_idx128_find_secondary (get_local $receiver) (get_local $receiver) (get_local $receiver) (i32.const 48) (i32.const 1024))) | ||
(if (i64.ne (i64.load (i32.const 1024)) (i64.const 1)) (then unreachable)) | ||
(drop (call $db_idx256_find_secondary (get_local $receiver) (get_local $receiver) (get_local $receiver) (i32.const 48) (i32.const 2) (i32.const 1024))) | ||
(if (i64.ne (i64.load (i32.const 1024)) (i64.const 1)) (then unreachable)) | ||
(drop (call $db_idx_double_find_secondary (get_local $receiver) (get_local $receiver) (get_local $receiver) (i32.const 48) (i32.const 1024))) | ||
(if (i64.ne (i64.load (i32.const 1024)) (i64.const 1)) (then unreachable)) | ||
(drop (call $db_idx_long_double_find_secondary (get_local $receiver) (get_local $receiver) (get_local $receiver) (i32.const 48) (i32.const 1024))) | ||
(if (i64.ne (i64.load (i32.const 1024)) (i64.const 1)) (then unreachable)) | ||
) | ||
|
||
;;secondary keys to be used | ||
(data (i32.const 16) "\00\00\00\00\01\02\03\04AbcdefghABCDEFGH01234567") | ||
(data (i32.const 48) "\00\00\00\00\01\02\03\05abcdefghABCDEFGH99999999") | ||
(data (i32.const 80) "\00\00\00\00\01\02\03\06aBcdefghABCDEFGH00000000") | ||
) |
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