-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: reset chain with wallet and transferred name
- Loading branch information
Showing
1 changed file
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* eslint-env mocha */ | ||
/* eslint prefer-arrow-callback: "off" */ | ||
|
||
'use strict'; | ||
|
||
const assert = require('bsert'); | ||
const Network = require('../lib/protocol/network'); | ||
const FullNode = require('../lib/node/fullnode'); | ||
const Address = require('../lib/primitives/address'); | ||
const rules = require('../lib/covenants/rules'); | ||
const Resource = require('../lib/dns/resource'); | ||
|
||
const network = Network.get('regtest'); | ||
|
||
const node = new FullNode({ | ||
memory: true, | ||
network: 'regtest', | ||
plugins: [require('../lib/wallet/plugin')], | ||
port: 10000, | ||
httpPort: 20000, | ||
rsPort: 30000, | ||
nsPort: 40000 | ||
}); | ||
|
||
const peer = new FullNode({ | ||
memory: true, | ||
network: 'regtest', | ||
listen: true | ||
}); | ||
|
||
const {wdb} = node.require('walletdb'); | ||
|
||
const name = rules.grindName(5, 1, network); | ||
let wallet, alice, aliceReceive; | ||
let balance1, walletNamestate1, nodeNamestate1; | ||
let balance3, walletNamestate3, nodeNamestate3; | ||
|
||
async function mineBlocks(n, addr) { | ||
addr = addr ? addr : new Address().toString('regtest'); | ||
for (let i = 0; i < n; i++) { | ||
const block = await node.miner.mineBlock(null, addr); | ||
await node.chain.add(block); | ||
} | ||
} | ||
|
||
describe('Chain reset with wallet', function() { | ||
this.timeout(20000); | ||
|
||
before(async () => { | ||
await peer.open(); | ||
await peer.connect(); | ||
peer.startSync(); | ||
|
||
await node.open(); | ||
await node.connect(); | ||
node.startSync(); | ||
|
||
wallet = await wdb.create(); | ||
alice = await wallet.getAccount(0); | ||
aliceReceive = await alice.receiveAddress(); | ||
}); | ||
|
||
after(async () => { | ||
await node.close(); | ||
await peer.close(); | ||
}); | ||
|
||
it('should fund wallet', async () => { | ||
await mineBlocks(10, aliceReceive); | ||
}); | ||
|
||
it('should open an auction and proceed to REGISTER', async () => { | ||
await wallet.sendOpen(name, false, {account: 0}); | ||
await mineBlocks(network.names.treeInterval + 2); | ||
|
||
await wallet.sendBid(name, 100000, 200000, {account: 0}); | ||
await mineBlocks(network.names.biddingPeriod); | ||
|
||
await wallet.sendReveal(name, {account: 0}); | ||
await mineBlocks(network.names.revealPeriod); | ||
|
||
const aliceResource = Resource.Resource.fromJSON({ | ||
records: [ | ||
{ | ||
type: 'TXT', | ||
txt: ['ALICE'] | ||
} | ||
] | ||
}); | ||
|
||
await wallet.sendUpdate(name, aliceResource, {account: 0}); | ||
await mineBlocks(network.names.treeInterval); | ||
}); | ||
|
||
it('should check balance and namestate', async () => { | ||
balance1 = await wallet.getBalance(); | ||
walletNamestate1 = await wallet.getNameStateByName(name); | ||
nodeNamestate1 = await node.chain.db.getNameStateByName(name); | ||
|
||
assert.deepStrictEqual(walletNamestate1, nodeNamestate1); | ||
}); | ||
|
||
it('should reset chain', async () => { | ||
// Wait for nodes to sync | ||
await new Promise(r => setTimeout(r, 1000)); | ||
assert.deepStrictEqual( | ||
node.chain.tip, | ||
peer.chain.tip | ||
); | ||
await node.chain.reset(1); | ||
|
||
await new Promise(r => setTimeout(r, 1000)); | ||
assert.deepStrictEqual( | ||
node.chain.tip, | ||
peer.chain.tip | ||
); | ||
}); | ||
|
||
it('should check balance and namestate', async () => { | ||
const balance2 = await wallet.getBalance(); | ||
const walletNamestate2 = await wallet.getNameStateByName(name); | ||
const nodeNamestate2 = await node.chain.db.getNameStateByName(name); | ||
|
||
assert.deepStrictEqual(walletNamestate1, walletNamestate2); | ||
assert.deepStrictEqual(balance1, balance2); | ||
assert.deepStrictEqual(walletNamestate2, nodeNamestate2); | ||
}); | ||
|
||
it('should TRANSFER and FINALIZE', async () => { | ||
const addr2 = await alice.receiveAddress(); | ||
await wallet.sendTransfer(name, addr2); | ||
await mineBlocks(network.names.transferLockup + 1); | ||
|
||
await wallet.sendFinalize(name); | ||
await mineBlocks(10); | ||
}); | ||
|
||
it('should check balance and namestate', async () => { | ||
balance3 = await wallet.getBalance(); | ||
walletNamestate3 = await wallet.getNameStateByName(name); | ||
nodeNamestate3 = await node.chain.db.getNameStateByName(name); | ||
|
||
assert.deepStrictEqual(walletNamestate3, nodeNamestate3); | ||
}); | ||
|
||
it('should reset chain', async () => { | ||
// Wait for nodes to sync | ||
await new Promise(r => setTimeout(r, 1000)); | ||
assert.deepStrictEqual( | ||
node.chain.tip, | ||
peer.chain.tip | ||
); | ||
await node.chain.reset(1); | ||
|
||
await new Promise(r => setTimeout(r, 1000)); | ||
assert.deepStrictEqual( | ||
node.chain.tip, | ||
peer.chain.tip | ||
); | ||
}); | ||
|
||
it('should check balance and namestate', async () => { | ||
const balance4 = await wallet.getBalance(); | ||
const walletNamestate4 = await wallet.getNameStateByName(name); | ||
const nodeNamestate4 = await node.chain.db.getNameStateByName(name); | ||
|
||
assert.deepStrictEqual(walletNamestate3, walletNamestate4); | ||
assert.deepStrictEqual(balance3, balance4); | ||
assert.deepStrictEqual(walletNamestate4, nodeNamestate4); | ||
}); | ||
}); |