mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-08-26 06:31:19 +00:00
feat(token): add Logos token API module
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(TokenModuleTests LANGUAGES CXX)
|
||||
|
||||
include(LogosTest)
|
||||
|
||||
logos_test(
|
||||
NAME token_instruction_transport_tests
|
||||
MODULE_SOURCES
|
||||
../src/token_instruction_words.cpp
|
||||
TEST_SOURCES
|
||||
main.cpp
|
||||
token_instruction_words_test.cpp
|
||||
EXTRA_INCLUDES
|
||||
../src
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
#include <logos_test.h>
|
||||
|
||||
LOGOS_TEST_MAIN()
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "token_instruction_words.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
#include <logos_test.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
LOGOS_TEST(instruction_words_encodes_words_little_endian) {
|
||||
const nlohmann::json input = nlohmann::json::array(
|
||||
{std::uint64_t{0}, std::uint64_t{1},
|
||||
std::uint64_t{std::numeric_limits<std::uint32_t>::max()}});
|
||||
|
||||
const auto actual = token_module::detail::jsonInstructionLeBytes(input);
|
||||
const std::vector<std::uint8_t> expected = {
|
||||
0x00, 0x00, 0x00, 0x00, // 0
|
||||
0x01, 0x00, 0x00, 0x00, // 1 (little-endian)
|
||||
0xff, 0xff, 0xff, 0xff, // u32::MAX
|
||||
};
|
||||
LOGOS_ASSERT_EQ(actual.size(), expected.size());
|
||||
for (std::size_t i = 0; i < expected.size(); ++i) {
|
||||
LOGOS_ASSERT_EQ(actual[i], expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
LOGOS_TEST(instruction_words_rejects_negative_word) {
|
||||
const nlohmann::json input = nlohmann::json::array({std::int64_t{-1}});
|
||||
|
||||
LOGOS_ASSERT_TRUE(token_module::detail::jsonInstructionLeBytes(input).empty());
|
||||
}
|
||||
|
||||
LOGOS_TEST(instruction_words_rejects_overflow_word) {
|
||||
const nlohmann::json input = nlohmann::json::array(
|
||||
{std::uint64_t{std::numeric_limits<std::uint32_t>::max()} + 1});
|
||||
|
||||
LOGOS_ASSERT_TRUE(token_module::detail::jsonInstructionLeBytes(input).empty());
|
||||
}
|
||||
|
||||
LOGOS_TEST(instruction_words_rejects_partial_invalid_input) {
|
||||
const nlohmann::json input = nlohmann::json::array({std::uint64_t{1}, 1.5});
|
||||
|
||||
LOGOS_ASSERT_TRUE(token_module::detail::jsonInstructionLeBytes(input).empty());
|
||||
}
|
||||
|
||||
LOGOS_TEST(instruction_words_rejects_non_array) {
|
||||
const nlohmann::json input = nlohmann::json::object({{"word", 1}});
|
||||
|
||||
LOGOS_ASSERT_TRUE(token_module::detail::jsonInstructionLeBytes(input).empty());
|
||||
}
|
||||
Reference in New Issue
Block a user