Fix issue with bool type dropdown
This commit is contained in:
parent
563c8c75f9
commit
3a7e30ec5c
@ -25,6 +25,7 @@ import ContentClear from 'material-ui/svg-icons/content/clear';
|
||||
import NavigationArrowBack from 'material-ui/svg-icons/navigation/arrow-back';
|
||||
import NavigationArrowForward from 'material-ui/svg-icons/navigation/arrow-forward';
|
||||
|
||||
import { toWei } from '~/api/util/wei';
|
||||
import { BusyStep, Button, CompletedStep, GasPriceEditor, IdentityIcon, Modal, TxHash } from '~/ui';
|
||||
import { MAX_GAS_ESTIMATION } from '~/util/constants';
|
||||
import { validateAddress, validateUint } from '~/util/validation';
|
||||
@ -56,12 +57,12 @@ class ExecuteContract extends Component {
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
isTest: PropTypes.bool,
|
||||
fromAddress: PropTypes.string,
|
||||
accounts: PropTypes.object,
|
||||
balances: PropTypes.object,
|
||||
contract: PropTypes.object,
|
||||
contract: PropTypes.object.isRequired,
|
||||
fromAddress: PropTypes.string,
|
||||
gasLimit: PropTypes.object.isRequired,
|
||||
isTest: PropTypes.bool,
|
||||
onClose: PropTypes.func.isRequired,
|
||||
onFromAddressChange: PropTypes.func.isRequired
|
||||
}
|
||||
@ -77,11 +78,11 @@ class ExecuteContract extends Component {
|
||||
funcError: null,
|
||||
gasEdit: false,
|
||||
rejected: false,
|
||||
step: STEP_DETAILS,
|
||||
sending: false,
|
||||
step: STEP_DETAILS,
|
||||
txhash: null,
|
||||
values: [],
|
||||
valuesError: [],
|
||||
txhash: null
|
||||
valuesError: []
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
@ -255,10 +256,6 @@ class ExecuteContract extends Component {
|
||||
valueError = validateAddress(_value).addressError;
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
value = _value === 'true';
|
||||
break;
|
||||
|
||||
case 'uint':
|
||||
valueError = validateUint(_value).valueError;
|
||||
break;
|
||||
@ -278,13 +275,12 @@ class ExecuteContract extends Component {
|
||||
}
|
||||
|
||||
estimateGas = (_fromAddress) => {
|
||||
const { api } = this.context;
|
||||
const { fromAddress } = this.props;
|
||||
const { amount, func, values } = this.state;
|
||||
const options = {
|
||||
gas: MAX_GAS_ESTIMATION,
|
||||
from: _fromAddress || fromAddress,
|
||||
value: api.util.toWei(amount || 0)
|
||||
value: toWei(amount || 0)
|
||||
};
|
||||
|
||||
if (!func) {
|
||||
|
69
js/src/modals/ExecuteContract/executeContract.spec.js
Normal file
69
js/src/modals/ExecuteContract/executeContract.spec.js
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
||||
// 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 { shallow } from 'enzyme';
|
||||
import React from 'react';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import ExecuteContract from './';
|
||||
|
||||
import { CONTRACT, STORE } from './executeContract.test.js';
|
||||
|
||||
let component;
|
||||
let onClose;
|
||||
let onFromAddressChange;
|
||||
|
||||
function render (props) {
|
||||
onClose = sinon.stub();
|
||||
onFromAddressChange = sinon.stub();
|
||||
|
||||
component = shallow(
|
||||
<ExecuteContract
|
||||
{ ...props }
|
||||
contract={ CONTRACT }
|
||||
onClose={ onClose }
|
||||
onFromAddressChange={ onFromAddressChange } />,
|
||||
{ context: { api: {}, store: STORE } }
|
||||
).find('ExecuteContract').shallow();
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
describe('modals/ExecuteContract/DetailsStep', () => {
|
||||
it('renders', () => {
|
||||
expect(render({ accounts: {} })).to.be.ok;
|
||||
});
|
||||
|
||||
describe('instance functions', () => {
|
||||
beforeEach(() => {
|
||||
render({
|
||||
accounts: {}
|
||||
});
|
||||
});
|
||||
|
||||
describe('onValueChange', () => {
|
||||
it('toggles boolean from false to true', () => {
|
||||
component.setState({
|
||||
func: CONTRACT.functions[0],
|
||||
values: [false]
|
||||
});
|
||||
component.instance().onValueChange(null, 0, true);
|
||||
|
||||
expect(component.state().values).to.deep.equal([true]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
64
js/src/modals/ExecuteContract/executeContract.test.js
Normal file
64
js/src/modals/ExecuteContract/executeContract.test.js
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
||||
// 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 BigNumber from 'bignumber.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const CONTRACT = {
|
||||
functions: [
|
||||
{
|
||||
name: 'test_a',
|
||||
signature: 'test_a',
|
||||
estimateGas: sinon.stub().resolves(new BigNumber(123)),
|
||||
inputs: [
|
||||
{
|
||||
name: 'test_bool',
|
||||
kind: {
|
||||
type: 'bool'
|
||||
}
|
||||
}
|
||||
],
|
||||
abi: {
|
||||
inputs: [
|
||||
{
|
||||
name: 'test_bool',
|
||||
type: 'bool'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const STORE = {
|
||||
dispatch: sinon.stub(),
|
||||
subscribe: sinon.stub(),
|
||||
getState: () => {
|
||||
return {
|
||||
balances: {
|
||||
balances: {}
|
||||
},
|
||||
nodeStatus: {
|
||||
gasLimit: new BigNumber(123)
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
CONTRACT,
|
||||
STORE
|
||||
};
|
Loading…
Reference in New Issue
Block a user