-
Notifications
You must be signed in to change notification settings - Fork 31
/
hello_test.cpp
65 lines (52 loc) · 2.01 KB
/
hello_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <eosio/eosio.hpp>
#include <eosio/tester.hpp>
#include <hello.hpp>
using namespace eosio;
using namespace eosio::native;
// need to create a dispatcher, codegen will not be done for native builds until a later release
EOSIO_DISPATCH(hello, (hi)(check))
EOSIO_TEST_BEGIN(hello_test)
// These can be redefined by the user to suit there needs per unit test
// the idea is that in a future release we will have a base library that
// initializes these to "useable" default implementations and probably
// helpers to more easily define read_action_data and action_data_size intrinsics
// like these
intrinsics::set_intrinsic<intrinsics::read_action_data>(
[](void* m, uint32_t len) {
check(len <= sizeof(eosio::name), "failed from read_action_data");
*((eosio::name*)m) = "hello"_n;
return len;
});
intrinsics::set_intrinsic<intrinsics::action_data_size>(
[]() {
return (uint32_t)sizeof(eosio::name);
});
intrinsics::set_intrinsic<intrinsics::require_auth>(
[](capi_name nm) {
});
// "Name : hello" should be in the print buffer
CHECK_PRINT("Name : hello",
[]() {
apply("test"_n.value, "test"_n.value, "hi"_n.value);
});
// should not assert
apply("test"_n.value, "test"_n.value, "check"_n.value);
name nm = "null"_n;
intrinsics::set_intrinsic<intrinsics::read_action_data>(
[&](void* m, uint32_t len) {
check(len <= sizeof(eosio::name), "failed from read_action_data");
*((eosio::name*)m) = nm;
return len;
});
REQUIRE_ASSERT( "check name not equal to `hello`",
[]() {
// should assert
apply("test"_n.value, "test"_n.value, "check"_n.value);
});
EOSIO_TEST_END
// boilerplate main, this will be generated in a future release
int main(int argc, char** argv) {
silence_output(true);
EOSIO_TEST(hello_test);
return has_failed();
}