mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-29 23:15:49 +00:00
Merge branch 'dev' into fixXahauV1
This commit is contained in:
@@ -106,10 +106,18 @@ struct GenesisMint_test : public beast::unit_test::suite
|
||||
using namespace std::literals::chrono_literals;
|
||||
|
||||
Env env{*this, envconfig(), features, nullptr};
|
||||
// Env env{*this, envconfig(), features, nullptr,
|
||||
// // beast::severities::kWarning
|
||||
// beast::severities::kTrace
|
||||
// };
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
auto const invoker = Account("invoker");
|
||||
env.fund(XRP(10000), alice, bob, invoker);
|
||||
auto const gw = Account("gateway");
|
||||
auto const USD = gw["USD"];
|
||||
auto const edward = Account("edward");
|
||||
env.fund(XRP(10000), alice, bob, invoker, edward);
|
||||
env.close();
|
||||
|
||||
// burn down the total ledger coins so that genesis mints don't mint
|
||||
// above 100B tripping invariant
|
||||
@@ -189,14 +197,14 @@ struct GenesisMint_test : public beast::unit_test::suite
|
||||
auto acc = env.le(keylet::account(carol.id()));
|
||||
BEAST_EXPECT(
|
||||
acc->getFieldAmount(sfBalance).xrp().drops() == 67890000000ULL);
|
||||
BEAST_EXPECT(acc->getFieldU32(sfSequence) == 50);
|
||||
BEAST_EXPECT(acc->getFieldU32(sfSequence) == 60);
|
||||
}
|
||||
|
||||
{
|
||||
auto acc = env.le(keylet::account(david.id()));
|
||||
BEAST_EXPECT(
|
||||
acc->getFieldAmount(sfBalance).xrp().drops() == 12345000000ULL);
|
||||
BEAST_EXPECT(acc->getFieldU32(sfSequence) == 50);
|
||||
BEAST_EXPECT(acc->getFieldU32(sfSequence) == 60);
|
||||
}
|
||||
|
||||
// lots of entries
|
||||
@@ -267,9 +275,6 @@ struct GenesisMint_test : public beast::unit_test::suite
|
||||
|
||||
// invalid amount should cause emit fail which should cause hook
|
||||
// rollback
|
||||
auto const gw = Account("gateway");
|
||||
auto const USD = gw["USD"];
|
||||
auto const edward = Account("edward");
|
||||
env(invoke::invoke(
|
||||
invoker,
|
||||
env.master,
|
||||
@@ -278,13 +283,36 @@ struct GenesisMint_test : public beast::unit_test::suite
|
||||
fee(XRP(1)),
|
||||
ter(tecHOOK_REJECTED));
|
||||
|
||||
// zero xrp is allowed
|
||||
env(invoke::invoke(
|
||||
invoker,
|
||||
env.master,
|
||||
genesis::makeBlob(
|
||||
{{edward.id(), XRP(0), std::nullopt, std::nullopt}})),
|
||||
fee(XRP(1)));
|
||||
// zero xrp is not allowed
|
||||
{
|
||||
env(invoke::invoke(
|
||||
invoker,
|
||||
env.master,
|
||||
genesis::makeBlob(
|
||||
{{edward.id(), XRP(0), std::nullopt, std::nullopt}})),
|
||||
fee(XRP(1)),
|
||||
ter(tesSUCCESS));
|
||||
|
||||
env.close();
|
||||
|
||||
// get the emitted txn id
|
||||
Json::Value params;
|
||||
params[jss::transaction] =
|
||||
env.tx()->getJson(JsonOptions::none)[jss::hash];
|
||||
auto const jrr = env.rpc("json", "tx", to_string(params));
|
||||
auto const meta = jrr[jss::result][jss::meta];
|
||||
auto const emissions = meta[sfHookEmissions.jsonName];
|
||||
auto const emission = emissions[0u][sfHookEmission.jsonName];
|
||||
auto const txId = emission[sfEmittedTxnID.jsonName];
|
||||
env.close();
|
||||
|
||||
// verify emitted result
|
||||
Json::Value params1;
|
||||
params1[jss::transaction] = txId;
|
||||
auto const jrr1 = env.rpc("json", "tx", to_string(params1));
|
||||
auto const meta1 = jrr1[jss::result][jss::meta];
|
||||
BEAST_EXPECT(meta1[sfTransactionResult.jsonName] == "tecINTERNAL");
|
||||
}
|
||||
|
||||
// missing an amount
|
||||
env(invoke::invoke(
|
||||
@@ -543,8 +571,26 @@ struct GenesisMint_test : public beast::unit_test::suite
|
||||
})),
|
||||
fee(XRP(1)));
|
||||
env.close();
|
||||
|
||||
// get the emitted txn id
|
||||
Json::Value params;
|
||||
params[jss::transaction] =
|
||||
env.tx()->getJson(JsonOptions::none)[jss::hash];
|
||||
auto const jrr = env.rpc("json", "tx", to_string(params));
|
||||
auto const meta = jrr[jss::result][jss::meta];
|
||||
auto const emissions = meta[sfHookEmissions.jsonName];
|
||||
auto const emission = emissions[0u][sfHookEmission.jsonName];
|
||||
auto const txId = emission[sfEmittedTxnID.jsonName];
|
||||
env.close();
|
||||
|
||||
// verify emitted result
|
||||
Json::Value params1;
|
||||
params1[jss::transaction] = txId;
|
||||
auto const jrr1 = env.rpc("json", "tx", to_string(params1));
|
||||
auto const meta1 = jrr1[jss::result][jss::meta];
|
||||
BEAST_EXPECT(
|
||||
meta1[sfTransactionResult.jsonName] == "tecINVARIANT_FAILED");
|
||||
|
||||
// check balance wasn't changed
|
||||
auto const le = env.le(keylet::account(greg.id()));
|
||||
BEAST_EXPECT(
|
||||
@@ -602,88 +648,22 @@ struct GenesisMint_test : public beast::unit_test::suite
|
||||
le->getFieldAmount(sfBalance).xrp().drops() == 10000000000ULL);
|
||||
}
|
||||
|
||||
void
|
||||
testGenesisMintTSH(FeatureBitset features)
|
||||
{
|
||||
testcase("GenesisMint TSH");
|
||||
using namespace jtx;
|
||||
using namespace std::literals::chrono_literals;
|
||||
|
||||
Env env{*this, envconfig(), features, nullptr};
|
||||
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
auto const invoker = Account("invoker");
|
||||
env.fund(XRP(10000), alice, bob, invoker);
|
||||
|
||||
// set tsh collect on bob
|
||||
env(fset(bob, asfTshCollect));
|
||||
|
||||
// burn down the total ledger coins so that genesis mints don't mint
|
||||
// above 100B tripping invariant
|
||||
env(burn(env.master), fee(XRP(10'000'000ULL)));
|
||||
env.close();
|
||||
|
||||
// set the test hook
|
||||
env(genesis::setMintHook(env.master), fee(XRP(10)));
|
||||
env.close();
|
||||
|
||||
// set the accept hook
|
||||
env(genesis::setAcceptHook(bob), fee(XRP(10)));
|
||||
env.close();
|
||||
|
||||
// test a mint
|
||||
{
|
||||
env(invoke::invoke(
|
||||
invoker,
|
||||
env.master,
|
||||
genesis::makeBlob({
|
||||
{bob.id(),
|
||||
XRP(123).value(),
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
})),
|
||||
fee(XRP(10)),
|
||||
ter(tesSUCCESS));
|
||||
|
||||
env.close();
|
||||
|
||||
// get the emitted txn id
|
||||
Json::Value params;
|
||||
params[jss::transaction] =
|
||||
env.tx()->getJson(JsonOptions::none)[jss::hash];
|
||||
auto const jrr = env.rpc("json", "tx", to_string(params));
|
||||
auto const meta = jrr[jss::result][jss::meta];
|
||||
auto const emissions = meta[sfHookEmissions.jsonName];
|
||||
auto const emission = emissions[0u][sfHookEmission.jsonName];
|
||||
auto const txId = emission[sfEmittedTxnID.jsonName];
|
||||
|
||||
// trigger the emitted txn
|
||||
env.close();
|
||||
|
||||
// verify tsh hook triggered
|
||||
Json::Value params1;
|
||||
params1[jss::transaction] = txId;
|
||||
auto const jrr1 = env.rpc("json", "tx", to_string(params1));
|
||||
auto const meta1 = jrr1[jss::result][jss::meta];
|
||||
auto const executions = meta1[sfHookExecutions.jsonName];
|
||||
auto const execution = executions[0u][sfHookExecution.jsonName];
|
||||
BEAST_EXPECT(execution[sfHookResult.jsonName] == 3);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void
|
||||
testWithFeats(FeatureBitset features)
|
||||
{
|
||||
testDisabled(features);
|
||||
testGenesisEmit(features);
|
||||
testGenesisNonEmit(features);
|
||||
testNonGenesisEmit(features);
|
||||
testNonGenesisNonEmit(features);
|
||||
}
|
||||
void
|
||||
run() override
|
||||
{
|
||||
using namespace test::jtx;
|
||||
auto const sa = supported_amendments();
|
||||
testDisabled(sa);
|
||||
testGenesisEmit(sa);
|
||||
testGenesisNonEmit(sa);
|
||||
testNonGenesisEmit(sa);
|
||||
testNonGenesisNonEmit(sa);
|
||||
testGenesisMintTSH(sa);
|
||||
testWithFeats(sa);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user