Skip to content

Commit c533bde

Browse files
committed
test: more in depth wallet name claim update tests
1 parent 71a6e0f commit c533bde

File tree

1 file changed

+81
-33
lines changed

1 file changed

+81
-33
lines changed

test/wallet-test.js

Lines changed: 81 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,8 @@ describe('Wallet', function() {
23012301
});
23022302

23032303
describe('Wallet Name Claims', function() {
2304+
// 'it' blocks in this 'describe' create state
2305+
// that later 'it' blocks depend on.
23042306
let wallet, update;
23052307
const network = Network.get('regtest');
23062308
const workers = new WorkerPool({enabled: false});
@@ -2317,15 +2319,6 @@ describe('Wallet', function() {
23172319
const entry = nextEntry(wdb);
23182320
await wdb.addBlock(entry, []);
23192321
}
2320-
2321-
// Use a fresh wallet.
2322-
const bal = await wallet.getBalance();
2323-
assert.equal(bal.tx, 0);
2324-
assert.equal(bal.coin, 0);
2325-
assert.equal(bal.unconfirmed, 0);
2326-
assert.equal(bal.confirmed, 0);
2327-
assert.equal(bal.ulocked, 0);
2328-
assert.equal(bal.clocked, 0);
23292322
});
23302323

23312324
after(async () => {
@@ -2338,6 +2331,15 @@ describe('Wallet', function() {
23382331
});
23392332

23402333
it('should confirm cloudflare CLAIM', async () => {
2334+
// Use a fresh wallet.
2335+
const pre = await wallet.getBalance();
2336+
assert.equal(pre.tx, 0);
2337+
assert.equal(pre.coin, 0);
2338+
assert.equal(pre.unconfirmed, 0);
2339+
assert.equal(pre.confirmed, 0);
2340+
assert.equal(pre.ulocked, 0);
2341+
assert.equal(pre.clocked, 0);
2342+
23412343
const claim = await wallet.sendFakeClaim('cloudflare');
23422344
assert(claim);
23432345

@@ -2350,16 +2352,16 @@ describe('Wallet', function() {
23502352
assert.equal(json.name, 'cloudflare');
23512353
assert.equal(json.state, 'LOCKED');
23522354

2353-
const bal = await wallet.getBalance();
2354-
assert.equal(bal.tx, 1);
2355-
assert.equal(bal.coin, 1);
2356-
assert.equal(bal.unconfirmed, lockup);
2357-
assert.equal(bal.confirmed, lockup);
2358-
assert.equal(bal.ulocked, lockup);
2359-
assert.equal(bal.clocked, lockup);
2355+
const post = await wallet.getBalance();
2356+
assert.equal(post.tx, 1);
2357+
assert.equal(post.coin, 1);
2358+
assert.equal(post.unconfirmed, lockup);
2359+
assert.equal(post.confirmed, lockup);
2360+
assert.equal(post.ulocked, lockup);
2361+
assert.equal(post.clocked, lockup);
23602362
});
23612363

2362-
it('should close the auction', async () => {
2364+
it('should advance past lockup period', async () => {
23632365
const ns = await wallet.getNameState(nameHash);
23642366
const json = ns.getJSON(wdb.state.height, network);
23652367
const {blocksUntilClosed} = json.stats;
@@ -2378,6 +2380,14 @@ describe('Wallet', function() {
23782380
});
23792381

23802382
it('should send an update for cloudflare', async () => {
2383+
const pre = await wallet.getBalance();
2384+
assert.equal(pre.tx, 1);
2385+
assert.equal(pre.coin, 1);
2386+
assert.equal(pre.unconfirmed, lockup);
2387+
assert.equal(pre.confirmed, lockup);
2388+
assert.equal(pre.ulocked, lockup);
2389+
assert.equal(pre.clocked, lockup);
2390+
23812391
const records = Resource.fromJSON({
23822392
records: [{type: 'NS', ns: 'ns1.easyhandshake.com.'}]
23832393
});
@@ -2397,33 +2407,71 @@ describe('Wallet', function() {
23972407
// take into account the transaction fee. Assert
23982408
// against the value of the newly created output.
23992409
const val = update.output(1).value;
2400-
const bal = await wallet.getBalance();
2401-
assert.equal(bal.tx, 2);
2402-
assert.equal(bal.coin, 2);
2403-
assert.equal(bal.unconfirmed, val);
2404-
assert.equal(bal.confirmed, val);
2405-
assert.equal(bal.ulocked, 0);
2406-
assert.equal(bal.clocked, 0);
2410+
const post = await wallet.getBalance();
2411+
assert.equal(post.tx, 2);
2412+
assert.equal(post.coin, 2);
2413+
assert.equal(post.unconfirmed, val);
2414+
assert.equal(post.confirmed, val);
2415+
assert.equal(post.ulocked, 0);
2416+
assert.equal(post.clocked, 0);
24072417
});
24082418

24092419
it('should remove a block and update balances correctly', async () => {
2420+
const val = update.output(1).value;
2421+
const pre = await wallet.getBalance();
2422+
assert.equal(pre.tx, 2);
2423+
assert.equal(pre.coin, 2);
2424+
assert.equal(pre.unconfirmed, val);
2425+
assert.equal(pre.confirmed, val);
2426+
assert.equal(pre.ulocked, 0);
2427+
assert.equal(pre.clocked, 0);
2428+
24102429
const cur = curEntry(wdb);
24112430
await wdb.removeBlock(cur);
24122431

2413-
const bal = await wallet.getBalance();
2414-
const val = update.output(1).value;
2415-
assert.equal(bal.tx, 2);
2416-
assert.equal(bal.coin, 2);
2417-
2432+
const post = await wallet.getBalance();
2433+
assert.equal(post.tx, 2);
2434+
assert.equal(post.coin, 2);
24182435
// The unconfirmed balance includes value in the mempool
24192436
// and the chain itself. The reorg'd tx can be included
24202437
// in another block so the unconfirmed total does not
24212438
// include the tx fee. That value has been effectively
24222439
// spent already.
2423-
assert.equal(bal.unconfirmed, val);
2424-
assert.equal(bal.confirmed, lockup);
2425-
assert.equal(bal.ulocked, 0);
2426-
assert.equal(bal.clocked, lockup);
2440+
assert.equal(post.unconfirmed, val);
2441+
assert.equal(post.confirmed, lockup);
2442+
assert.equal(post.ulocked, 0);
2443+
assert.equal(post.clocked, lockup);
2444+
});
2445+
2446+
it('should update balances correctly after abandon', async () => {
2447+
const val = update.output(1).value;
2448+
const pre = await wallet.getBalance();
2449+
assert.equal(pre.tx, 2);
2450+
assert.equal(pre.coin, 2);
2451+
assert.equal(pre.unconfirmed, val);
2452+
assert.equal(pre.confirmed, lockup);
2453+
assert.equal(pre.ulocked, 0);
2454+
assert.equal(pre.clocked, lockup);
2455+
2456+
assert(await wallet.txdb.hasTX(update.hash()));
2457+
await wallet.abandon(update.hash());
2458+
2459+
// The UPDATE was abandoned and now the wallet
2460+
// reflects only the CLAIM, so these values
2461+
// should match the wallet balance post
2462+
// 'should confirm cloudflare CLAIM'
2463+
const post = await wallet.getBalance();
2464+
assert.equal(post.tx, 1);
2465+
assert.equal(post.coin, 1);
2466+
assert.equal(post.unconfirmed, lockup);
2467+
assert.equal(post.confirmed, lockup);
2468+
assert.equal(post.ulocked, lockup);
2469+
assert.equal(post.clocked, lockup);
2470+
2471+
const coins = await wallet.getCoins();
2472+
assert.equal(coins.length, 1);
2473+
const [claim] = coins;
2474+
assert.equal(claim.covenant.isClaim(), true);
24272475
});
24282476
});
24292477
});

0 commit comments

Comments
 (0)