Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
32a1efd0
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,发现更多精彩内容 >>
提交
32a1efd0
编写于
5月 22, 2018
作者:
K
Kevin Heifner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use new get_amount() of asset
上级
2c98697a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
66 addition
and
64 deletion
+66
-64
programs/cleos/main.cpp
programs/cleos/main.cpp
+3
-3
unittests/bootseq_tests.cpp
unittests/bootseq_tests.cpp
+1
-1
unittests/currency_tests.cpp
unittests/currency_tests.cpp
+7
-7
unittests/eosio.system_tests.cpp
unittests/eosio.system_tests.cpp
+39
-39
unittests/eosio.token_tests.cpp
unittests/eosio.token_tests.cpp
+4
-2
unittests/misc_tests.cpp
unittests/misc_tests.cpp
+12
-12
未找到文件。
programs/cleos/main.cpp
浏览文件 @
32a1efd0
...
...
@@ -576,7 +576,7 @@ authority parse_json_authority_or_key(const std::string& authorityJsonOrFile) {
asset
to_asset
(
const
string
&
code
,
const
string
&
s
)
{
static
map
<
eosio
::
chain
::
symbol_code
,
eosio
::
chain
::
symbol
>
cache
;
auto
a
=
asset
::
from_string
(
s
);
eosio
::
chain
::
symbol_code
sym
=
a
.
sym
.
to_symbol_code
();
eosio
::
chain
::
symbol_code
sym
=
a
.
get_symbol
()
.
to_symbol_code
();
auto
it
=
cache
.
find
(
sym
);
auto
sym_str
=
a
.
symbol_name
();
if
(
it
==
cache
.
end
()
)
{
...
...
@@ -588,7 +588,7 @@ asset to_asset( const string& code, const string& s ) {
auto
obj_it
=
obj
.
find
(
sym_str
);
if
(
obj_it
!=
obj
.
end
())
{
auto
result
=
obj_it
->
value
().
as
<
eosio
::
chain_apis
::
read_only
::
get_currency_stats_result
>
();
auto
p
=
cache
.
insert
(
make_pair
(
sym
,
result
.
max_supply
.
sym
));
auto
p
=
cache
.
insert
(
make_pair
(
sym
,
result
.
max_supply
.
get_symbol
()
));
it
=
p
.
first
;
}
else
{
FC_THROW
(
"Symbol ${s} is not supported by token contract ${c}"
,
(
"s"
,
sym_str
)(
"c"
,
code
));
...
...
@@ -598,7 +598,7 @@ asset to_asset( const string& code, const string& s ) {
if
(
a
.
decimals
()
<
expected_symbol
.
decimals
()
)
{
auto
factor
=
expected_symbol
.
precision
()
/
a
.
precision
();
auto
a_old
=
a
;
a
=
asset
(
a
.
amount
*
factor
,
expected_symbol
);
a
=
asset
(
a
.
get_amount
()
*
factor
,
expected_symbol
);
}
else
if
(
a
.
decimals
()
>
expected_symbol
.
decimals
()
)
{
FC_THROW
(
"Too many decimal digits in ${a}, only ${d} supported"
,
(
"a"
,
a
)(
"d"
,
expected_symbol
.
decimals
()));
}
// else precision matches
...
...
unittests/bootseq_tests.cpp
浏览文件 @
32a1efd0
...
...
@@ -309,7 +309,7 @@ BOOST_FIXTURE_TEST_CASE( bootseq_test, bootseq_tester ) {
produce_min_num_of_blocks_to_spend_time_wo_inactive_prod
(
fc
::
seconds
(
30
*
24
*
3600
));
// 30 days
// Since the total activated stake is larger than 150,000,000, pool should be filled reward should be bigger than zero
claim_rewards
(
N
(
runnerup1
));
BOOST_TEST
(
get_balance
(
N
(
runnerup1
)).
amount
>
0
);
BOOST_TEST
(
get_balance
(
N
(
runnerup1
)).
get_amount
()
>
0
);
const
auto
first_june_2018
=
fc
::
seconds
(
1527811200
);
// 2018-06-01
const
auto
first_june_2028
=
fc
::
seconds
(
1843430400
);
// 2028-06-01
...
...
unittests/currency_tests.cpp
浏览文件 @
32a1efd0
...
...
@@ -329,7 +329,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
// Missing decimal point, should create asset with 0 decimals
{
asset
a
=
asset
::
from_string
(
"10 CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
amount
,
10
);
BOOST_REQUIRE_EQUAL
(
a
.
get_amount
()
,
10
);
BOOST_REQUIRE_EQUAL
(
a
.
precision
(),
1
);
BOOST_REQUIRE_EQUAL
(
a
.
decimals
(),
0
);
BOOST_REQUIRE_EQUAL
(
a
.
symbol_name
(),
"CUR"
);
...
...
@@ -356,7 +356,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
// Multiple spaces
{
asset
a
=
asset
::
from_string
(
"1000000000.00000 CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
amount
,
100000000000000
);
BOOST_REQUIRE_EQUAL
(
a
.
get_amount
()
,
100000000000000
);
BOOST_REQUIRE_EQUAL
(
a
.
decimals
(),
5
);
BOOST_REQUIRE_EQUAL
(
a
.
symbol_name
(),
"CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
to_string
(),
"1000000000.00000 CUR"
);
...
...
@@ -365,7 +365,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
// Valid asset
{
asset
a
=
asset
::
from_string
(
"1000000000.00000 CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
amount
,
100000000000000
);
BOOST_REQUIRE_EQUAL
(
a
.
get_amount
()
,
100000000000000
);
BOOST_REQUIRE_EQUAL
(
a
.
decimals
(),
5
);
BOOST_REQUIRE_EQUAL
(
a
.
symbol_name
(),
"CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
to_string
(),
"1000000000.00000 CUR"
);
...
...
@@ -374,7 +374,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
// Negative asset
{
asset
a
=
asset
::
from_string
(
"-001000000.00010 CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
amount
,
-
100000000010
);
BOOST_REQUIRE_EQUAL
(
a
.
get_amount
()
,
-
100000000010
);
BOOST_REQUIRE_EQUAL
(
a
.
decimals
(),
5
);
BOOST_REQUIRE_EQUAL
(
a
.
symbol_name
(),
"CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
to_string
(),
"-1000000.00010 CUR"
);
...
...
@@ -383,7 +383,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
// Negative asset below 1
{
asset
a
=
asset
::
from_string
(
"-000000000.00100 CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
amount
,
-
100
);
BOOST_REQUIRE_EQUAL
(
a
.
get_amount
()
,
-
100
);
BOOST_REQUIRE_EQUAL
(
a
.
decimals
(),
5
);
BOOST_REQUIRE_EQUAL
(
a
.
symbol_name
(),
"CUR"
);
BOOST_REQUIRE_EQUAL
(
a
.
to_string
(),
"-0.00100 CUR"
);
...
...
@@ -392,7 +392,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
// Negative asset below 1
{
asset
a
=
asset
::
from_string
(
"-0.0001 PPP"
);
BOOST_REQUIRE_EQUAL
(
a
.
amount
,
-
1
);
BOOST_REQUIRE_EQUAL
(
a
.
get_amount
()
,
-
1
);
BOOST_REQUIRE_EQUAL
(
a
.
decimals
(),
4
);
BOOST_REQUIRE_EQUAL
(
a
.
symbol_name
(),
"PPP"
);
BOOST_REQUIRE_EQUAL
(
a
.
to_string
(),
"-0.0001 PPP"
);
...
...
@@ -575,7 +575,7 @@ BOOST_FIXTURE_TEST_CASE( test_input_quantity, currency_tester ) try {
BOOST_CHECK_EQUAL
(
true
,
chain_has_transaction
(
trace
->
id
));
BOOST_CHECK_EQUAL
(
asset
::
from_string
(
"100.0000 CUR"
),
get_balance
(
N
(
alice
)));
BOOST_CHECK_EQUAL
(
1000000
,
get_balance
(
N
(
alice
)).
amount
);
BOOST_CHECK_EQUAL
(
1000000
,
get_balance
(
N
(
alice
)).
get_amount
()
);
}
...
...
unittests/eosio.system_tests.cpp
浏览文件 @
32a1efd0
...
...
@@ -353,7 +353,7 @@ public:
double
stake2votes
(
asset
stake
)
{
auto
now
=
control
->
pending_block_time
().
time_since_epoch
().
count
()
/
1000000
;
return
stake
.
amount
*
pow
(
2
,
int64_t
((
now
-
(
config
::
block_timestamp_epoch
/
1000
))
/
(
86400
*
7
))
/
double
(
52
)
);
// 52 week periods (i.e. ~years)
return
stake
.
get_amount
()
*
pow
(
2
,
int64_t
((
now
-
(
config
::
block_timestamp_epoch
/
1000
))
/
(
86400
*
7
))
/
double
(
52
)
);
// 52 week periods (i.e. ~years)
}
double
stake2votes
(
const
string
&
s
)
{
...
...
@@ -398,7 +398,7 @@ fc::mutable_variant_object voter( account_name acct ) {
}
fc
::
mutable_variant_object
voter
(
account_name
acct
,
const
asset
&
vote_stake
)
{
return
voter
(
acct
)(
"staked"
,
vote_stake
.
amount
);
return
voter
(
acct
)(
"staked"
,
vote_stake
.
get_amount
()
);
}
fc
::
mutable_variant_object
voter
(
account_name
acct
,
int64_t
vote_stake
)
{
...
...
@@ -410,7 +410,7 @@ fc::mutable_variant_object proxy( account_name acct ) {
}
inline
uint64_t
M
(
const
string
&
eos_str
)
{
return
core_from_string
(
eos_str
).
amount
;
return
core_from_string
(
eos_str
).
get_amount
()
;
}
BOOST_AUTO_TEST_SUITE
(
eosio_system_tests
)
...
...
@@ -542,8 +542,8 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL
(
core_from_string
(
"110.0000"
),
total
[
"cpu_weight"
].
as
<
asset
>
());
total
=
get_total_stake
(
"alice1111111"
);
BOOST_REQUIRE_EQUAL
(
core_from_string
(
"210.0000"
).
amount
,
total
[
"net_weight"
].
as
<
asset
>
().
amount
);
BOOST_REQUIRE_EQUAL
(
core_from_string
(
"110.0000"
).
amount
,
total
[
"cpu_weight"
].
as
<
asset
>
().
amount
);
BOOST_REQUIRE_EQUAL
(
core_from_string
(
"210.0000"
).
get_amount
(),
total
[
"net_weight"
].
as
<
asset
>
().
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
core_from_string
(
"110.0000"
).
get_amount
(),
total
[
"cpu_weight"
].
as
<
asset
>
().
get_amount
()
);
REQUIRE_MATCHING_OBJECT
(
voter
(
"alice1111111"
,
core_from_string
(
"300.0000"
)),
get_voter_info
(
"alice1111111"
)
);
...
...
@@ -1480,22 +1480,22 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
BOOST_REQUIRE_EQUAL
(
0
,
initial_perblock_bucket
);
BOOST_REQUIRE_EQUAL
(
0
,
initial_pervote_bucket
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
secs_between_fills
)
*
continuous_rate
)
/
secs_per_year
),
supply
.
amount
-
initial_supply
.
amount
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
secs_between_fills
)
*
(
4.
*
continuous_rate
/
5.
)
/
secs_per_year
)
),
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
get_amount
()
*
double
(
secs_between_fills
)
*
continuous_rate
)
/
secs_per_year
),
supply
.
get_amount
()
-
initial_supply
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
get_amount
()
*
double
(
secs_between_fills
)
*
(
4.
*
continuous_rate
/
5.
)
/
secs_per_year
)
),
savings
-
initial_savings
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
secs_between_fills
)
*
(
0.25
*
continuous_rate
/
5.
)
/
secs_per_year
)
),
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
get_amount
()
*
double
(
secs_between_fills
)
*
(
0.25
*
continuous_rate
/
5.
)
/
secs_per_year
)
),
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
int64_t
from_perblock_bucket
=
int64_t
(
initial_supply
.
amount
*
double
(
secs_between_fills
)
*
(
0.25
*
continuous_rate
/
5.
)
/
secs_per_year
)
;
int64_t
from_pervote_bucket
=
int64_t
(
initial_supply
.
amount
*
double
(
secs_between_fills
)
*
(
0.75
*
continuous_rate
/
5.
)
/
secs_per_year
)
;
int64_t
from_perblock_bucket
=
int64_t
(
initial_supply
.
get_amount
()
*
double
(
secs_between_fills
)
*
(
0.25
*
continuous_rate
/
5.
)
/
secs_per_year
)
;
int64_t
from_pervote_bucket
=
int64_t
(
initial_supply
.
get_amount
()
*
double
(
secs_between_fills
)
*
(
0.75
*
continuous_rate
/
5.
)
/
secs_per_year
)
;
if
(
from_pervote_bucket
>=
100
*
10000
)
{
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
+
from_pervote_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
+
from_pervote_bucket
,
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
0
,
pervote_bucket
);
}
else
{
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
,
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
from_pervote_bucket
,
pervote_bucket
);
}
}
...
...
@@ -1557,20 +1557,20 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
BOOST_REQUIRE_EQUAL
(
claim_time
,
prod
[
"last_claim_time"
].
as
<
uint64_t
>
());
auto
usecs_between_fills
=
claim_time
-
initial_claim_time
;
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
double
(
initial_supply
.
amount
)
*
double
(
usecs_between_fills
)
*
continuous_rate
/
usecs_per_year
)
),
supply
.
amount
-
initial_supply
.
amount
);
BOOST_REQUIRE_EQUAL
(
(
supply
.
amount
-
initial_supply
.
amount
)
-
(
supply
.
amount
-
initial_supply
.
amount
)
/
5
,
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
double
(
initial_supply
.
get_amount
()
)
*
double
(
usecs_between_fills
)
*
continuous_rate
/
usecs_per_year
)
),
supply
.
get_amount
()
-
initial_supply
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
(
supply
.
get_amount
()
-
initial_supply
.
get_amount
())
-
(
supply
.
get_amount
()
-
initial_supply
.
get_amount
()
)
/
5
,
savings
-
initial_savings
);
int64_t
to_producer
=
int64_t
(
(
double
(
initial_supply
.
amount
)
*
double
(
usecs_between_fills
)
*
continuous_rate
)
/
usecs_per_year
)
/
5
;
int64_t
to_producer
=
int64_t
(
(
double
(
initial_supply
.
get_amount
()
)
*
double
(
usecs_between_fills
)
*
continuous_rate
)
/
usecs_per_year
)
/
5
;
int64_t
to_perblock_bucket
=
to_producer
/
4
;
int64_t
to_pervote_bucket
=
to_producer
-
to_perblock_bucket
;
if
(
to_pervote_bucket
+
initial_pervote_bucket
>=
100
*
10000
)
{
BOOST_REQUIRE_EQUAL
(
to_perblock_bucket
+
to_pervote_bucket
+
initial_pervote_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
to_perblock_bucket
+
to_pervote_bucket
+
initial_pervote_bucket
,
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
0
,
pervote_bucket
);
}
else
{
BOOST_REQUIRE_EQUAL
(
to_perblock_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
to_perblock_bucket
,
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
to_pervote_bucket
+
initial_pervote_bucket
,
pervote_bucket
);
}
}
...
...
@@ -1599,8 +1599,8 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
const
int64_t
savings
=
get_global_state
()[
"savings"
].
as
<
int64_t
>
();
// Amount issued per year is very close to the 5% inflation target. Small difference (500 tokens out of 50'000'000 issued)
// is due to compounding every 8 hours in this test as opposed to theoretical continuous compounding
BOOST_REQUIRE
(
500
*
10000
>
int64_t
(
double
(
initial_supply
.
amount
)
*
double
(
0.05
))
-
(
supply
.
amount
-
initial_supply
.
amount
));
BOOST_REQUIRE
(
500
*
10000
>
int64_t
(
double
(
initial_supply
.
amount
)
*
double
(
0.04
))
-
(
savings
-
initial_savings
));
BOOST_REQUIRE
(
500
*
10000
>
int64_t
(
double
(
initial_supply
.
get_amount
())
*
double
(
0.05
))
-
(
supply
.
get_amount
()
-
initial_supply
.
get_amount
()
));
BOOST_REQUIRE
(
500
*
10000
>
int64_t
(
double
(
initial_supply
.
get_amount
()
)
*
double
(
0.04
))
-
(
savings
-
initial_savings
));
}
}
FC_LOG_AND_RETHROW
()
...
...
@@ -1757,12 +1757,12 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
const
int32_t
secs_between_fills
=
static_cast
<
int32_t
>
(
usecs_between_fills
/
1000000
);
const
double
expected_supply_growth
=
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
cont_rate
/
usecs_per_year
;
BOOST_REQUIRE_EQUAL
(
int64_t
(
expected_supply_growth
),
supply
.
amount
-
initial_supply
.
amount
);
const
double
expected_supply_growth
=
initial_supply
.
get_amount
()
*
double
(
usecs_between_fills
)
*
cont_rate
/
usecs_per_year
;
BOOST_REQUIRE_EQUAL
(
int64_t
(
expected_supply_growth
),
supply
.
get_amount
()
-
initial_supply
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
expected_supply_growth
)
-
int64_t
(
expected_supply_growth
)
/
5
,
savings
-
initial_savings
);
const
int64_t
expected_perblock_bucket
=
int64_t
(
initial_supply
.
amount
*
secs_between_fills
*
(
0.25
*
cont_rate
/
5.
)
/
secs_per_year
)
;
const
int64_t
expected_pervote_bucket
=
int64_t
(
initial_supply
.
amount
*
secs_between_fills
*
(
0.75
*
cont_rate
/
5.
)
/
secs_per_year
)
;
const
int64_t
expected_perblock_bucket
=
int64_t
(
initial_supply
.
get_amount
()
*
secs_between_fills
*
(
0.25
*
cont_rate
/
5.
)
/
secs_per_year
)
;
const
int64_t
expected_pervote_bucket
=
int64_t
(
initial_supply
.
get_amount
()
*
secs_between_fills
*
(
0.75
*
cont_rate
/
5.
)
/
secs_per_year
)
;
const
int64_t
from_perblock_bucket
=
initial_unpaid_blocks
*
expected_perblock_bucket
/
initial_tot_unpaid_blocks
;
const
int64_t
from_pervote_bucket
=
int64_t
(
vote_shares
[
prod_index
]
*
expected_pervote_bucket
);
...
...
@@ -1770,10 +1770,10 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
BOOST_REQUIRE
(
1
>=
abs
(
int32_t
(
initial_tot_unpaid_blocks
-
tot_unpaid_blocks
)
-
int32_t
(
initial_unpaid_blocks
-
unpaid_blocks
))
);
if
(
from_pervote_bucket
>=
100
*
10000
)
{
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
+
from_pervote_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
+
from_pervote_bucket
,
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
expected_pervote_bucket
-
from_pervote_bucket
,
pervote_bucket
);
}
else
{
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
,
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
expected_pervote_bucket
,
pervote_bucket
);
}
...
...
@@ -1788,7 +1788,7 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
const
auto
prod_name
=
producer_names
[
prod_index
];
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
prod_name
,
N
(
claimrewards
),
mvo
()(
"owner"
,
prod_name
)));
BOOST_REQUIRE_EQUAL
(
0
,
get_balance
(
prod_name
).
amount
);
BOOST_REQUIRE_EQUAL
(
0
,
get_balance
(
prod_name
).
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
wasm_assert_msg
(
"already claimed rewards within past day"
),
push_action
(
prod_name
,
N
(
claimrewards
),
mvo
()(
"owner"
,
prod_name
)));
}
...
...
@@ -1826,23 +1826,23 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
const
uint64_t
usecs_between_fills
=
claim_time
-
initial_claim_time
;
const
double
expected_supply_growth
=
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
cont_rate
/
usecs_per_year
;
BOOST_REQUIRE_EQUAL
(
int64_t
(
expected_supply_growth
),
supply
.
amount
-
initial_supply
.
amount
);
const
double
expected_supply_growth
=
initial_supply
.
get_amount
()
*
double
(
usecs_between_fills
)
*
cont_rate
/
usecs_per_year
;
BOOST_REQUIRE_EQUAL
(
int64_t
(
expected_supply_growth
),
supply
.
get_amount
()
-
initial_supply
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
expected_supply_growth
)
-
int64_t
(
expected_supply_growth
)
/
5
,
savings
-
initial_savings
);
const
int64_t
expected_perblock_bucket
=
int64_t
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
0.25
*
cont_rate
/
5.
)
/
usecs_per_year
)
const
int64_t
expected_perblock_bucket
=
int64_t
(
initial_supply
.
get_amount
()
*
double
(
usecs_between_fills
)
*
(
0.25
*
cont_rate
/
5.
)
/
usecs_per_year
)
+
initial_perblock_bucket
;
const
int64_t
expected_pervote_bucket
=
int64_t
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
0.75
*
cont_rate
/
5.
)
/
usecs_per_year
)
const
int64_t
expected_pervote_bucket
=
int64_t
(
initial_supply
.
get_amount
()
*
double
(
usecs_between_fills
)
*
(
0.75
*
cont_rate
/
5.
)
/
usecs_per_year
)
+
initial_pervote_bucket
;
const
int64_t
from_perblock_bucket
=
initial_unpaid_blocks
*
expected_perblock_bucket
/
initial_tot_unpaid_blocks
;
const
int64_t
from_pervote_bucket
=
int64_t
(
vote_shares
[
prod_index
]
*
expected_pervote_bucket
);
BOOST_REQUIRE
(
1
>=
abs
(
int32_t
(
initial_tot_unpaid_blocks
-
tot_unpaid_blocks
)
-
int32_t
(
initial_unpaid_blocks
-
unpaid_blocks
))
);
if
(
from_pervote_bucket
>=
100
*
10000
)
{
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
+
from_pervote_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
+
from_pervote_bucket
,
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
expected_pervote_bucket
-
from_pervote_bucket
,
pervote_bucket
);
}
else
{
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
,
balance
.
get_amount
()
-
initial_balance
.
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
expected_pervote_bucket
,
pervote_bucket
);
}
...
...
@@ -1857,7 +1857,7 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
const
auto
prod_name
=
producer_names
[
prod_index
];
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
prod_name
,
N
(
claimrewards
),
mvo
()(
"owner"
,
prod_name
)));
BOOST_REQUIRE
(
100
*
10000
<=
get_balance
(
prod_name
).
amount
);
BOOST_REQUIRE
(
100
*
10000
<=
get_balance
(
prod_name
).
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
wasm_assert_msg
(
"already claimed rewards within past day"
),
push_action
(
prod_name
,
N
(
claimrewards
),
mvo
()(
"owner"
,
prod_name
)));
}
...
...
@@ -2142,10 +2142,10 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
BOOST_CHECK_EQUAL
(
0
,
get_global_state
()[
"total_unpaid_blocks"
].
as
<
uint32_t
>
());
BOOST_REQUIRE_EQUAL
(
wasm_assert_msg
(
"not enough has been staked for producers to claim rewards"
),
push_action
(
producer_names
.
front
(),
N
(
claimrewards
),
mvo
()(
"owner"
,
producer_names
.
front
())));
BOOST_REQUIRE_EQUAL
(
0
,
get_balance
(
producer_names
.
front
()).
amount
);
BOOST_REQUIRE_EQUAL
(
0
,
get_balance
(
producer_names
.
front
()).
get_amount
()
);
BOOST_REQUIRE_EQUAL
(
wasm_assert_msg
(
"not enough has been staked for producers to claim rewards"
),
push_action
(
producer_names
.
back
(),
N
(
claimrewards
),
mvo
()(
"owner"
,
producer_names
.
back
())));
BOOST_REQUIRE_EQUAL
(
0
,
get_balance
(
producer_names
.
back
()).
amount
);
BOOST_REQUIRE_EQUAL
(
0
,
get_balance
(
producer_names
.
back
()).
get_amount
()
);
}
// stake across 15% boundary
...
...
@@ -2187,7 +2187,7 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
BOOST_REQUIRE_EQUAL
(
true
,
rest_didnt_produce
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
producer_names
.
front
(),
N
(
claimrewards
),
mvo
()(
"owner"
,
producer_names
.
front
())));
BOOST_REQUIRE
(
0
<
get_balance
(
producer_names
.
front
()).
amount
);
BOOST_REQUIRE
(
0
<
get_balance
(
producer_names
.
front
()).
get_amount
()
);
}
}
FC_LOG_AND_RETHROW
()
...
...
unittests/eosio.token_tests.cpp
浏览文件 @
32a1efd0
...
...
@@ -149,7 +149,8 @@ BOOST_FIXTURE_TEST_CASE( create_max_supply, eosio_token_tester ) try {
produce_blocks
(
1
);
asset
max
(
10
,
symbol
(
SY
(
0
,
NKT
)));
max
.
amount
=
4611686018427387904
;
share_type
amount
=
4611686018427387904
;
memcpy
(
&
max
,
&
amount
,
sizeof
(
share_type
));
// hack in an invalid amount
BOOST_CHECK_EXCEPTION
(
create
(
N
(
alice
),
max
)
,
asset_type_exception
,
[](
const
asset_type_exception
&
e
)
{
return
expect_assert_message
(
e
,
"magnitude of asset amount must be less than 2^62"
);
...
...
@@ -171,7 +172,8 @@ BOOST_FIXTURE_TEST_CASE( create_max_decimals, eosio_token_tester ) try {
asset
max
(
10
,
symbol
(
SY
(
0
,
NKT
)));
//1.0000000000000000000 => 0x8ac7230489e80000L
max
.
amount
=
0x8ac7230489e80000L
;
share_type
amount
=
0x8ac7230489e80000L
;
memcpy
(
&
max
,
&
amount
,
sizeof
(
share_type
));
// hack in an invalid amount
BOOST_CHECK_EXCEPTION
(
create
(
N
(
alice
),
max
)
,
asset_type_exception
,
[](
const
asset_type_exception
&
e
)
{
return
expect_assert_message
(
e
,
"magnitude of asset amount must be less than 2^62"
);
...
...
unittests/misc_tests.cpp
浏览文件 @
32a1efd0
...
...
@@ -59,23 +59,23 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow)
// precision = 19, magnitude < 2^61
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"0.1000000000000000000 CUR"
)
,
assert_exception
,
[](
const
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"precision should be <= 18"
);
return
expect_assert_message
(
e
,
"precision
19
should be <= 18"
);
});
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"-0.1000000000000000000 CUR"
)
,
assert_exception
,
[](
const
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"precision should be <= 18"
);
return
expect_assert_message
(
e
,
"precision
19
should be <= 18"
);
});
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"1.0000000000000000000 CUR"
)
,
assert_exception
,
[](
const
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"precision should be <= 18"
);
return
expect_assert_message
(
e
,
"precision
19
should be <= 18"
);
});
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"-1.0000000000000000000 CUR"
)
,
assert_exception
,
[](
const
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"precision should be <= 18"
);
return
expect_assert_message
(
e
,
"precision
19
should be <= 18"
);
});
// precision = 18, magnitude < 2^58
a
=
asset
::
from_string
(
"0.100000000000000000 CUR"
);
BOOST_CHECK_EQUAL
(
a
.
amount
,
100000000000000000L
);
BOOST_CHECK_EQUAL
(
a
.
get_amount
()
,
100000000000000000L
);
a
=
asset
::
from_string
(
"-0.100000000000000000 CUR"
);
BOOST_CHECK_EQUAL
(
a
.
amount
,
-
100000000000000000L
);
BOOST_CHECK_EQUAL
(
a
.
get_amount
()
,
-
100000000000000000L
);
// precision = 18, magnitude = 2^62
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"4.611686018427387904 CUR"
)
,
asset_type_exception
,
[](
const
asset_type_exception
&
e
)
{
...
...
@@ -93,9 +93,9 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow)
// precision = 18, magnitude = 2^62-1
a
=
asset
::
from_string
(
"4.611686018427387903 CUR"
);
BOOST_CHECK_EQUAL
(
a
.
amount
,
4611686018427387903L
);
BOOST_CHECK_EQUAL
(
a
.
get_amount
()
,
4611686018427387903L
);
a
=
asset
::
from_string
(
"-4.611686018427387903 CUR"
);
BOOST_CHECK_EQUAL
(
a
.
amount
,
-
4611686018427387903L
);
BOOST_CHECK_EQUAL
(
a
.
get_amount
()
,
-
4611686018427387903L
);
// precision = 0, magnitude = 2^62
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"4611686018427387904 CUR"
)
,
asset_type_exception
,
[](
const
asset_type_exception
&
e
)
{
...
...
@@ -107,9 +107,9 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow)
// precision = 0, magnitude = 2^62-1
a
=
asset
::
from_string
(
"4611686018427387903 CUR"
);
BOOST_CHECK_EQUAL
(
a
.
amount
,
4611686018427387903L
);
BOOST_CHECK_EQUAL
(
a
.
get_amount
()
,
4611686018427387903L
);
a
=
asset
::
from_string
(
"-4611686018427387903 CUR"
);
BOOST_CHECK_EQUAL
(
a
.
amount
,
-
4611686018427387903L
);
BOOST_CHECK_EQUAL
(
a
.
get_amount
()
,
-
4611686018427387903L
);
// precision = 18, magnitude = 2^65
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"36.893488147419103232 CUR"
)
,
overflow_exception
,
[](
const
overflow_exception
&
e
)
{
...
...
@@ -137,10 +137,10 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow)
// precision = 20, magnitude > 2^142
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"100000000000000000000000.00000000000000000000 CUR"
)
,
assert_exception
,
[](
const
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"precision should be <= 18"
);
return
expect_assert_message
(
e
,
"precision
20
should be <= 18"
);
});
BOOST_CHECK_EXCEPTION
(
asset
::
from_string
(
"-100000000000000000000000.00000000000000000000 CUR"
)
,
assert_exception
,
[](
const
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"precision should be <= 18"
);
return
expect_assert_message
(
e
,
"precision
20
should be <= 18"
);
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录