static void doInflation(Application& app, int nbAccounts, std::function<int64(int)> getBalance, std::function<int(int)> getVote, int expectedWinnerCount) { using xdr::operator==; // simulate the expected inflation based off the current ledger state std::map<int, int64> balances; // load account balances for (int i = 0; i < nbAccounts; i++) { if (getBalance(i) < 0) { balances[i] = -1; requireNoAccount(getTestAccount(i), app); } else { AccountFrame::pointer act; act = loadAccount(getTestAccount(i), app); balances[i] = act->getBalance(); // double check that inflationDest is setup properly if (act->getAccount().inflationDest) { REQUIRE(getTestAccount(getVote(i)).getPublicKey() == *act->getAccount().inflationDest); } else { REQUIRE(getVote(i) < 0); } } } LedgerManager& lm = app.getLedgerManager(); LedgerHeader& cur = lm.getCurrentLedgerHeader(); cur.feePool = 10000; int64 expectedTotcoins = cur.totalCoins; int64 expectedFees = cur.feePool; std::vector<int64> expectedBalances; auto root = getRoot(app.getNetworkID()); TransactionFramePtr txFrame = createInflation( app.getNetworkID(), root, getAccountSeqNum(root, app) + 1); expectedFees += txFrame->getFee(); expectedBalances = simulateInflation(nbAccounts, expectedTotcoins, expectedFees, [&](int i) { return balances[i]; }, getVote); // perform actual inflation { LedgerDelta delta(lm.getCurrentLedgerHeader(), app.getDatabase()); REQUIRE(applyCheck(txFrame, delta, app)); delta.commit(); } // verify ledger state LedgerHeader& cur2 = lm.getCurrentLedgerHeader(); REQUIRE(cur2.totalCoins == expectedTotcoins); REQUIRE(cur2.feePool == expectedFees); // verify balances InflationResult const& infResult = getFirstResult(*txFrame).tr().inflationResult(); auto const& payouts = infResult.payouts(); int actualChanges = 0; for (int i = 0; i < nbAccounts; i++) { auto const& k = getTestAccount(i); if (expectedBalances[i] < 0) { requireNoAccount(k, app); REQUIRE(balances[i] < 0); // account didn't get deleted } else { AccountFrame::pointer act; act = loadAccount(k, app); REQUIRE(expectedBalances[i] == act->getBalance()); if (expectedBalances[i] != balances[i]) { REQUIRE(balances[i] >= 0); actualChanges++; bool found = false; for (auto const& p : payouts) { if (p.destination == k.getPublicKey()) { int64 computedFromResult = balances[i] + p.amount; REQUIRE(computedFromResult == expectedBalances[i]); found = true; break; } } REQUIRE(found); } } } REQUIRE(actualChanges == expectedWinnerCount); REQUIRE(expectedWinnerCount == payouts.size()); }
Asset idrCur = makeAsset(gateway, "IDR"); Asset usdCur = makeAsset(gateway, "USD"); // sets up gateway account const int64_t gatewayPayment = minBalance2 + morePayment; applyCreateAccountTx(app, root, gateway, rootSeq++, gatewayPayment); SequenceNumber gateway_seq = getAccountSeqNum(gateway, app) + 1; AccountFrame::pointer a1Account, rootAccount; rootAccount = loadAccount(root, app); a1Account = loadAccount(a1, app); REQUIRE(rootAccount->getMasterWeight() == 1); REQUIRE(rootAccount->getHighThreshold() == 0); REQUIRE(rootAccount->getLowThreshold() == 0); REQUIRE(rootAccount->getMediumThreshold() == 0); REQUIRE(a1Account->getBalance() == paymentAmount); REQUIRE(a1Account->getMasterWeight() == 1); REQUIRE(a1Account->getHighThreshold() == 0); REQUIRE(a1Account->getLowThreshold() == 0); REQUIRE(a1Account->getMediumThreshold() == 0); // root did 2 transactions at this point REQUIRE(rootAccount->getBalance() == (100000000000000000 - paymentAmount - gatewayPayment - txfee * 2)); LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader(), app.getDatabase()); SECTION("Create account") { SECTION("Success") {