This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Function body code size test #7947
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
155ced2
Add test for function body code size
jeffreyssmith2nd afff0a2
Fix whitespace
jeffreyssmith2nd 1135e22
Review feedback
jeffreyssmith2nd 4d49dd4
Fix incorrect exception type and cleanup code
jeffreyssmith2nd 3eac480
Fix function body size
jeffreyssmith2nd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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 { | ||
|
@@ -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() | ||
|
@@ -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_execution_error); | ||
produce_blocks(1); | ||
} | ||
} FC_LOG_AND_RETHROW() | ||
|
@@ -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_execution_error); | ||
produce_blocks(1); | ||
} | ||
} FC_LOG_AND_RETHROW() | ||
|
@@ -1843,6 +1845,34 @@ BOOST_FIXTURE_TEST_CASE( depth_tests, TESTER ) try { | |
|
||
} FC_LOG_AND_RETHROW() | ||
|
||
// TODO: Update to use eos-vm once merged | ||
BOOST_AUTO_TEST_CASE( code_size ) try { | ||
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> code_end = { 0x0b }; | ||
|
||
std::vector<U8> code_function_body; | ||
code_function_body.insert(code_function_body.end(), wasm_constraints::maximum_code_size + 4, 0x01); | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.