Skip to content

Commit

Permalink
Limit xahau genesis to networks starting with 2133X (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardAH authored Nov 23, 2024
1 parent 61ac04a commit 21863b0
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 26 deletions.
7 changes: 7 additions & 0 deletions src/ripple/app/tx/impl/Change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ Change::activateXahauGenesis()
bool const isTest =
(ctx_.tx.getFlags() & tfTestSuite) && ctx_.app.config().standalone();

// RH NOTE: we'll only configure xahau governance structure on networks that
// begin with 2133... so production xahau: 21337 and its testnet 21338
// with 21330-21336 and 21339 also valid and reserved for dev nets etc.
// all other Network IDs will be conventionally configured.
if ((ctx_.app.config().NETWORK_ID / 10) != 2133 && !isTest)
return;

auto [ng_entries, l1_entries, l2_entries, gov_params] =
normalizeXahauGenesis(
isTest ? TestNonGovernanceDistribution : NonGovernanceDistribution,
Expand Down
147 changes: 121 additions & 26 deletions src/test/app/XahauGenesis_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <ripple/app/misc/HashRouter.h>
#include <ripple/app/tx/apply.h>
#include <ripple/app/tx/impl/XahauGenesis.h>
#include <ripple/core/Config.h>
#include <ripple/json/json_reader.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h>
Expand All @@ -27,6 +28,7 @@
#include <ripple/protocol/jss.h>
#include <string>
#include <test/jtx.h>
#include <test/jtx/envconfig.h>
#include <vector>

#define BEAST_REQUIRE(x) \
Expand Down Expand Up @@ -59,7 +61,18 @@ maybe_to_string(T val, std::enable_if_t<!std::is_integral_v<T>, int> = 0)
using namespace XahauGenesis;

namespace ripple {

inline std::unique_ptr<Config>
makeNetworkConfig(uint32_t networkID)
{
using namespace test::jtx;
return envconfig([&](std::unique_ptr<Config> cfg) {
cfg->NETWORK_ID = networkID;
return cfg;
});
}
namespace test {

/*
Accounts used in this test suite:
alice: AE123A8556F3CF91154711376AFB0F894F832B3D,
Expand Down Expand Up @@ -125,7 +138,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
bool burnedViaTest =
false, // means the calling test already burned some of the genesis
bool skipTests = false,
bool const testFlag = false)
bool const testFlag = false,
bool const badNetID = false)
{
using namespace jtx;

Expand Down Expand Up @@ -183,6 +197,20 @@ struct XahauGenesis_test : public beast::unit_test::suite
if (skipTests)
return;

if (badNetID)
{
BEAST_EXPECT(
100000000000000000ULL ==
env.app().getLedgerMaster().getClosedLedger()->info().drops);

auto genesisAccRoot = env.le(keylet::account(genesisAccID));
BEAST_REQUIRE(!!genesisAccRoot);
BEAST_EXPECT(
genesisAccRoot->getFieldAmount(sfBalance) ==
XRPAmount(100000000000000000ULL));
return;
}

// sum the initial distribution balances, these should equal total coins
// in the closed ledger
std::vector<std::pair<std::string, XRPAmount>> const& l1membership =
Expand Down Expand Up @@ -442,17 +470,59 @@ struct XahauGenesis_test : public beast::unit_test::suite
{
testcase("Test activation");
using namespace jtx;
Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

activate(__LINE__, env, false, false, false);
}

void
testBadNetworkIDActivation(FeatureBitset features)
{
testcase("Test Bad Network ID activation");
using namespace jtx;
std::vector<int> badNetIDs{
0,
1,
2,
10,
100,
1000,
10000,
20000,
21000,
21328,
21329,
21340,
21341,
65535};

for (int netid : badNetIDs)
{
Env env{
*this,
makeNetworkConfig(netid),
features - featureXahauGenesis};
activate(__LINE__, env, false, false, false, true);
}

for (int netid = 21330; netid <= 21339; ++netid)
{
Env env{
*this,
makeNetworkConfig(netid),
features - featureXahauGenesis};
activate(__LINE__, env, false, false, false, false);
}
}

void
testWithSignerList(FeatureBitset features)
{
using namespace jtx;
testcase("Test signerlist");
Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

Account const alice{"alice", KeyType::ed25519};
env.fund(XRP(1000), alice);
Expand All @@ -468,7 +538,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
{
using namespace jtx;
testcase("Test regkey");
Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

env.memoize(env.master);
Account const alice("alice");
Expand Down Expand Up @@ -667,7 +738,11 @@ struct XahauGenesis_test : public beast::unit_test::suite
{
using namespace jtx;
testcase("Test governance membership voting L1");
Env env{*this, envconfig(), features - featureXahauGenesis, nullptr};
Env env{
*this,
makeNetworkConfig(21337),
features - featureXahauGenesis,
nullptr};

auto const alice = Account("alice");
auto const bob = Account("bob");
Expand Down Expand Up @@ -2111,7 +2186,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace jtx;
testcase("Test governance membership voting L2");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

auto const alice = Account("alice");
auto const bob = Account("bob");
Expand Down Expand Up @@ -3708,7 +3784,7 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test last close time");

Env env{*this, envconfig(), features};
Env env{*this, makeNetworkConfig(21337), features};
validateTime(lastClose(env), 0);

// last close = 0
Expand Down Expand Up @@ -3738,7 +3814,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace jtx;
testcase("test claim reward rate is == 0");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

STAmount const feesXRP = XRP(1);

Expand Down Expand Up @@ -3783,7 +3860,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace jtx;
testcase("test claim reward rate is > 1");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

STAmount const feesXRP = XRP(1);

Expand Down Expand Up @@ -3828,7 +3906,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace jtx;
testcase("test claim reward delay is == 0");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

STAmount const feesXRP = XRP(1);

Expand Down Expand Up @@ -3873,7 +3952,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace jtx;
testcase("test claim reward delay is < 0");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

STAmount const feesXRP = XRP(1);

Expand Down Expand Up @@ -3918,7 +3998,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace jtx;
testcase("test claim reward before time");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

STAmount const feesXRP = XRP(1);

Expand Down Expand Up @@ -3968,7 +4049,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test claim reward valid without unl report");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};
bool const has240819 = env.current()->rules().enabled(fix240819);

double const rateDrops = 0.00333333333 * 1'000'000;
Expand Down Expand Up @@ -4115,7 +4197,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test claim reward valid with unl report");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -4250,7 +4333,7 @@ struct XahauGenesis_test : public beast::unit_test::suite
{
FeatureBitset _features = features - featureXahauGenesis;
auto const amend = withXahauV1 ? _features : _features - fixXahauV1;
Env env{*this, envconfig(), amend};
Env env{*this, makeNetworkConfig(21337), amend};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -4387,7 +4470,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test claim reward optin optout");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};
bool const has240819 = env.current()->rules().enabled(fix240819);

double const rateDrops = 0.00333333333 * 1'000'000;
Expand Down Expand Up @@ -4499,7 +4583,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test claim reward bal == 1");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -4587,7 +4672,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test claim reward elapsed_since_last == 1");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -4668,7 +4754,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test claim reward elapsed_since_last == 0");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

STAmount const feesXRP = XRP(1);

Expand Down Expand Up @@ -4929,7 +5016,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test compound interest over 12 claims");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -5027,7 +5115,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test deposit");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -5117,7 +5206,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test deposit withdraw");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -5209,7 +5299,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test deposit late");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -5299,7 +5390,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test deposit late withdraw");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -5392,7 +5484,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test no claim");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -5480,7 +5573,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
using namespace std::chrono_literals;
testcase("test no claim late");

Env env{*this, envconfig(), features - featureXahauGenesis};
Env env{
*this, makeNetworkConfig(21337), features - featureXahauGenesis};

double const rateDrops = 0.00333333333 * 1'000'000;
STAmount const feesXRP = XRP(1);
Expand Down Expand Up @@ -5594,6 +5688,7 @@ struct XahauGenesis_test : public beast::unit_test::suite
testGovernHookWithFeats(FeatureBitset features)
{
testPlainActivation(features);
testBadNetworkIDActivation(features);
testWithSignerList(features);
testWithRegularKey(features);
testGovernanceL1(features);
Expand Down

0 comments on commit 21863b0

Please sign in to comment.