2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-12-28 18:09:54 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import Store from './store';
|
|
|
|
|
|
|
|
import { ABI, CONTRACTS, createApi } from './addContract.test.js';
|
|
|
|
|
|
|
|
const INVALID_ADDR = '0x123';
|
|
|
|
const VALID_ADDR = '0x5A5eFF38DA95b0D58b6C616f2699168B480953C9';
|
|
|
|
const DUPE_ADDR = Object.keys(CONTRACTS)[0];
|
|
|
|
|
|
|
|
let api;
|
|
|
|
let store;
|
|
|
|
|
|
|
|
function createStore () {
|
|
|
|
api = createApi();
|
|
|
|
store = new Store(api, CONTRACTS);
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:06:16 +02:00
|
|
|
describe('views/Contracts/AddContract/Store', () => {
|
2016-12-28 18:09:54 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
createStore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('constructor', () => {
|
|
|
|
it('creates an instance', () => {
|
|
|
|
expect(store).to.be.ok;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('defaults to custom ABI', () => {
|
2017-05-12 12:06:16 +02:00
|
|
|
expect(store.abiType).to.equal('custom');
|
2016-12-28 18:09:54 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('@actions', () => {
|
|
|
|
describe('nextStep/prevStep', () => {
|
|
|
|
it('moves to the next/prev step', () => {
|
|
|
|
expect(store.step).to.equal(0);
|
|
|
|
store.nextStep();
|
|
|
|
expect(store.step).to.equal(1);
|
|
|
|
store.prevStep();
|
|
|
|
expect(store.step).to.equal(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-12 12:06:16 +02:00
|
|
|
describe('setAbiType', () => {
|
2016-12-28 18:09:54 +01:00
|
|
|
beforeEach(() => {
|
2017-05-12 12:06:16 +02:00
|
|
|
store.setAbiType('multisig');
|
2016-12-28 18:09:54 +01:00
|
|
|
});
|
|
|
|
|
2017-05-12 12:06:16 +02:00
|
|
|
it('changes the type', () => {
|
|
|
|
expect(store.abiType).to.equal('multisig');
|
2016-12-28 18:09:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('changes the abi', () => {
|
|
|
|
expect(store.abi).to.deep.equal(store.abiTypes[1].value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setAddress', () => {
|
|
|
|
it('sets a valid address', () => {
|
|
|
|
store.setAddress(VALID_ADDR);
|
|
|
|
expect(store.address).to.equal(VALID_ADDR);
|
|
|
|
expect(store.addressError).to.be.null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the error on invalid address', () => {
|
|
|
|
store.setAddress(INVALID_ADDR);
|
|
|
|
expect(store.address).to.equal(INVALID_ADDR);
|
|
|
|
expect(store.addressError).not.to.be.null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the error on suplicate address', () => {
|
|
|
|
store.setAddress(DUPE_ADDR);
|
|
|
|
expect(store.address).to.equal(DUPE_ADDR);
|
|
|
|
expect(store.addressError).not.to.be.null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setDescription', () => {
|
|
|
|
it('sets the description', () => {
|
|
|
|
store.setDescription('test description');
|
|
|
|
expect(store.description).to.equal('test description');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setName', () => {
|
|
|
|
it('sets the name', () => {
|
|
|
|
store.setName('some name');
|
|
|
|
expect(store.name).to.equal('some name');
|
|
|
|
expect(store.nameError).to.be.null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the error', () => {
|
|
|
|
store.setName('s');
|
|
|
|
expect(store.name).to.equal('s');
|
|
|
|
expect(store.nameError).not.to.be.null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('@computed', () => {
|
|
|
|
describe('hasError', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.setAddress(VALID_ADDR);
|
|
|
|
store.setName('valid name');
|
|
|
|
store.setAbi(ABI);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is false with no errors', () => {
|
|
|
|
expect(store.hasError).to.be.false;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is true with address error', () => {
|
|
|
|
store.setAddress(DUPE_ADDR);
|
|
|
|
expect(store.hasError).to.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is true with name error', () => {
|
|
|
|
store.setName('s');
|
|
|
|
expect(store.hasError).to.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is true with abi error', () => {
|
|
|
|
store.setAbi('');
|
|
|
|
expect(store.hasError).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('interactions', () => {
|
|
|
|
describe('addContract', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.setAddress(VALID_ADDR);
|
|
|
|
store.setName('valid name');
|
|
|
|
store.setAbi(ABI);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the account name', () => {
|
|
|
|
return store.addContract().then(() => {
|
|
|
|
expect(api.parity.setAccountName).to.have.been.calledWith(VALID_ADDR, 'valid name');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the account meta', () => {
|
|
|
|
return store.addContract().then(() => {
|
|
|
|
expect(api.parity.setAccountMeta).to.have.been.called;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|