Skip to content

Commit

Permalink
Bundle flag and balance checks into authorize
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Jan 18, 2024
1 parent 8b24f77 commit 94cbc20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
24 changes: 0 additions & 24 deletions src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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});
Expand All @@ -405,25 +397,16 @@ 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,
.holder = &bob,
.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});
}
Expand All @@ -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});

Expand Down Expand Up @@ -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});

Expand Down
27 changes: 25 additions & 2 deletions src/test/jtx/impl/mpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_);
}

Expand Down

0 comments on commit 94cbc20

Please sign in to comment.