test_api.cpp 7.7 KB
Newer Older
1 2 3 4
/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
5
#include <eosiolib/eosio.hpp>
6
#include <eosiolib/transaction.hpp>
7

M
Matias Romeo 已提交
8
#include "test_api.hpp"
9 10 11
#include "test_action.cpp"
#include "test_print.cpp"
#include "test_types.cpp"
B
Bucky Kittinger 已提交
12
#include "test_fixedpoint.cpp"
13
#include "test_math.cpp"
B
Bucky Kittinger 已提交
14 15 16 17
#include "test_compiler_builtins.cpp"
#include "test_real.cpp"
#include "test_crypto.cpp"
#include "test_chain.cpp"
18
#include "test_transaction.cpp"
B
Bucky Kittinger 已提交
19
#include "test_checktime.cpp"
M
Matias Romeo 已提交
20
#include "test_permission.cpp"
21
#include "test_datastream.cpp"
22

23 24
account_name global_receiver;

M
Matias Romeo 已提交
25
extern "C" {
26
   void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
27 28 29 30 31 32 33 34 35 36 37 38 39
      if( code == N(eosio) && action == N(onerror) ) {
         auto error_dtrx = eosio::deferred_transaction::from_current_action();
         eosio::print("onerror called\n");
         auto error_action = error_dtrx.actions.at(0).name;

         // Error handlers for deferred transactions in these tests currently only support the first action

         WASM_TEST_ERROR_HANDLER("test_action", "assert_false", test_transaction, assert_false_error_handler );


         return;
      }

B
Bucky Kittinger 已提交
40 41 42 43
      if ( action == N(cf_action) ) {
         test_action::test_cf_action();
         return;
      }
B
Bucky Kittinger 已提交
44 45
      WASM_TEST_HANDLER(test_action, assert_true_cf);

B
Bucky Kittinger 已提交
46
      require_auth(code);
B
Bucky Kittinger 已提交
47

M
Matias Romeo 已提交
48
      //test_types
49 50 51 52 53
      WASM_TEST_HANDLER(test_types, types_size);
      WASM_TEST_HANDLER(test_types, char_to_symbol);
      WASM_TEST_HANDLER(test_types, string_to_name);
      WASM_TEST_HANDLER(test_types, name_class);

B
Bucky Kittinger 已提交
54 55 56 57
      //test_compiler_builtins
      WASM_TEST_HANDLER(test_compiler_builtins, test_multi3);
      WASM_TEST_HANDLER(test_compiler_builtins, test_divti3);
      WASM_TEST_HANDLER(test_compiler_builtins, test_divti3_by_0);
B
Bucky Kittinger 已提交
58 59 60 61 62 63
      WASM_TEST_HANDLER(test_compiler_builtins, test_udivti3);
      WASM_TEST_HANDLER(test_compiler_builtins, test_udivti3_by_0);
      WASM_TEST_HANDLER(test_compiler_builtins, test_modti3);
      WASM_TEST_HANDLER(test_compiler_builtins, test_modti3_by_0);
      WASM_TEST_HANDLER(test_compiler_builtins, test_umodti3);
      WASM_TEST_HANDLER(test_compiler_builtins, test_umodti3_by_0);
B
Bucky Kittinger 已提交
64
      WASM_TEST_HANDLER(test_compiler_builtins, test_lshlti3);
65 66 67
      WASM_TEST_HANDLER(test_compiler_builtins, test_lshrti3);
      WASM_TEST_HANDLER(test_compiler_builtins, test_ashlti3);
      WASM_TEST_HANDLER(test_compiler_builtins, test_ashrti3);
B
Bucky Kittinger 已提交
68

69
      //test_action
70 71 72
      WASM_TEST_HANDLER(test_action, read_action_normal);
      WASM_TEST_HANDLER(test_action, read_action_to_0);
      WASM_TEST_HANDLER(test_action, read_action_to_64k);
73
      WASM_TEST_HANDLER_EX(test_action, require_notice);
74
      WASM_TEST_HANDLER(test_action, require_auth);
75 76
      WASM_TEST_HANDLER(test_action, assert_false);
      WASM_TEST_HANDLER(test_action, assert_true);
B
Bucky Kittinger 已提交
77
      WASM_TEST_HANDLER(test_action, now);
B
Bucky Kittinger 已提交
78
      WASM_TEST_HANDLER(test_action, test_abort);
79
      WASM_TEST_HANDLER_EX(test_action, test_current_receiver);
B
Bucky Kittinger 已提交
80 81
      WASM_TEST_HANDLER(test_action, test_current_sender);
      WASM_TEST_HANDLER(test_action, test_publication_time);
M
Matias Romeo 已提交
82

K
Kevin Heifner 已提交
83 84 85 86 87 88
      // test named actions
      // We enforce action name matches action data type name, so name mangling will not work for these tests.
      if ( action == N(dummy_action) ) {
         test_action::test_dummy_action();
         return;
      }
M
Matias Romeo 已提交
89
      //test_print
90
      WASM_TEST_HANDLER(test_print, test_prints);
B
Bucky Kittinger 已提交
91
      WASM_TEST_HANDLER(test_print, test_prints_l);
92
      WASM_TEST_HANDLER(test_print, test_printi);
93
      WASM_TEST_HANDLER(test_print, test_printui);
94 95
      WASM_TEST_HANDLER(test_print, test_printi128);
      WASM_TEST_HANDLER(test_print, test_printn);
M
Matias Romeo 已提交
96

97 98 99
      //test_math
      WASM_TEST_HANDLER(test_math, test_multeq);
      WASM_TEST_HANDLER(test_math, test_diveq);
B
Bucky Kittinger 已提交
100 101
      WASM_TEST_HANDLER(test_math, test_i64_to_double);
      WASM_TEST_HANDLER(test_math, test_double_to_i64);
102 103 104 105 106
      WASM_TEST_HANDLER(test_math, test_diveq_by_0);
      WASM_TEST_HANDLER(test_math, test_double_api);
      WASM_TEST_HANDLER(test_math, test_double_api_div_0);

      //test crypto
B
Bucky Kittinger 已提交
107
      WASM_TEST_HANDLER(test_crypto, test_recover_key);
B
Bucky Kittinger 已提交
108 109
      WASM_TEST_HANDLER(test_crypto, test_recover_key_assert_true);
      WASM_TEST_HANDLER(test_crypto, test_recover_key_assert_false);
B
Bucky Kittinger 已提交
110
      WASM_TEST_HANDLER(test_crypto, test_sha1);
111
      WASM_TEST_HANDLER(test_crypto, test_sha256);
B
Bucky Kittinger 已提交
112 113 114
      WASM_TEST_HANDLER(test_crypto, test_sha512);
      WASM_TEST_HANDLER(test_crypto, test_ripemd160);
      WASM_TEST_HANDLER(test_crypto, sha1_no_data);
115
      WASM_TEST_HANDLER(test_crypto, sha256_no_data);
B
Bucky Kittinger 已提交
116 117
      WASM_TEST_HANDLER(test_crypto, sha512_no_data);
      WASM_TEST_HANDLER(test_crypto, ripemd160_no_data);
B
Bucky Kittinger 已提交
118 119 120
      WASM_TEST_HANDLER(test_crypto, sha256_null);
      WASM_TEST_HANDLER(test_crypto, assert_sha256_false);
      WASM_TEST_HANDLER(test_crypto, assert_sha256_true);
B
Bucky Kittinger 已提交
121 122 123 124 125 126
      WASM_TEST_HANDLER(test_crypto, assert_sha1_false);
      WASM_TEST_HANDLER(test_crypto, assert_sha1_true);
      WASM_TEST_HANDLER(test_crypto, assert_sha512_false);
      WASM_TEST_HANDLER(test_crypto, assert_sha512_true);
      WASM_TEST_HANDLER(test_crypto, assert_ripemd160_false);
      WASM_TEST_HANDLER(test_crypto, assert_ripemd160_true);
127 128

      //test transaction
B
Bucky Kittinger 已提交
129 130
      WASM_TEST_HANDLER(test_transaction, test_tapos_block_num);
      WASM_TEST_HANDLER(test_transaction, test_tapos_block_prefix);
B
Bucky Kittinger 已提交
131
      WASM_TEST_HANDLER(test_transaction, send_action);
B
Bucky Kittinger 已提交
132
      WASM_TEST_HANDLER(test_transaction, send_action_inline_fail);
B
Bucky Kittinger 已提交
133 134 135
      WASM_TEST_HANDLER(test_transaction, send_action_empty);
      WASM_TEST_HANDLER(test_transaction, send_action_large);
      WASM_TEST_HANDLER(test_transaction, send_action_recurse);
B
Bucky Kittinger 已提交
136 137
      WASM_TEST_HANDLER(test_transaction, test_read_transaction);
      WASM_TEST_HANDLER(test_transaction, test_transaction_size);
138 139
      WASM_TEST_HANDLER_EX(test_transaction, send_transaction);
      WASM_TEST_HANDLER_EX(test_transaction, send_transaction_empty);
140
      WASM_TEST_HANDLER_EX(test_transaction, send_transaction_trigger_error_handler);
141 142
      WASM_TEST_HANDLER_EX(test_transaction, send_transaction_large);
      WASM_TEST_HANDLER_EX(test_transaction, send_action_sender);
143
      WASM_TEST_HANDLER_EX(test_transaction, send_transaction_expiring_late);
144
      WASM_TEST_HANDLER(test_transaction, deferred_print);
145
      WASM_TEST_HANDLER_EX(test_transaction, send_deferred_transaction);
146
      WASM_TEST_HANDLER(test_transaction, cancel_deferred_transaction);
M
Matias Romeo 已提交
147 148
      WASM_TEST_HANDLER(test_transaction, send_cf_action);
      WASM_TEST_HANDLER(test_transaction, send_cf_action_fail);
149 150
      WASM_TEST_HANDLER(test_transaction, read_inline_action);
      WASM_TEST_HANDLER(test_transaction, read_inline_cf_action);
151 152 153 154 155 156 157 158 159 160

      //test chain
      WASM_TEST_HANDLER(test_chain, test_activeprods);

      // test fixed_point
      WASM_TEST_HANDLER(test_fixedpoint, create_instances);
      WASM_TEST_HANDLER(test_fixedpoint, test_addition);
      WASM_TEST_HANDLER(test_fixedpoint, test_subtraction);
      WASM_TEST_HANDLER(test_fixedpoint, test_multiplication);
      WASM_TEST_HANDLER(test_fixedpoint, test_division);
B
Bucky Kittinger 已提交
161
      WASM_TEST_HANDLER(test_fixedpoint, test_division_by_0);
162 163 164 165 166 167

      // test double
      WASM_TEST_HANDLER(test_real, create_instances);
      WASM_TEST_HANDLER(test_real, test_addition);
      WASM_TEST_HANDLER(test_real, test_multiplication);
      WASM_TEST_HANDLER(test_real, test_division);
B
Bucky Kittinger 已提交
168
      WASM_TEST_HANDLER(test_real, test_division_by_0);
169

B
Bucky Kittinger 已提交
170 171 172
      // test checktime
      WASM_TEST_HANDLER(test_checktime, checktime_pass);
      WASM_TEST_HANDLER(test_checktime, checktime_failure);
M
Matias Romeo 已提交
173

174 175 176
      // test datastream
      WASM_TEST_HANDLER(test_datastream, test_basic);

M
Matias Romeo 已提交
177
      // test permission
178
      WASM_TEST_HANDLER_EX(test_permission, check_authorization);
M
Matias Romeo 已提交
179

180
      //unhandled test call
181
      eosio_assert(false, "Unknown Test");
182

M
Matias Romeo 已提交
183 184
   }
}