Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Function body code size test #7947

Merged
merged 5 commits into from
Sep 23, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions unittests/wasm_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#include <eosio/chain/wast_to_wasm.hpp>
#include <eosio/testing/tester.hpp>

#include <Inline/Serialization.h>
#include <IR/Module.h>
#include <Runtime/Runtime.h>
#include <WASM/WASM.h>

#include <boost/test/unit_test.hpp>
#include <boost/algorithm/string/predicate.hpp>
Expand Down Expand Up @@ -883,7 +886,6 @@ BOOST_FIXTURE_TEST_CASE( lotso_globals, TESTER ) try {
BOOST_CHECK_THROW(set_code(N(globals),
string(ss.str() + "(global $z (mut i64) (i64.const -12)))")
.c_str()), eosio::chain::wasm_execution_error);

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( offset_check, TESTER ) try {
Expand Down Expand Up @@ -1382,7 +1384,7 @@ BOOST_FIXTURE_TEST_CASE( lotso_stack_4, TESTER ) try {
ss << "(local i32)";
ss << " )";
ss << ")";
BOOST_CHECK_THROW(set_code(N(stackz), ss.str().c_str()), fc::exception);
BOOST_CHECK_THROW(set_code(N(stackz), ss.str().c_str()), wasm_serialization_error);
produce_blocks(1);
}
} FC_LOG_AND_RETHROW()
Expand Down Expand Up @@ -1445,7 +1447,7 @@ BOOST_FIXTURE_TEST_CASE( lotso_stack_7, TESTER ) try {
ss << "(param i32)";
ss << " )";
ss << ")";
BOOST_CHECK_THROW(set_code(N(stackz), ss.str().c_str()), fc::exception);
BOOST_CHECK_THROW(set_code(N(stackz), ss.str().c_str()), wasm_serialization_error);
produce_blocks(1);
}
} FC_LOG_AND_RETHROW()
Expand Down Expand Up @@ -1486,7 +1488,7 @@ BOOST_FIXTURE_TEST_CASE( lotso_stack_9, TESTER ) try {
ss << "(local f32)";
ss << " )";
ss << ")";
BOOST_CHECK_THROW(set_code(N(stackz), ss.str().c_str()), fc::exception);
BOOST_CHECK_THROW(set_code(N(stackz), ss.str().c_str()), wasm_serialization_error);
produce_blocks(1);
}
} FC_LOG_AND_RETHROW()
Expand Down Expand Up @@ -1843,6 +1845,39 @@ BOOST_FIXTURE_TEST_CASE( depth_tests, TESTER ) try {

} FC_LOG_AND_RETHROW()

// TODO: Update to use eos-vm once merged
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to have to update tests, just because the implementation changes.

BOOST_FIXTURE_TEST_CASE( code_size, TESTER ) try {
jeffreyssmith2nd marked this conversation as resolved.
Show resolved Hide resolved
using namespace IR;
using namespace Runtime;
using namespace Serialization;
std::vector<U8> code_start = {
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60,
0x03, 0x7e, 0x7e, 0x7e, 0x00, 0x03, 0x02, 0x01, 0x00, 0x07, 0x09, 0x01,
0x05, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x00, 0x00, 0x0a, 0x8b, 0x80, 0x80,
0x0a, 0x01, 0x86, 0x80, 0x80, 0x0a, 0x00
};

std::vector<U8> function_body = {
0x41, 0xff, 0xff, 0xff, 0xff, 0x07, 0x1a
};
jeffreyssmith2nd marked this conversation as resolved.
Show resolved Hide resolved

std::vector<U8> code_end = { 0x0b };

std::vector<U8> code_function_body;
for(unsigned int i = 0; i < wasm_constraints::maximum_code_size; i+=7) {
code_function_body.insert(code_function_body.end(), function_body.begin(), function_body.end());
}

std::vector<U8> code;
code.insert(code.end(), code_start.begin(), code_start.end());
code.insert(code.end(), code_function_body.begin(), code_function_body.end());
code.insert(code.end(), code_end.begin(), code_end.end());

Module module;
Serialization::MemoryInputStream stream((const U8*)code.data(), code.size());
BOOST_CHECK_THROW(WASM::serialize(stream, module), FatalSerializationException);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really fond of testing internal components that are not directly visible to users. We don't really care about exactly where the restriction is enforced as long as the user-visible behavior is fixed.


} FC_LOG_AND_RETHROW()
// TODO: restore net_usage_tests
#if 0
BOOST_FIXTURE_TEST_CASE(net_usage_tests, tester ) try {
Expand Down