UNPKG

machinomy

Version:

Micropayments powered by Ethereum

44 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const PaymentRequiredResponse_1 = require("./PaymentRequiredResponse"); const BigNumber = require("bignumber.js"); const Signature_1 = require("./Signature"); const expect = require('expect'); describe('PaymentRequiredResponse', () => { describe('deserialize', () => { it('success', () => { const response = PaymentRequiredResponse_1.PaymentRequiredResponseSerializer.instance.deserialize({ 'paywall-version': PaymentRequiredResponse_1.TRANSPORT_VERSION, 'paywall-address': '0x1234', 'paywall-price': '1000', 'paywall-gateway': 'http://honkhost:8080/machinomy', 'paywall-meta': 'hello', 'paywall-token-contract': '0xbeef', 'paywall-channels': '[{"channelId": "0x111", "spent": "10", "sign": "0xbabe"}]' }); expect(response.receiver).toBe('0x1234'); expect(response.price).toEqual(new BigNumber.BigNumber(1000)); expect(response.gateway).toBe('http://honkhost:8080/machinomy'); expect(response.meta).toBe('hello'); expect(response.tokenContract).toBe('0xbeef'); expect(response.remoteChannelInfo.channels.length).toBe(1); expect(response.remoteChannelInfo.channels[0].channelId).toBe('0x111'); expect(response.remoteChannelInfo.channels[0].spent).toEqual(new BigNumber.BigNumber(10)); expect(response.remoteChannelInfo.channels[0].sign).toEqual(Signature_1.default.fromRpcSig('0xbabe')); }); it('wrongversion', () => { expect(() => { PaymentRequiredResponse_1.PaymentRequiredResponseSerializer.instance.deserialize({ 'paywall-version': '', 'paywall-address': '0x1234', 'paywall-price': '1000', 'paywall-gateway': 'http://honkhost:8080/machinomy', 'paywall-meta': 'hello', 'paywall-token-contract': '0xbeef', 'paywall-channels': '[{"channelId": "0x111", "spent": "10", "sign": "0xbabe"}]' }); }).toThrow(); }); }); }); //# sourceMappingURL=PaymentRequiredResponse.test.js.map