diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 81d78bdf1df..746cc1933ab 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2170,6 +2170,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows( const read_only:: read_only::get_table_rows_result read_only::get_kv_table_rows_context( const read_only::get_kv_table_rows_params& pp, kv_context &kv_context, const abi_def &abi )const { read_only::get_kv_table_rows_params p(pp); + EOS_ASSERT(p.limit > 0, chain::contract_table_query_exception, "invalid limit : ${n}", ("n", p.limit)); string tbl_name = p.table.to_string(); // Check valid table name @@ -2213,6 +2214,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea const string &index_value = *p.index_value; p.lower_bound = p.index_value; unbounded = true; + p.reverse = false; } /////////////////////////////////////////////////////////// @@ -2284,8 +2286,8 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea if( has_upper_bound ) { auto exact_match = kv_context.kv_get(p.code.to_uint64_t(), ub_key.data(), ub_key.size(), value_size); status_ub = ub_itr->kv_it_lower_bound(ub_key.data(), ub_key.size(), &ub_key_size, &ub_value_size); - if( p.reverse && !point_query && !exact_match ) { - status_ub = ub_itr->kv_it_prev(&ub_key_size, &ub_value_size); + if( !point_query && !exact_match ) { + status_ub = ub_itr->kv_it_prev(&ub_key_size, &ub_value_size); } EOS_ASSERT(status_ub != chain::kv_it_stat::iterator_erased, chain::contract_table_query_exception, "Invalid upper bound iterator in ${t} ${i}", ("t", p.table)("i", p.index_name)); @@ -2320,7 +2322,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea } unsigned int count = 0; - for( count = 0; cur_time <= end_time && count < p.limit && cmp < 0; cur_time = fc::time_point::now() ) { + for( count = 0; cur_time <= end_time && count < p.limit && cmp <= 0; cur_time = fc::time_point::now() ) { row_key.resize(key_size); status = itr->kv_it_key(0, row_key.data(), key_size, actual_size); EOS_ASSERT(key_size == actual_size, chain::contract_table_query_exception, "Invalid iterator in ${t} ${i}", ("t", p.table)("i", p.index_name)); @@ -2354,9 +2356,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea auto time_left = end_time - cur_time; try { row_var = abis.binary_to_variant( p.table.to_string(), row_value, abi_serializer::create_yield_function( time_left ), shorten_abi_errors ); - } - catch ( fc::exception &e ) - { + } catch ( fc::exception &e ) { row_var = fc::variant( row_value ); } } else { @@ -2371,7 +2371,10 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea } else { status = itr->kv_it_next(&key_size, &value_size); } - EOS_ASSERT(status != chain::kv_it_stat::iterator_erased, chain::contract_table_query_exception, "Invalid lower bound iterator in ${t} ${i}", ("t", p.table)("i", p.index_name)); + if( status == chain::kv_it_stat::iterator_end ) { + break; + } + EOS_ASSERT(status == chain::kv_it_stat::iterator_ok, chain::contract_table_query_exception, "Invalid iterator in ${t} ${i}", ("t", p.table)("i", p.index_name)); if (unbounded) { cur_status = itr->kv_it_status(); @@ -2386,7 +2389,7 @@ read_only::get_table_rows_result read_only::get_kv_table_rows_context( const rea } } - if (count == p.limit && cmp < 0) + if (count == p.limit && cmp <= 0) { result.more = true; row_key.resize(key_size); diff --git a/tests/get_kv_table_addr_tests.cpp b/tests/get_kv_table_addr_tests.cpp index 064bde42db7..086a7f9bdaf 100644 --- a/tests/get_kv_table_addr_tests.cpp +++ b/tests/get_kv_table_addr_tests.cpp @@ -151,7 +151,7 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try { p.upper_bound = "lois"; p.reverse = false; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + BOOST_REQUIRE_EQUAL(2u, result.rows.size()); chk_result(0, 2); p.index_name = "accname"_n; @@ -174,7 +174,7 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try { p.upper_bound = "steve"; p.reverse = true; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(2u, result.rows.size()); + BOOST_REQUIRE_EQUAL(3u, result.rows.size()); chk_result(0, 4); chk_result(1, 3); diff --git a/tests/get_kv_table_nodeos_tests.cpp b/tests/get_kv_table_nodeos_tests.cpp index 19a7a543226..73937eadf56 100644 --- a/tests/get_kv_table_nodeos_tests.cpp +++ b/tests/get_kv_table_nodeos_tests.cpp @@ -65,6 +65,9 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { auto arg = mutable_variant_object(); push_action("kvtable"_n, "setup"_n, "kvtable"_n, arg); + ////////////////////////////// + // primarykey + ////////////////////////////// eosio::chain_apis::read_only plugin(*(this->control), {}, fc::microseconds::maximum()); eosio::chain_apis::read_only::get_kv_table_rows_params p; p.code = "kvtable"_n; @@ -80,6 +83,12 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { BOOST_REQUIRE_EQUAL(1u, result.rows.size()); chk_result(0, 1); + p.reverse = true; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + chk_result(0, 1); + p.reverse = false; + p.index_name = "primarykey"_n; p.index_value = "bobj"; p.encode_type = "name"; @@ -95,10 +104,11 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { p.lower_bound = "bobb"; p.upper_bound = "bobe"; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(3u, result.rows.size()); + BOOST_REQUIRE_EQUAL(4u, result.rows.size()); chk_result(0, 2); chk_result(1, 3); chk_result(2, 4); + chk_result(3, 5); p.lower_bound = "aaaa"; p.upper_bound = ""; @@ -161,15 +171,16 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { p.lower_bound = "bobj"; p.upper_bound = "bobz"; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(0u, result.rows.size()); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); p.lower_bound = "bobb"; p.upper_bound = "bobe"; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(3u, result.rows.size()); + BOOST_REQUIRE_EQUAL(4u, result.rows.size()); chk_result(0, 5); chk_result(1, 4); chk_result(2, 3); + chk_result(3, 2); p.lower_bound = ""; p.upper_bound = "bobe"; @@ -219,6 +230,9 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { chk_result(3, 9); chk_result(4, 10); + ////////////////////////////// + // foo + ////////////////////////////// p.reverse = false; p.index_name = "foo"_n; p.index_value = "A"; // 10 @@ -235,12 +249,20 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { BOOST_REQUIRE_EQUAL(1u, result.rows.size()); chk_result(0, 10); + p.index_value = ""; + p.encode_type = "hex"; + p.lower_bound = "1"; + p.upper_bound = "10"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + + p.index_value = ""; p.encode_type = "dec"; p.lower_bound = "0"; p.upper_bound = "10"; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(9u, result.rows.size()); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); chk_result(0, 1); chk_result(1, 2); chk_result(2, 3); @@ -254,7 +276,7 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { p.lower_bound = "2"; p.upper_bound = "9"; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(7u, result.rows.size()); + BOOST_REQUIRE_EQUAL(8u, result.rows.size()); chk_result(0, 2); chk_result(1, 3); chk_result(2, 4); @@ -262,6 +284,7 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { chk_result(4, 6); chk_result(5, 7); chk_result(6, 8); + chk_result(7, 9); p.lower_bound = "0"; p.upper_bound = ""; @@ -334,6 +357,9 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { chk_result(3, 9); chk_result(4, 10); + ////////////////////////////// + // bar + ////////////////////////////// p.index_name = "bar"_n; p.index_value = "boba"; p.encode_type = "string"; @@ -357,10 +383,36 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { p.lower_bound = "bobb"; p.upper_bound = "bobe"; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(3u, result.rows.size()); + BOOST_REQUIRE_EQUAL(4u, result.rows.size()); chk_result(0, 2); chk_result(1, 3); chk_result(2, 4); + chk_result(3, 5); + + p.index_value = ""; + p.lower_bound = "boba1"; + p.upper_bound = "bobj"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(9u, result.rows.size()); + + p.index_value = ""; + p.lower_bound = "boba"; + p.upper_bound = "bobj1"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + + p.index_value = ""; + p.lower_bound = "boba"; + p.upper_bound = "c"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + + p.index_value = ""; + p.lower_bound = "a"; + p.upper_bound = "c"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + p.lower_bound = "aaaa"; p.upper_bound = ""; @@ -385,6 +437,16 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { result = plugin.read_only::get_kv_table_rows(p); BOOST_REQUIRE_EQUAL(0u, result.rows.size()); + p.lower_bound = "b"; + p.upper_bound = "bobj1"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + + p.lower_bound = "bobj"; + p.upper_bound = "bobz"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + p.reverse = true; p.lower_bound = ""; p.upper_bound = "bobz"; @@ -392,18 +454,24 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { BOOST_REQUIRE_EQUAL(10u, result.rows.size()); chk_result(0, 10); + p.lower_bound = "b"; + p.upper_bound = "bobj1"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + p.lower_bound = "bobj"; p.upper_bound = "bobz"; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(0u, result.rows.size()); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); p.lower_bound = "bobb"; p.upper_bound = "bobe"; result = plugin.read_only::get_kv_table_rows(p); - BOOST_REQUIRE_EQUAL(3u, result.rows.size()); + BOOST_REQUIRE_EQUAL(4u, result.rows.size()); chk_result(0, 5); chk_result(1, 4); chk_result(2, 3); + chk_result(3, 2); p.lower_bound = ""; p.upper_bound = "bobe"; @@ -436,7 +504,6 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { chk_result(2, 5); p.lower_bound = result.next_key; - p.encode_type = "bytes"; p.limit = 20; result = plugin.read_only::get_kv_table_rows(p); BOOST_REQUIRE_EQUAL(5u, result.rows.size()); @@ -446,6 +513,289 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_nodeos_test, TESTER ) try { chk_result(2, 8); chk_result(3, 9); chk_result(4, 10); + + ////////////////////////////// + // uint32_t : 0, 10, 20,..., 80, 90 + ////////////////////////////// + p.reverse = false; + p.index_name = "u"_n; + p.index_value = "A"; // 10 + p.encode_type = "hex"; + p.lower_bound = ""; + p.upper_bound = ""; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + chk_result(0, 1); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "10"; + p.upper_bound = "100"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0"; + p.upper_bound = "110"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + chk_result(0, 1); + chk_result(1, 2); + chk_result(2, 3); + chk_result(3, 4); + chk_result(4, 5); + chk_result(5, 6); + chk_result(6, 7); + chk_result(7, 8); + chk_result(8, 9); + + ////////////////////////////// + // int32_t : -40, -30,..., 40, 50 + ////////////////////////////// + p.reverse = false; + p.index_name = "i"_n; + p.index_value = "A"; + p.encode_type = "hex"; + p.lower_bound = ""; + p.upper_bound = ""; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + chk_result(0, 6); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-10"; + p.upper_bound = "100"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(7u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-100"; + p.upper_bound = "100"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + chk_result(0, 1); + chk_result(1, 2); + chk_result(2, 3); + chk_result(3, 4); + chk_result(4, 5); + chk_result(5, 6); + chk_result(6, 7); + chk_result(7, 8); + chk_result(8, 9); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-100"; + p.upper_bound = "100"; + p.limit = 2; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(2u, result.rows.size()); + BOOST_REQUIRE_EQUAL(result.more, true); + BOOST_REQUIRE_EQUAL(result.next_key != "", true); + chk_result(0, 1); + chk_result(1, 2); + + p.lower_bound = result.next_key; + p.upper_bound = ""; + p.encode_type = "bytes"; + p.limit = 2; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(2u, result.rows.size()); + BOOST_REQUIRE_EQUAL(result.more, true); + BOOST_REQUIRE_EQUAL(result.next_key != "", true); + chk_result(0, 3); + chk_result(1, 4); + + ////////////////////////////// + // int64_t : -400, -300,...,400, 500 + ////////////////////////////// + p.reverse = false; + p.index_name = "ii"_n; + p.index_value = "100"; + p.encode_type = "dec"; + p.lower_bound = ""; + p.upper_bound = ""; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + chk_result(0, 6); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-100"; + p.upper_bound = "100"; + p.limit = 10; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(3u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-1000"; + p.upper_bound = "1000"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + chk_result(0, 1); + chk_result(1, 2); + chk_result(2, 3); + chk_result(3, 4); + chk_result(4, 5); + chk_result(5, 6); + chk_result(6, 7); + chk_result(7, 8); + chk_result(8, 9); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-1000"; + p.upper_bound = "1000"; + p.limit = 2; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(2u, result.rows.size()); + BOOST_REQUIRE_EQUAL(result.more, true); + BOOST_REQUIRE_EQUAL(result.next_key != "", true); + chk_result(0, 1); + chk_result(1, 2); + + p.encode_type = "bytes"; + p.lower_bound = result.next_key; + p.upper_bound = ""; + p.limit = 2; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(2u, result.rows.size()); + BOOST_REQUIRE_EQUAL(result.more, true); + BOOST_REQUIRE_EQUAL(result.next_key != "", true); + chk_result(0, 3); + chk_result(1, 4); + + ////////////////////////////// + // double: 0, 1.01, 2.02,..., 9.09 + ////////////////////////////// + p.reverse = false; + p.index_name = "ff"_n; + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0.0"; + p.upper_bound = "100"; + p.limit = 20; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0.001"; + p.upper_bound = "1000.0"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(9u, result.rows.size()); + chk_result(0, 2); + chk_result(1, 3); + chk_result(2, 4); + chk_result(3, 5); + chk_result(4, 6); + chk_result(5, 7); + chk_result(6, 8); + chk_result(7, 9); + chk_result(8, 10); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0.001"; + p.upper_bound = ""; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(9u, result.rows.size()); + chk_result(0, 2); + chk_result(8, 10); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-0.0001"; + p.upper_bound = "0.00001"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-10.0001"; + p.upper_bound = "0.00001"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0.00001"; + p.upper_bound = "10.00001"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(9u, result.rows.size()); + + p.reverse = true; + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0.0"; + p.upper_bound = "100"; + p.limit = 20; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(10u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0.001"; + p.upper_bound = "1000.0"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(9u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = ""; + p.upper_bound = "4.039999999"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(4u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-0.0001"; + p.upper_bound = "0.00001"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "-10.0001"; + p.upper_bound = "0.00001"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(1u, result.rows.size()); + + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0.00001"; + p.upper_bound = "10.00001"; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(9u, result.rows.size()); + + p.reverse = false; + p.index_value = ""; + p.encode_type = "dec"; + p.lower_bound = "0.02"; + p.upper_bound = "3.03000001"; + p.limit = 2; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(2u, result.rows.size()); + BOOST_REQUIRE_EQUAL(result.more, true); + BOOST_REQUIRE_EQUAL(result.next_key != "", true); + chk_result(0, 2); + chk_result(1, 3); + + p.encode_type = "bytes"; + p.lower_bound = result.next_key; + p.upper_bound = ""; + p.limit = 2; + result = plugin.read_only::get_kv_table_rows(p); + BOOST_REQUIRE_EQUAL(2u, result.rows.size()); + BOOST_REQUIRE_EQUAL(result.more, true); + BOOST_REQUIRE_EQUAL(result.next_key != "", true); + chk_result(0, 4); + chk_result(1, 5); + } FC_LOG_AND_RETHROW() diff --git a/unittests/test-contracts/kv_table_test/kv_table_test.abi b/unittests/test-contracts/kv_table_test/kv_table_test.abi index 5787834ee83..f208703c15c 100644 --- a/unittests/test-contracts/kv_table_test/kv_table_test.abi +++ b/unittests/test-contracts/kv_table_test/kv_table_test.abi @@ -18,6 +18,22 @@ { "name": "bar", "type": "string" + }, + { + "name": "u32", + "type": "uint32" + }, + { + "name": "i32", + "type": "int32" + }, + { + "name": "i64", + "type": "int64" + }, + { + "name": "f64", + "type": "float64" } ] }, @@ -58,6 +74,18 @@ }, "bar": { "type": "string" + }, + "u": { + "type": "uint32" + }, + "i": { + "type": "int32" + }, + "ii": { + "type": "int64" + }, + "ff": { + "type": "float64" } } } diff --git a/unittests/test-contracts/kv_table_test/kv_table_test.cpp b/unittests/test-contracts/kv_table_test/kv_table_test.cpp index eaa8544cf6f..f842d2738a4 100644 --- a/unittests/test-contracts/kv_table_test/kv_table_test.cpp +++ b/unittests/test-contracts/kv_table_test/kv_table_test.cpp @@ -1,4 +1,7 @@ #include +#include + +using namespace eosio; class [[eosio::contract]] kv_table_test : public eosio::contract { public: @@ -6,11 +9,19 @@ class [[eosio::contract]] kv_table_test : public eosio::contract { eosio::name primary_key; uint64_t foo; std::string bar; + uint32_t u32; + int32_t i32; + int64_t i64; + double f64; bool operator==(const my_struct& b) const { return primary_key == b.primary_key && foo == b.foo && - bar == b.bar; + bar == b.bar && + u32 == b.u32 && + i32 == b.i32 && + i64 == b.i64 && + f64 == b.f64; } }; @@ -18,9 +29,13 @@ class [[eosio::contract]] kv_table_test : public eosio::contract { KV_NAMED_INDEX("primarykey"_n, primary_key) KV_NAMED_INDEX("foo"_n, foo) KV_NAMED_INDEX("bar"_n, bar) + KV_NAMED_INDEX("u"_n, u32) + KV_NAMED_INDEX("i"_n, i32) + KV_NAMED_INDEX("ii"_n, i64) + KV_NAMED_INDEX("ff"_n, f64) my_table(eosio::name contract_name) { - init(contract_name, primary_key, foo, bar); + init(contract_name, primary_key, foo, bar, u32, i32, i64, f64); } }; @@ -30,11 +45,17 @@ class [[eosio::contract]] kv_table_test : public eosio::contract { void setup() { my_table t{"kvtable"_n}; char base[5] = {'b', 'o', 'b', 'a', 0}; + for (int i = 0; i < 10; ++i) { my_struct s; s.primary_key = eosio::name{base}; s.foo = i + 1; s.bar = base; + s.u32 = (i + 1) * 10; + s.i32 = (i + 1 ) * 10 - 50; + s.f64 = i + i / 100.0; + s.i64 = (i + 1) * 100 - 500; + t.put(s, get_self()); ++base[3]; diff --git a/unittests/test-contracts/kv_table_test/kv_table_test.wasm b/unittests/test-contracts/kv_table_test/kv_table_test.wasm index 356e0e15fa9..ccc1d370430 100755 Binary files a/unittests/test-contracts/kv_table_test/kv_table_test.wasm and b/unittests/test-contracts/kv_table_test/kv_table_test.wasm differ