Skip to content

Commit

Permalink
Update lastUpdateTime testing and other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed May 3, 2024
1 parent 91445cf commit 2ffc3b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/test/app/Oracle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,36 +231,38 @@ struct Oracle_test : public beast::unit_test::suite
// Invalid update time
using namespace std::chrono;
Env env(*this);
auto closeTime = [&]() {
return duration_cast<seconds>(
env.current()->info().closeTime.time_since_epoch() -
10'000s)
.count();
};
env.fund(XRP(1'000), owner);
Oracle oracle(env, {.owner = owner});
BEAST_EXPECT(oracle.exists());
env.close(seconds(400));
// Less than the last close time - 300s
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.lastUpdateTime = static_cast<std::uint32_t>(
testStartTime.count() + 400 - 301),
.lastUpdateTime = static_cast<std::uint32_t>(closeTime() - 301),
.err = ter(tecINVALID_UPDATE_TIME)});
// Greater than last close time + 300s
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.lastUpdateTime = static_cast<std::uint32_t>(
testStartTime.count() + 400 + 301),
.lastUpdateTime = static_cast<std::uint32_t>(closeTime() + 311),
.err = ter(tecINVALID_UPDATE_TIME)});
oracle.set(UpdateArg{.series = {{"XRP", "USD", 740, 1}}});
BEAST_EXPECT(oracle.expectLastUpdateTime(
static_cast<std::uint32_t>(testStartTime.count() + 450)));
// Less than the previous lastUpdateTime
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.lastUpdateTime =
static_cast<std::uint32_t>(testStartTime.count() + 449),
.lastUpdateTime = static_cast<std::uint32_t>(449),
.err = ter(tecINVALID_UPDATE_TIME)});
// Less than the epoch time
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.lastUpdateTime =
static_cast<std::uint32_t>(testStartTime.count() - 1),
.lastUpdateTime = static_cast<int>(epoch_offset.count() - 1),
.err = ter(tecINVALID_UPDATE_TIME)});
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/jtx/Oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace test {
namespace jtx {
namespace oracle {

using AnyValue = std::variant<std::string, double, int, std::uint32_t>;
using AnyValue = std::variant<std::string, double, Json::Int, Json::UInt>;
using OraclesData =
std::vector<std::pair<std::optional<Account>, std::optional<AnyValue>>>;

Expand Down
2 changes: 1 addition & 1 deletion src/test/rpc/GetAggregatePrice_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite

// entire and trimmed stats
auto ret =
Oracle::aggregatePrice(env, "XRP", "USD", oracles, 20, 200);
Oracle::aggregatePrice(env, "XRP", "USD", oracles, 20, "200");
BEAST_EXPECT(ret[jss::entire_set][jss::mean] == "74.6");
BEAST_EXPECT(ret[jss::entire_set][jss::size].asUInt() == 7);
BEAST_EXPECT(
Expand Down

0 comments on commit 2ffc3b0

Please sign in to comment.