TSH Tests (#222)

This commit is contained in:
Denis Angell
2023-12-03 10:13:05 +01:00
committed by GitHub
parent 7881b7f69f
commit 27f43ba9ee
8 changed files with 5099 additions and 403 deletions

View File

@@ -755,6 +755,7 @@ if (tests)
src/test/app/ValidatorList_test.cpp src/test/app/ValidatorList_test.cpp
src/test/app/ValidatorSite_test.cpp src/test/app/ValidatorSite_test.cpp
src/test/app/SetHook_test.cpp src/test/app/SetHook_test.cpp
src/test/app/SetHookTSH_test.cpp
src/test/app/Wildcard_test.cpp src/test/app/Wildcard_test.cpp
src/test/app/XahauGenesis_test.cpp src/test/app/XahauGenesis_test.cpp
src/test/app/tx/apply_test.cpp src/test/app/tx/apply_test.cpp
@@ -896,6 +897,7 @@ if (tests)
src/test/jtx/impl/token.cpp src/test/jtx/impl/token.cpp
src/test/jtx/impl/trust.cpp src/test/jtx/impl/trust.cpp
src/test/jtx/impl/txflags.cpp src/test/jtx/impl/txflags.cpp
src/test/jtx/impl/unl.cpp
src/test/jtx/impl/uritoken.cpp src/test/jtx/impl/uritoken.cpp
src/test/jtx/impl/utility.cpp src/test/jtx/impl/utility.cpp

View File

@@ -5549,73 +5549,6 @@ class Import_test : public beast::unit_test::suite
} }
} }
// std::unique_ptr<Config>
// network::makeGenesisConfig(
// FeatureBitset features,
// uint32_t networkID,
// std::string fee,
// std::string a_res,
// std::string o_res,
// uint32_t ledgerID)
// {
// using namespace jtx;
// // IMPORT VL KEY
// std::vector<std::string> const keys = {
// "ED74D4036C6591A4BDF9C54CEFA39B996A"
// "5DCE5F86D11FDA1874481CE9D5A1CDC1"};
// Json::Value jsonValue;
// Json::Reader reader;
// reader.parse(ImportTCHalving::base_genesis, jsonValue);
// foreachFeature(features, [&](uint256 const& feature) {
// std::string featureName = featureToName(feature);
// std::optional<uint256> featureHash =
// getRegisteredFeature(featureName);
// if (featureHash.has_value())
// {
// std::string hashString = to_string(featureHash.value());
// jsonValue["ledger"]["accountState"][1]["Amendments"].append(
// hashString);
// }
// });
// jsonValue["ledger_current_index"] = ledgerID;
// jsonValue["ledger"]["ledger_index"] = to_string(ledgerID);
// jsonValue["ledger"]["seqNum"] = to_string(ledgerID);
// return envconfig([&](std::unique_ptr<Config> cfg) {
// cfg->NETWORK_ID = networkID;
// cfg->START_LEDGER = jsonValue.toStyledString();
// cfg->START_UP = Config::LOAD_JSON;
// Section config;
// config.append(
// {"reference_fee = " + fee,
// "account_reserve = " + a_res,
// "owner_reserve = " + o_res});
// auto setup = setup_FeeVote(config);
// cfg->FEES = setup;
// for (auto const& strPk : keys)
// {
// auto pkHex = strUnHex(strPk);
// if (!pkHex)
// Throw<std::runtime_error>(
// "Import VL Key '" + strPk + "' was not valid hex.");
// auto const pkType = publicKeyType(makeSlice(*pkHex));
// if (!pkType)
// Throw<std::runtime_error>(
// "Import VL Key '" + strPk +
// "' was not a valid key type.");
// cfg->IMPORT_VL_KEYS.emplace(strPk, makeSlice(*pkHex));
// }
// return cfg;
// });
// }
void void
testHalving(FeatureBitset features) testHalving(FeatureBitset features)
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -42,35 +42,6 @@ namespace test {
* are put in their existing unit test files. * are put in their existing unit test files.
*/ */
/**
* Test the size of the negative UNL in a ledger,
* also test if the ledger has ToDisalbe and/or ToReEnable
*
* @param l the ledger
* @param size the expected negative UNL size
* @param hasToDisable if expect ToDisable in ledger
* @param hasToReEnable if expect ToDisable in ledger
* @return true if meet all three expectation
*/
bool
negUnlSizeTest(
std::shared_ptr<Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable);
/**
* Try to apply a ttUNL_MODIFY Tx, and test the apply result
*
* @param env the test environment
* @param view the OpenView of the ledger
* @param tx the ttUNL_MODIFY Tx
* @param pass if the Tx should be applied successfully
* @return true if meet the expectation of apply result
*/
bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass);
/** /**
* Verify the content of negative UNL entries (public key and ledger sequence) * Verify the content of negative UNL entries (public key and ledger sequence)
* of a ledger * of a ledger
@@ -85,15 +56,6 @@ VerifyPubKeyAndSeq(
std::shared_ptr<Ledger const> const& l, std::shared_ptr<Ledger const> const& l,
hash_map<PublicKey, std::uint32_t> nUnlLedgerSeq); hash_map<PublicKey, std::uint32_t> nUnlLedgerSeq);
/**
* Count the number of Tx in a TxSet
*
* @param txSet the TxSet
* @return the number of Tx
*/
std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet);
/** /**
* Create fake public keys * Create fake public keys
* *
@@ -103,17 +65,6 @@ countTx(std::shared_ptr<SHAMap> const& txSet);
std::vector<PublicKey> std::vector<PublicKey>
createPublicKeys(std::size_t n); createPublicKeys(std::size_t n);
/**
* Create ttUNL_MODIFY Tx
*
* @param disabling disabling or re-enabling a validator
* @param seq current ledger seq
* @param txKey the public key of the validator
* @return the ttUNL_MODIFY Tx
*/
STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey);
class NegativeUNL_test : public beast::unit_test::suite class NegativeUNL_test : public beast::unit_test::suite
{ {
/** /**
@@ -245,14 +196,16 @@ class NegativeUNL_test : public beast::unit_test::suite
l = std::make_shared<Ledger>( l = std::make_shared<Ledger>(
*l, env.app().timeKeeper().closeTime()); *l, env.app().timeKeeper().closeTime());
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]); auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]); auto txReEnable_1 = unl::createTx(false, l->seq(), publicKeys[1]);
OpenView accum(&*l); OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, false)); BEAST_EXPECT(
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_1, false)); unl::applyAndTestResult(env, accum, txDisable_0, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_1, false));
accum.apply(*l); accum.apply(*l);
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false)); BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
} }
{ {
@@ -266,18 +219,21 @@ class NegativeUNL_test : public beast::unit_test::suite
BEAST_EXPECT(l->isFlagLedger()); BEAST_EXPECT(l->isFlagLedger());
l->updateNegativeUNL(); l->updateNegativeUNL();
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]); auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
auto txDisable_1 = createTx(true, l->seq(), publicKeys[1]); auto txDisable_1 = unl::createTx(true, l->seq(), publicKeys[1]);
auto txReEnable_2 = createTx(false, l->seq(), publicKeys[2]); auto txReEnable_2 = unl::createTx(false, l->seq(), publicKeys[2]);
// can apply 1 and only 1 ToDisable Tx, // can apply 1 and only 1 ToDisable Tx,
// cannot apply ToReEnable Tx, since negative UNL is empty // cannot apply ToReEnable Tx, since negative UNL is empty
OpenView accum(&*l); OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, true)); BEAST_EXPECT(
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_1, false)); unl::applyAndTestResult(env, accum, txDisable_0, true));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_2, false)); BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_1, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_2, false));
accum.apply(*l); accum.apply(*l);
auto good_size = negUnlSizeTest(l, 0, true, false); auto good_size = unl::negUnlSizeTest(l, 0, true, false);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -292,7 +248,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(3) ledgers before the next flag ledger //(3) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i) for (auto i = 0; i < 256; ++i)
{ {
auto good_size = negUnlSizeTest(l, 0, true, false); auto good_size = unl::negUnlSizeTest(l, 0, true, false);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
BEAST_EXPECT(l->validatorToDisable() == publicKeys[0]); BEAST_EXPECT(l->validatorToDisable() == publicKeys[0]);
@@ -304,7 +260,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(4) next flag ledger //(4) next flag ledger
// test if the ledger updated correctly // test if the ledger updated correctly
auto good_size = negUnlSizeTest(l, 1, false, false); auto good_size = unl::negUnlSizeTest(l, 1, false, false);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -312,20 +268,25 @@ class NegativeUNL_test : public beast::unit_test::suite
nUnlLedgerSeq.emplace(publicKeys[0], l->seq()); nUnlLedgerSeq.emplace(publicKeys[0], l->seq());
} }
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]); auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
auto txDisable_1 = createTx(true, l->seq(), publicKeys[1]); auto txDisable_1 = unl::createTx(true, l->seq(), publicKeys[1]);
auto txReEnable_0 = createTx(false, l->seq(), publicKeys[0]); auto txReEnable_0 = unl::createTx(false, l->seq(), publicKeys[0]);
auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]); auto txReEnable_1 = unl::createTx(false, l->seq(), publicKeys[1]);
auto txReEnable_2 = createTx(false, l->seq(), publicKeys[2]); auto txReEnable_2 = unl::createTx(false, l->seq(), publicKeys[2]);
OpenView accum(&*l); OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, false)); BEAST_EXPECT(
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_1, true)); unl::applyAndTestResult(env, accum, txDisable_0, false));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_1, false)); BEAST_EXPECT(
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_2, false)); unl::applyAndTestResult(env, accum, txDisable_1, true));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_0, true)); BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_1, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_2, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_0, true));
accum.apply(*l); accum.apply(*l);
good_size = negUnlSizeTest(l, 1, true, true); good_size = unl::negUnlSizeTest(l, 1, true, true);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -341,7 +302,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(5) ledgers before the next flag ledger //(5) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i) for (auto i = 0; i < 256; ++i)
{ {
auto good_size = negUnlSizeTest(l, 1, true, true); auto good_size = unl::negUnlSizeTest(l, 1, true, true);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -357,19 +318,20 @@ class NegativeUNL_test : public beast::unit_test::suite
//(6) next flag ledger //(6) next flag ledger
// test if the ledger updated correctly // test if the ledger updated correctly
auto good_size = negUnlSizeTest(l, 1, false, false); auto good_size = unl::negUnlSizeTest(l, 1, false, false);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
BEAST_EXPECT(l->negativeUNL().count(publicKeys[1])); BEAST_EXPECT(l->negativeUNL().count(publicKeys[1]));
} }
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]); auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
OpenView accum(&*l); OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, true)); BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_0, true));
accum.apply(*l); accum.apply(*l);
good_size = negUnlSizeTest(l, 1, true, false); good_size = unl::negUnlSizeTest(l, 1, true, false);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -385,7 +347,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(7) ledgers before the next flag ledger //(7) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i) for (auto i = 0; i < 256; ++i)
{ {
auto good_size = negUnlSizeTest(l, 1, true, false); auto good_size = unl::negUnlSizeTest(l, 1, true, false);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -400,7 +362,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(8) next flag ledger //(8) next flag ledger
// test if the ledger updated correctly // test if the ledger updated correctly
auto good_size = negUnlSizeTest(l, 2, false, false); auto good_size = unl::negUnlSizeTest(l, 2, false, false);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -410,16 +372,19 @@ class NegativeUNL_test : public beast::unit_test::suite
BEAST_EXPECT(VerifyPubKeyAndSeq(l, nUnlLedgerSeq)); BEAST_EXPECT(VerifyPubKeyAndSeq(l, nUnlLedgerSeq));
} }
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]); auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
auto txReEnable_0 = createTx(false, l->seq(), publicKeys[0]); auto txReEnable_0 = unl::createTx(false, l->seq(), publicKeys[0]);
auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]); auto txReEnable_1 = unl::createTx(false, l->seq(), publicKeys[1]);
OpenView accum(&*l); OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_0, true)); BEAST_EXPECT(
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_1, false)); unl::applyAndTestResult(env, accum, txReEnable_0, true));
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, false)); BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_1, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_0, false));
accum.apply(*l); accum.apply(*l);
good_size = negUnlSizeTest(l, 2, false, true); good_size = unl::negUnlSizeTest(l, 2, false, true);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -434,7 +399,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(9) ledgers before the next flag ledger //(9) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i) for (auto i = 0; i < 256; ++i)
{ {
auto good_size = negUnlSizeTest(l, 2, false, true); auto good_size = unl::negUnlSizeTest(l, 2, false, true);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -450,7 +415,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(10) next flag ledger //(10) next flag ledger
// test if the ledger updated correctly // test if the ledger updated correctly
auto good_size = negUnlSizeTest(l, 1, false, false); auto good_size = unl::negUnlSizeTest(l, 1, false, false);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -459,12 +424,13 @@ class NegativeUNL_test : public beast::unit_test::suite
BEAST_EXPECT(VerifyPubKeyAndSeq(l, nUnlLedgerSeq)); BEAST_EXPECT(VerifyPubKeyAndSeq(l, nUnlLedgerSeq));
} }
auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]); auto txReEnable_1 = unl::createTx(false, l->seq(), publicKeys[1]);
OpenView accum(&*l); OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_1, true)); BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_1, true));
accum.apply(*l); accum.apply(*l);
good_size = negUnlSizeTest(l, 1, false, true); good_size = unl::negUnlSizeTest(l, 1, false, true);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -478,7 +444,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(11) ledgers before the next flag ledger //(11) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i) for (auto i = 0; i < 256; ++i)
{ {
auto good_size = negUnlSizeTest(l, 1, false, true); auto good_size = unl::negUnlSizeTest(l, 1, false, true);
BEAST_EXPECT(good_size); BEAST_EXPECT(good_size);
if (good_size) if (good_size)
{ {
@@ -492,14 +458,14 @@ class NegativeUNL_test : public beast::unit_test::suite
l->updateNegativeUNL(); l->updateNegativeUNL();
//(12) next flag ledger //(12) next flag ledger
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false)); BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
} }
{ {
//(13) ledgers before the next flag ledger //(13) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i) for (auto i = 0; i < 256; ++i)
{ {
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false)); BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
l = std::make_shared<Ledger>( l = std::make_shared<Ledger>(
*l, env.app().timeKeeper().closeTime()); *l, env.app().timeKeeper().closeTime());
} }
@@ -507,7 +473,7 @@ class NegativeUNL_test : public beast::unit_test::suite
l->updateNegativeUNL(); l->updateNegativeUNL();
//(14) next flag ledger //(14) next flag ledger
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false)); BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
} }
} }
@@ -542,11 +508,11 @@ class NegativeUNLNoAmendment_test : public beast::unit_test::suite
*l, env.app().timeKeeper().closeTime()); *l, env.app().timeKeeper().closeTime());
} }
BEAST_EXPECT(l->seq() == 256); BEAST_EXPECT(l->seq() == 256);
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]); auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
OpenView accum(&*l); OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, false)); BEAST_EXPECT(unl::applyAndTestResult(env, accum, txDisable_0, false));
accum.apply(*l); accum.apply(*l);
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false)); BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
} }
void void
@@ -634,8 +600,8 @@ struct NetworkHistory
OpenView accum(&*l); OpenView accum(&*l);
if (l->negativeUNL().size() < param.negUNLSize) if (l->negativeUNL().size() < param.negUNLSize)
{ {
auto tx = createTx(true, l->seq(), UNLKeys[nidx]); auto tx = unl::createTx(true, l->seq(), UNLKeys[nidx]);
if (!applyAndTestResult(env, accum, tx, true)) if (!unl::applyAndTestResult(env, accum, tx, true))
break; break;
++nidx; ++nidx;
} }
@@ -643,15 +609,15 @@ struct NetworkHistory
{ {
if (param.hasToDisable) if (param.hasToDisable)
{ {
auto tx = createTx(true, l->seq(), UNLKeys[nidx]); auto tx = unl::createTx(true, l->seq(), UNLKeys[nidx]);
if (!applyAndTestResult(env, accum, tx, true)) if (!unl::applyAndTestResult(env, accum, tx, true))
break; break;
++nidx; ++nidx;
} }
if (param.hasToReEnable) if (param.hasToReEnable)
{ {
auto tx = createTx(false, l->seq(), UNLKeys[0]); auto tx = unl::createTx(false, l->seq(), UNLKeys[0]);
if (!applyAndTestResult(env, accum, tx, true)) if (!unl::applyAndTestResult(env, accum, tx, true))
break; break;
} }
} }
@@ -659,7 +625,7 @@ struct NetworkHistory
} }
l->updateSkipList(); l->updateSkipList();
} }
return negUnlSizeTest( return unl::negUnlSizeTest(
l, param.negUNLSize, param.hasToDisable, param.hasToReEnable); l, param.negUNLSize, param.hasToDisable, param.hasToReEnable);
} }
@@ -759,7 +725,7 @@ voteAndCheck(
vote.doVoting( vote.doVoting(
history.lastLedger(), history.UNLKeySet, history.validations, txSet); history.lastLedger(), history.UNLKeySet, history.validations, txSet);
return countTx(txSet) >= expect; return unl::countTx(txSet) >= expect;
} }
/** /**
@@ -782,11 +748,11 @@ class NegativeUNLVoteInternal_test : public beast::unit_test::suite
PublicKey toDisableKey; PublicKey toDisableKey;
PublicKey toReEnableKey; PublicKey toReEnableKey;
LedgerIndex seq(1234); LedgerIndex seq(1234);
BEAST_EXPECT(countTx(txSet) == 0); BEAST_EXPECT(unl::countTx(txSet) == 0);
vote.addTx(seq, toDisableKey, NegativeUNLVote::ToDisable, txSet); vote.addTx(seq, toDisableKey, NegativeUNLVote::ToDisable, txSet);
BEAST_EXPECT(countTx(txSet) == 1); BEAST_EXPECT(unl::countTx(txSet) == 1);
vote.addTx(seq, toReEnableKey, NegativeUNLVote::ToReEnable, txSet); vote.addTx(seq, toReEnableKey, NegativeUNLVote::ToReEnable, txSet);
BEAST_EXPECT(countTx(txSet) == 2); BEAST_EXPECT(unl::countTx(txSet) == 2);
// content of a tx is implicitly tested after applied to a ledger // content of a tx is implicitly tested after applied to a ledger
// in later test cases // in later test cases
} }
@@ -1912,31 +1878,6 @@ BEAST_DEFINE_TESTSUITE(NegativeUNLVoteFilterValidations, consensus, ripple);
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
bool
negUnlSizeTest(
std::shared_ptr<Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable)
{
bool sameSize = l->negativeUNL().size() == size;
bool sameToDisable =
(l->validatorToDisable() != std::nullopt) == hasToDisable;
bool sameToReEnable =
(l->validatorToReEnable() != std::nullopt) == hasToReEnable;
return sameSize && sameToDisable && sameToReEnable;
}
bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED;
}
bool bool
VerifyPubKeyAndSeq( VerifyPubKeyAndSeq(
@@ -1975,34 +1916,6 @@ VerifyPubKeyAndSeq(
return nUnlLedgerSeq.size() == 0; return nUnlLedgerSeq.size() == 0;
} }
std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet)
{
/*uint64_t counter = 0;
if (txSet)
for (auto const& item : *txSet)
{
SerialIter sit(item.slice());
auto tx = std::make_shared<STTx
const>(SerialIter{sit.getSlice(sit.getVLDataLength())});
if (tx->getFieldU16(sfTransactionType) == ttUNL_MODIFY)
counter++;
}
*/
std::size_t count = 0;
for (auto i = txSet->begin(); i != txSet->end(); ++i)
{
// RH TODO: why does the above parse??
auto raw = i->slice();
if (raw[0] == 0x12U && raw[1] == 0 && raw[2] == 0x66U)
count++;
}
return count;
};
std::vector<PublicKey> std::vector<PublicKey>
createPublicKeys(std::size_t n) createPublicKeys(std::size_t n)
{ {
@@ -2019,16 +1932,5 @@ createPublicKeys(std::size_t n)
return keys; return keys;
} }
STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey)
{
auto fill = [&](auto& obj) {
obj.setFieldU8(sfUNLModifyDisabling, disabling ? 1 : 0);
obj.setFieldU32(sfLedgerSequence, seq);
obj.setFieldVL(sfUNLModifyValidator, txKey);
};
return STTx(ttUNL_MODIFY, fill);
}
} // namespace test } // namespace test
} // namespace ripple } // namespace ripple

View File

@@ -51,23 +51,6 @@ namespace test {
// * are put in their existing unit test files. // * are put in their existing unit test files.
// */ // */
// /**
// * Test the size of the negative UNL in a ledger,
// * also test if the ledger has ToDisalbe and/or ToReEnable
// *
// * @param l the ledger
// * @param size the expected negative UNL size
// * @param hasToDisable if expect ToDisable in ledger
// * @param hasToReEnable if expect ToDisable in ledger
// * @return true if meet all three expectation
// */
inline bool
negUnlSizeTest(
std::shared_ptr<Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable);
// /** // /**
// * Try to apply a ttUNL_MODIFY Tx, and test the apply result // * Try to apply a ttUNL_MODIFY Tx, and test the apply result
// * // *
@@ -110,9 +93,6 @@ countUNLRTx(std::shared_ptr<SHAMap> const& txSet);
std::vector<std::string> const keys = { std::vector<std::string> const keys = {
"ED74D4036C6591A4BDF9C54CEFA39B996A5DCE5F86D11FDA1874481CE9D5A1CDC1"}; "ED74D4036C6591A4BDF9C54CEFA39B996A5DCE5F86D11FDA1874481CE9D5A1CDC1"};
std::unique_ptr<Config>
makeNetworkVLConfig(uint32_t networkID, std::vector<std::string> keys);
/** /**
* Verify if the UNL report exists * Verify if the UNL report exists
* *
@@ -165,38 +145,6 @@ createUNLRTx(
PublicKey const& importKey, PublicKey const& importKey,
PublicKey const& valKey); PublicKey const& valKey);
/**
* Count the number of Tx in a TxSet
*
* @param txSet the TxSet
* @return the number of Tx
*/
inline std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet);
/**
* Create ttUNL_MODIFY Tx
*
* @param disabling disabling or re-enabling a validator
* @param seq current ledger seq
* @param txKey the public key of the validator
* @return the ttUNL_MODIFY Tx
*/
inline STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey);
/**
* Try to apply a ttUNL_MODIFY Tx, and test the apply result
*
* @param env the test environment
* @param view the OpenView of the ledger
* @param tx the ttUNL_MODIFY Tx
* @param pass if the Tx should be applied successfully
* @return true if meet the expectation of apply result
*/
inline bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass);
class UNLReport_test : public beast::unit_test::suite class UNLReport_test : public beast::unit_test::suite
{ {
// Import VL Keys // Import VL Keys
@@ -345,7 +293,10 @@ class UNLReport_test : public beast::unit_test::suite
// telIMPORT_VL_KEY_NOT_RECOGNISED // telIMPORT_VL_KEY_NOT_RECOGNISED
{ {
test::jtx::Env env{ test::jtx::Env env{
*this, makeNetworkVLConfig(21337, keys), features, nullptr}; *this,
jtx::network::makeNetworkVLConfig(21337, keys),
features,
nullptr};
auto l = std::make_shared<Ledger>( auto l = std::make_shared<Ledger>(
create_genesis, create_genesis,
@@ -374,7 +325,10 @@ class UNLReport_test : public beast::unit_test::suite
// SUCCESS // SUCCESS
{ {
test::jtx::Env env{ test::jtx::Env env{
*this, makeNetworkVLConfig(21337, keys), features, nullptr}; *this,
jtx::network::makeNetworkVLConfig(21337, keys),
features,
nullptr};
auto l = std::make_shared<Ledger>( auto l = std::make_shared<Ledger>(
create_genesis, create_genesis,
@@ -413,7 +367,10 @@ class UNLReport_test : public beast::unit_test::suite
using namespace jtx; using namespace jtx;
test::jtx::Env env{ test::jtx::Env env{
*this, makeNetworkVLConfig(21337, keys), features, nullptr}; *this,
jtx::network::makeNetworkVLConfig(21337, keys),
features,
nullptr};
std::vector<PublicKey> ivlKeys; std::vector<PublicKey> ivlKeys;
for (auto const& strPk : _ivlKeys) for (auto const& strPk : _ivlKeys)
@@ -674,7 +631,8 @@ struct URNetworkHistory
URNetworkHistory(beast::unit_test::suite& suite, Parameter const& p) URNetworkHistory(beast::unit_test::suite& suite, Parameter const& p)
: env(suite, : env(suite,
p.withVL ? makeNetworkVLConfig(21337, keys) : jtx::envconfig(), p.withVL ? jtx::network::makeNetworkVLConfig(21337, keys)
: jtx::envconfig(),
jtx::supported_amendments() | featureNegativeUNL) jtx::supported_amendments() | featureNegativeUNL)
, param(p) , param(p)
, validations(env.app().getValidations()) , validations(env.app().getValidations())
@@ -728,8 +686,8 @@ struct URNetworkHistory
OpenView accum(&*l); OpenView accum(&*l);
if (l->negativeUNL().size() < param.negUNLSize) if (l->negativeUNL().size() < param.negUNLSize)
{ {
auto tx = createTx(true, l->seq(), UNLKeys[nidx]); auto tx = unl::createTx(true, l->seq(), UNLKeys[nidx]);
if (!applyAndTestResult(env, accum, tx, true)) if (!unl::applyAndTestResult(env, accum, tx, true))
break; break;
++nidx; ++nidx;
} }
@@ -737,15 +695,15 @@ struct URNetworkHistory
{ {
if (param.hasToDisable) if (param.hasToDisable)
{ {
auto tx = createTx(true, l->seq(), UNLKeys[nidx]); auto tx = unl::createTx(true, l->seq(), UNLKeys[nidx]);
if (!applyAndTestResult(env, accum, tx, true)) if (!unl::applyAndTestResult(env, accum, tx, true))
break; break;
++nidx; ++nidx;
} }
if (param.hasToReEnable) if (param.hasToReEnable)
{ {
auto tx = createTx(false, l->seq(), UNLKeys[0]); auto tx = unl::createTx(false, l->seq(), UNLKeys[0]);
if (!applyAndTestResult(env, accum, tx, true)) if (!unl::applyAndTestResult(env, accum, tx, true))
break; break;
} }
} }
@@ -753,7 +711,7 @@ struct URNetworkHistory
} }
l->updateSkipList(); l->updateSkipList();
} }
return negUnlSizeTest( return unl::negUnlSizeTest(
l, param.negUNLSize, param.hasToDisable, param.hasToReEnable); l, param.negUNLSize, param.hasToDisable, param.hasToReEnable);
} }
@@ -854,7 +812,8 @@ voteAndCheckUNLR(
vote.doVoting( vote.doVoting(
history.lastLedger(), history.UNLKeySet, history.validations, txSet); history.lastLedger(), history.UNLKeySet, history.validations, txSet);
return countUNLRTx(txSet) == expectReport && countTx(txSet) >= expectModify; return countUNLRTx(txSet) == expectReport &&
unl::countTx(txSet) >= expectModify;
} }
/* /*
@@ -1235,22 +1194,6 @@ BEAST_DEFINE_TESTSUITE(UNLReportVoteNewValidator, consensus, ripple);
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
inline bool
negUnlSizeTest(
std::shared_ptr<Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable)
{
bool sameSize = l->negativeUNL().size() == size;
bool sameToDisable =
(l->validatorToDisable() != std::nullopt) == hasToDisable;
bool sameToReEnable =
(l->validatorToReEnable() != std::nullopt) == hasToReEnable;
return sameSize && sameToDisable && sameToReEnable;
}
bool bool
applyAndTestUNLRResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass) applyAndTestUNLRResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{ {
@@ -1313,38 +1256,6 @@ countUNLRTx(std::shared_ptr<SHAMap> const& txSet)
return count; return count;
}; };
std::unique_ptr<Config>
makeNetworkVLConfig(uint32_t networkID, std::vector<std::string> keys)
{
using namespace jtx;
return envconfig([&](std::unique_ptr<Config> cfg) {
cfg->NETWORK_ID = networkID;
Section config;
config.append(
{"reference_fee = 10",
"account_reserve = 1000000",
"owner_reserve = 200000"});
auto setup = setup_FeeVote(config);
cfg->FEES = setup;
for (auto const& strPk : keys)
{
auto pkHex = strUnHex(strPk);
if (!pkHex)
Throw<std::runtime_error>(
"Import VL Key '" + strPk + "' was not valid hex.");
auto const pkType = publicKeyType(makeSlice(*pkHex));
if (!pkType)
Throw<std::runtime_error>(
"Import VL Key '" + strPk + "' was not a valid key type.");
cfg->IMPORT_VL_KEYS.emplace(strPk, makeSlice(*pkHex));
}
return cfg;
});
}
bool bool
hasUNLReport(jtx::Env const& env) hasUNLReport(jtx::Env const& env)
{ {
@@ -1412,54 +1323,5 @@ createUNLRTx(
return STTx(ttUNL_REPORT, fill); return STTx(ttUNL_REPORT, fill);
} }
inline STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey)
{
auto fill = [&](auto& obj) {
obj.setFieldU8(sfUNLModifyDisabling, disabling ? 1 : 0);
obj.setFieldU32(sfLedgerSequence, seq);
obj.setFieldVL(sfUNLModifyValidator, txKey);
};
return STTx(ttUNL_MODIFY, fill);
}
inline std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet)
{
/*uint64_t counter = 0;
if (txSet)
for (auto const& item : *txSet)
{
SerialIter sit(item.slice());
auto tx = std::make_shared<STTx
const>(SerialIter{sit.getSlice(sit.getVLDataLength())});
if (tx->getFieldU16(sfTransactionType) == ttUNL_MODIFY)
counter++;
}
*/
std::size_t count = 0;
for (auto i = txSet->begin(); i != txSet->end(); ++i)
{
// RH TODO: why does the above parse??
auto raw = i->slice();
if (raw[0] == 0x12U && raw[1] == 0 && raw[2] == 0x66U)
count++;
}
return count;
};
inline bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED;
}
} // namespace test } // namespace test
} // namespace ripple } // namespace ripple

View File

@@ -70,6 +70,7 @@
#include <test/jtx/token.h> #include <test/jtx/token.h>
#include <test/jtx/trust.h> #include <test/jtx/trust.h>
#include <test/jtx/txflags.h> #include <test/jtx/txflags.h>
#include <test/jtx/unl.h>
#include <test/jtx/uritoken.h> #include <test/jtx/uritoken.h>
#include <test/jtx/utility.h> #include <test/jtx/utility.h>

95
src/test/jtx/impl/unl.cpp Normal file
View File

@@ -0,0 +1,95 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 XRPL Labs
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/app/tx/apply.h>
#include <ripple/protocol/jss.h>
#include <test/jtx/unl.h>
namespace ripple {
namespace test {
namespace unl {
bool
negUnlSizeTest(
std::shared_ptr<Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable)
{
bool sameSize = l->negativeUNL().size() == size;
bool sameToDisable =
(l->validatorToDisable() != std::nullopt) == hasToDisable;
bool sameToReEnable =
(l->validatorToReEnable() != std::nullopt) == hasToReEnable;
return sameSize && sameToDisable && sameToReEnable;
}
bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED;
}
std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet)
{
/*uint64_t counter = 0;
if (txSet)
for (auto const& item : *txSet)
{
SerialIter sit(item.slice());
auto tx = std::make_shared<STTx
const>(SerialIter{sit.getSlice(sit.getVLDataLength())});
if (tx->getFieldU16(sfTransactionType) == ttUNL_MODIFY)
counter++;
}
*/
std::size_t count = 0;
for (auto i = txSet->begin(); i != txSet->end(); ++i)
{
// RH TODO: why does the above parse??
auto raw = i->slice();
if (raw[0] == 0x12U && raw[1] == 0 && raw[2] == 0x66U)
count++;
}
return count;
};
STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey)
{
auto fill = [&](auto& obj) {
obj.setFieldU8(sfUNLModifyDisabling, disabling ? 1 : 0);
obj.setFieldU32(sfLedgerSequence, seq);
obj.setFieldVL(sfUNLModifyValidator, txKey);
};
return STTx(ttUNL_MODIFY, fill);
}
} // namespace unl
} // namespace test
} // namespace ripple

86
src/test/jtx/unl.h Normal file
View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 XRPL Labs
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_TEST_JTX_UNL_H_INCLUDED
#define RIPPLE_TEST_JTX_UNL_H_INCLUDED
#include <ripple/protocol/STAmount.h>
#include <test/jtx/Account.h>
#include <test/jtx/Env.h>
namespace ripple {
namespace test {
namespace unl {
/**
* Test the size of the negative UNL in a ledger,
* also test if the ledger has ToDisalbe and/or ToReEnable
*
* @param l the ledger
* @param size the expected negative UNL size
* @param hasToDisable if expect ToDisable in ledger
* @param hasToReEnable if expect ToDisable in ledger
* @return true if meet all three expectation
*/
bool
negUnlSizeTest(
std::shared_ptr<Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable);
/**
* Try to apply a ttUNL_MODIFY Tx, and test the apply result
*
* @param env the test environment
* @param view the OpenView of the ledger
* @param tx the ttUNL_MODIFY Tx
* @param pass if the Tx should be applied successfully
* @return true if meet the expectation of apply result
*/
bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass);
/**
* Count the number of Tx in a TxSet
*
* @param txSet the TxSet
* @return the number of Tx
*/
std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet);
/**
* Create ttUNL_MODIFY Tx
*
* @param disabling disabling or re-enabling a validator
* @param seq current ledger seq
* @param txKey the public key of the validator
* @return the ttUNL_MODIFY Tx
*/
STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey);
} // namespace unl
} // namespace test
} // namespace ripple
#endif // RIPPLE_TEST_JTX_UNL_H_INCLUDED