Use structured bindings in some places:

Most of the new uses either:
* Replace some uses of `tie`
* bind to pairs when iterating through maps
This commit is contained in:
seelabs
2019-08-06 09:11:32 -07:00
parent 9c58f23cf8
commit 7912ee6f7b
66 changed files with 428 additions and 466 deletions

View File

@@ -887,7 +887,7 @@ struct PayStrand_test : public beast::unit_test::suite
STPath const& path,
TER expTer,
auto&&... expSteps) {
auto r = toStrand(
auto [ter, strand] = toStrand(
*env.current(),
alice,
bob,
@@ -898,10 +898,10 @@ struct PayStrand_test : public beast::unit_test::suite
true,
false,
env.app().logs().journal("Flow"));
BEAST_EXPECT(r.first == expTer);
BEAST_EXPECT(ter == expTer);
if (sizeof...(expSteps) !=0 )
BEAST_EXPECT(equal(
r.second, std::forward<decltype(expSteps)>(expSteps)...));
strand, std::forward<decltype(expSteps)>(expSteps)...));
};
{
@@ -914,7 +914,7 @@ struct PayStrand_test : public beast::unit_test::suite
{
STPath const path =
STPath({ipe(bob["USD"]), cpe(EUR.currency)});
auto r = toStrand(
auto [ter, _] = toStrand(
*env.current(),
alice,
alice,
@@ -925,11 +925,13 @@ struct PayStrand_test : public beast::unit_test::suite
true,
false,
env.app().logs().journal("Flow"));
BEAST_EXPECT(r.first == tesSUCCESS);
(void)ter;
(void)_;
BEAST_EXPECT(ter == tesSUCCESS);
}
{
STPath const path = STPath({ipe(USD), cpe(xrpCurrency())});
auto r = toStrand(
auto [ter, _] = toStrand(
*env.current(),
alice,
alice,
@@ -940,7 +942,9 @@ struct PayStrand_test : public beast::unit_test::suite
true,
false,
env.app().logs().journal("Flow"));
BEAST_EXPECT(r.first == tesSUCCESS);
(void)ter;
(void)_;
BEAST_EXPECT(ter == tesSUCCESS);
}
return;
};
@@ -1210,7 +1214,7 @@ struct PayStrand_test : public beast::unit_test::suite
test(env, USD, boost::none, STPath(), terNO_AUTH);
// Check pure issue redeem still works
auto r = toStrand(
auto [ter, strand] = toStrand(
*env.current(),
alice,
gw,
@@ -1221,8 +1225,8 @@ struct PayStrand_test : public beast::unit_test::suite
true,
false,
env.app().logs().journal("Flow"));
BEAST_EXPECT(r.first == tesSUCCESS);
BEAST_EXPECT(equal(r.second, D{alice, gw, usdC}));
BEAST_EXPECT(ter == tesSUCCESS);
BEAST_EXPECT(equal(strand, D{alice, gw, usdC}));
}
{
// Check path with sendMax and node with correct sendMax already set
@@ -1251,7 +1255,7 @@ struct PayStrand_test : public beast::unit_test::suite
path.emplace_back(boost::none, USD.currency, USD.account.id());
path.emplace_back(boost::none, xrpCurrency(), boost::none);
auto r = toStrand(
auto [ter, strand] = toStrand(
*env.current(),
alice,
bob,
@@ -1262,8 +1266,8 @@ struct PayStrand_test : public beast::unit_test::suite
false,
false,
env.app().logs().journal("Flow"));
BEAST_EXPECT(r.first == tesSUCCESS);
BEAST_EXPECT(equal(r.second, D{alice, gw, usdC}, B{USD.issue(), xrpIssue()}, XRPS{bob}));
BEAST_EXPECT(ter == tesSUCCESS);
BEAST_EXPECT(equal(strand, D{alice, gw, usdC}, B{USD.issue(), xrpIssue()}, XRPS{bob}));
}
}

View File

@@ -103,8 +103,8 @@ class TxQ_test : public beast::unit_test::suite
section.set("zero_basefee_transaction_feelevel", "100000000000");
section.set("normal_consensus_increase_percent", "0");
for (auto const& value : extraTxQ)
section.set(value.first, value.second);
for (auto const& [k, v] : extraTxQ)
section.set(k, v);
// Some tests specify different fee settings that are enabled by
// a FeeVote
@@ -112,9 +112,9 @@ class TxQ_test : public beast::unit_test::suite
{
auto& votingSection = p->section("voting");
for (auto const & value : extraVoting)
for (auto const& [k, v] : extraVoting)
{
votingSection.set(value.first, value.second);
votingSection.set(k, v);
}
// In order for the vote to occur, we must run as a validator
@@ -836,16 +836,16 @@ public:
std::int64_t fee = 20;
auto seq = env.seq(alice);
BEAST_EXPECT(aliceStat.size() == 7);
for (auto const& tx : aliceStat)
for (auto const& [txSeq, details] : aliceStat)
{
BEAST_EXPECT(tx.first == seq);
BEAST_EXPECT(tx.second.feeLevel == mulDiv(fee, 256, 10).second);
BEAST_EXPECT(tx.second.lastValid);
BEAST_EXPECT((tx.second.consequences &&
tx.second.consequences->fee == drops(fee) &&
tx.second.consequences->potentialSpend == drops(0) &&
tx.second.consequences->category == TxConsequences::normal) ||
tx.first == env.seq(alice) + 6);
BEAST_EXPECT(txSeq == seq);
BEAST_EXPECT(details.feeLevel == mulDiv(fee, 256, 10).second);
BEAST_EXPECT(details.lastValid);
BEAST_EXPECT((details.consequences &&
details.consequences->fee == drops(fee) &&
details.consequences->potentialSpend == drops(0) &&
details.consequences->category == TxConsequences::normal) ||
txSeq == env.seq(alice) + 6);
++seq;
}
}

View File

@@ -226,10 +226,10 @@ public:
saveDot(std::ostream & out, VertexName&& vertexName) const
{
out << "digraph {\n";
for (auto const& vData : graph_)
for (auto const& [vertex, links] : graph_)
{
auto const fromName = vertexName(vData.first);
for (auto const& eData : vData.second)
auto const fromName = vertexName(vertex);
for (auto const& eData : links)
{
auto const toName = vertexName(eData.first);
out << fromName << " -> " << toName << ";\n";

View File

@@ -91,9 +91,9 @@ public:
return tmp;
// Since counts are sorted, shouldn't need to worry much about numerical
// error
for (auto const& it : counts_)
for (auto const& [bin, count] : counts_)
{
tmp += it.first * it.second;
tmp += bin * count;
}
return tmp/samples;
}

View File

@@ -801,11 +801,11 @@ struct Peer
bool
handle(TxSet const& txs)
{
auto const it = txSets.insert(std::make_pair(txs.id(), txs));
if (it.second)
bool const inserted = txSets.insert(std::make_pair(txs.id(), txs)).second;
if (inserted)
consensus.gotTxSet(now(), txs);
// relay only if new
return it.second;
return inserted;
}
bool

View File

@@ -217,10 +217,10 @@ public:
for (std::size_t i = 0; i < 32; i++)
{
auto const keypair = randomKeyPair (KeyType::secp256k1);
auto const [pk, sk] = randomKeyPair (KeyType::secp256k1);
BEAST_EXPECT(keypair.first == derivePublicKey (KeyType::secp256k1, keypair.second));
BEAST_EXPECT(*publicKeyType (keypair.first) == KeyType::secp256k1);
BEAST_EXPECT(pk == derivePublicKey (KeyType::secp256k1, sk));
BEAST_EXPECT(*publicKeyType (pk) == KeyType::secp256k1);
for (std::size_t j = 0; j < 32; j++)
{
@@ -231,14 +231,14 @@ public:
crypto_prng());
auto sig = signDigest (
keypair.first, keypair.second, digest);
pk, sk, digest);
BEAST_EXPECT(sig.size() != 0);
BEAST_EXPECT(verifyDigest (keypair.first,
BEAST_EXPECT(verifyDigest (pk,
digest, sig, true));
// Wrong digest:
BEAST_EXPECT(!verifyDigest (keypair.first,
BEAST_EXPECT(!verifyDigest (pk,
~digest, sig, true));
// Slightly change the signature:
@@ -246,11 +246,11 @@ public:
ptr[j % sig.size()]++;
// Wrong signature:
BEAST_EXPECT(!verifyDigest (keypair.first,
BEAST_EXPECT(!verifyDigest (pk,
digest, sig, true));
// Wrong digest and signature:
BEAST_EXPECT(!verifyDigest (keypair.first,
BEAST_EXPECT(!verifyDigest (pk,
~digest, sig, true));
}
}
@@ -260,10 +260,10 @@ public:
{
for (std::size_t i = 0; i < 32; i++)
{
auto const keypair = randomKeyPair (type);
auto const [pk, sk] = randomKeyPair (type);
BEAST_EXPECT(keypair.first == derivePublicKey (type, keypair.second));
BEAST_EXPECT(*publicKeyType (keypair.first) == type);
BEAST_EXPECT(pk == derivePublicKey (type, sk));
BEAST_EXPECT(*publicKeyType (pk) == type);
for (std::size_t j = 0; j < 32; j++)
{
@@ -274,11 +274,11 @@ public:
crypto_prng());
auto sig = sign (
keypair.first, keypair.second,
pk, sk,
makeSlice (data));
BEAST_EXPECT(sig.size() != 0);
BEAST_EXPECT(verify(keypair.first,
BEAST_EXPECT(verify(pk,
makeSlice(data), sig, true));
// Construct wrong data:
@@ -290,7 +290,7 @@ public:
std::max_element (badData.begin(), badData.end()));
// Wrong data: should fail
BEAST_EXPECT(!verify (keypair.first,
BEAST_EXPECT(!verify (pk,
makeSlice(badData), sig, true));
// Slightly change the signature:
@@ -298,11 +298,11 @@ public:
ptr[j % sig.size()]++;
// Wrong signature: should fail
BEAST_EXPECT(!verify (keypair.first,
BEAST_EXPECT(!verify (pk,
makeSlice(data), sig, true));
// Wrong data and signature: should fail
BEAST_EXPECT(!verify (keypair.first,
BEAST_EXPECT(!verify (pk,
makeSlice(badData), sig, true));
}
}

View File

@@ -216,23 +216,23 @@ public:
{
testcase ("Account keypair generation & signing (secp256k1)");
auto const keyPair = generateKeyPair (
auto const [pk, sk] = generateKeyPair (
KeyType::secp256k1,
generateSeed ("masterpassphrase"));
BEAST_EXPECT(toBase58(calcAccountID(keyPair.first)) ==
BEAST_EXPECT(toBase58(calcAccountID(pk)) ==
"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
BEAST_EXPECT(toBase58(TokenType::AccountPublic, keyPair.first) ==
BEAST_EXPECT(toBase58(TokenType::AccountPublic, pk) ==
"aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw");
BEAST_EXPECT(toBase58(TokenType::AccountSecret, keyPair.second) ==
BEAST_EXPECT(toBase58(TokenType::AccountSecret, sk) ==
"p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh");
auto sig = sign (keyPair.first, keyPair.second, makeSlice(message1));
auto sig = sign (pk, sk, makeSlice(message1));
BEAST_EXPECT(sig.size() != 0);
BEAST_EXPECT(verify (keyPair.first, makeSlice(message1), sig));
BEAST_EXPECT(verify (pk, makeSlice(message1), sig));
// Correct public key but wrong message
BEAST_EXPECT(!verify (keyPair.first, makeSlice(message2), sig));
BEAST_EXPECT(!verify (pk, makeSlice(message2), sig));
// Verify with incorrect public key
{
@@ -249,30 +249,30 @@ public:
if (auto ptr = sig.data())
ptr[sig.size() / 2]++;
BEAST_EXPECT(!verify (keyPair.first, makeSlice(message1), sig));
BEAST_EXPECT(!verify (pk, makeSlice(message1), sig));
}
}
{
testcase ("Account keypair generation & signing (ed25519)");
auto const keyPair = generateKeyPair (
auto const [pk, sk] = generateKeyPair (
KeyType::ed25519,
generateSeed ("masterpassphrase"));
BEAST_EXPECT(to_string(calcAccountID(keyPair.first)) ==
BEAST_EXPECT(to_string(calcAccountID(pk)) ==
"rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf");
BEAST_EXPECT(toBase58(TokenType::AccountPublic, keyPair.first) ==
BEAST_EXPECT(toBase58(TokenType::AccountPublic, pk) ==
"aKGheSBjmCsKJVuLNKRAKpZXT6wpk2FCuEZAXJupXgdAxX5THCqR");
BEAST_EXPECT(toBase58(TokenType::AccountSecret, keyPair.second) ==
BEAST_EXPECT(toBase58(TokenType::AccountSecret, sk) ==
"pwDQjwEhbUBmPuEjFpEG75bFhv2obkCB7NxQsfFxM7xGHBMVPu9");
auto sig = sign (keyPair.first, keyPair.second, makeSlice(message1));
auto sig = sign (pk, sk, makeSlice(message1));
BEAST_EXPECT(sig.size() != 0);
BEAST_EXPECT(verify (keyPair.first, makeSlice(message1), sig));
BEAST_EXPECT(verify (pk, makeSlice(message1), sig));
// Correct public key but wrong message
BEAST_EXPECT(!verify (keyPair.first, makeSlice(message2), sig));
BEAST_EXPECT(!verify (pk, makeSlice(message2), sig));
// Verify with incorrect public key
{
@@ -289,7 +289,7 @@ public:
if (auto ptr = sig.data())
ptr[sig.size() / 2]++;
BEAST_EXPECT(!verify (keyPair.first, makeSlice(message1), sig));
BEAST_EXPECT(!verify (pk, makeSlice(message1), sig));
}
}
}

View File

@@ -641,10 +641,10 @@ class ServerStatus_test :
}
int readCount = 0;
for (auto& c : clients)
for (auto& [soc, buf] : clients)
{
boost::beast::http::response<boost::beast::http::string_body> resp;
async_read(c.first, c.second, resp, yield[ec]);
async_read(soc, buf, resp, yield[ec]);
++readCount;
// expect the reads to fail for the clients that connected at or
// above the limit. If limit is 0, all reads should succeed

View File

@@ -142,8 +142,8 @@ results::print(S& s)
if (top.size() > 0)
{
s << "Longest suite times:\n";
for (auto const& i : top)
s << std::setw(8) << fmtdur(i.second) << " " << i.first << '\n';
for (auto const& [name, dur] : top)
s << std::setw(8) << fmtdur(dur) << " " << name << '\n';
}
auto const elapsed = clock_type::now() - start;