Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
16eaee65
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,发现更多精彩内容 >>
提交
16eaee65
编写于
4月 07, 2018
作者:
B
Brian Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added unit test for tic_tac_toe to ensure it continues to work with contract API. GH #2214
上级
878be869
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
211 addition
and
0 deletion
+211
-0
tests/wasm_tests/tic_tac_toe_tests.cpp
tests/wasm_tests/tic_tac_toe_tests.cpp
+211
-0
未找到文件。
tests/wasm_tests/tic_tac_toe_tests.cpp
0 → 100644
浏览文件 @
16eaee65
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <boost/test/unit_test.hpp>
#pragma GCC diagnostic pop
#include <boost/algorithm/string/predicate.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/chain/contracts/abi_serializer.hpp>
#include <tic_tac_toe/tic_tac_toe.wast.hpp>
#include <tic_tac_toe/tic_tac_toe.abi.hpp>
#include <eosio.system/eosio.system.wast.hpp>
#include <eosio.system/eosio.system.abi.hpp>
#include <proxy/proxy.wast.hpp>
#include <proxy/proxy.abi.hpp>
#include <Runtime/Runtime.h>
#include <fc/variant_object.hpp>
#include <fc/io/json.hpp>
#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif
using
namespace
eosio
;
using
namespace
eosio
::
chain
;
using
namespace
eosio
::
chain
::
contracts
;
using
namespace
eosio
::
testing
;
using
namespace
fc
;
struct
movement
{
uint32_t
row
;
uint32_t
column
;
template
<
typename
DataStream
>
friend
DataStream
&
operator
<<
(
DataStream
&
ds
,
const
movement
&
t
){
\
return
ds
<<
t
.
row
<<
t
.
column
;
}
template
<
typename
DataStream
>
friend
DataStream
&
operator
>>
(
DataStream
&
ds
,
movement
&
t
){
return
ds
>>
t
.
row
>>
t
.
column
;
}
};
BOOST_AUTO_TEST_SUITE
(
tic_tac_toe_tests
)
BOOST_AUTO_TEST_CASE
(
tic_tac_toe_game
)
try
{
TESTER
chain
;
abi_serializer
abi_ser
=
json
::
from_string
(
tic_tac_toe_abi
).
as
<
abi_def
>
();
chain
.
set_code
(
config
::
system_account_name
,
eosio_system_wast
);
chain
.
set_abi
(
config
::
system_account_name
,
eosio_system_abi
);
chain
.
produce_blocks
();
chain
.
create_account
(
N
(
tic
.
tac
.
toe
));
chain
.
produce_blocks
(
10
);
chain
.
set_code
(
N
(
tic
.
tac
.
toe
),
tic_tac_toe_wast
);
chain
.
set_abi
(
N
(
tic
.
tac
.
toe
),
tic_tac_toe_abi
);
chain
.
produce_blocks
();
chain
.
create_account
(
N
(
player1
));
chain
.
create_account
(
N
(
player2
));
chain
.
produce_blocks
(
10
);
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
create
),
N
(
player1
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
);
chain
.
produce_blocks
();
auto
mvt
=
mutable_variant_object
()
(
"row"
,
1
)
(
"column"
,
1
);
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player1
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player1"
)
(
"mvt"
,
mvt
)
);
mvt
=
mutable_variant_object
()
(
"row"
,
0
)
(
"column"
,
1
);
BOOST_CHECK_EXCEPTION
(
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player1
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player1"
)
(
"mvt"
,
mvt
)
),
transaction_exception
,
assert_message_contains
(
"not your turn"
));
mvt
=
mutable_variant_object
()
(
"row"
,
1
)
(
"column"
,
1
);
BOOST_CHECK_EXCEPTION
(
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player2"
)
(
"mvt"
,
mvt
)
),
transaction_exception
,
assert_message_contains
(
"not a valid movement"
));
mvt
=
mutable_variant_object
()
(
"row"
,
0
)
(
"column"
,
1
);
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player2"
)
(
"mvt"
,
mvt
)
);
mvt
=
mutable_variant_object
()
(
"row"
,
0
)
(
"column"
,
0
);
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player1
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player1"
)
(
"mvt"
,
mvt
)
);
mvt
=
mutable_variant_object
()
(
"row"
,
0
)
(
"column"
,
2
);
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player2"
)
(
"mvt"
,
mvt
)
);
mvt
=
mutable_variant_object
()
(
"row"
,
2
)
(
"column"
,
2
);
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player1
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player1"
)
(
"mvt"
,
mvt
)
);
mvt
=
mutable_variant_object
()
(
"row"
,
2
)
(
"column"
,
0
);
BOOST_CHECK_EXCEPTION
(
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player2"
)
(
"mvt"
,
mvt
)
),
transaction_exception
,
assert_message_contains
(
"the game has ended"
));
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
close
),
N
(
player1
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
);
mvt
=
mutable_variant_object
()
(
"row"
,
2
)
(
"column"
,
0
);
BOOST_CHECK_EXCEPTION
(
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player2"
)
(
"mvt"
,
mvt
)
),
transaction_exception
,
assert_message_contains
(
"game doesn't exists"
));
BOOST_CHECK_EXCEPTION
(
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
restart
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player2"
)
(
"host"
,
"player1"
)
(
"by"
,
"player2"
)
),
transaction_exception
,
assert_message_contains
(
"game doesn't exists"
));
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
create
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player1"
)
(
"host"
,
"player2"
)
);
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
restart
),
N
(
player1
),
mutable_variant_object
()
(
"challenger"
,
"player1"
)
(
"host"
,
"player2"
)
(
"by"
,
"player1"
)
);
// making a move and ...
mvt
=
mutable_variant_object
()
(
"row"
,
1
)
(
"column"
,
1
);
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player1"
)
(
"host"
,
"player2"
)
(
"by"
,
"player2"
)
(
"mvt"
,
mvt
)
);
// ... repeating to get exception to ensure restart above actually did something
mvt
=
mutable_variant_object
()
(
"row"
,
0
)
(
"column"
,
1
);
BOOST_CHECK_EXCEPTION
(
chain
.
push_action
(
N
(
tic
.
tac
.
toe
),
N
(
move
),
N
(
player2
),
mutable_variant_object
()
(
"challenger"
,
"player1"
)
(
"host"
,
"player2"
)
(
"by"
,
"player2"
)
(
"mvt"
,
mvt
)
),
transaction_exception
,
assert_message_contains
(
"not your turn"
));
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录