Skip to content

Commit 4871f12

Browse files
authored
Merge pull request #501 from ethereum/abi-translate
Do not translate constant functions from <0.4.0 as payable
2 parents 8d11de6 + dd6874c commit 4871f12

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

abi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function update (compilerVersion, abi) {
1919
}
2020

2121
if (item.type !== 'event') {
22-
// add 'payable' to everything
23-
if (semver.lt(compilerVersion, '0.4.0')) {
22+
// add 'payable' to everything, except constant functions
23+
if (!item.constant && semver.lt(compilerVersion, '0.4.0')) {
2424
item.payable = true;
2525
}
2626

test/abi.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ tape('ABI translator', function (t) {
1515
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'constructor' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
1616
st.end();
1717
});
18-
t.test('0.3.6 (function)', function (st) {
18+
t.test('0.3.6 (non-constant function)', function (st) {
1919
var input = [ { inputs: [], type: 'function' } ];
2020
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'function' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
2121
st.end();
2222
});
23+
t.test('0.3.6 (constant function)', function (st) {
24+
var input = [ { inputs: [], type: 'function', constant: true } ];
25+
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], constant: true, stateMutability: 'view', type: 'function' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
26+
st.end();
27+
});
2328
t.test('0.3.6 (event)', function (st) {
2429
var input = [ { inputs: [], type: 'event' } ];
2530
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], type: 'event' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
@@ -35,11 +40,21 @@ tape('ABI translator', function (t) {
3540
st.deepEqual(abi.update('0.4.0', input), [ { inputs: [], type: 'constructor', payable: true, stateMutability: 'payable' }, { type: 'fallback', stateMutability: 'nonpayable' } ]);
3641
st.end();
3742
});
43+
t.test('0.4.0 (non-constant function)', function (st) {
44+
var input = [ { inputs: [], type: 'function' } ];
45+
st.deepEqual(abi.update('0.4.0', input), [ { inputs: [], stateMutability: 'nonpayable', type: 'function' } ]);
46+
st.end();
47+
});
3848
t.test('0.4.0 (constant function)', function (st) {
3949
var input = [ { inputs: [], type: 'function', constant: true } ];
4050
st.deepEqual(abi.update('0.4.0', input), [ { inputs: [], constant: true, stateMutability: 'view', type: 'function' } ]);
4151
st.end();
4252
});
53+
t.test('0.4.0 (payable function)', function (st) {
54+
var input = [ { inputs: [], payable: true, type: 'function' } ];
55+
st.deepEqual(abi.update('0.4.0', input), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'function' } ]);
56+
st.end();
57+
});
4358
t.test('0.4.1 (constructor not payable)', function (st) {
4459
var input = [ { inputs: [], payable: false, type: 'constructor' } ];
4560
st.deepEqual(abi.update('0.4.1', input), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'constructor' } ]);

0 commit comments

Comments
 (0)