This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Contract test api #98
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a075744
Contract for testing API (wip)
elmato b476e53
make db.h functions have C linkage
elmato 3fdbd63
rewrite base32 encoding/decoding
elmato c1d0fbd
add tests to db module (i64 functions) + tests for print/math modules
elmato f150cb8
Add -fno-builtin -ffreestanding -nostdlib options to wasm compiler
elmato e515509
Use code from current context to invoke the correct recipient
elmato e1a074c
Group load functions of i128i128 objects
elmato 6ba6a5c
Normalize store and load functions precondition checks and skip keys …
elmato 5963104
Implement load_secondary_i128i128
elmato 04a6b71
make store_i128i128 to work like store_i64
elmato 6065bce
Remove recipients from message contructor
elmato 73e3a6c
remove key parameter from load_secondary_i128i128
elmato 3344491
API unit test refactor and first test case for i128i128 db api functions
elmato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_subdirectory(currency) | ||
add_subdirectory(exchange) | ||
add_subdirectory(infinite) | ||
add_subdirectory(test_api) | ||
#add_subdirectory(social) |
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
#pragma once | ||
|
||
extern "C" { | ||
#include <eoslib/db.h> | ||
} | ||
|
||
|
||
|
||
|
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,2 @@ | ||
file(GLOB SOURCE_FILES "*.cpp") | ||
add_wast_target(test_api "${SOURCE_FILES}" "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_SOURCE_DIR}) |
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,55 @@ | ||
#include <eoslib/eos.hpp> | ||
#include "test_api.hpp" | ||
|
||
extern "C" { | ||
|
||
void init() { | ||
|
||
} | ||
|
||
void apply( unsigned long long code, unsigned long long action ) { | ||
|
||
//eos::print("==> CONTRACT: ", code, " ", action, "\n"); | ||
|
||
//test_types | ||
WASM_TEST_HANDLER(test_types, types_size); | ||
WASM_TEST_HANDLER(test_types, char_to_symbol); | ||
WASM_TEST_HANDLER(test_types, string_to_name); | ||
WASM_TEST_HANDLER(test_types, name_class); | ||
|
||
//test_message | ||
WASM_TEST_HANDLER(test_message, read_message); | ||
WASM_TEST_HANDLER(test_message, read_message_to_0); | ||
WASM_TEST_HANDLER(test_message, read_message_to_64k); | ||
WASM_TEST_HANDLER_EX(test_message, require_notice); | ||
WASM_TEST_HANDLER(test_message, require_auth); | ||
WASM_TEST_HANDLER(test_message, assert_false); | ||
WASM_TEST_HANDLER(test_message, assert_true); | ||
WASM_TEST_HANDLER(test_message, now); | ||
|
||
//test_print | ||
WASM_TEST_HANDLER(test_print, test_prints); | ||
WASM_TEST_HANDLER(test_print, test_printi); | ||
WASM_TEST_HANDLER(test_print, test_printi128); | ||
WASM_TEST_HANDLER(test_print, test_printn); | ||
|
||
//test_math | ||
WASM_TEST_HANDLER(test_math, test_multeq_i128); | ||
WASM_TEST_HANDLER(test_math, test_diveq_i128); | ||
WASM_TEST_HANDLER(test_math, test_diveq_i128_by_0); | ||
|
||
//test db | ||
WASM_TEST_HANDLER(test_db, key_i64_general); | ||
WASM_TEST_HANDLER(test_db, key_i64_remove_all); | ||
WASM_TEST_HANDLER(test_db, key_i64_small_load); | ||
WASM_TEST_HANDLER(test_db, key_i64_small_store); | ||
WASM_TEST_HANDLER(test_db, key_i64_store_scope); | ||
WASM_TEST_HANDLER(test_db, key_i64_remove_scope); | ||
WASM_TEST_HANDLER(test_db, key_i64_not_found); | ||
WASM_TEST_HANDLER(test_db, key_i128i128_general); | ||
|
||
//unhandled test call | ||
WASM_TEST_ERROR_CODE = WASM_TEST_FAIL; | ||
} | ||
|
||
} |
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,96 @@ | ||
#pragma once | ||
|
||
#define WASM_TEST_ERROR_CODE *((unsigned int *)((1<<16) - 2*sizeof(unsigned int))) | ||
#define WASM_TEST_ERROR_MESSAGE *((unsigned int *)((1<<16) - 1*sizeof(unsigned int))) | ||
|
||
#define WASM_TEST_FAIL 0xDEADBEEF | ||
#define WASM_TEST_PASS 0xB0CABACA | ||
|
||
#define WASM_ASSERT(m, message) if(!(m)) { WASM_TEST_ERROR_MESSAGE=(unsigned int)message; return WASM_TEST_FAIL; } | ||
|
||
typedef unsigned long long u64; | ||
#define WASM_TEST_HANDLER(CLASS, METHOD) \ | ||
if( u32(action>>32) == DJBH(#CLASS) && u32(action) == DJBH(#METHOD) ) { \ | ||
WASM_TEST_ERROR_CODE = CLASS::METHOD(); \ | ||
return; \ | ||
} | ||
|
||
#define WASM_TEST_HANDLER_EX(CLASS, METHOD) \ | ||
if( u32(action>>32) == DJBH(#CLASS) && u32(action) == DJBH(#METHOD) ) { \ | ||
WASM_TEST_ERROR_CODE = CLASS::METHOD(code, action); \ | ||
return; \ | ||
} | ||
|
||
typedef unsigned int u32; | ||
static constexpr u32 DJBH(const char* cp) | ||
{ | ||
u32 hash = 5381; | ||
while (*cp) | ||
hash = 33 * hash ^ (unsigned char) *cp++; | ||
return hash; | ||
} | ||
|
||
#pragma pack(push, 1) | ||
struct dummy_message { | ||
char a; //1 | ||
unsigned long long b; //8 | ||
int c; //4 | ||
}; | ||
|
||
struct u128_msg { | ||
unsigned __int128 values[3]; //16*3 | ||
}; | ||
#pragma pack(pop) | ||
|
||
static_assert( sizeof(dummy_message) == 13 , "unexpected packing" ); | ||
static_assert( sizeof(u128_msg) == 16*3 , "unexpected packing" ); | ||
|
||
struct test_types { | ||
static unsigned int types_size(); | ||
static unsigned int char_to_symbol(); | ||
static unsigned int string_to_name(); | ||
static unsigned int name_class(); | ||
}; | ||
|
||
struct test_print { | ||
static unsigned int test_prints(); | ||
static unsigned int test_printi(); | ||
static unsigned int test_printi128(); | ||
static unsigned int test_printn(); | ||
}; | ||
|
||
#define DUMMY_MESSAGE_DEFAULT_A 0x45 | ||
#define DUMMY_MESSAGE_DEFAULT_B 0xab11cd1244556677 | ||
#define DUMMY_MESSAGE_DEFAULT_C 0x7451ae12 | ||
|
||
struct test_message { | ||
|
||
static unsigned int read_message(); | ||
static unsigned int read_message_to_0(); | ||
static unsigned int read_message_to_64k(); | ||
static unsigned int require_notice(unsigned long long code, unsigned long long action); | ||
static unsigned int require_auth(); | ||
static unsigned int assert_false(); | ||
static unsigned int assert_true(); | ||
static unsigned int now(); | ||
|
||
}; | ||
|
||
struct test_math { | ||
static unsigned int test_multeq_i128(); | ||
static unsigned int test_diveq_i128(); | ||
static unsigned int test_diveq_i128_by_0(); | ||
}; | ||
|
||
struct test_db { | ||
static unsigned int key_i64_general(); | ||
static unsigned int key_i64_remove_all(); | ||
static unsigned int key_i64_small_load(); | ||
static unsigned int key_i64_small_store(); | ||
static unsigned int key_i64_store_scope(); | ||
static unsigned int key_i64_remove_scope(); | ||
static unsigned int key_i64_not_found(); | ||
|
||
static unsigned int key_i128i128_general(); | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? Could we document this wasm.cmake file to explain why each and every argument is listed?