UNPKG

@omisego/omg-js-childchain

Version:

Module to interact with OMG ChildChain

55 lines (42 loc) 2.06 kB
/* Copyright 2019 OmiseGO Pte Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ const mocha = require('mocha') const describe = mocha.describe const it = mocha.it const chai = require('chai') const chaiAsPromised = require('chai-as-promised') const ChildChain = require('../src/childchain') const mockAx = require('./mock') chai.use(chaiAsPromised) const assert = chai.assert const watcherUrl = 'http://omg-watcher' const plasmaContractAddress = '0xE009136B58a8B2eEb80cfa18aD2Ea6D389d3A375' describe('getUtxo', () => { it('should return object with empty array as utxo with an address', async () => { const address = '0xd72afdfa06ae5857a639051444f7608fea1528d4' const expectedObject = [] mockAx.onPost(`${watcherUrl}/account.get_utxos`, { address, jsonrpc: '2.0', id: 0 }).reply(200, JSON.stringify({ success: true, data: expectedObject })) const childChain = new ChildChain({ watcherUrl, plasmaContractAddress }) const returnUtxo = await childChain.getUtxos(address) assert.deepEqual(expectedObject, returnUtxo) }) it('should throw an error on failure', async () => { const address = '0x01234' const errorObject = { code: 'the_error_code', description: 'The error description' } mockAx.onPost(`${watcherUrl}/account.get_utxos`, { address, jsonrpc: '2.0', id: 0 }).reply(200, JSON.stringify({ success: false, data: errorObject })) const childChain = new ChildChain({ watcherUrl, plasmaContractAddress }) return assert.isRejected(childChain.getUtxos(address), Error, errorObject.description) }) })