Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle flag and balance checks into authorize #17

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the need for arg.account == nullptr check here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, the default account is the issuer.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's valid for arg.account to be nullptr. If arg.account is nullptr then by default it's the 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
Loading