Skip to content

Commit 7027819

Browse files
committed
Add check for output strings
1 parent b04e21f commit 7027819

File tree

1 file changed

+57
-19
lines changed

1 file changed

+57
-19
lines changed

src/test/app/HostFuncImpl_test.cpp

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,9 +1917,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite
19171917
using namespace test::jtx;
19181918

19191919
{
1920-
Env env{*this};
1920+
Env env(*this);
19211921
OpenView ov{*env.current()};
1922-
ApplyContext ac = createApplyContext(env, ov);
1922+
test::StreamSink sink{beast::severities::kTrace};
1923+
beast::Journal jlog{sink};
1924+
ApplyContext ac = createApplyContext(env, ov, jlog);
19231925

19241926
auto const dummyEscrow =
19251927
keylet::escrow(env.master, env.seq(env.master));
@@ -1929,12 +1931,26 @@ struct HostFuncImpl_test : public beast::unit_test::suite
19291931
std::string data = "abc";
19301932
auto const slice = Slice(data.data(), data.size());
19311933
auto const result = hfs.trace(msg, slice, false);
1932-
BEAST_EXPECT(result.has_value());
1933-
BEAST_EXPECT(result.value() == msg.size() + data.size());
1934+
if (BEAST_EXPECT(result.has_value()))
1935+
{
1936+
BEAST_EXPECT(result.value() == msg.size() + data.size());
1937+
auto const messages = sink.messages().str();
1938+
BEAST_EXPECT(messages.find(msg) != std::string::npos);
1939+
}
19341940

19351941
auto const resultHex = hfs.trace(msg, slice, true);
1936-
BEAST_EXPECT(resultHex.has_value());
1937-
BEAST_EXPECT(resultHex.value() == msg.size() + data.size() * 2);
1942+
if (BEAST_EXPECT(resultHex.has_value()))
1943+
{
1944+
BEAST_EXPECT(resultHex.has_value());
1945+
BEAST_EXPECT(resultHex.value() == msg.size() + data.size() * 2);
1946+
auto const messages = sink.messages().str();
1947+
std::string hex;
1948+
hex.reserve(data.size() * 2);
1949+
boost::algorithm::hex(
1950+
data.begin(), data.end(), std::back_inserter(hex));
1951+
BEAST_EXPECT(messages.find(msg) != std::string::npos);
1952+
BEAST_EXPECT(messages.find(hex) != std::string::npos);
1953+
}
19381954
}
19391955

19401956
{
@@ -1966,9 +1982,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite
19661982
using namespace test::jtx;
19671983

19681984
{
1969-
Env env{*this};
1985+
Env env(*this);
19701986
OpenView ov{*env.current()};
1971-
ApplyContext ac = createApplyContext(env, ov);
1987+
test::StreamSink sink{beast::severities::kTrace};
1988+
beast::Journal jlog{sink};
1989+
ApplyContext ac = createApplyContext(env, ov, jlog);
19721990

19731991
auto const dummyEscrow =
19741992
keylet::escrow(env.master, env.seq(env.master));
@@ -1977,8 +1995,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite
19771995
std::string msg = "trace number";
19781996
int64_t num = 123456789;
19791997
auto const result = hfs.traceNum(msg, num);
1980-
BEAST_EXPECT(result.has_value());
1981-
BEAST_EXPECT(result.value() == msg.size() + sizeof(num));
1998+
if (BEAST_EXPECT(result.has_value()))
1999+
{
2000+
BEAST_EXPECT(result.value() == msg.size() + sizeof(num));
2001+
auto const messages = sink.messages().str();
2002+
BEAST_EXPECT(messages.find(msg) != std::string::npos);
2003+
BEAST_EXPECT(
2004+
messages.find(std::to_string(num)) != std::string::npos);
2005+
}
19822006
}
19832007

19842008
{
@@ -2009,21 +2033,26 @@ struct HostFuncImpl_test : public beast::unit_test::suite
20092033
using namespace test::jtx;
20102034

20112035
{
2012-
Env env{*this};
2036+
Env env(*this);
20132037
OpenView ov{*env.current()};
2014-
ApplyContext ac = createApplyContext(env, ov);
2038+
test::StreamSink sink{beast::severities::kTrace};
2039+
beast::Journal jlog{sink};
2040+
ApplyContext ac = createApplyContext(env, ov, jlog);
20152041

20162042
auto const dummyEscrow =
20172043
keylet::escrow(env.master, env.seq(env.master));
20182044
WasmHostFunctionsImpl hfs(ac, dummyEscrow);
20192045

20202046
std::string msg = "trace account";
2021-
// Valid account
2047+
auto const result = hfs.traceAccount(msg, env.master.id());
2048+
if (BEAST_EXPECT(result.has_value()))
20222049
{
2023-
auto const result = hfs.traceAccount(msg, env.master.id());
2024-
if (BEAST_EXPECT(result.has_value()))
2025-
BEAST_EXPECT(
2026-
result.value() == msg.size() + env.master.id().size());
2050+
BEAST_EXPECT(
2051+
result.value() == msg.size() + env.master.id().size());
2052+
auto const messages = sink.messages().str();
2053+
BEAST_EXPECT(messages.find(msg) != std::string::npos);
2054+
BEAST_EXPECT(
2055+
messages.find(env.master.human()) != std::string::npos);
20272056
}
20282057
}
20292058

@@ -2054,9 +2083,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite
20542083
using namespace test::jtx;
20552084

20562085
{
2057-
Env env{*this};
2086+
Env env(*this);
20582087
OpenView ov{*env.current()};
2059-
ApplyContext ac = createApplyContext(env, ov);
2088+
test::StreamSink sink{beast::severities::kTrace};
2089+
beast::Journal jlog{sink};
2090+
ApplyContext ac = createApplyContext(env, ov, jlog);
20602091

20612092
auto const dummyEscrow =
20622093
keylet::escrow(env.master, env.seq(env.master));
@@ -2067,7 +2098,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite
20672098
{
20682099
auto const result = hfs.traceAmount(msg, amount);
20692100
if (BEAST_EXPECT(result.has_value()))
2101+
{
20702102
BEAST_EXPECT(*result == msg.size());
2103+
auto const messages = sink.messages().str();
2104+
BEAST_EXPECT(messages.find(msg) != std::string::npos);
2105+
BEAST_EXPECT(
2106+
messages.find(amount.getFullText()) !=
2107+
std::string::npos);
2108+
}
20712109
}
20722110

20732111
// IOU amount

0 commit comments

Comments
 (0)