|
| 1 | +import elliptic from 'elliptic'; |
| 2 | +import BN from 'bn.js'; |
| 3 | +import {pairs} from './keypairs.fixtures'; |
| 4 | +import Znode from '../node'; |
| 5 | +import jestFetch from 'jest-fetch-mock'; |
| 6 | + |
| 7 | +const secp256k1 = elliptic.ec('secp256k1'); |
| 8 | +const node = new Znode({url: 'http://localhost:4201'}); |
| 9 | +const fetchMock = fetch as typeof jestFetch; |
| 10 | + |
| 11 | +describe('node', () => { |
| 12 | + beforeEach(() => { |
| 13 | + fetchMock.resetMocks(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should be able to broadcast a well-formed transaction', (done) => { |
| 17 | + const privateKey = pairs[1].private; |
| 18 | + const publicKey = secp256k1 |
| 19 | + .keyFromPrivate(privateKey, 'hex') |
| 20 | + .getPublic(true, 'hex'); |
| 21 | + |
| 22 | + const tx = { |
| 23 | + version: 8, |
| 24 | + nonce: 8, |
| 25 | + to: pairs[0].digest.slice(0, 40), |
| 26 | + from: pairs[1].digest.slice(0, 40), |
| 27 | + pubKey: publicKey, |
| 28 | + amount: new BN('888', 10), |
| 29 | + gasPrice: 8, |
| 30 | + gasLimit: 88, |
| 31 | + code: '', |
| 32 | + data: '', |
| 33 | + }; |
| 34 | + |
| 35 | + // setup mock response here |
| 36 | + const response = JSON.stringify({some: 'random_data'}); |
| 37 | + fetchMock.mockResponseOnce(response); |
| 38 | + |
| 39 | + node.createTransaction(tx, (err, res) => { |
| 40 | + expect(err).toBeFalsy(); |
| 41 | + expect(JSON.stringify(res)).toEqual(response); |
| 42 | + done(); |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
0 commit comments