Skip to content

Commit

Permalink
still trying to get fees working
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjatlanta committed Dec 18, 2018
1 parent e2e571a commit 5c7a9e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions libraries/chain/include/graphene/chain/protocol/htlc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <graphene/chain/htlc_object.hpp>
#include <graphene/chain/protocol/base.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <algorithm> // std::min
#include <algorithm> // std::max

namespace graphene {
namespace chain {
Expand Down Expand Up @@ -73,7 +73,7 @@ namespace graphene {
*/
share_type calculate_fee(const fee_parameters_type& fee_params)const
{
uint32_t days = std::min<uint64_t>(1, claim_period_seconds / (60 * 60 * 24));
uint64_t days = std::max<uint64_t>(1, claim_period_seconds / (60 * 60 * 24));
return fee_params.fee + (fee_params.fee_per_day * days);
}

Expand Down Expand Up @@ -112,7 +112,7 @@ namespace graphene {
share_type calculate_fee(const fee_parameters_type& fee_params)const
{
if (fee_params.fee_per_kb > 0)
return std::min<share_type>(1, preimage.size() / (1024 * fee_params.fee_per_kb));
return std::max<share_type>(1, preimage.size() / (1024 * fee_params.fee_per_kb));
return 0;
}
};
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace graphene {
*/
share_type calculate_fee(const fee_parameters_type& fee_params)const
{
uint32_t days = std::min<uint64_t>(1, seconds_to_add / (60 * 60 * 24));
uint32_t days = std::max<uint64_t>(1, seconds_to_add / (60 * 60 * 24));
return fee_params.fee + (fee_params.fee_per_day * days);
}
};
Expand Down
14 changes: 7 additions & 7 deletions tests/tests/htlc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE( htlc_expires )

ACTORS((alice)(bob));

int64_t init_balance(100000);
int64_t init_balance(100 * GRAPHENE_BLOCKCHAIN_PRECISION);

transfer( committee_account, alice_id, graphene::chain::asset(init_balance) );

Expand All @@ -162,8 +162,8 @@ BOOST_AUTO_TEST_CASE( htlc_expires )
// Alice puts a contract on the blockchain
{
graphene::chain::htlc_create_operation create_operation;

create_operation.amount = graphene::chain::asset( 10000 );
BOOST_TEST_MESSAGE("Alice (who has 100 coins, is transferring 2 coins to Bob");
create_operation.amount = graphene::chain::asset( 2 * GRAPHENE_BLOCKCHAIN_PRECISION );
create_operation.to = bob_id;
create_operation.claim_period_seconds = 60;
create_operation.preimage_hash = preimage_hash;
Expand All @@ -180,18 +180,18 @@ BOOST_AUTO_TEST_CASE( htlc_expires )
generate_block();
}

// verify funds on hold (TODO: make sure this can cover fees)
BOOST_CHECK_EQUAL( get_balance(alice_id, graphene::chain::asset_id_type()), 90000 );
// verify funds on hold... 100 - 2 = 98, minus the 1 coin fee = 9
BOOST_CHECK_EQUAL( get_balance(alice_id, graphene::chain::asset_id_type()), 97 * GRAPHENE_BLOCKCHAIN_PRECISION );

// make sure Bob (or anyone) can see the details of the transaction
graphene::app::database_api db_api(db);
auto obj = db_api.get_objects( {alice_htlc_id }).front();
graphene::chain::htlc_object htlc = obj.template as<graphene::chain::htlc_object>(GRAPHENE_MAX_NESTED_OBJECTS);

// let it expire (wait for timeout)
generate_blocks(fc::time_point_sec(120) );
generate_blocks( fc::time_point::now() + fc::seconds(120) );
// verify funds return (minus the fees)
BOOST_CHECK_EQUAL( get_balance(alice_id, graphene::chain::asset_id_type()), 90000 );
BOOST_CHECK_EQUAL( get_balance(alice_id, graphene::chain::asset_id_type()), 99 * GRAPHENE_BLOCKCHAIN_PRECISION );
// verify Bob cannot execute the contract after the fact
}

Expand Down

0 comments on commit 5c7a9e8

Please sign in to comment.