Merge branch 'develop' into ipcProvider

Conflicts:
	dist/web3-light.js
	dist/web3-light.min.js
	dist/web3.js
	dist/web3.js.map
	dist/web3.min.js
This commit is contained in:
Marek Kotewicz 2015-07-09 12:02:53 +02:00
commit 706fc21128
32 changed files with 1122 additions and 15354 deletions

View File

@ -1,7 +1,7 @@
{
"name": "web3",
"namespace": "ethereum",
"version": "0.6.1",
"version": "0.8.1",
"description": "Ethereum Compatible JavaScript API",
"main": [
"./dist/web3.js",

7775
dist/web3-light.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

7777
dist/web3.js vendored

File diff suppressed because it is too large Load Diff

153
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

8
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
document.getElementById('coinbase').innerText = 'coinbase: ' + coinbase;
document.getElementById('original').innerText = ' original balance: ' + originalBalance + ' watching...';
web3.eth.filter('pending').watch(function() {
web3.eth.filter('latest').watch(function() {
var currentBalance = web3.eth.getBalance(coinbase).toNumber();
document.getElementById("current").innerText = 'current: ' + currentBalance;
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);

View File

@ -31,25 +31,18 @@
// let's assume that coinbase is our account
web3.eth.defaultAccount = web3.eth.coinbase;
var watch = web3.eth.filter('latest');
// create contract
myContract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);
if (contractMined) {
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if (err) {
console.error(err);
return;
}
myContract = contract;
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
});
}
function callExampleContract() {

View File

@ -0,0 +1,77 @@
<!doctype>
<html>
<head>
<script type="text/javascript" src="../dist/web3.js"></script>
<script type="text/javascript">
var web3 = require('web3');
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
// solidity code code
var source = "" +
"contract test {\n" +
" function take(uint[] a, uint b) constant returns(uint d) {\n" +
" return a[b];\n" +
" }\n" +
"}\n";
var compiled = web3.eth.compile.solidity(source);
var code = compiled.test.code;
// contract json abi, this is autogenerated using solc CLI
var abi = compiled.test.info.abiDefinition;
var myContract;
function createExampleContract() {
// hide create button
document.getElementById('create').style.visibility = 'hidden';
document.getElementById('code').innerText = code;
// let's assume that coinbase is our account
web3.eth.defaultAccount = web3.eth.coinbase;
// create contract
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if (err) {
console.error(err);
return;
}
myContract = contract;
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
});
}
function callExampleContract() {
// this should be generated by ethereum
var param = parseInt(document.getElementById('value').value);
// call the contract
var res = myContract.take([0,6,5,2,1,5,6], param);
document.getElementById('result').innerText = res.toString(10);
}
</script>
</head>
<body>
<h1>contract</h1>
<div id="code"></div>
<div id="status"></div>
<div id='create'>
<button type="button" onClick="createExampleContract();">create example contract</button>
</div>
<div id='call' style='visibility: hidden;'>
<div>var array = [0,6,5,2,1,5,6];</div>
<div>var x = array[
<input type="number" id="value" onkeyup='callExampleContract()'></input>
];
</div>
</div>
<div id="result"></div>
</body>
</html>

View File

@ -35,29 +35,22 @@
// let's assume that we have a private key to coinbase ;)
web3.eth.defaultAccount = web3.eth.coinbase;
var watch = web3.eth.filter('latest');
contract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + contract.address);
document.getElementById('create').style.visibility = 'hidden';
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);
if (contractMined) {
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
web3.eth.contract(abi).new({data: code}, function (err, c) {
if (err) {
console.error(err);
return;
}
});
inc = contract.Incremented({odd: true});
inc.watch(update);
contract = c;
console.log('address: ' + contract.address);
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
inc = contract.Incremented({odd: true}, update);
});
};
var counter = 0;

View File

@ -17,7 +17,7 @@ var bower = require('bower');
var streamify = require('gulp-streamify');
var replace = require('gulp-replace');
var DEST = './dist/';
var DEST = path.join(__dirname, 'dist/');
var src = 'index';
var dst = 'web3';
var lightDst = 'web3-light';
@ -29,7 +29,7 @@ var browserifyOptions = {
bundleExternal: true
};
gulp.task('versionReplace', function(){
gulp.task('version', function(){
gulp.src(['./package.json'])
.pipe(replace(/\"version\"\: \"(.{5})\"/, '"version": "'+ version.version + '"'))
.pipe(gulp.dest('./'));
@ -41,24 +41,24 @@ gulp.task('versionReplace', function(){
.pipe(gulp.dest('./'));
});
gulp.task('bower', function(cb){
gulp.task('bower', ['version'], function(cb){
bower.commands.install().on('end', function (installed){
console.log(installed);
cb();
});
});
gulp.task('clean', ['lint'], function(cb) {
del([ DEST ], cb);
});
gulp.task('lint', function(){
gulp.task('lint', ['bower'], function(){
return gulp.src(['./*.js', './lib/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('buildLight', ['clean'], function () {
gulp.task('clean', ['lint'], function(cb) {
del([ DEST ], cb);
});
gulp.task('light', ['clean'], function () {
return browserify(browserifyOptions)
.require('./' + src + '.js', {expose: 'web3'})
.ignore('bignumber.js')
@ -73,7 +73,7 @@ gulp.task('buildLight', ['clean'], function () {
.pipe(gulp.dest( DEST ));
});
gulp.task('buildStandalone', ['clean'], function () {
gulp.task('standalone', ['clean'], function () {
return browserify(browserifyOptions)
.require('./' + src + '.js', {expose: 'web3'})
.require('bignumber.js') // expose it to dapp users
@ -92,10 +92,5 @@ gulp.task('watch', function() {
gulp.watch(['./lib/*.js'], ['lint', 'build']);
});
gulp.task('light', ['versionReplace','bower', 'lint', 'buildLight']);
gulp.task('standalone', ['versionReplace','bower', 'lint', 'buildStandalone']);
gulp.task('default', ['light', 'standalone']);
gulp.task('version', ['versionReplace']);
gulp.task('default', ['version', 'bower', 'lint', 'clean', 'light', 'standalone']);

View File

@ -262,6 +262,13 @@ var coder = new SolidityCoder([
inputFormatter: f.formatInputBytes,
outputFormatter: f.formatOutputBytes
}),
new SolidityType({
name: 'string',
match: 'strict',
mode: 'bytes',
inputFormatter: f.formatInputString,
outputFormatter: f.formatOutputString
}),
new SolidityType({
name: 'real',
match: 'prefix',

View File

@ -43,26 +43,43 @@ var formatInputInt = function (value) {
};
/**
* Formats input value to byte representation of string
* Formats input bytes
*
* @method formatInputBytes
* @param {String}
* @returns {SolidityParam}
*/
var formatInputBytes = function (value) {
var result = utils.fromAscii(value, c.ETH_PADDING).substr(2);
var result = utils.padRight(utils.toHex(value).substr(2), 64);
return new SolidityParam(result);
};
/**
* Formats input bytes
*
* @method formatDynamicInputBytes
* @param {String}
* @returns {SolidityParam}
*/
var formatInputDynamicBytes = function (value) {
value = utils.toHex(value).substr(2);
var l = Math.floor((value.length + 63) / 64);
var result = utils.padRight(value, l * 64);
var length = Math.floor(value.length / 2);
return new SolidityParam(formatInputInt(length).value + result, 32);
};
/**
* Formats input value to byte representation of string
*
* @method formatInputDynamicBytes
* @method formatInputString
* @param {String}
* @returns {SolidityParam}
*/
var formatInputDynamicBytes = function (value) {
var result = utils.fromAscii(value, c.ETH_PADDING).substr(2);
var formatInputString = function (value) {
var result = utils.fromAscii(value).substr(2);
var l = Math.floor((result.length + 63) / 64);
result = utils.padRight(result, l * 64);
return new SolidityParam(formatInputInt(value.length).value + result, 32);
};
@ -165,27 +182,38 @@ var formatOutputBool = function (param) {
};
/**
* Should be used to format output string
* Should be used to format output bytes
*
* @method formatOutputBytes
* @param {SolidityParam} left-aligned hex representation of string
* @returns {String} ascii string
* @returns {String} hex string
*/
var formatOutputBytes = function (param) {
// length might also be important!
return utils.toAscii(param.staticPart());
return '0x' + param.staticPart();
};
/**
* Should be used to format output bytes
*
* @method formatOutputDynamicBytes
* @param {SolidityParam} left-aligned hex representation of string
* @returns {String} hex string
*/
var formatOutputDynamicBytes = function (param) {
var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
return '0x' + param.dynamicPart().substr(64, length);
};
/**
* Should be used to format output string
*
* @method formatOutputDynamicBytes
* @method formatOutputString
* @param {SolidityParam} left-aligned hex representation of string
* @returns {String} ascii string
*/
var formatOutputDynamicBytes = function (param) {
// length might also be important!
return utils.toAscii(param.dynamicPart().slice(64));
var formatOutputString = function (param) {
var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
return utils.toAscii(param.dynamicPart().substr(64, length));
};
/**
@ -204,6 +232,7 @@ module.exports = {
formatInputInt: formatInputInt,
formatInputBytes: formatInputBytes,
formatInputDynamicBytes: formatInputDynamicBytes,
formatInputString: formatInputString,
formatInputBool: formatInputBool,
formatInputReal: formatInputReal,
formatOutputInt: formatOutputInt,
@ -213,6 +242,7 @@ module.exports = {
formatOutputBool: formatOutputBool,
formatOutputBytes: formatOutputBytes,
formatOutputDynamicBytes: formatOutputDynamicBytes,
formatOutputString: formatOutputString,
formatOutputAddress: formatOutputAddress
};

View File

@ -182,13 +182,14 @@ var getOffset = function (bytes, index) {
*/
SolidityParam.decodeBytes = function (bytes, index) {
index = index || 0;
//TODO add support for strings longer than 32 bytes
//var length = parseInt('0x' + bytes.substr(offset * 64, 64));
var offset = getOffset(bytes, index);
// 2 * , cause we also parse length
return new SolidityParam(bytes.substr(offset * 2, 2 * 64), 0);
var l = parseInt('0x' + bytes.substr(offset * 2, 64));
l = Math.floor((l + 31) / 32);
// (1 + l) * , cause we also parse length
return new SolidityParam(bytes.substr(offset * 2, (1 + l) * 64), 0);
};
/**

9
lib/utils/browser-xhr.js Normal file
View File

@ -0,0 +1,9 @@
'use strict';
// go env doesn't have and need XMLHttpRequest
if (typeof XMLHttpRequest === 'undefined') {
exports.XMLHttpRequest = {};
} else {
exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line
}

View File

@ -75,6 +75,19 @@ var padLeft = function (string, chars, sign) {
return new Array(chars - string.length + 1).join(sign ? sign : "0") + string;
};
/**
* Should be called to pad string to expected length
*
* @method padRight
* @param {String} string to be padded
* @param {Number} characters that result string should have
* @param {String} sign, by default 0
* @returns {String} right aligned string
*/
var padRight = function (string, chars, sign) {
return string + (new Array(chars - string.length + 1).join(sign ? sign : "0"));
};
/**
* Should be called to get sting from it's hex representation
*
@ -91,10 +104,6 @@ var toAscii = function(hex) {
}
for (; i < l; i+=2) {
var code = parseInt(hex.substr(i, 2), 16);
if (code === 0) {
break;
}
str += String.fromCharCode(code);
}
@ -204,7 +213,7 @@ var fromDecimal = function (value) {
* @return {String}
*/
var toHex = function (val) {
/*jshint maxcomplexity:7 */
/*jshint maxcomplexity: 8 */
if (isBoolean(val))
return fromDecimal(+val);
@ -218,9 +227,11 @@ var toHex = function (val) {
// if its a negative number, pass it through fromDecimal
if (isString(val)) {
if (val.indexOf('-0x') === 0)
return fromDecimal(val);
return fromDecimal(val);
else if (!isFinite(val))
return fromAscii(val);
else if(val.indexOf('0x') === 0)
return val;
}
return fromDecimal(val);
@ -471,6 +482,7 @@ var isIBAN = function (iban) {
module.exports = {
padLeft: padLeft,
padRight: padRight,
toHex: toHex,
toDecimal: toDecimal,
fromDecimal: fromDecimal,

View File

@ -1,3 +1,3 @@
{
"version": "0.6.1"
"version": "0.8.1"
}

View File

@ -96,6 +96,63 @@ var contract = function (abi) {
return new ContractFactory(abi);
};
/**
* Should be called to check if the contract gets properly deployed on the blockchain.
*
* @method checkForContractAddress
* @param {Object} contract
* @param {Function} callback
* @returns {Undefined}
*/
var checkForContractAddress = function(contract, abi, callback){
var count = 0;
// wait for receipt
var filter = web3.eth.filter('latest', function(e){
if(!e) {
count++;
// console.log('Checking for contract address', count);
// stop watching after 50 blocks (timeout)
if(count > 50) {
if(callback)
callback(new Error('Contract couldn\'t be deployed'));
filter.stopWatching();
} else {
web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
if(receipt) {
web3.eth.getCode(receipt.contractAddress, function(e, code){
if(code.length > 2) {
// console.log('Contract code deployed!');
contract.address = receipt.contractAddress;
// attach events and methods
addFunctionsToContract(contract, abi);
addEventsToContract(contract, abi);
if(callback)
callback(null, contract);
} else if(callback) {
callback(new Error('The contract code couldn\'t be stored'));
}
filter.stopWatching();
});
}
});
}
}
});
};
/**
* Should be called to create new ContractFactory instance
*
@ -114,10 +171,12 @@ var ContractFactory = function (abi) {
* @param {Any} contract constructor param2 (optional)
* @param {Object} contract transaction object (required)
* @param {Function} callback
* @returns {Contract} returns contract if no callback was passed,
* otherwise calls callback function (err, contract)
* @returns {Contract} returns contract instance
*/
ContractFactory.prototype.new = function () {
var _this = this;
var contract = new Contract(this.abi);
// parse arguments
var options = {}; // required!
var callback;
@ -137,18 +196,27 @@ ContractFactory.prototype.new = function () {
var bytes = encodeConstructorParams(this.abi, args);
options.data += bytes;
if (!callback) {
var address = web3.eth.sendTransaction(options);
return this.at(address);
if(callback) {
// wait for the contract address adn check if the code was deployed
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress(contract, _this.abi, callback);
}
});
} else {
var hash = web3.eth.sendTransaction(options);
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress(contract, _this.abi);
}
var self = this;
web3.eth.sendTransaction(options, function (err, address) {
if (err) {
callback(err);
}
self.at(address, callback);
});
return contract;
};
/**
@ -161,12 +229,17 @@ ContractFactory.prototype.new = function () {
* otherwise calls callback function (err, contract)
*/
ContractFactory.prototype.at = function (address, callback) {
var contract = new Contract(this.abi, address);
// TODO: address is required
// attach functions
addFunctionsToContract(contract, this.abi);
addEventsToContract(contract, this.abi);
if (callback) {
callback(null, new Contract(this.abi, address));
callback(null, contract);
}
return new Contract(this.abi, address);
return contract;
};
/**
@ -178,8 +251,6 @@ ContractFactory.prototype.at = function (address, callback) {
*/
var Contract = function (abi, address) {
this.address = address;
addFunctionsToContract(this, abi);
addEventsToContract(this, abi);
};
module.exports = contract;

View File

@ -152,6 +152,13 @@ var getTransactionFromBlock = new Method({
outputFormatter: formatters.outputTransactionFormatter
});
var getTransactionReceipt = new Method({
name: 'getTransactionReceipt',
call: 'eth_getTransactionReceipt',
params: 1,
outputFormatter: formatters.outputTransactionReceiptFormatter
});
var getTransactionCount = new Method({
name: 'getTransactionCount',
call: 'eth_getTransactionCount',
@ -230,6 +237,7 @@ var methods = [
getBlockUncleCount,
getTransaction,
getTransactionFromBlock,
getTransactionReceipt,
getTransactionCount,
call,
estimateGas,

View File

@ -103,8 +103,8 @@ SolidityEvent.prototype.encode = function (indexed, options) {
result.topics = [];
result.address = this._address;
if (!this._anonymous) {
result.address = this._address;
result.topics.push('0x' + this.signature());
}

View File

@ -135,6 +135,7 @@ var Filter = function (options, methods, formatter, callback) {
});
this.options = getOptions(options);
this.implementation = implementation;
this.filterId = null;
this.callbacks = [];
this.pollFilters = [];
this.formatter = formatter;
@ -145,12 +146,13 @@ var Filter = function (options, methods, formatter, callback) {
});
} else {
self.filterId = id;
// get filter logs at start
// get filter logs for the already existing watch calls
self.callbacks.forEach(function(cb){
getLogsAtStart(self, cb);
});
pollFilter(self);
if(self.callbacks.length > 0)
pollFilter(self);
// start to watch immediately
if(callback) {

View File

@ -85,8 +85,8 @@ var inputTransactionFormatter = function (options){
* Formats the output of a transaction to its proper values
*
* @method outputTransactionFormatter
* @param {Object} transaction
* @returns {Object} transaction
* @param {Object} tx
* @returns {Object}
*/
var outputTransactionFormatter = function (tx){
if(tx.blockNumber !== null)
@ -100,12 +100,36 @@ var outputTransactionFormatter = function (tx){
return tx;
};
/**
* Formats the output of a transaction receipt to its proper values
*
* @method outputTransactionReceiptFormatter
* @param {Object} receipt
* @returns {Object}
*/
var outputTransactionReceiptFormatter = function (receipt){
if(receipt.blockNumber !== null)
receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
if(receipt.transactionIndex !== null)
receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
if(utils.isArray(receipt.logs)) {
receipt.logs = receipt.logs.map(function(log){
return outputLogFormatter(log);
});
}
return receipt;
};
/**
* Formats the output of a block to its proper values
*
* @method outputBlockFormatter
* @param {Object} block object
* @returns {Object} block object
* @param {Object} block
* @returns {Object}
*/
var outputBlockFormatter = function(block) {
@ -213,6 +237,7 @@ module.exports = {
inputPostFormatter: inputPostFormatter,
outputBigNumberFormatter: outputBigNumberFormatter,
outputTransactionFormatter: outputTransactionFormatter,
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
outputBlockFormatter: outputBlockFormatter,
outputLogFormatter: outputLogFormatter,
outputPostFormatter: outputPostFormatter

View File

@ -188,8 +188,9 @@ SolidityFunction.prototype.request = function () {
var format = this.unpackOutput.bind(this);
return {
method: this._constant ? 'eth_call' : 'eth_sendTransaction',
callback: callback,
payload: payload,
params: [payload],
format: format
};
};

View File

@ -1,7 +1,7 @@
/* jshint ignore:start */
Package.describe({
name: 'ethereum:web3',
version: '0.6.1',
version: '0.8.1',
summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC',
git: 'https://github.com/ethereum/ethereum.js',
// By default, Meteor will default to using README.md for documentation.

View File

@ -1,7 +1,7 @@
{
"name": "web3",
"namespace": "ethereum",
"version": "0.6.1",
"version": "0.8.1",
"description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC",
"main": "./index.js",
"directories": {
@ -13,6 +13,7 @@
"xmlhttprequest": "*"
},
"browser": {
"xmlhttprequest": "./lib/utils/browser-xhr.js"
},
"devDependencies": {
"bower": ">=1.4.1",
@ -55,30 +56,30 @@
],
"author": "ethdev.com",
"authors": [
{
"name": "Jeffery Wilcke",
"email": "jeff@ethdev.com",
"url": "https://github.com/obscuren"
},
{
"name": "Marek Kotewicz",
"email": "marek@ethdev.com",
"url": "https://github.com/debris"
},
{
"name": "Fabian Vogelsteller",
"email": "fabian@ethdev.com",
"homepage": "http://frozeman.de"
},
{
"name": "Marian Oancea",
"email": "marian@ethdev.com",
"url": "https://github.com/cubedro"
},
{
"name": "Fabian Vogelsteller",
"email": "fabian@frozeman.de",
"homepage": "http://frozeman.de"
},
{
"name": "Gav Wood",
"email": "g@ethdev.com",
"homepage": "http://gavwood.com"
},
{
"name": "Jeffery Wilcke",
"email": "jeff@ethdev.com",
"url": "https://github.com/obscuren"
}
],
"license": "LGPL-3.0"

View File

@ -28,6 +28,16 @@ describe('lib/web3/batch', function () {
done();
};
provider.injectValidation(function (payload) {
var first = payload[0];
var second = payload[1];
assert.equal(first.method, 'eth_getBalance');
assert.deepEqual(first.params, ['0x0000000000000000000000000000000000000000', 'latest']);
assert.equal(second.method, 'eth_getBalance');
assert.deepEqual(second.params, ['0x0000000000000000000000000000000000000005', 'latest']);
});
var batch = web3.createBatch();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000005', 'latest', callback2));
@ -55,7 +65,7 @@ describe('lib/web3/batch', function () {
}];
var address = '0x0000000000000000000000000000000000000000';
var address = '0x1000000000000000000000000000000000000001';
var result = '0x126';
var result2 = '0x0000000000000000000000000000000000000000000000000000000000000123';
@ -71,6 +81,19 @@ describe('lib/web3/batch', function () {
done();
};
provider.injectValidation(function (payload) {
var first = payload[0];
var second = payload[1];
assert.equal(first.method, 'eth_getBalance');
assert.deepEqual(first.params, ['0x0000000000000000000000000000000000000000', 'latest']);
assert.equal(second.method, 'eth_call');
assert.deepEqual(second.params, [{
'to': '0x1000000000000000000000000000000000000001',
'data': '0xe3d670d70000000000000000000000001000000000000000000000000000000000000001'
}]);
});
var batch = web3.createBatch();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
batch.add(web3.eth.contract(abi).at(address).balance.request(address, callback2));

View File

@ -20,10 +20,53 @@ describe('lib/solidity/coder', function () {
test({ type: 'int256', expected: new bn(1), value: '0000000000000000000000000000000000000000000000000000000000000001'});
test({ type: 'int256', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
test({ type: 'int256', expected: new bn(-1), value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
test({ type: 'bytes32', expected: 'gavofyork', value: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'bytes', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000020' +
test({ type: 'int8', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
test({ type: 'int32', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
test({ type: 'int64', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
test({ type: 'int128', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
test({ type: 'bytes32', expected: '0x6761766f66796f726b0000000000000000000000000000000000000000000000',
value: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'bytes', expected: '0x6761766f66796f726b',
value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'bytes32', expected: '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
value: '731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
test({ type: 'bytes', expected: '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000020' +
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
test({ type: 'bytes', expected: '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000040' +
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
test({ type: 'bytes', expected: '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000060' +
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
test({ type: 'string', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'string', expected: '\xc3\xa4\x00\x00\xc3\xa4',
value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000006' +
'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
test({ type: 'string', expected: '\xc3',
value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000001' +
'c300000000000000000000000000000000000000000000000000000000000000'});
test({ type: 'bytes', expected: '0xc3a40000c3a4',
value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000006' +
'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
test({ type: 'bytes32', expected: '0xc3a40000c3a40000000000000000000000000000000000000000000000000000',
value: 'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
test({ type: 'int[]', expected: [], value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000000'});
test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000020' +
@ -49,6 +92,11 @@ describe('lib/solidity/coder', function () {
test({ type: 'ureal', expected: new bn(8.5), value: '0000000000000000000000000000000880000000000000000000000000000000'});
test({ type: 'address', expected: '0x407d73d8a49eeb85d32cf465507dd71d507100c1',
value: '000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1'});
test({ type: 'string', expected: 'welcome to ethereum. welcome to ethereum. welcome to ethereum.',
value: '0000000000000000000000000000000000000000000000000000000000000020' +
'000000000000000000000000000000000000000000000000000000000000003e' +
'77656c636f6d6520746f20657468657265756d2e2077656c636f6d6520746f20' +
'657468657265756d2e2077656c636f6d6520746f20657468657265756d2e0000'});
});
});
@ -62,26 +110,44 @@ describe('lib/solidity/coder', function () {
test({ types: ['int'], expected: [new bn(1)], values: '0000000000000000000000000000000000000000000000000000000000000001'});
test({ types: ['bytes32', 'int'], expected: ['gavofyork', new bn(5)],
test({ types: ['bytes32', 'int'], expected: ['0x6761766f66796f726b0000000000000000000000000000000000000000000000', new bn(5)],
values: '6761766f66796f726b0000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000005'});
test({ types: ['int', 'bytes32'], expected: [new bn(5), 'gavofyork'],
test({ types: ['int', 'bytes32'], expected: [new bn(5), '0x6761766f66796f726b0000000000000000000000000000000000000000000000'],
values: '0000000000000000000000000000000000000000000000000000000000000005' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ types: ['int', 'bytes', 'int', 'int', 'int', 'int[]'], expected: [new bn(1), 'gavofyork', new bn(2), new bn(3), new bn(4),
test({ types: ['int', 'string', 'int', 'int', 'int', 'int[]'], expected: [new bn(1), 'gavofyork', new bn(2), new bn(3), new bn(4),
[new bn(5), new bn(6), new bn(7)]],
values: '0000000000000000000000000000000000000000000000000000000000000001' +
'00000000000000000000000000000000000000000000000000000000000000c0' +
'0000000000000000000000000000000000000000000000000000000000000002' +
'0000000000000000000000000000000000000000000000000000000000000003' +
'0000000000000000000000000000000000000000000000000000000000000004' +
'0000000000000000000000000000000000000000000000000000000000000100' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000003' +
'0000000000000000000000000000000000000000000000000000000000000005' +
'0000000000000000000000000000000000000000000000000000000000000006' +
'0000000000000000000000000000000000000000000000000000000000000007'});
'00000000000000000000000000000000000000000000000000000000000000c0' +
'0000000000000000000000000000000000000000000000000000000000000002' +
'0000000000000000000000000000000000000000000000000000000000000003' +
'0000000000000000000000000000000000000000000000000000000000000004' +
'0000000000000000000000000000000000000000000000000000000000000100' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000003' +
'0000000000000000000000000000000000000000000000000000000000000005' +
'0000000000000000000000000000000000000000000000000000000000000006' +
'0000000000000000000000000000000000000000000000000000000000000007'});
test({ types: ['int', 'bytes', 'int', 'bytes'], expected: [
new bn(5),
'0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
new bn(3),
'0x331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'431a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
],
values: '0000000000000000000000000000000000000000000000000000000000000005' +
'0000000000000000000000000000000000000000000000000000000000000080' +
'0000000000000000000000000000000000000000000000000000000000000003' +
'00000000000000000000000000000000000000000000000000000000000000e0' +
'0000000000000000000000000000000000000000000000000000000000000040' +
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'0000000000000000000000000000000000000000000000000000000000000040' +
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'431a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
});
});

View File

@ -20,10 +20,37 @@ describe('lib/solidity/coder', function () {
test({ type: 'int256', value: 1, expected: '0000000000000000000000000000000000000000000000000000000000000001'});
test({ type: 'int256', value: 16, expected: '0000000000000000000000000000000000000000000000000000000000000010'});
test({ type: 'int256', value: -1, expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
test({ type: 'bytes32', value: 'gavofyork', expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'bytes', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000020' +
test({ type: 'bytes32', value: '0x6761766f66796f726b',
expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'bytes32', value: '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
expected: '731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
test({ type: 'bytes32', value: '0x02838654a83c213dae3698391eabbd54a5b6e1fb3452bc7fa4ea0dd5c8ce7e29',
expected: '02838654a83c213dae3698391eabbd54a5b6e1fb3452bc7fa4ea0dd5c8ce7e29'});
test({ type: 'bytes', value: '0x6761766f66796f726b',
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'bytes', value: '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000020' +
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
test({ type: 'string', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'bytes', value: '0xc3a40000c3a4',
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000006' +
'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
test({ type: 'bytes32', value: '0xc3a40000c3a4',
expected: 'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
test({ type: 'string', value: '\xc3\xa4\x00\x00\xc3\xa4',
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000006' +
'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
test({ type: 'string', value: '\xc3',
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000001' +
'c300000000000000000000000000000000000000000000000000000000000000'});
test({ type: 'int[]', value: [], expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000000'});
test({ type: 'int[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000020' +
@ -48,6 +75,25 @@ describe('lib/solidity/coder', function () {
test({ type: 'ureal', value: 1, expected: '0000000000000000000000000000000100000000000000000000000000000000'});
test({ type: 'ureal', value: 2.125, expected: '0000000000000000000000000000000220000000000000000000000000000000'});
test({ type: 'ureal', value: 8.5, expected: '0000000000000000000000000000000880000000000000000000000000000000'});
test({ type: 'bytes', value: '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000040' +
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
test({ type: 'bytes', value: '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000060' +
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
test({ type: 'string', value: 'welcome to ethereum. welcome to ethereum. welcome to ethereum.',
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'000000000000000000000000000000000000000000000000000000000000003e' +
'77656c636f6d6520746f20657468657265756d2e2077656c636f6d6520746f20' +
'657468657265756d2e2077656c636f6d6520746f20657468657265756d2e0000'});
});
});
@ -67,8 +113,9 @@ describe('lib/solidity/coder', function () {
test({ types: ['int256'], values: [1], expected: '0000000000000000000000000000000000000000000000000000000000000001'});
test({ types: ['int256'], values: [16], expected: '0000000000000000000000000000000000000000000000000000000000000010'});
test({ types: ['int256'], values: [-1], expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
test({ types: ['bytes32'], values: ['gavofyork'], expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ types: ['bytes'], values: ['gavofyork'], expected: '0000000000000000000000000000000000000000000000000000000000000020' +
test({ types: ['bytes32'], values: ['0x6761766f66796f726b'],
expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ types: ['string'], values: ['gavofyork'], expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ types: ['int[]'], values: [[3]], expected: '0000000000000000000000000000000000000000000000000000000000000020' +
@ -91,18 +138,18 @@ describe('lib/solidity/coder', function () {
'0000000000000000000000000000000000000000000000000000000000000002' +
'0000000000000000000000000000000000000000000000000000000000000003' +
'0000000000000000000000000000000000000000000000000000000000000004'});
test({ types: ['bytes32', 'int'], values: ['gavofyork', 5],
test({ types: ['bytes32', 'int'], values: ['0x6761766f66796f726b', 5],
expected: '6761766f66796f726b0000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000005'});
test({ types: ['int', 'bytes32'], values: [5, 'gavofyork'],
test({ types: ['int', 'bytes32'], values: [5, '0x6761766f66796f726b'],
expected: '0000000000000000000000000000000000000000000000000000000000000005' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ types: ['bytes', 'int'], values: ['gavofyork', 5],
test({ types: ['string', 'int'], values: ['gavofyork', 5],
expected: '0000000000000000000000000000000000000000000000000000000000000040' +
'0000000000000000000000000000000000000000000000000000000000000005' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ types: ['bytes', 'bool', 'int[]'], values: ['gavofyork', true, [1, 2, 3]],
test({ types: ['string', 'bool', 'int[]'], values: ['gavofyork', true, [1, 2, 3]],
expected: '0000000000000000000000000000000000000000000000000000000000000060' +
'0000000000000000000000000000000000000000000000000000000000000001' +
'00000000000000000000000000000000000000000000000000000000000000a0' +
@ -112,7 +159,7 @@ describe('lib/solidity/coder', function () {
'0000000000000000000000000000000000000000000000000000000000000001' +
'0000000000000000000000000000000000000000000000000000000000000002' +
'0000000000000000000000000000000000000000000000000000000000000003'});
test({ types: ['bytes', 'int[]'], values: ['gavofyork', [1, 2, 3]],
test({ types: ['string', 'int[]'], values: ['gavofyork', [1, 2, 3]],
expected: '0000000000000000000000000000000000000000000000000000000000000040' +
'0000000000000000000000000000000000000000000000000000000000000080' +
'0000000000000000000000000000000000000000000000000000000000000009' +
@ -121,12 +168,12 @@ describe('lib/solidity/coder', function () {
'0000000000000000000000000000000000000000000000000000000000000001' +
'0000000000000000000000000000000000000000000000000000000000000002' +
'0000000000000000000000000000000000000000000000000000000000000003'});
test({ types: ['int', 'bytes'], values: [5, 'gavofyork'],
test({ types: ['int', 'string'], values: [5, 'gavofyork'],
expected: '0000000000000000000000000000000000000000000000000000000000000005' +
'0000000000000000000000000000000000000000000000000000000000000040' +
'0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ types: ['int', 'bytes', 'int', 'int', 'int', 'int[]'], values: [1, 'gavofyork', 2, 3, 4, [5, 6, 7]],
test({ types: ['int', 'string', 'int', 'int', 'int', 'int[]'], values: [1, 'gavofyork', 2, 3, 4, [5, 6, 7]],
expected: '0000000000000000000000000000000000000000000000000000000000000001' +
'00000000000000000000000000000000000000000000000000000000000000c0' +
'0000000000000000000000000000000000000000000000000000000000000002' +
@ -139,6 +186,24 @@ describe('lib/solidity/coder', function () {
'0000000000000000000000000000000000000000000000000000000000000005' +
'0000000000000000000000000000000000000000000000000000000000000006' +
'0000000000000000000000000000000000000000000000000000000000000007'});
test({ types: ['int', 'bytes', 'int', 'bytes'], values: [
5,
'0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
3,
'0x331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'431a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
],
expected: '0000000000000000000000000000000000000000000000000000000000000005' +
'0000000000000000000000000000000000000000000000000000000000000080' +
'0000000000000000000000000000000000000000000000000000000000000003' +
'00000000000000000000000000000000000000000000000000000000000000e0' +
'0000000000000000000000000000000000000000000000000000000000000040' +
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'0000000000000000000000000000000000000000000000000000000000000040' +
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
'431a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
});
});

View File

@ -14,6 +14,7 @@ var tests = [
{ value: '-0x1', expected: '-0x1'},
{ value: '-15', expected: '-0xf'},
{ value: '-0xf', expected: '-0xf'},
{ value: '0x657468657265756d', expected: '0x657468657265756d'},
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},

View File

@ -219,15 +219,27 @@ describe('web3.eth.contract', function() {
]
}];
var steps = 1;
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();
if(steps === 1) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_sendTransaction');
assert.equal(payload.params[0].data, code + '0000000000000000000000000000000000000000000000000000000000000002');
steps++;
} else if(steps === 2) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_newBlockFilter');
done();
}
});
var myCon = contract(description).new(2, {data: code});
contract(description).new(2, {data: code}, function(e, myCon){
});
});
});

View File

@ -6,7 +6,6 @@ var testMethod = require('./helpers/test.method.js');
var method = 'getTransaction';
var txResult = {
"status": "mined",
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"nonce":"0x5",
"blockHash": "0x6fd9e2a26ab",
@ -20,7 +19,6 @@ var txResult = {
"input":"0x603880600c6000396000f30060"
};
var formattedTxResult = {
"status": "mined",
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"nonce":5,
"blockHash": "0x6fd9e2a26ab",

View File

@ -0,0 +1,70 @@
var chai = require('chai');
var web3 = require('../index');
var BigNumber = require('bignumber.js');
var testMethod = require('./helpers/test.method.js');
var method = 'getTransactionReceipt';
var txResult = {
"blockHash": "0x6fd9e2a26ab",
"blockNumber": "0x15df",
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": "0x1",
"contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"cumulativeGasUsed":"0x7f110",
"gasUsed": "0x7f110",
"logs": [{
transactionIndex: '0x3e8',
logIndex: '0x3e8',
blockNumber: '0x3e8',
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
data: '0x7b2274657374223a2274657374227',
topics: ['0x68656c6c6f','0x6d79746f70696373']
},{
transactionIndex: null,
logIndex: null,
blockNumber: null,
transactionHash: null,
blockHash: null,
data: '0x7b2274657374223a2274657374227',
topics: ['0x68656c6c6f','0x6d79746f70696373']
}]
};
var formattedTxResult = {
"blockHash": "0x6fd9e2a26ab",
"blockNumber": 5599,
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": 1,
"contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"cumulativeGasUsed": 520464,
"gasUsed": 520464,
"logs": [{
transactionIndex: 1000,
logIndex: 1000,
blockNumber: 1000,
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
data: '0x7b2274657374223a2274657374227',
topics: ['0x68656c6c6f','0x6d79746f70696373']
},{
transactionIndex: null,
logIndex: null,
blockNumber: null,
transactionHash: null,
blockHash: null,
data: '0x7b2274657374223a2274657374227',
topics: ['0x68656c6c6f','0x6d79746f70696373']
}]
};
var tests = [{
args: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'],
formattedArgs: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'],
result: txResult,
formattedResult: formattedTxResult,
call: 'eth_'+ method
}];
testMethod.runTests('eth', method, tests);