mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Squashed 'libjsqrc/ethereumjs/' changes from 73b9ed2..4def095
4def095 updated README.md 15b4dbd updated bower && package.json files 0ccc05a web3 in global namespace ccc59d1 version 0.2.6 9c2c946 Merge branch 'web3' into develop 6763f34 tests for creating new contract with nondefault constructor, added missing files 2ef5efc fixed #70, creating contract with nondefault constructor dbe4015 Merge branch 'master' into develop 48b351a add gasPrice test and fixed failing uncle tests 7f75f3e fixed gasPrice output ddec629 fixed getUncle parameter count 1e89ef0 changed to eth_protocolVersion 6add9bd Merge pull request #151 from ethereum/develop git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: 4def0958d35cb5b8d92d277423af4d435dd89f16
This commit is contained in:
parent
3e4a9de0b0
commit
1efd3c2687
106
abi.formatConstructorParams.js
Normal file
106
abi.formatConstructorParams.js
Normal file
@ -0,0 +1,106 @@
|
||||
var chai = require('chai');
|
||||
var assert = require('assert');
|
||||
var abi = require('../lib/solidity/abi');
|
||||
|
||||
describe('lib/solidity/abi', function () {
|
||||
describe('formatConstructorParams', function () {
|
||||
it('should format uint256 properly', function () {
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "constructor",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
// when
|
||||
var bytes = abi.formatConstructorParams(description, [2]);
|
||||
|
||||
// then
|
||||
assert.equal(bytes, '0000000000000000000000000000000000000000000000000000000000000002');
|
||||
});
|
||||
|
||||
it('should not find matching constructor', function () {
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "constructor",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
// when
|
||||
var bytes = abi.formatConstructorParams(description, []);
|
||||
|
||||
// then
|
||||
assert.equal(bytes, '');
|
||||
});
|
||||
|
||||
it('should not find matching constructor2', function () {
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "constructor",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
// when
|
||||
var bytes = abi.formatConstructorParams(description, [1,2]);
|
||||
|
||||
// then
|
||||
assert.equal(bytes, '');
|
||||
});
|
||||
|
||||
it('should not find matching constructor3', function () {
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
// when
|
||||
var bytes = abi.formatConstructorParams(description, [2]);
|
||||
|
||||
// then
|
||||
assert.equal(bytes, '');
|
||||
});
|
||||
|
||||
it('should find matching constructor with multiple args', function () {
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "constructor",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}, {
|
||||
"name": "b",
|
||||
"type": "uint256"
|
||||
}]
|
||||
}];
|
||||
|
||||
// when
|
||||
var bytes = abi.formatConstructorParams(description, ['1', '5']);
|
||||
|
||||
// then
|
||||
assert.equal(bytes, '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000005');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
var assert = require('assert');
|
||||
var chai = require('chai');
|
||||
var assert = chai.assert;
|
||||
var BigNumber = require('bignumber.js');
|
||||
var abi = require('../lib/solidity/abi.js');
|
||||
var abi = require('../lib/solidity/abi');
|
||||
var clone = function (object) { return JSON.parse(JSON.stringify(object)); };
|
||||
|
||||
var description = [{
|
||||
@ -19,9 +20,9 @@ var description = [{
|
||||
]
|
||||
}];
|
||||
|
||||
describe('lib/solidity/abi', function() {
|
||||
describe('inputParser', function() {
|
||||
it('should parse input uint', function() {
|
||||
describe('lib/solidity/abi', function () {
|
||||
describe('inputParser', function () {
|
||||
it('should parse input uint', function () {
|
||||
|
||||
// given
|
||||
var d = clone(description);
|
||||
|
@ -1,5 +1,5 @@
|
||||
var assert = require('assert');
|
||||
var utils = require('../lib/utils/utils.js');
|
||||
var utils = require('../lib/solidity/utils');
|
||||
|
||||
describe('lib/utils/utils', function() {
|
||||
it('should filter functions and events from input array properly', function () {
|
||||
|
@ -8,7 +8,7 @@ var tests = [
|
||||
{ value: 'function', is: false},
|
||||
{ value: {}, is: false},
|
||||
{ value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true },
|
||||
{ value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: false }
|
||||
{ value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: true }
|
||||
];
|
||||
|
||||
describe('lib/utils/utils', function () {
|
||||
|
23
utils.isStrictAddress.js
Normal file
23
utils.isStrictAddress.js
Normal file
@ -0,0 +1,23 @@
|
||||
var chai = require('chai');
|
||||
var utils = require('../lib/utils/utils.js');
|
||||
var assert = chai.assert;
|
||||
|
||||
var tests = [
|
||||
{ value: function () {}, is: false},
|
||||
{ value: new Function(), is: false},
|
||||
{ value: 'function', is: false},
|
||||
{ value: {}, is: false},
|
||||
{ value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true },
|
||||
{ value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: false }
|
||||
];
|
||||
|
||||
describe('lib/utils/utils', function () {
|
||||
describe('isStrictAddress', function () {
|
||||
tests.forEach(function (test) {
|
||||
it('shoud test if value ' + test.value + ' is address: ' + test.is, function () {
|
||||
assert.equal(utils.isStrictAddress(test.value), test.is);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,7 @@
|
||||
var assert = require('assert');
|
||||
var contract = require('../lib/web3/contract.js');
|
||||
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
||||
var web3 = require('../index');
|
||||
|
||||
describe('web3.eth.contract', function() {
|
||||
it('should create simple contract with one method from abi with explicit type name', function () {
|
||||
@ -20,10 +22,11 @@ describe('web3.eth.contract', function() {
|
||||
}
|
||||
]
|
||||
}];
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
// when
|
||||
var Con = contract(description);
|
||||
var myCon = new Con(null);
|
||||
var myCon = new Con(address);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof myCon.test);
|
||||
@ -48,10 +51,11 @@ describe('web3.eth.contract', function() {
|
||||
}
|
||||
]
|
||||
}];
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
// when
|
||||
var Con = contract(description);
|
||||
var myCon = new Con(null);
|
||||
var myCon = new Con(address);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof myCon.test);
|
||||
@ -90,10 +94,11 @@ describe('web3.eth.contract', function() {
|
||||
}
|
||||
]
|
||||
}];
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
// when
|
||||
var Con = contract(description);
|
||||
var myCon = new Con(null);
|
||||
var myCon = new Con(address);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof myCon.test);
|
||||
@ -134,10 +139,11 @@ describe('web3.eth.contract', function() {
|
||||
}
|
||||
]
|
||||
}];
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
// when
|
||||
var Con = contract(description);
|
||||
var myCon = new Con(null);
|
||||
var myCon = new Con(address);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof myCon.test);
|
||||
@ -162,11 +168,11 @@ describe('web3.eth.contract', function() {
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
// when
|
||||
var Con = contract(description);
|
||||
var myCon = new Con(null);
|
||||
var myCon = new Con(address);
|
||||
|
||||
// then
|
||||
assert.equal('undefined', typeof myCon.test);
|
||||
@ -191,11 +197,11 @@ describe('web3.eth.contract', function() {
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
// when
|
||||
var Con = contract(description);
|
||||
var myCon = new Con(null);
|
||||
var myCon = new Con(address);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof myCon.test);
|
||||
@ -203,5 +209,32 @@ describe('web3.eth.contract', function() {
|
||||
|
||||
});
|
||||
|
||||
it('should create contract with nondefault constructor', function (done) {
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
web3.reset(); // reset different polls
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
var code = '0x31241231231123123123123121cf121212i123123123123123512312412512111111';
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "constructor",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
provider.injectResult(address);
|
||||
provider.injectValidation(function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, 'eth_sendTransaction');
|
||||
assert.equal(payload.params[0].data, code + '0000000000000000000000000000000000000000000000000000000000000002');
|
||||
done();
|
||||
});
|
||||
|
||||
var Con = contract(description);
|
||||
var myCon = new Con(code, 2);
|
||||
});
|
||||
});
|
||||
|
||||
|
39
web3.eth.gasPrice.js
Normal file
39
web3.eth.gasPrice.js
Normal file
@ -0,0 +1,39 @@
|
||||
var chai = require('chai');
|
||||
var assert = chai.assert;
|
||||
var web3 = require('../index');
|
||||
var BigNumber = require('bignumber.js');
|
||||
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
||||
|
||||
var method = 'gasPrice';
|
||||
|
||||
var tests = [{
|
||||
result: '0x15f90',
|
||||
formattedResult: new BigNumber(90000),
|
||||
call: 'eth_'+ method
|
||||
}];
|
||||
|
||||
describe('web3.eth', function () {
|
||||
describe(method, function () {
|
||||
tests.forEach(function (test, index) {
|
||||
it('property test: ' + index, function () {
|
||||
|
||||
// given
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
provider.injectResult(test.result);
|
||||
provider.injectValidation(function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, test.call);
|
||||
assert.deepEqual(payload.params, []);
|
||||
});
|
||||
|
||||
// when
|
||||
var result = web3.eth[method];
|
||||
|
||||
// then
|
||||
assert.deepEqual(test.formattedResult, result);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -118,19 +118,19 @@ var formattedBlockResultWithTx = {
|
||||
|
||||
var tests = [{
|
||||
args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 2],
|
||||
formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x2', false],
|
||||
formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x2'],
|
||||
result: blockResult,
|
||||
formattedResult: formattedBlockResult,
|
||||
call: 'eth_getUncleByBlockHashAndIndex'
|
||||
},{
|
||||
args: [436, 1],
|
||||
formattedArgs: ['0x1b4', '0x1', false],
|
||||
formattedArgs: ['0x1b4', '0x1'],
|
||||
result: blockResult,
|
||||
formattedResult: formattedBlockResult,
|
||||
call: 'eth_getUncleByBlockNumberAndIndex'
|
||||
},{
|
||||
args: [436, 1, true],
|
||||
formattedArgs: ['0x1b4', '0x1', true],
|
||||
formattedArgs: ['0x1b4', '0x1'],
|
||||
result: blockResultWithTx,
|
||||
formattedResult: formattedBlockResultWithTx,
|
||||
call: 'eth_getUncleByBlockNumberAndIndex'
|
||||
|
Loading…
Reference in New Issue
Block a user