UNPKG

wehelpjs

Version:

wehelpjs is the JavaScript API Library for the WeYouMe blockchain

165 lines (148 loc) 3.97 kB
import Promise from 'bluebird'; import should from 'should'; import wehelpjs from '../src'; const username = process.env.NODE_USERNAME || 'guest123'; const password = process.env.NODE_PASSWORD; const postingWif = password ? wehelpjs.auth.toWif(username, password, 'posting') : '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg'; describe('wehelpjs.broadcast:', () => { it('exists', () => { should.exist(wehelpjs.broadcast); }); it('has generated methods', () => { should.exist(wehelpjs.broadcast.vote); should.exist(wehelpjs.broadcast.voteWith); should.exist(wehelpjs.broadcast.comment); should.exist(wehelpjs.broadcast.transfer); }); it('has backing methods', () => { should.exist(wehelpjs.broadcast.send); }); it('has promise methods', () => { should.exist(wehelpjs.broadcast.sendAsync); should.exist(wehelpjs.broadcast.voteAsync); should.exist(wehelpjs.broadcast.transferAsync); }); describe('patching transaction with default global properties', () => { it('works', async () => { const tx = await wehelpjs.broadcast._prepareTransaction({ extensions: [], operations: [['vote', { voter: 'yamadapc', author: 'yamadapc', permlink: 'test-1-2-3-4-5-6-7-9', }]], }); tx.should.have.properties([ 'expiration', 'ref_block_num', 'ref_block_prefix', 'extensions', 'operations', ]); }); }); describe('downvoting', () => { it('works', async () => { const tx = await wehelpjs.broadcast.voteAsync( postingWif, username, 'yamadapc', 'test-1-2-3-4-5-6-7-9', -1000 ); tx.should.have.properties([ 'expiration', 'ref_block_num', 'ref_block_prefix', 'extensions', 'operations', 'signatures', ]); }); }); describe('voting', () => { beforeEach(() => { return Promise.delay(2000); }); it('works', async () => { const tx = await wehelpjs.broadcast.voteAsync( postingWif, username, 'yamadapc', 'test-1-2-3-4-5-6-7-9', 10000 ); tx.should.have.properties([ 'expiration', 'ref_block_num', 'ref_block_prefix', 'extensions', 'operations', 'signatures', ]); }); it('works with callbacks', (done) => { wehelpjs.broadcast.vote( postingWif, username, 'yamadapc', 'test-1-2-3-4-5-6-7-9', 5000, (err, tx) => { if (err) return done(err); tx.should.have.properties([ 'expiration', 'ref_block_num', 'ref_block_prefix', 'extensions', 'operations', 'signatures', ]); done(); } ); }); }); describe('customJson', () => { before(() => { return Promise.delay(2000); }); it('works', async () => { const tx = await wehelpjs.broadcast.customJsonAsync( postingWif, [], [username], 'follow', JSON.stringify([ 'follow', { follower: username, following: 'fabien', what: ['blog'], }, ]) ); tx.should.have.properties([ 'expiration', 'ref_block_num', 'ref_block_prefix', 'extensions', 'operations', 'signatures', ]); }); }); describe('writeOperations', () => { it('receives a properly formatted error response', () => { const wif = wehelpjs.auth.toWif('username', 'password', 'posting'); return wehelpjs.broadcast.voteAsync(wif, 'voter', 'author', 'permlink', 0). then(() => { throw new Error('writeOperation should have failed but it didn\'t'); }, (e) => { should.exist(e.message); }); }); }); });