|
4 | 4 | 'use strict'; |
5 | 5 |
|
6 | 6 | const assert = require('bsert'); |
7 | | -const consensus = require('../lib/protocol/consensus'); |
8 | 7 | const Network = require('../lib/protocol/network'); |
9 | | -const Coin = require('../lib/primitives/coin'); |
10 | | -const Script = require('../lib/script/script'); |
11 | | -const Opcode = require('../lib/script/opcode'); |
12 | 8 | const FullNode = require('../lib/node/fullnode'); |
13 | | -const Wallet = require('../lib/wallet/wallet'); |
14 | | -const MTX = require('../lib/primitives/mtx'); |
15 | | -const TX = require('../lib/primitives/tx'); |
16 | | -const Address = require('../lib/primitives/address'); |
17 | 9 | const rules = require('../lib/covenants/rules'); |
18 | 10 | const network = Network.get('regtest'); |
19 | 11 |
|
@@ -151,4 +143,77 @@ describe('Node http', function() { |
151 | 143 | }); |
152 | 144 | }); |
153 | 145 | }); |
| 146 | + |
| 147 | + describe('getNameResource', () => { |
| 148 | + const zonefile = { compat: false, version: 0, ttl: 172800, ns: ['[email protected]'] }; |
| 149 | + it('It should return null when an auction has not been initiated', async () => { |
| 150 | + const resource = await nclient.getNameResource(NAME0); |
| 151 | + assert.equal(resource, null); |
| 152 | + }); |
| 153 | + |
| 154 | + describe('When an auction has been initiated', () => { |
| 155 | + beforeEach(async () => { |
| 156 | + await mineBlocks(250); |
| 157 | + await wclient.execute('sendopen', [NAME0]); |
| 158 | + // Question: We have to mine ~7 blocks here to get 'getauctioninfo' to work consistently. Will pass w. 4 |
| 159 | + await mineBlocks(7); |
| 160 | + const { stats: { blocksUntilBidding } } = await wclient.execute('getauctioninfo', [NAME0]); |
| 161 | + await mineBlocks(blocksUntilBidding); |
| 162 | + const sendBid = await wclient.execute('sendbid', [NAME0, 12, 12]); |
| 163 | + assert(sendBid); |
| 164 | + const { stats: { blocksUntilReveal } } = await wclient.execute('getauctioninfo', [NAME0]); |
| 165 | + // Question: We have to mine ~2 blocks here to get 'sendreveal' to work consistently. Will pass w. 1. |
| 166 | + await mineBlocks(blocksUntilReveal + 2); |
| 167 | + await wclient.execute('sendreveal', [NAME0]); |
| 168 | + const { stats: { blocksUntilClose } } = await wclient.execute('getauctioninfo', [NAME0]); |
| 169 | + await mineBlocks(blocksUntilClose); |
| 170 | + await wclient.execute('sendupdate', [NAME0, zonefile]); |
| 171 | + await mineBlocks(1); |
| 172 | + }); |
| 173 | + it('It should return the resource', async () => { |
| 174 | + const resource = await nclient.getNameResource(NAME0); |
| 175 | + assert.deepEqual(resource, zonefile); |
| 176 | + }); |
| 177 | + }); |
| 178 | + }); |
| 179 | + |
| 180 | + describe('getNameProof', () => { |
| 181 | + it('It should return null when an auction has not been initiated', async () => { |
| 182 | + const proof = await nclient.getNameProof(NAME0); |
| 183 | + assert.equal(proof.proof.type, 'TYPE_DEADEND'); |
| 184 | + assert.equal(proof.name, NAME0); |
| 185 | + }); |
| 186 | + |
| 187 | + describe('When an auction has been initiated', () => { |
| 188 | + beforeEach(async () => { |
| 189 | + await mineBlocks(250); |
| 190 | + await wclient.execute('sendopen', [NAME0]); |
| 191 | + // Question: We have to mine ~7 blocks here to get 'getauctioninfo' to work consistently. Will pass w. 4 |
| 192 | + await mineBlocks(7); |
| 193 | + const { stats: { blocksUntilBidding } } = await wclient.execute('getauctioninfo', [NAME0]); |
| 194 | + await mineBlocks(blocksUntilBidding); |
| 195 | + const sendBid = await wclient.execute('sendbid', [NAME0, 12, 12]); |
| 196 | + assert(sendBid); |
| 197 | + const { stats: { blocksUntilReveal } } = await wclient.execute('getauctioninfo', [NAME0]); |
| 198 | + // Question: We have to mine ~2 blocks here to get 'sendreveal' to work consistently. Will pass w. 1. |
| 199 | + await mineBlocks(blocksUntilReveal + 2); |
| 200 | + await wclient.execute('sendreveal', [NAME0]); |
| 201 | + const { stats: { blocksUntilClose } } = await wclient.execute('getauctioninfo', [NAME0]); |
| 202 | + await mineBlocks(blocksUntilClose); |
| 203 | + await wclient.execute('sendupdate', [NAME0, { compat: false, version: 0, ttl: 172800, ns: ['[email protected]'] }]); |
| 204 | + await mineBlocks(1); |
| 205 | + }); |
| 206 | + it('It should return the name\'s proof', async () => { |
| 207 | + const proof = await nclient.getNameProof(NAME0); |
| 208 | + assert.equal(proof.proof.type, 'TYPE_EXISTS'); |
| 209 | + assert.equal(proof.name, NAME0); |
| 210 | + }); |
| 211 | + }); |
| 212 | + }); |
| 213 | + describe('grindName', () => { |
| 214 | + it('It should grind a name', async () => { |
| 215 | + const { name } = await nclient.grindName(10); |
| 216 | + assert(name); |
| 217 | + }); |
| 218 | + }); |
154 | 219 | }); |
0 commit comments