Use signature of functions instead of names (#3448)

* Use signature of functions instead of names #3411

* Fixes contract tests #3448
This commit is contained in:
Nicolas Gotchac 2016-11-15 15:58:33 +01:00 committed by Jaco Greeff
parent b5dedd8aeb
commit 20185e5aac
4 changed files with 16 additions and 4 deletions

View File

@ -40,9 +40,12 @@ export default class Contract {
this._events.forEach((evt) => { this._events.forEach((evt) => {
this._instance[evt.name] = evt; this._instance[evt.name] = evt;
this._instance[evt.signature] = evt;
}); });
this._functions.forEach((fn) => { this._functions.forEach((fn) => {
this._instance[fn.name] = fn; this._instance[fn.name] = fn;
this._instance[fn.signature] = fn;
}); });
this._sendSubscriptionChanges(); this._sendSubscriptionChanges();

View File

@ -20,6 +20,7 @@ import sinon from 'sinon';
import { TEST_HTTP_URL, mockHttp } from '../../../test/mockRpc'; import { TEST_HTTP_URL, mockHttp } from '../../../test/mockRpc';
import Abi from '../../abi'; import Abi from '../../abi';
import { sha3 } from '../util/sha3';
import Api from '../api'; import Api from '../api';
import Contract from './contract'; import Contract from './contract';
@ -113,7 +114,13 @@ describe('api/contract/Contract', () => {
]); ]);
contract.at('6789'); contract.at('6789');
expect(Object.keys(contract.instance)).to.deep.equal(['Drained', 'balanceOf', 'address']); expect(Object.keys(contract.instance)).to.deep.equal([
'Drained',
/^(?:0x)(.+)$/.exec(sha3('Drained(uint256)'))[1],
'balanceOf',
/^(?:0x)(.+)$/.exec(sha3('balanceOf(address)'))[1].substr(0, 8),
'address'
]);
expect(contract.address).to.equal('6789'); expect(contract.address).to.equal('6789');
}); });
}); });

View File

@ -33,6 +33,7 @@ export default class InputQuery extends Component {
inputs: PropTypes.array.isRequired, inputs: PropTypes.array.isRequired,
outputs: PropTypes.array.isRequired, outputs: PropTypes.array.isRequired,
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
signature: PropTypes.string.isRequired,
className: PropTypes.string className: PropTypes.string
} }
@ -177,7 +178,7 @@ export default class InputQuery extends Component {
onClick = () => { onClick = () => {
const { values } = this.state; const { values } = this.state;
const { inputs, contract, name, outputs } = this.props; const { inputs, contract, name, outputs, signature } = this.props;
this.setState({ this.setState({
isLoading: true, isLoading: true,
@ -187,7 +188,7 @@ export default class InputQuery extends Component {
const inputValues = inputs.map(input => values[input.name]); const inputValues = inputs.map(input => values[input.name]);
contract contract
.instance[name] .instance[signature]
.call({}, inputValues) .call({}, inputValues)
.then(results => { .then(results => {
if (outputs.length === 1) { if (outputs.length === 1) {

View File

@ -70,7 +70,7 @@ export default class Queries extends Component {
} }
renderInputQuery (fn) { renderInputQuery (fn) {
const { abi, name } = fn; const { abi, name, signature } = fn;
const { contract } = this.props; const { contract } = this.props;
return ( return (
@ -80,6 +80,7 @@ export default class Queries extends Component {
inputs={ abi.inputs } inputs={ abi.inputs }
outputs={ abi.outputs } outputs={ abi.outputs }
name={ name } name={ name }
signature={ signature }
contract={ contract } contract={ contract }
/> />
</div> </div>