"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

require("../../injector");

var _Metadata = _interopRequireDefault(require("../../Metadata"));

var _static = _interopRequireDefault(require("../../Metadata/static"));

var _Call = _interopRequireDefault(require("./Call"));

// Copyright 2017-2019 @polkadot/api-metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
describe('Call', () => {
  beforeEach(() => {
    _Call.default.injectMetadata(new _Metadata.default(_static.default));
  });
  it('handles decoding correctly (bare)', () => {
    expect(new _Call.default({
      args: [],
      callIndex: [6, 1] // balances.setBalance

    }).toU8a()).toEqual(new Uint8Array([6, 1, 0, 0, 0]));
  });
  it('handles creation from a hex value properly', () => {
    expect(new _Call.default('0x0601').toU8a()).toEqual(new Uint8Array([6, 1, 0, 0, 0])); // balances.setBalance
  });
  describe('hasOrigin', () => {
    const test = {
      args: [],
      callIndex: [2, 2] // timestamp

    };
    it('is false with no arguments', () => {
      expect(new _Call.default(test, {
        args: []
      }).hasOrigin).toEqual(false);
    });
    it('is false with first argument as non-Origin', () => {
      expect(new _Call.default(test, {
        args: [{
          name: 'a',
          type: 'u32'
        }]
      }).hasOrigin).toEqual(false);
    });
    it('is false with first argument as non-Origin', () => {
      expect(new _Call.default(test, {
        args: [{
          name: 'a',
          type: 'Origin'
        }]
      }).hasOrigin).toEqual(true);
    });
  });
});