Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
9e22215c
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9e22215c
编写于
9月 06, 2017
作者:
B
Bart Wyatt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Basic tests, more incoming ref EOSIO/eos#175
上级
00c57d7f
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
162 addition
and
30 deletion
+162
-30
CMakeModules/wasm.cmake
CMakeModules/wasm.cmake
+1
-1
contracts/eoslib/math.h
contracts/eoslib/math.h
+1
-1
contracts/eoslib/message.h
contracts/eoslib/message.h
+1
-18
contracts/eoslib/system.h
contracts/eoslib/system.h
+39
-0
contracts/test_api/test_api.cpp
contracts/test_api/test_api.cpp
+8
-0
contracts/test_api/test_api.hpp
contracts/test_api/test_api.hpp
+21
-6
contracts/test_api/test_transaction.cpp
contracts/test_api/test_transaction.cpp
+71
-0
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+5
-4
tests/api_tests/api_tests.cpp
tests/api_tests/api_tests.cpp
+15
-0
未找到文件。
CMakeModules/wasm.cmake
浏览文件 @
9e22215c
...
@@ -121,7 +121,7 @@ macro(add_wast_target target SOURCE_FILES INCLUDE_FOLDERS DESTINATION_FOLDER)
...
@@ -121,7 +121,7 @@ macro(add_wast_target target SOURCE_FILES INCLUDE_FOLDERS DESTINATION_FOLDER)
add_custom_command
(
OUTPUT
${
DESTINATION_FOLDER
}
/
${
target
}
.wast
add_custom_command
(
OUTPUT
${
DESTINATION_FOLDER
}
/
${
target
}
.wast
DEPENDS
${
target
}
.s
DEPENDS
${
target
}
.s
COMMAND
${
BINARYEN_BIN
}
/s2wasm -o
${
DESTINATION_FOLDER
}
/
${
target
}
.wast -s 1
024
${
target
}
.s
COMMAND
${
BINARYEN_BIN
}
/s2wasm -o
${
DESTINATION_FOLDER
}
/
${
target
}
.wast -s 1
6384
${
target
}
.s
COMMENT
"Generating WAST
${
target
}
.wast"
COMMENT
"Generating WAST
${
target
}
.wast"
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
VERBATIM
VERBATIM
...
...
contracts/eoslib/math.h
浏览文件 @
9e22215c
#pragma once
#pragma once
#include <eoslib/
types
.h>
#include <eoslib/
system
.h>
extern
"C"
{
extern
"C"
{
/**
/**
...
...
contracts/eoslib/message.h
浏览文件 @
9e22215c
#pragma once
#pragma once
#include <eoslib/
types
.h>
#include <eoslib/
system
.h>
extern
"C"
{
extern
"C"
{
/**
/**
...
@@ -106,22 +106,5 @@ extern "C" {
...
@@ -106,22 +106,5 @@ extern "C" {
*/
*/
AccountName
currentCode
();
AccountName
currentCode
();
/**
* Aborts processing of this message and unwinds all pending changes if the test condition is true
* @brief Aborts processing of this message and unwinds all pending changes
* @param test - 0 to abort, 1 to ignore
* @param cstr - a null terminated message to explain the reason for failure
*/
void
assert
(
uint32_t
test
,
const
char
*
cstr
);
/**
* Returns the time in seconds from 1970 of the last accepted block (not the block including this message)
* @brief Get time of the last accepted block
* @return time in seconds from 1970 of the last accepted block
*/
Time
now
();
///@ } messagecapi
///@ } messagecapi
}
}
contracts/eoslib/system.h
0 → 100644
浏览文件 @
9e22215c
#pragma once
#include <eoslib/types.h>
extern
"C"
{
/**
* @defgroup systemapi System API
* @ingroup contractdev
* @brief Define API for interating with system level intrinsics
*
*/
/**
* @defgroup systemcapi System C API
* @ingroup systemapi
* @brief Define API for interating with system level intrinsics
*
* @{
*/
/**
* Aborts processing of this message and unwinds all pending changes if the test condition is true
* @brief Aborts processing of this message and unwinds all pending changes
* @param test - 0 to abort, 1 to ignore
* @param cstr - a null terminated message to explain the reason for failure
*/
void
assert
(
uint32_t
test
,
const
char
*
cstr
);
/**
* Returns the time in seconds from 1970 of the last accepted block (not the block including this message)
* @brief Get time of the last accepted block
* @return time in seconds from 1970 of the last accepted block
*/
Time
now
();
///@ } systemcapi
}
contracts/test_api/test_api.cpp
浏览文件 @
9e22215c
...
@@ -60,6 +60,14 @@ extern "C" {
...
@@ -60,6 +60,14 @@ extern "C" {
WASM_TEST_HANDLER
(
test_crypto
,
asert_sha256_true
);
WASM_TEST_HANDLER
(
test_crypto
,
asert_sha256_true
);
WASM_TEST_HANDLER
(
test_crypto
,
asert_no_data
);
WASM_TEST_HANDLER
(
test_crypto
,
asert_no_data
);
//test transaction
WASM_TEST_HANDLER
(
test_transaction
,
send_message
);
WASM_TEST_HANDLER
(
test_transaction
,
send_message_max
);
WASM_TEST_HANDLER
(
test_transaction
,
send_message_large
);
WASM_TEST_HANDLER
(
test_transaction
,
send_transaction
);
WASM_TEST_HANDLER
(
test_transaction
,
send_transaction_max
);
WASM_TEST_HANDLER
(
test_transaction
,
send_transaction_large
);
//unhandled test call
//unhandled test call
WASM_TEST_ERROR_CODE
=
WASM_TEST_FAIL
;
WASM_TEST_ERROR_CODE
=
WASM_TEST_FAIL
;
}
}
...
...
contracts/test_api/test_api.hpp
浏览文件 @
9e22215c
...
@@ -9,12 +9,6 @@
...
@@ -9,12 +9,6 @@
#define WASM_ASSERT(m, message) if(!(m)) { WASM_TEST_ERROR_MESSAGE=(unsigned int)message; return WASM_TEST_FAIL; }
#define WASM_ASSERT(m, message) if(!(m)) { WASM_TEST_ERROR_MESSAGE=(unsigned int)message; return WASM_TEST_FAIL; }
typedef
unsigned
long
long
u64
;
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; \
}
typedef
unsigned
int
u32
;
typedef
unsigned
int
u32
;
static
constexpr
u32
DJBH
(
const
char
*
cp
)
static
constexpr
u32
DJBH
(
const
char
*
cp
)
{
{
...
@@ -24,6 +18,17 @@ static constexpr u32 DJBH(const char* cp)
...
@@ -24,6 +18,17 @@ static constexpr u32 DJBH(const char* cp)
return
hash
;
return
hash
;
}
}
static
constexpr
u64
WASM_TEST_ACTION
(
const
char
*
cls
,
const
char
*
method
)
{
return
u64
(
DJBH
(
cls
))
<<
32
|
u64
(
DJBH
(
method
));
}
#define WASM_TEST_HANDLER(CLASS, METHOD) \
if( action == WASM_TEST_ACTION(#CLASS, #METHOD) ) { \
WASM_TEST_ERROR_CODE = CLASS::METHOD(); \
return; \
}
#pragma pack(push, 1)
#pragma pack(push, 1)
struct
dummy_message
{
struct
dummy_message
{
char
a
;
//1
char
a
;
//1
...
@@ -99,3 +104,13 @@ struct test_crypto {
...
@@ -99,3 +104,13 @@ struct test_crypto {
static
unsigned
int
asert_sha256_true
();
static
unsigned
int
asert_sha256_true
();
static
unsigned
int
asert_no_data
();
static
unsigned
int
asert_no_data
();
};
};
struct
test_transaction
{
static
unsigned
int
send_message
();
static
unsigned
int
send_message_max
();
static
unsigned
int
send_message_large
();
static
unsigned
int
send_transaction
();
static
unsigned
int
send_transaction_max
();
static
unsigned
int
send_transaction_large
();
};
contracts/test_api/test_transaction.cpp
0 → 100644
浏览文件 @
9e22215c
#include <eoslib/transaction.hpp>
#include "test_api.hpp"
unsigned
int
test_transaction
::
send_message
()
{
dummy_message
payload
=
{
DUMMY_MESSAGE_DEFAULT_A
,
DUMMY_MESSAGE_DEFAULT_B
,
DUMMY_MESSAGE_DEFAULT_C
};
auto
msg
=
messageCreate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message"
),
&
payload
,
sizeof
(
dummy_message
));
messageSend
(
msg
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_transaction
::
send_transaction
()
{
dummy_message
payload
=
{
DUMMY_MESSAGE_DEFAULT_A
,
DUMMY_MESSAGE_DEFAULT_B
,
DUMMY_MESSAGE_DEFAULT_C
};
auto
msg
=
messageCreate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message"
),
&
payload
,
sizeof
(
dummy_message
));
auto
trx
=
transactionCreate
();
transactionRequireScope
(
trx
,
N
(
testapi
));
transactionAddMessage
(
trx
,
msg
);
transactionSend
(
trx
);
return
WASM_TEST_PASS
;
}
/**
* cause failure due to too many pending inline messages
*/
unsigned
int
test_transaction
::
send_message_max
()
{
dummy_message
payload
=
{
DUMMY_MESSAGE_DEFAULT_A
,
DUMMY_MESSAGE_DEFAULT_B
,
DUMMY_MESSAGE_DEFAULT_C
};
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
messageCreate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message"
),
&
payload
,
sizeof
(
dummy_message
));
}
return
WASM_TEST_FAIL
;
}
/**
* cause failure due to a large message payload
*/
unsigned
int
test_transaction
::
send_message_large
()
{
char
large_message
[
8
*
1024
];
messageCreate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message"
),
large_message
,
sizeof
(
large_message
));
return
WASM_TEST_FAIL
;
}
/**
* cause failure due to too many pending deferred transactions
*/
unsigned
int
test_transaction
::
send_transaction_max
()
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
transactionCreate
();
}
return
WASM_TEST_FAIL
;
}
/**
* cause failure due to a large transaction size
*/
unsigned
int
test_transaction
::
send_transaction_large
()
{
auto
trx
=
transactionCreate
();
transactionRequireScope
(
trx
,
N
(
testapi
));
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
char
large_message
[
4
*
1024
];
auto
msg
=
messageCreate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message"
),
large_message
,
sizeof
(
large_message
));
transactionAddMessage
(
trx
,
msg
);
}
transactionSend
(
trx
);
return
WASM_TEST_FAIL
;
}
libraries/chain/wasm_interface.cpp
浏览文件 @
9e22215c
...
@@ -293,17 +293,18 @@ DEFINE_INTRINSIC_FUNCTION4(env,messageCreate,messageCreate,i32,i64,code,i64,type
...
@@ -293,17 +293,18 @@ DEFINE_INTRINSIC_FUNCTION4(env,messageCreate,messageCreate,i32,i64,code,i64,type
EOS_ASSERT
(
length
>
0
,
tx_unknown_argument
,
EOS_ASSERT
(
length
>
0
,
tx_unknown_argument
,
"Attempting to push an empty message"
);
"Attempting to push an empty message"
);
const
char
*
buffer
=
nullptr
;
Bytes
payload
;
try
{
try
{
// memoryArrayPtr checks that the entire array of bytes is valid and
// memoryArrayPtr checks that the entire array of bytes is valid and
// within the bounds of the memory segment so that transactions cannot pass
// within the bounds of the memory segment so that transactions cannot pass
// bad values in attempts to read improper memory
// bad values in attempts to read improper memory
buffer
=
memoryArrayPtr
<
const
char
>
(
mem
,
data
,
uint32_t
(
length
)
);
const
char
*
buffer
=
memoryArrayPtr
<
const
char
>
(
mem
,
uint32_t
(
data
),
uint32_t
(
length
)
);
payload
.
insert
(
payload
.
end
(),
buffer
,
buffer
+
length
);
}
catch
(
const
Runtime
::
Exception
&
e
)
{
}
catch
(
const
Runtime
::
Exception
&
e
)
{
FC_THROW_EXCEPTION
(
tx_unknown_argument
,
"Message data is not a valid memory range"
);
FC_THROW_EXCEPTION
(
tx_unknown_argument
,
"Message data is not a valid memory range"
);
}
}
auto
&
pmsg
=
wasm
.
current_apply_context
->
create_pending_message
(
Name
(
code
),
Name
(
type
),
Bytes
(
buffer
,
buffer
+
length
)
);
auto
&
pmsg
=
wasm
.
current_apply_context
->
create_pending_message
(
Name
(
code
),
Name
(
type
),
payload
);
return
pmsg
.
handle
;
return
pmsg
.
handle
;
}
}
...
...
tests/api_tests/api_tests.cpp
浏览文件 @
9e22215c
...
@@ -143,6 +143,8 @@ bool is_access_violation(fc::unhandled_exception const & e) {
...
@@ -143,6 +143,8 @@ bool is_access_violation(fc::unhandled_exception const & e) {
bool
is_tx_missing_recipient
(
tx_missing_recipient
const
&
e
)
{
return
true
;}
bool
is_tx_missing_recipient
(
tx_missing_recipient
const
&
e
)
{
return
true
;}
bool
is_tx_missing_auth
(
tx_missing_auth
const
&
e
)
{
return
true
;
}
bool
is_tx_missing_auth
(
tx_missing_auth
const
&
e
)
{
return
true
;
}
bool
is_tx_missing_scope
(
tx_missing_scope
const
&
e
)
{
return
true
;
}
bool
is_tx_missing_scope
(
tx_missing_scope
const
&
e
)
{
return
true
;
}
bool
is_tx_resource_exhausted
(
tx_resource_exhausted
const
&
e
)
{
return
true
;
}
bool
is_tx_unknown_argument
(
tx_unknown_argument
const
&
e
)
{
return
true
;
}
bool
is_assert_exception
(
fc
::
assert_exception
const
&
e
)
{
return
true
;
}
bool
is_assert_exception
(
fc
::
assert_exception
const
&
e
)
{
return
true
;
}
std
::
vector
<
std
::
string
>
capture
;
std
::
vector
<
std
::
string
>
capture
;
...
@@ -380,6 +382,19 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture)
...
@@ -380,6 +382,19 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture)
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_crypto"
,
"asert_no_data"
),
{},
{}
),
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_crypto"
,
"asert_no_data"
),
{},
{}
),
fc
::
assert_exception
,
is_assert_exception
);
fc
::
assert_exception
,
is_assert_exception
);
//Test transaction
BOOST_CHECK_MESSAGE
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_transaction"
,
"send_message"
),
{},
{})
==
WASM_TEST_PASS
,
"test_transaction::send_message()"
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_transaction"
,
"send_message_large"
),
{},
{}
),
tx_resource_exhausted
,
is_tx_resource_exhausted
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_transaction"
,
"send_message_max"
),
{},
{}
),
tx_resource_exhausted
,
is_tx_resource_exhausted
);
BOOST_CHECK_MESSAGE
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_transaction"
,
"send_transaction"
),
{},
{})
==
WASM_TEST_PASS
,
"test_transaction::send_message()"
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_transaction"
,
"send_transaction_large"
),
{},
{}
),
tx_resource_exhausted
,
is_tx_resource_exhausted
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_transaction"
,
"send_transaction_max"
),
{},
{}
),
tx_resource_exhausted
,
is_tx_resource_exhausted
);
}
FC_LOG_AND_RETHROW
()
}
}
FC_LOG_AND_RETHROW
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录