Skip to content

Commit

Permalink
start test
Browse files Browse the repository at this point in the history
  • Loading branch information
thejohnfreeman committed Oct 10, 2024
1 parent 993666c commit b51960a
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 5 deletions.
93 changes: 93 additions & 0 deletions src/test/app/Vault_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#include <test/jtx.h>
#include <xrpl/protocol/Feature.h>

namespace ripple {

struct SetArg {

};

class Vault_test : public beast::unit_test::suite
{
void
testCreateUpdateDelete()
{
using namespace test::jtx;
testcase("Create / Update / Delete");
Env env{*this};

// IOU vault
{
// issuer = Account()
// submit(fund(issuer))
// asset = issuer[IOU]
// owner = Account()
// tx = vault::create(owner=owner, asset=asset)
// submit(fset(issuer, asfGlobalFreeze))
// TODO: VaultSet (create) fail: Asset is IOU and issuer.GlobalFreeze
// submit(tx) => fail
// tx[sfData] = blob(300)
// submit(tx) => fail
// TODO: VaultSet (create) fail: Data too large (>256 bytes)
}

// MPT vault
{
// represent an issuer account
// fund the issuer account
// create issuer.MPT
// represent an asset for issuer.MPT
// create a vault with issuer.MPT asset
}

// (create) => no sfVaultID
// (update) => sfVaultID
// TODO: VaultSet (create) fail: Metadata too large (>1024 bytes)
// TODO: VaultSet (create) succeed
// TODO: VaultSet (update) succeed
// TODO: VaultSet (update) fail: wrong owner
// TODO: VaultSet (update) fail: Data too large
// TODO: VaultSet (update) fail: Metadata present
// TODO: VaultSet (update) fail: AssetMaximum < AssetTotal
// TODO: VaultSet (update) fail: tfPrivate flag
// TODO: VaultSet (update) fail: tfShareNonTransferable flag
// TODO: Payment to VaultSet.PA fail
// TODO: VaultDelete succeed
// TODO: VaultDelete fail: missing vault
// TODO: VaultSet (update) fail: missing vault

// TODO: VaultSet (create) fail: Asset is MPT but !CanTransfer
// TODO: VaultSet (create) fail: Asset is MPT but Locked

}

public:
void
run() override
{
testCreateUpdateDelete();
}
};

BEAST_DEFINE_TESTSUITE_PRIO(Vault, tx, ripple, 1);

} // namespace ripple
47 changes: 47 additions & 0 deletions src/test/jtx/impl/vault.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#include <test/jtx/vault.h>

#include <xrpl/json/json_value.h>
#include <xrpl/protocol/jss.h>

#include <optional>

namespace ripple {
namespace test {
namespace jtx {
namespace vault {

Json::Value
create(CreateArgs const& args)
{
Json::Value jv;
jv[jss::TransactionType] = jss::VaultSet;
jv[jss::Account] = args.owner.human();
// jv[jss::Asset] = args.asset;
if (args.flags)
jv[jss::Flags] = *args.flags;
return jv;
}

}
} // namespace jtx
} // namespace test
} // namespace ripple
48 changes: 48 additions & 0 deletions src/test/jtx/vault.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#ifndef RIPPLE_TEST_JTX_VAULT_H_INCLUDED
#define RIPPLE_TEST_JTX_VAULT_H_INCLUDED

#include <xrpl/json/json_value.h>
#include <test/jtx/Env.h>

#include <optional>

namespace ripple {
namespace test {
namespace jtx {
namespace vault {

struct CreateArgs {
Account owner;
// Asset asset;
std::optional<std::uint32_t> flags{};
};

/** Return a VaultSet transaction to create a Vault. */
Json::Value
create(CreateArgs const& args);

}
} // namespace jtx
} // namespace test
} // namespace ripple

#endif
11 changes: 6 additions & 5 deletions src/xrpld/app/tx/detail/VaultSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ VaultSet::preflight(PreflightContext const& ctx)
}

XRPAmount
AMMCreate::calculateBaseFee(ReadView const& view, STTx const& tx)
VaultSet::calculateBaseFee(ReadView const& view, STTx const& tx)
{
// TODO: What should the base fee be? One increment does not seem enough.
return view.fees().increment * 4;
// One reserve increment is typically much greater than one base fee.
return view.fees().increment;
}

TER
Expand Down Expand Up @@ -83,8 +83,8 @@ VaultSet::doApply()
// Assert identical immutable fields if given.
if (tx.isFieldPresent(sfAsset) && tx[sfAsset] != vault->at(sfAsset))
return tecIMMUTABLE;

// TODO: sfMPTokenMetadata?
if (tx.isFieldPresent(sfMPTokenMetadata) && tx[sfMPTokenMetadata] != vault->at(sfMPTokenMetadata))
return tecIMMUTABLE;

// Update mutable flags and fields if given.
if (tx.isFieldPresent(sfData))
Expand All @@ -108,6 +108,7 @@ VaultSet::doApply()
if (!maybe)
return maybe.error();
auto& pseudo = *maybe;
// TODO: create empty MPToken or RippleState for Asset.
auto pseudoId = pseudo->at(sfAccount);
auto txFlags = tx[sfFlags];
std::uint32_t mptFlags = 0;
Expand Down

0 comments on commit b51960a

Please sign in to comment.