Skip to content

Commit

Permalink
Merge 87a3a2e into 2d1cbe9
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Mar 25, 2021
2 parents 2d1cbe9 + 87a3a2e commit 3e022aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/covenants/namestate.js
Expand Up @@ -209,7 +209,7 @@ class NameState extends bio.Struct {
if (this.isClaimable(height, network))
return false;

// If we haven't been renewed in a year, start over.
// If we haven't been renewed in two years, start over.
if (height >= this.renewal + network.names.renewalWindow)
return true;

Expand Down Expand Up @@ -654,6 +654,7 @@ class NameState extends bio.Struct {

if (height != null) {
network = Network.get(network);

state = this.state(height, network);
state = statesByVal[state];
stats = this.toStats(height, network);
Expand Down Expand Up @@ -740,6 +741,14 @@ class NameState extends bio.Struct {

const stats = {};

if (this.isExpired(height, network)) {
const expired = this.renewal + network.names.renewalWindow;
stats.blocksSinceExpired = height - expired;

// Exit early
return stats;
}

if (this.isOpening(height, network)) {
const start = this.height;
const end = this.height + openPeriod;
Expand Down
13 changes: 13 additions & 0 deletions test/auction-test.js
Expand Up @@ -423,6 +423,19 @@ describe('Auction', function() {
blocksUntilValidFinalize = stats.blocksUntilValidFinalize;
});

it('should not have any stats after expiration', async () => {
const ns = await chain.db.getNameStateByName(NAME1);
const start = ns.renewal;
const expiration = start + network.names.renewalWindow;

// Test the namestate JSON without advancing the chain
let json = ns.getJSON(expiration - 1, network);
assert.strictEqual(json.stats.blocksUntilExpire, 1);

json = ns.getJSON(expiration, network);
assert.strictEqual(json.stats.blocksSinceExpired, 0);
});

it('should finalize at expected height', async () => {
const mtx = await winner.createFinalize(NAME1);

Expand Down

0 comments on commit 3e022aa

Please sign in to comment.