Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
4c826bc7
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,发现更多精彩内容 >>
提交
4c826bc7
编写于
8月 01, 2017
作者:
M
Matias Romeo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add tests for crypto api
上级
5ab11964
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
163 addition
and
0 deletion
+163
-0
contracts/test_api/test_api.hpp
contracts/test_api/test_api.hpp
+7
-0
contracts/test_api/test_crypto.cpp
contracts/test_api/test_crypto.cpp
+145
-0
tests/api_tests/api_tests.cpp
tests/api_tests/api_tests.cpp
+11
-0
未找到文件。
contracts/test_api/test_api.hpp
浏览文件 @
4c826bc7
...
...
@@ -94,3 +94,10 @@ struct test_db {
static
unsigned
int
key_i128i128_general
();
};
struct
test_crypto
{
static
unsigned
int
test_sha256
();
static
unsigned
int
sha256_no_data
();
static
unsigned
int
asert_sha256_false
();
static
unsigned
int
asert_sha256_true
();
static
unsigned
int
asert_no_data
();
};
contracts/test_api/test_crypto.cpp
0 → 100644
浏览文件 @
4c826bc7
#include <eoslib/eos.hpp>
#include <eoslib/crypto.h>
#include "test_api.hpp"
static
const
char
test1
[]
=
"abc"
;
static
const
unsigned
char
test1_ok
[]
=
{
0xba
,
0x78
,
0x16
,
0xbf
,
0x8f
,
0x01
,
0xcf
,
0xea
,
0x41
,
0x41
,
0x40
,
0xde
,
0x5d
,
0xae
,
0x22
,
0x23
,
0xb0
,
0x03
,
0x61
,
0xa3
,
0x96
,
0x17
,
0x7a
,
0x9c
,
0xb4
,
0x10
,
0xff
,
0x61
,
0xf2
,
0x00
,
0x15
,
0xad
};
const
char
test2
[]
=
""
;
const
unsigned
char
test2_ok
[]
=
{
0xe3
,
0xb0
,
0xc4
,
0x42
,
0x98
,
0xfc
,
0x1c
,
0x14
,
0x9a
,
0xfb
,
0xf4
,
0xc8
,
0x99
,
0x6f
,
0xb9
,
0x24
,
0x27
,
0xae
,
0x41
,
0xe4
,
0x64
,
0x9b
,
0x93
,
0x4c
,
0xa4
,
0x95
,
0x99
,
0x1b
,
0x78
,
0x52
,
0xb8
,
0x55
};
static
const
char
test3
[]
=
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
;
static
const
unsigned
char
test3_ok
[]
=
{
0x24
,
0x8d
,
0x6a
,
0x61
,
0xd2
,
0x06
,
0x38
,
0xb8
,
0xe5
,
0xc0
,
0x26
,
0x93
,
0x0c
,
0x3e
,
0x60
,
0x39
,
0xa3
,
0x3c
,
0xe4
,
0x59
,
0x64
,
0xff
,
0x21
,
0x67
,
0xf6
,
0xec
,
0xed
,
0xd4
,
0x19
,
0xdb
,
0x06
,
0xc1
};
static
const
char
test4
[]
=
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
;
static
const
unsigned
char
test4_ok
[]
=
{
0xcf
,
0x5b
,
0x16
,
0xa7
,
0x78
,
0xaf
,
0x83
,
0x80
,
0x03
,
0x6c
,
0xe5
,
0x9e
,
0x7b
,
0x04
,
0x92
,
0x37
,
0x0b
,
0x24
,
0x9b
,
0x11
,
0xe8
,
0xf0
,
0x7a
,
0x51
,
0xaf
,
0xac
,
0x45
,
0x03
,
0x7a
,
0xfe
,
0xe9
,
0xd1
};
static
const
char
test5
[]
=
"message digest"
;
static
const
unsigned
char
test5_ok
[]
=
{
0xf7
,
0x84
,
0x6f
,
0x55
,
0xcf
,
0x23
,
0xe1
,
0x4e
,
0xeb
,
0xea
,
0xb5
,
0xb4
,
0xe1
,
0x55
,
0x0c
,
0xad
,
0x5b
,
0x50
,
0x9e
,
0x33
,
0x48
,
0xfb
,
0xc4
,
0xef
,
0xa3
,
0xa1
,
0x41
,
0x3d
,
0x39
,
0x3c
,
0xb6
,
0x50
};
extern
"C"
{
uint32_t
my_strlen
(
const
char
*
str
)
{
uint32_t
len
=
0
;
while
(
str
[
len
])
++
len
;
return
len
;
}
bool
my_memcmp
(
void
*
s1
,
void
*
s2
,
uint32_t
n
)
{
unsigned
char
*
c1
=
(
unsigned
char
*
)
s1
;
unsigned
char
*
c2
=
(
unsigned
char
*
)
s2
;
for
(
uint32_t
i
=
0
;
i
<
n
;
++
i
)
{
if
(
c1
[
i
]
!=
c2
[
i
])
{
eos
::
print
(
"Rompio en index "
,
i
);
return
false
;
}
}
return
true
;
}
void
my_to_hex
(
void
*
vdata
,
uint32_t
datalen
,
char
*
dst
,
uint32_t
dst_len
)
{
unsigned
char
*
data
=
(
unsigned
char
*
)
vdata
;
const
char
symbols
[]
=
"0123456789abcdef"
;
uint32_t
i
=
0
;
for
(
i
=
0
;
i
<
dst_len
-
1
&&
i
/
2
<
datalen
;
++
i
)
{
unsigned
char
b
=
!
(
i
%
2
)
?
data
[
i
/
2
]
>>
4
:
data
[
i
/
2
]
&
0x0F
;
dst
[
i
]
=
symbols
[
b
];
}
dst
[
i
]
=
0
;
}
}
unsigned
int
test_crypto
::
test_sha256
()
{
uint256
tmp
;
sha256
(
(
char
*
)
test1
,
my_strlen
(
test1
),
&
tmp
);
WASM_ASSERT
(
my_memcmp
((
void
*
)
test1_ok
,
&
tmp
,
sizeof
(
uint256
)),
"sha256 test1"
);
sha256
(
(
char
*
)
test3
,
my_strlen
(
test3
),
&
tmp
);
WASM_ASSERT
(
my_memcmp
((
void
*
)
test3_ok
,
&
tmp
,
sizeof
(
uint256
)),
"sha256 test3"
);
sha256
(
(
char
*
)
test4
,
my_strlen
(
test4
),
&
tmp
);
WASM_ASSERT
(
my_memcmp
((
void
*
)
test4_ok
,
&
tmp
,
sizeof
(
uint256
)),
"sha256 test4"
);
sha256
(
(
char
*
)
test5
,
my_strlen
(
test5
),
&
tmp
);
WASM_ASSERT
(
my_memcmp
((
void
*
)
test5_ok
,
&
tmp
,
sizeof
(
uint256
)),
"sha256 test5"
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_crypto
::
sha256_no_data
()
{
uint256
tmp
;
sha256
(
(
char
*
)
test2
,
my_strlen
(
test2
),
&
tmp
);
WASM_ASSERT
(
my_memcmp
((
void
*
)
test2_ok
,
&
tmp
,
sizeof
(
uint256
)),
"sha256 test2"
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_crypto
::
asert_sha256_false
()
{
uint256
tmp
;
sha256
(
(
char
*
)
test1
,
my_strlen
(
test1
),
&
tmp
);
tmp
.
words
[
0
]
^=
(
uint64_t
)(
-
1
);
assert_sha256
(
(
char
*
)
test1
,
my_strlen
(
test1
),
&
tmp
);
return
WASM_TEST_FAIL
;
}
unsigned
int
test_crypto
::
asert_sha256_true
()
{
uint256
tmp
;
sha256
(
(
char
*
)
test1
,
my_strlen
(
test1
),
&
tmp
);
assert_sha256
(
(
char
*
)
test1
,
my_strlen
(
test1
),
&
tmp
);
sha256
(
(
char
*
)
test3
,
my_strlen
(
test3
),
&
tmp
);
assert_sha256
(
(
char
*
)
test3
,
my_strlen
(
test3
),
&
tmp
);
sha256
(
(
char
*
)
test4
,
my_strlen
(
test4
),
&
tmp
);
assert_sha256
(
(
char
*
)
test4
,
my_strlen
(
test4
),
&
tmp
);
sha256
(
(
char
*
)
test5
,
my_strlen
(
test5
),
&
tmp
);
assert_sha256
(
(
char
*
)
test5
,
my_strlen
(
test5
),
&
tmp
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_crypto
::
asert_no_data
()
{
uint256
*
tmp
=
(
uint256
*
)
test2_ok
;
assert_sha256
(
(
char
*
)
test2
,
my_strlen
(
test2
),
tmp
);
return
WASM_TEST_FAIL
;
}
\ No newline at end of file
tests/api_tests/api_tests.cpp
浏览文件 @
4c826bc7
...
...
@@ -369,6 +369,17 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture)
//Test db (i128i128)
BOOST_CHECK_MESSAGE
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_db"
,
"key_i128i128_general"
),
{},
{}
)
==
WASM_TEST_PASS
,
"test_db::key_i128i128_general()"
);
//Test crypto
BOOST_CHECK_MESSAGE
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_crypto"
,
"test_sha256"
),
{},
{}
)
==
WASM_TEST_PASS
,
"test_crypto::test_sha256()"
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_crypto"
,
"sha256_no_data"
),
{},
{}
),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_crypto"
,
"asert_sha256_false"
),
{},
{}
),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_MESSAGE
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_crypto"
,
"asert_sha256_true"
),
{},
{}
)
==
WASM_TEST_PASS
,
"test_crypto::asert_sha256_true()"
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_crypto"
,
"asert_no_data"
),
{},
{}
),
fc
::
assert_exception
,
is_assert_exception
);
}
FC_LOG_AND_RETHROW
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录