Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
RickiNano committed Jan 19, 2025
1 parent 5101153 commit cea6dae
Showing 1 changed file with 66 additions and 66 deletions.
132 changes: 66 additions & 66 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,78 +2388,78 @@ TEST (rpc, decimal_nano_to_raw)
auto node1 = add_ipc_enabled_node (system);
auto const rpc_ctx = add_rpc (system, node1);

std::cout << "1";
// One raw as decimal
boost::property_tree::ptree request1;
request1.put ("action", "decimal_nano_to_raw");
request1.put ("amount", "0.000000000000000000000000000001");
auto response (wait_response (system, rpc_ctx, request1));
boost::property_tree::ptree request;
request.put ("action", "decimal_nano_to_raw");
request.put ("amount", "0.000000000000000000000000000001");
auto response (wait_response (system, rpc_ctx, request));
ASSERT_EQ ("1", response.get<std::string> ("amount"));

std::cout << "2";
// Precision overflow (less than one raw)
boost::property_tree::ptree requesta;
requesta.put ("action", "decimal_nano_to_raw");
requesta.put ("amount", "0.0000000000000000000000000000001");
response = wait_response (system, rpc_ctx, requesta);
ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));

std::cout << "3";
// Zero as decimal
boost::property_tree::ptree request2;
request2.put ("action", "decimal_nano_to_raw");
request2.put ("amount", "0.00");
response = wait_response (system, rpc_ctx, request2);
ASSERT_EQ ("0", response.get<std::string> ("amount"));

std::cout << "4";
// Integer only
boost::property_tree::ptree request3;
request3.put ("action", "decimal_nano_to_raw");
request3.put ("amount", "5");
response = wait_response (system, rpc_ctx, request3);
ASSERT_EQ ((5 * nano::nano_ratio).convert_to<std::string> (), response.get<std::string> ("amount"));

std::cout << "5";
// Integer value as decimal
boost::property_tree::ptree request4;
request4.put ("action", "decimal_nano_to_raw");
request4.put ("amount", "7.00000");
response = wait_response (system, rpc_ctx, request4);
ASSERT_EQ ((7 * nano::nano_ratio).convert_to<std::string> (), response.get<std::string> ("amount"));

std::cout << "6";
// Negative value
boost::property_tree::ptree request5;
request5.put ("action", "decimal_nano_to_raw");
request5.put ("amount", "-5");
response = wait_response (system, rpc_ctx, request5);
std::cout << response.get<std::string> ("error");
ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));

std::cout << "7";
// Multiple decimal seperators.
boost::property_tree::ptree request6;
request6.put ("action", "decimal_nano_to_raw");
request6.put ("amount", "7.234.154");
response = wait_response (system, rpc_ctx, request6);
ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));

std::cout << "8";
// Comma as decimal seperator
boost::property_tree::ptree request7;
request7.put ("action", "decimal_nano_to_raw");
request7.put ("amount", "3,14");
response = wait_response (system, rpc_ctx, request7);
ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));
//std::cout << "2";
//// Precision overflow (less than one raw)
//boost::property_tree::ptree requesta;
//requesta.put ("action", "decimal_nano_to_raw");
//requesta.put ("amount", "0.0000000000000000000000000000001");
//response = wait_response (system, rpc_ctx, requesta);
//ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));

//std::cout << "3";
//// Zero as decimal
//boost::property_tree::ptree request2;
//request2.put ("action", "decimal_nano_to_raw");
//request2.put ("amount", "0.00");
//response = wait_response (system, rpc_ctx, request2);
//ASSERT_EQ ("0", response.get<std::string> ("amount"));

//std::cout << "4";
//// Integer only
//boost::property_tree::ptree request3;
//request3.put ("action", "decimal_nano_to_raw");
//request3.put ("amount", "5");
//response = wait_response (system, rpc_ctx, request3);
//ASSERT_EQ ((5 * nano::nano_ratio).convert_to<std::string> (), response.get<std::string> ("amount"));

//std::cout << "5";
//// Integer value as decimal
//boost::property_tree::ptree request4;
//request4.put ("action", "decimal_nano_to_raw");
//request4.put ("amount", "7.00000");
//response = wait_response (system, rpc_ctx, request4);
//ASSERT_EQ ((7 * nano::nano_ratio).convert_to<std::string> (), response.get<std::string> ("amount"));

//std::cout << "6";
//// Negative value
//boost::property_tree::ptree request5;
//request5.put ("action", "decimal_nano_to_raw");
//request5.put ("amount", "-5");
//response = wait_response (system, rpc_ctx, request5);
//std::cout << response.get<std::string> ("error");
//ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));

//std::cout << "7";
//// Multiple decimal seperators.
//boost::property_tree::ptree request6;
//request6.put ("action", "decimal_nano_to_raw");
//request6.put ("amount", "7.234.154");
//response = wait_response (system, rpc_ctx, request6);
//ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));

//std::cout << "8";
//// Comma as decimal seperator
//boost::property_tree::ptree request7;
//request7.put ("action", "decimal_nano_to_raw");
//request7.put ("amount", "3,14");
//response = wait_response (system, rpc_ctx, request7);
//ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));

std::cout << "9";
// Empty input
boost::property_tree::ptree request8;
request8.put ("action", "decimal_nano_to_raw");
request8.put ("amount", "");
response = wait_response (system, rpc_ctx, request8);
request.clear ();
response.clear ();
request.put ("action", "decimal_nano_to_raw");
request.put ("amount", "");
response = wait_response (system, rpc_ctx, request);
ASSERT_EQ (std::error_code (nano::error_common::invalid_amount).message (), response.get<std::string> ("error"));

}

TEST (rpc, account_representative)
Expand Down

0 comments on commit cea6dae

Please sign in to comment.