Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const Bitcoin = require('../');
- const bitcoin = new Bitcoin('testnet');
- const opReturn = '12345678901234567890123456789012345678901234567890123456789012345678901234567890';
- const bin = new Buffer(8);
- bin.writeDoubleBE(Math.random());
- describe('Bitcoin', function () {
- describe('#register(data)', function () {
- function testRegister(data, done) {
- bitcoin.register(data)
- .then(txId => {
- if (typeof txId !== 'string') throw `${txId} is not a string`;
- if (!/^[a-fA-F0-9]{64}$/.test(txId)) throw `${txId} is not a valid transaction id`;
- done();
- })
- .catch(done);
- }
- it('should return the transaction id', function (done) {
- testRegister('', done);
- });
- it('should return the transaction id', function (done) {
- testRegister(opReturn, done);
- });
- it('should return the transaction id', function (done) {
- testRegister(bin, done);
- });
- it('should throw an error', function (done) {
- bitcoin.register(opReturn + opReturn)
- .then(txId => done('returned'))
- .catch(() => done());
- });
- });
- describe('#verify(txId)', function () {
- function testVerify(data, done) {
- bitcoin.register(data)
- .then(bitcoin.verify.bind(bitcoin))
- .then(tx => {
- if (typeof tx.data !== 'object') throw `data ${tx.data} is not an object`;
- if (tx.data.toString() !== data.toString()) throw `data ${tx.data} is not equal to ${data}`;
- if (tx.time <= 0) throw `time ${time} is not greater than 0`;
- if (tx.confirmations < 0) throw `confirmations ${confirmations} is not equal to or greater than 0`;
- done();
- })
- .catch(done);
- }
- it('should return the transaction data', function (done) {
- testVerify(opReturn, done);
- });
- it('should return the transaction data', function (done) {
- testVerify(bin, done);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement