-
Notifications
You must be signed in to change notification settings - Fork 0
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 EOSIO#98 from elmato/contract-test-api
Contract test api
- Loading branch information
Showing
21 changed files
with
1,244 additions
and
110 deletions.
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.