Skip to content

Commit

Permalink
test for set and retract
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Feb 23, 2023
1 parent a7d6e06 commit c395a71
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: XUS
: DiemFramework
source_digest: D1611C38F9E92CAC70CC447F649626BFBE90A52D8CAD202E0438710EE1C45B82
source_digest: 51040330F757378BD6E3ABA93A5A4B56F5863AA63100508E82329A0618C08780
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [Function `get_median`](#0x1_ProofOfFee_get_median)
- [Function `get_consensus_reward`](#0x1_ProofOfFee_get_consensus_reward)
- [Function `current_bid`](#0x1_ProofOfFee_current_bid)
- [Function `is_already_retracted`](#0x1_ProofOfFee_is_already_retracted)
- [Function `top_n_accounts`](#0x1_ProofOfFee_top_n_accounts)
- [Function `set_bid`](#0x1_ProofOfFee_set_bid)
- [Function `retract_bid`](#0x1_ProofOfFee_retract_bid)
Expand Down Expand Up @@ -798,6 +799,34 @@ find the median bid to push to history



</details>

<a name="0x1_ProofOfFee_is_already_retracted"></a>

## Function `is_already_retracted`



<pre><code><b>public</b> <b>fun</b> <a href="ProofOfFee.md#0x1_ProofOfFee_is_already_retracted">is_already_retracted</a>(node_addr: <b>address</b>): (bool, u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="ProofOfFee.md#0x1_ProofOfFee_is_already_retracted">is_already_retracted</a>(node_addr: <b>address</b>): (bool, u64) <b>acquires</b> <a href="ProofOfFee.md#0x1_ProofOfFee_ProofOfFeeAuction">ProofOfFeeAuction</a> {
<b>if</b> (<b>exists</b>&lt;<a href="ProofOfFee.md#0x1_ProofOfFee_ProofOfFeeAuction">ProofOfFeeAuction</a>&gt;(node_addr)) {
<b>let</b> when_retract = *&<b>borrow_global</b>&lt;<a href="ProofOfFee.md#0x1_ProofOfFee_ProofOfFeeAuction">ProofOfFeeAuction</a>&gt;(node_addr).last_epoch_retracted;
<b>return</b> (<a href="DiemConfig.md#0x1_DiemConfig_get_current_epoch">DiemConfig::get_current_epoch</a>() &gt;= when_retract, when_retract)
};
<b>return</b> (<b>false</b>, 0)
}
</code></pre>



</details>

<a name="0x1_ProofOfFee_top_n_accounts"></a>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,15 @@ address DiemFramework {
return (0, 0)
}

// which epoch did they last retract a bid?
public fun is_already_retracted(node_addr: address): (bool, u64) acquires ProofOfFeeAuction {
if (exists<ProofOfFeeAuction>(node_addr)) {
let when_retract = *&borrow_global<ProofOfFeeAuction>(node_addr).last_epoch_retracted;
return (DiemConfig::get_current_epoch() >= when_retract, when_retract)
};
return (false, 0)
}

// Get the top N validators by bid, this is FILTERED by default
public fun top_n_accounts(account: &signer, n: u64, unfiltered: bool): vector<address> acquires ProofOfFeeAuction, ConsensusReward {
assert!(Signer::address_of(account) == @DiemRoot, Errors::requires_role(140101));
Expand Down
9 changes: 9 additions & 0 deletions diem-move/diem-framework/DPN/sources/0L/ProofOfFee.move
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,15 @@ address DiemFramework {
return (0, 0)
}

// which epoch did they last retract a bid?
public fun is_already_retracted(node_addr: address): (bool, u64) acquires ProofOfFeeAuction {
if (exists<ProofOfFeeAuction>(node_addr)) {
let when_retract = *&borrow_global<ProofOfFeeAuction>(node_addr).last_epoch_retracted;
return (DiemConfig::get_current_epoch() >= when_retract, when_retract)
};
return (false, 0)
}

// Get the top N validators by bid, this is FILTERED by default
public fun top_n_accounts(account: &signer, n: u64, unfiltered: bool): vector<address> acquires ProofOfFeeAuction, ConsensusReward {
assert!(Signer::address_of(account) == @DiemRoot, Errors::requires_role(140101));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 4 tasks
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,22 @@ script {
assert!(bid == 30, 1005);
assert!(expires == 1111, 1006);
}
}

//# run --admin-script --signers DiemRoot Bob
script {
use DiemFramework::ProofOfFee;
use DiemFramework::DiemConfig;

fun main(_vm: signer, b_sig: signer) {
let this_epoch = DiemConfig::get_current_epoch();
// should initialize if not already initialized
ProofOfFee::retract_bid(&b_sig);
let (bid, expires) = ProofOfFee::current_bid(@Bob);
let (is_rectracted, epoch) = ProofOfFee::is_already_retracted(@Bob);
assert!(is_rectracted, 1007);
assert!(epoch == this_epoch, 1008);
assert!(bid == 0, 1009);
assert!(expires == 0, 10010);
}
}

0 comments on commit c395a71

Please sign in to comment.