Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
132294d9
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,发现更多精彩内容 >>
提交
132294d9
编写于
6月 26, 2017
作者:
B
Brian Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added test to verify float instructions rejected
上级
184a2de9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
789 addition
and
0 deletion
+789
-0
tests/tests/block_tests.cpp
tests/tests/block_tests.cpp
+789
-0
未找到文件。
tests/tests/block_tests.cpp
浏览文件 @
132294d9
...
...
@@ -1256,4 +1256,793 @@ BOOST_FIXTURE_TEST_CASE(wipe, testing_fixture)
}
}
FC_LOG_AND_RETHROW
()
}
//Test account script float rejection
BOOST_FIXTURE_TEST_CASE
(
create_script_w_float
,
testing_fixture
)
{
try
{
Make_Database
(
db
);
db
.
produce_blocks
(
10
);
Make_Account
(
db
,
simplecoin
);
db
.
produce_blocks
(
1
);
/*
auto c_apply = R"(
typedef long long uint64_t;
typedef unsigned int uint32_t;
void print( char* string, int length );
void printi( int );
void printi64( uint64_t );
void assert( int test, char* message );
void store( const char* key, int keylength, const char* value, int valuelen );
int load( const char* key, int keylength, char* value, int maxlen );
int remove( const char* key, int keyLength );
void* memcpy( void* dest, const void* src, uint32_t size );
int readMessage( char* dest, int destsize );
void* malloc( unsigned int size ) {
static char dynamic_memory[1024*8];
static int start = 0;
int old_start = start;
start += 8*((size+7)/8);
assert( start < sizeof(dynamic_memory), "out of memory" );
return &dynamic_memory[old_start];
}
typedef struct {
uint64_t name[4];
} AccountName;
typedef struct {
uint32_t length;
char data[];
} String;
typedef struct {
char* start;
char* pos;
char* end;
} DataStream;
void DataStream_init( DataStream* ds, char* start, int length ) {
ds->start = start;
ds->end = start + length;
ds->pos = start;
}
void AccountName_initString( AccountName* a, String* s ) {
assert( s->length <= sizeof(AccountName), "String is longer than account name allows" );
memcpy( a, s->data, s->length );
}
void AccountName_initCString( AccountName* a, const char* s, uint32_t len ) {
assert( len <= sizeof(AccountName), "String is longer than account name allows" );
memcpy( a, s, len );
}
void AccountName_unpack( DataStream* ds, AccountName* account );
void uint64_unpack( DataStream* ds, uint64_t* value ) {
assert( ds->pos + sizeof(uint64_t) <= ds->end, "read past end of stream" );
memcpy( (char*)value, ds->pos, 8 );
ds->pos += sizeof(uint64_t);
}
void Varint_unpack( DataStream* ds, uint32_t* value );
void String_unpack( DataStream* ds, String** value ) {
static uint32_t size;
Varint_unpack( ds, &size );
assert( ds->pos + size <= ds->end, "read past end of stream");
String* str = (String*)malloc( size + sizeof(String) );
memcpy( str->data, ds->pos, size );
*value = str;
}
/// END BUILT IN LIBRARY.... everything below this is "user contract"
typedef struct {
AccountName from;
AccountName to;
uint64_t amount;
String* memo;
} Transfer;
void Transfer_unpack( DataStream* ds, Transfer* transfer )
{
AccountName_unpack( ds, &transfer->from );
AccountName_unpack( ds, &transfer->to );
uint64_unpack( ds, &transfer->amount );
String_unpack( ds, &transfer->memo );
}
typedef struct {
uint64_t balance;
} Balance;
void onInit() {
static Balance initial;
static AccountName simplecoin;
AccountName_initCString( &simplecoin, "simplecoin", 10 );
initial.balance = 1000*1000;
store( (const char*)&simplecoin, sizeof(AccountName), (const char*)&initial, sizeof(Balance));
}
void onApply_Transfer_simplecoin() {
static char buffer[100];
int read = readMessage( buffer, 100 );
static Transfer message;
static DataStream ds;
DataStream_init( &ds, buffer, read );
Transfer_unpack( &ds, &message );
static Balance from_balance;
static Balance to_balance;
to_balance.balance = 0;
read = load( (const char*)&message.from, sizeof(message.from), (char*)&from_balance.balance, sizeof(from_balance.balance) );
assert( read == sizeof(Balance), "no existing balance" );
assert( from_balance.balance >= message.amount, "insufficient funds" );
read = load( (const char*)&message.to, sizeof(message.to), (char*)&to_balance.balance, sizeof(to_balance.balance) );
to_balance.balance += message.amount;
from_balance.balance -= message.amount;
double bal = to_balance.balance;
if( bal + 0.5 < 50.5 )
return;
if( from_balance.balance )
store( (const char*)&message.from, sizeof(AccountName), (const char*)&from_balance.balance, sizeof(from_balance.balance) );
else
remove( (const char*)&message.from, sizeof(AccountName) );
store( (const char*)&message.to, sizeof(message.to), (const char*)&to_balance.balance, sizeof(to_balance.balance) );
}
");
*/
std
::
string
wast_apply
=
R"(
(module
(type $FUNCSIG$vii (func (param i32 i32)))
(type $FUNCSIG$viiii (func (param i32 i32 i32 i32)))
(type $FUNCSIG$iii (func (param i32 i32) (result i32)))
(type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32)))
(type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32)))
(import "env" "AccountName_unpack" (func $AccountName_unpack (param i32 i32)))
(import "env" "Varint_unpack" (func $Varint_unpack (param i32 i32)))
(import "env" "assert" (func $assert (param i32 i32)))
(import "env" "load" (func $load (param i32 i32 i32 i32) (result i32)))
(import "env" "memcpy" (func $memcpy (param i32 i32 i32) (result i32)))
(import "env" "readMessage" (func $readMessage (param i32 i32) (result i32)))
(import "env" "remove" (func $remove (param i32 i32) (result i32)))
(import "env" "store" (func $store (param i32 i32 i32 i32)))
(table 0 anyfunc)
(memory $0 1)
(data (i32.const 8224) "out of memory\00")
(data (i32.const 8240) "String is longer than account name allows\00")
(data (i32.const 8288) "read past end of stream\00")
(data (i32.const 8368) "simplecoin\00")
(data (i32.const 8608) "no existing balance\00")
(data (i32.const 8640) "insufficient funds\00")
(export "memory" (memory $0))
(export "malloc" (func $malloc))
(export "DataStream_init" (func $DataStream_init))
(export "AccountName_initString" (func $AccountName_initString))
(export "AccountName_initCString" (func $AccountName_initCString))
(export "uint64_unpack" (func $uint64_unpack))
(export "String_unpack" (func $String_unpack))
(export "Transfer_unpack" (func $Transfer_unpack))
(export "onInit" (func $onInit))
(export "onApply_Transfer_simplecoin" (func $onApply_Transfer_simplecoin))
(func $malloc (param $0 i32) (result i32)
(local $1 i32)
(i32.store offset=8208
(i32.const 0)
(tee_local $0
(i32.add
(tee_local $1
(i32.load offset=8208
(i32.const 0)
)
)
(i32.and
(i32.add
(get_local $0)
(i32.const 7)
)
(i32.const -8)
)
)
)
)
(call $assert
(i32.lt_u
(get_local $0)
(i32.const 8192)
)
(i32.const 8224)
)
(i32.add
(get_local $1)
(i32.const 16)
)
)
(func $DataStream_init (param $0 i32) (param $1 i32) (param $2 i32)
(i32.store
(get_local $0)
(get_local $1)
)
(i32.store offset=4
(get_local $0)
(get_local $1)
)
(i32.store offset=8
(get_local $0)
(i32.add
(get_local $1)
(get_local $2)
)
)
)
(func $AccountName_initString (param $0 i32) (param $1 i32)
(call $assert
(i32.lt_u
(i32.load
(get_local $1)
)
(i32.const 33)
)
(i32.const 8240)
)
(drop
(call $memcpy
(get_local $0)
(i32.add
(get_local $1)
(i32.const 4)
)
(i32.load
(get_local $1)
)
)
)
)
(func $AccountName_initCString (param $0 i32) (param $1 i32) (param $2 i32)
(call $assert
(i32.lt_u
(get_local $2)
(i32.const 33)
)
(i32.const 8240)
)
(drop
(call $memcpy
(get_local $0)
(get_local $1)
(get_local $2)
)
)
)
(func $uint64_unpack (param $0 i32) (param $1 i32)
(call $assert
(i32.le_u
(i32.add
(i32.load offset=4
(get_local $0)
)
(i32.const 8)
)
(i32.load offset=8
(get_local $0)
)
)
(i32.const 8288)
)
(i64.store align=1
(get_local $1)
(i64.load align=1
(i32.load offset=4
(get_local $0)
)
)
)
(i32.store offset=4
(get_local $0)
(i32.add
(i32.load offset=4
(get_local $0)
)
(i32.const 8)
)
)
)
(func $String_unpack (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(call $Varint_unpack
(get_local $0)
(i32.const 8312)
)
(call $assert
(i32.le_u
(i32.add
(i32.load offset=4
(get_local $0)
)
(i32.load offset=8312
(i32.const 0)
)
)
(i32.load offset=8
(get_local $0)
)
)
(i32.const 8288)
)
(i32.store offset=8208
(i32.const 0)
(tee_local $3
(i32.add
(i32.and
(i32.add
(i32.load offset=8312
(i32.const 0)
)
(i32.const 11)
)
(i32.const -8)
)
(tee_local $2
(i32.load offset=8208
(i32.const 0)
)
)
)
)
)
(call $assert
(i32.lt_u
(get_local $3)
(i32.const 8192)
)
(i32.const 8224)
)
(drop
(call $memcpy
(i32.add
(get_local $2)
(i32.const 20)
)
(i32.load offset=4
(get_local $0)
)
(i32.load offset=8312
(i32.const 0)
)
)
)
(i32.store
(get_local $1)
(i32.add
(get_local $2)
(i32.const 16)
)
)
)
(func $Transfer_unpack (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(call $AccountName_unpack
(get_local $0)
(get_local $1)
)
(call $AccountName_unpack
(get_local $0)
(i32.add
(get_local $1)
(i32.const 32)
)
)
(call $assert
(i32.le_u
(i32.add
(i32.load offset=4
(get_local $0)
)
(i32.const 8)
)
(i32.load offset=8
(get_local $0)
)
)
(i32.const 8288)
)
(i64.store offset=64 align=1
(get_local $1)
(i64.load align=1
(i32.load offset=4
(get_local $0)
)
)
)
(i32.store offset=4
(get_local $0)
(i32.add
(i32.load offset=4
(get_local $0)
)
(i32.const 8)
)
)
(call $Varint_unpack
(get_local $0)
(i32.const 8312)
)
(call $assert
(i32.le_u
(i32.add
(i32.load offset=4
(get_local $0)
)
(i32.load offset=8312
(i32.const 0)
)
)
(i32.load offset=8
(get_local $0)
)
)
(i32.const 8288)
)
(i32.store offset=8208
(i32.const 0)
(tee_local $3
(i32.add
(i32.and
(i32.add
(i32.load offset=8312
(i32.const 0)
)
(i32.const 11)
)
(i32.const -8)
)
(tee_local $2
(i32.load offset=8208
(i32.const 0)
)
)
)
)
)
(call $assert
(i32.lt_u
(get_local $3)
(i32.const 8192)
)
(i32.const 8224)
)
(drop
(call $memcpy
(i32.add
(get_local $2)
(i32.const 20)
)
(i32.load offset=4
(get_local $0)
)
(i32.load offset=8312
(i32.const 0)
)
)
)
(i32.store offset=72
(get_local $1)
(i32.add
(get_local $2)
(i32.const 16)
)
)
)
(func $onInit
(call $assert
(i32.const 1)
(i32.const 8240)
)
(i64.store offset=8320
(i32.const 0)
(i64.const 1000000)
)
(i32.store16 offset=8336
(i32.const 0)
(i32.load16_u offset=8376 align=1
(i32.const 0)
)
)
(i64.store offset=8328
(i32.const 0)
(i64.load offset=8368 align=1
(i32.const 0)
)
)
(call $store
(i32.const 8328)
(i32.const 32)
(i32.const 8320)
(i32.const 8)
)
)
(func $onApply_Transfer_simplecoin
(local $0 i32)
(local $1 i32)
(local $2 i64)
(set_local $0
(call $readMessage
(i32.const 8384)
(i32.const 100)
)
)
(i32.store offset=8568
(i32.const 0)
(i32.const 8384)
)
(i32.store offset=8572
(i32.const 0)
(i32.const 8384)
)
(i32.store offset=8576
(i32.const 0)
(i32.add
(get_local $0)
(i32.const 8384)
)
)
(call $AccountName_unpack
(i32.const 8568)
(i32.const 8488)
)
(call $AccountName_unpack
(i32.const 8568)
(i32.const 8520)
)
(call $assert
(i32.le_u
(i32.add
(i32.load offset=8572
(i32.const 0)
)
(i32.const 8)
)
(i32.load offset=8576
(i32.const 0)
)
)
(i32.const 8288)
)
(i64.store offset=8552
(i32.const 0)
(i64.load align=1
(tee_local $0
(i32.load offset=8572
(i32.const 0)
)
)
)
)
(i32.store offset=8572
(i32.const 0)
(i32.add
(get_local $0)
(i32.const 8)
)
)
(call $Varint_unpack
(i32.const 8568)
(i32.const 8312)
)
(call $assert
(i32.le_u
(i32.add
(i32.load offset=8572
(i32.const 0)
)
(i32.load offset=8312
(i32.const 0)
)
)
(i32.load offset=8576
(i32.const 0)
)
)
(i32.const 8288)
)
(i32.store offset=8208
(i32.const 0)
(tee_local $1
(i32.add
(i32.and
(i32.add
(i32.load offset=8312
(i32.const 0)
)
(i32.const 11)
)
(i32.const -8)
)
(tee_local $0
(i32.load offset=8208
(i32.const 0)
)
)
)
)
)
(call $assert
(i32.lt_u
(get_local $1)
(i32.const 8192)
)
(i32.const 8224)
)
(drop
(call $memcpy
(i32.add
(get_local $0)
(i32.const 20)
)
(i32.load offset=8572
(i32.const 0)
)
(i32.load offset=8312
(i32.const 0)
)
)
)
(i64.store offset=8592
(i32.const 0)
(i64.const 0)
)
(i32.store offset=8560
(i32.const 0)
(i32.add
(get_local $0)
(i32.const 16)
)
)
(call $assert
(i32.eq
(call $load
(i32.const 8488)
(i32.const 32)
(i32.const 8584)
(i32.const 8)
)
(i32.const 8)
)
(i32.const 8608)
)
(call $assert
(i64.ge_s
(i64.load offset=8584
(i32.const 0)
)
(i64.load offset=8552
(i32.const 0)
)
)
(i32.const 8640)
)
(drop
(call $load
(i32.const 8520)
(i32.const 32)
(i32.const 8592)
(i32.const 8)
)
)
(i64.store offset=8592
(i32.const 0)
(i64.add
(i64.load offset=8592
(i32.const 0)
)
(tee_local $2
(i64.load offset=8552
(i32.const 0)
)
)
)
)
(i64.store offset=8584
(i32.const 0)
(tee_local $2
(i64.sub
(i64.load offset=8584
(i32.const 0)
)
(get_local $2)
)
)
)
(block $label$0
(br_if $label$0
(f64.lt
(f64.add
(f64.convert_s/i64
(get_local $2)
)
(f64.const 0.5)
)
(f64.const 50.5)
)
)
(block $label$1
(br_if $label$1
(i64.eqz
(get_local $2)
)
)
(call $store
(i32.const 8488)
(i32.const 32)
(i32.const 8584)
(i32.const 8)
)
(br $label$0)
)
(drop
(call $remove
(i32.const 8488)
(i32.const 32)
)
)
)
(call $store
(i32.const 8520)
(i32.const 32)
(i32.const 8592)
(i32.const 8)
)
)
)
)"
;
types
::
SetCode
handler
;
handler
.
account
=
"simplecoin"
;
types
::
DefineStruct
interface
;
interface
.
scope
=
"simplecoin"
;
interface
.
definition
=
types
::
GetStruct
<
types
::
Transfer
>::
type
();
auto
wasm
=
assemble_wast
(
wast_apply
);
handler
.
code
.
resize
(
wasm
.
size
());
memcpy
(
handler
.
code
.
data
(),
wasm
.
data
(),
wasm
.
size
()
);
eos
::
chain
::
SignedTransaction
trx
;
trx
.
messages
.
resize
(
2
);
trx
.
messages
[
0
].
sender
=
"simplecoin"
;
trx
.
messages
[
0
].
recipient
=
config
::
SystemContractName
;
trx
.
setMessage
(
0
,
"DefineStruct"
,
interface
);
trx
.
messages
[
1
].
sender
=
"simplecoin"
;
trx
.
messages
[
1
].
recipient
=
config
::
SystemContractName
;
trx
.
setMessage
(
1
,
"SetCode"
,
handler
);
trx
.
expiration
=
db
.
head_block_time
()
+
100
;
trx
.
set_reference_block
(
db
.
head_block_id
());
try
{
db
.
push_transaction
(
trx
);
BOOST_FAIL
(
"floating point instructions should be rejected"
);
/* } catch (const Serialization::FatalSerializationException& fse) {
BOOST_CHECK_EQUAL("float instructions not allowed", fse.message);
*/
}
catch
(
const
std
::
exception
&
exp
)
{
BOOST_FAIL
(
"Serialization::FatalSerializationException does not inherit from std::exception"
);
}
catch
(...)
{
// empty throw expected, since
}
}
FC_LOG_AND_RETHROW
()
}
BOOST_AUTO_TEST_SUITE_END
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录