From 94cbc20786bb934b6482a1309bd3ffe24f3adb60 Mon Sep 17 00:00:00 2001 From: Gregory Tsipenyuk Date: Thu, 18 Jan 2024 14:24:07 -0500 Subject: [PATCH] Bundle flag and balance checks into authorize --- src/test/app/MPToken_test.cpp | 24 ------------------------ src/test/jtx/impl/mpt.cpp | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index aa13f01a4f3..87ad670f285 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -305,24 +305,19 @@ class MPToken_test : public beast::unit_test::suite // bob now holds a mptoken object mptAlice.authorize({.account = &bob, .holderCount = 1}); - BEAST_EXPECT(mptAlice.checkFlags(0, &bob)); - // alice tries to unauthorize bob. // although tx is successful, // but nothing happens because bob hasn't been authorized yet mptAlice.authorize({.holder = &bob, .flags = tfMPTUnauthorize}); - BEAST_EXPECT(mptAlice.checkFlags(0, &bob)); // alice authorizes bob // make sure bob's mptoken has set lsfMPTAuthorized mptAlice.authorize({.holder = &bob}); - BEAST_EXPECT(mptAlice.checkFlags(lsfMPTAuthorized, &bob)); // alice tries authorizes bob again. // tx is successful, but bob is already authorized, // so no changes mptAlice.authorize({.holder = &bob}); - BEAST_EXPECT(mptAlice.checkFlags(lsfMPTAuthorized, &bob)); // bob deletes his mptoken mptAlice.authorize( @@ -385,9 +380,6 @@ class MPToken_test : public beast::unit_test::suite // bob creates a mptoken mptAlice.authorize({.account = &bob, .holderCount = 1}); - BEAST_EXPECT(mptAlice.checkFlags(0, &bob)); - BEAST_EXPECT(mptAlice.checkMPTokenAmount(bob, 0)); - // bob deletes his mptoken mptAlice.authorize( {.account = &bob, .holderCount = 0, .flags = tfMPTUnauthorize}); @@ -405,15 +397,9 @@ class MPToken_test : public beast::unit_test::suite // bob creates a mptoken mptAlice.authorize({.account = &bob, .holderCount = 1}); - BEAST_EXPECT(mptAlice.checkFlags(0, &bob)); - BEAST_EXPECT(mptAlice.checkMPTokenAmount(bob, 0)); - // alice authorizes bob mptAlice.authorize({.account = &alice, .holder = &bob}); - // make sure bob's mptoken has lsfMPTAuthorized set - BEAST_EXPECT(mptAlice.checkFlags(lsfMPTAuthorized, &bob)); - // Unauthorize bob's mptoken mptAlice.authorize( {.account = &alice, @@ -421,9 +407,6 @@ class MPToken_test : public beast::unit_test::suite .holderCount = 1, .flags = tfMPTUnauthorize}); - // ensure bob's mptoken no longer has lsfMPTAuthorized set - BEAST_EXPECT(mptAlice.checkFlags(0, &bob)); - mptAlice.authorize( {.account = &bob, .holderCount = 0, .flags = tfMPTUnauthorize}); } @@ -439,9 +422,6 @@ class MPToken_test : public beast::unit_test::suite // bob creates a mptoken mptAlice.authorize({.account = &bob, .holderCount = 1}); - BEAST_EXPECT(mptAlice.checkFlags(0, &bob)); - BEAST_EXPECT(mptAlice.checkMPTokenAmount(bob, 0)); - // alice deletes her issuance mptAlice.destroy({.ownerCount = 0}); @@ -588,10 +568,6 @@ class MPToken_test : public beast::unit_test::suite mptAlice.authorize({.account = &bob, .holderCount = 1}); - // both the mptissuance and mptoken are not locked - BEAST_EXPECT(mptAlice.checkFlags(lsfMPTCanLock)); - BEAST_EXPECT(mptAlice.checkFlags(0, &bob)); - // locks bob's mptoken mptAlice.set({.account = &alice, .holder = &bob, .flags = tfMPTLock}); diff --git a/src/test/jtx/impl/mpt.cpp b/src/test/jtx/impl/mpt.cpp index a1ff282d7d3..3dc52fd87a6 100644 --- a/src/test/jtx/impl/mpt.cpp +++ b/src/test/jtx/impl/mpt.cpp @@ -161,7 +161,24 @@ MPTTester::authorize(MPTAuthorize const& arg) } if (arg.holder) jv[sfMPTokenHolder.jsonName] = arg.holder->human(); - submit(arg, jv); + if (submit(arg, jv) == tesSUCCESS) + { + if (arg.account == nullptr || *arg.account == issuer_) + { + // issuer un-authorizes the holder + if (arg.flags.value_or(0) == tfMPTUnauthorize) + env_.require(mptflags(*this, 0, arg.holder)); + // issuer authorizes the holder + else + env_.require(mptflags(*this, lsfMPTAuthorized, arg.holder)); + } + else if (arg.flags.value_or(0) == 0) + { + // holder creates a token + env_.require(mptflags(*this, 0, arg.account)); + env_.require(mptpay(*this, *arg.account, 0)); + } + } } void @@ -248,7 +265,13 @@ MPTTester::checkMPTokenOutstandingAmount(std::uint64_t expectedAmount) const MPTTester::checkFlags(uint32_t const expectedFlags, AccountP holder_) const { return forObject( - [&](SLEP const& sle) { return expectedFlags == sle->getFlags(); }, + [&](SLEP const& sle) { + auto const flags = sle->getFlags(); + if (flags != expectedFlags) + std::cout << flags << " " << expectedFlags << " " + << (std::uint64_t)holder_ << std::endl; + return expectedFlags == flags; + }, holder_); }