mirror of https://github.com/ethereum/go-ethereum
Conflicts: libjsqrc/ethereumjs/dist/ethereum.js libjsqrc/ethereumjs/dist/ethereum.js.map libjsqrc/ethereumjs/dist/ethereum.min.js libjsqrc/ethereumjs/lib/abi.jspull/272/merge
commit
6d02c0d392
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,89 @@ |
||||
/* |
||||
This file is part of ethereum.js. |
||||
|
||||
ethereum.js is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU Lesser General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
ethereum.js 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 Lesser General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU Lesser General Public License |
||||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
/** @file filter.js |
||||
* @authors: |
||||
* Jeffrey Wilcke <jeff@ethdev.com> |
||||
* Marek Kotewicz <marek@ethdev.com> |
||||
* Marian Oancea <marian@ethdev.com> |
||||
* Gav Wood <g@ethdev.com> |
||||
* @date 2014 |
||||
*/ |
||||
|
||||
// TODO: is these line is supposed to be here?
|
||||
if (process.env.NODE_ENV !== 'build') { |
||||
var web3 = require('./web3'); // jshint ignore:line
|
||||
} |
||||
|
||||
/// should be used when we want to watch something
|
||||
/// it's using inner polling mechanism and is notified about changes
|
||||
var Filter = function(options, impl) { |
||||
this.impl = impl; |
||||
this.callbacks = []; |
||||
|
||||
var self = this; |
||||
this.promise = impl.newFilter(options); |
||||
this.promise.then(function (id) { |
||||
self.id = id; |
||||
web3.on(impl.changed, id, self.trigger.bind(self)); |
||||
web3.provider.startPolling({call: impl.changed, args: [id]}, id); |
||||
}); |
||||
}; |
||||
|
||||
/// alias for changed*
|
||||
Filter.prototype.arrived = function(callback) { |
||||
this.changed(callback); |
||||
}; |
||||
|
||||
/// gets called when there is new eth/shh message
|
||||
Filter.prototype.changed = function(callback) { |
||||
var self = this; |
||||
this.promise.then(function(id) { |
||||
self.callbacks.push(callback); |
||||
}); |
||||
}; |
||||
|
||||
/// trigger calling new message from people
|
||||
Filter.prototype.trigger = function(messages) { |
||||
for(var i = 0; i < this.callbacks.length; i++) { |
||||
this.callbacks[i].call(this, messages); |
||||
} |
||||
}; |
||||
|
||||
/// should be called to uninstall current filter
|
||||
Filter.prototype.uninstall = function() { |
||||
var self = this; |
||||
this.promise.then(function (id) { |
||||
self.impl.uninstallFilter(id); |
||||
web3.provider.stopPolling(id); |
||||
web3.off(impl.changed, id); |
||||
}); |
||||
}; |
||||
|
||||
/// should be called to manually trigger getting latest messages from the client
|
||||
Filter.prototype.messages = function() { |
||||
var self = this; |
||||
return this.promise.then(function (id) { |
||||
return self.impl.getMessages(id); |
||||
}); |
||||
}; |
||||
|
||||
/// alias for messages
|
||||
Filter.prototype.logs = function () { |
||||
return this.messages(); |
||||
}; |
||||
|
||||
module.exports = Filter; |
@ -0,0 +1,122 @@ |
||||
/* |
||||
This file is part of ethereum.js. |
||||
|
||||
ethereum.js is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU Lesser General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
ethereum.js 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 Lesser General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU Lesser General Public License |
||||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
/** @file providermanager.js |
||||
* @authors: |
||||
* Jeffrey Wilcke <jeff@ethdev.com> |
||||
* Marek Kotewicz <marek@ethdev.com> |
||||
* Marian Oancea <marian@ethdev.com> |
||||
* Gav Wood <g@ethdev.com> |
||||
* @date 2014 |
||||
*/ |
||||
|
||||
// TODO: is these line is supposed to be here?
|
||||
if (process.env.NODE_ENV !== 'build') { |
||||
var web3 = require('./web3'); // jshint ignore:line
|
||||
} |
||||
|
||||
/** |
||||
* Provider manager object prototype |
||||
* It's responsible for passing messages to providers |
||||
* If no provider is set it's responsible for queuing requests |
||||
* It's also responsible for polling the ethereum node for incoming messages |
||||
* Default poll timeout is 12 seconds |
||||
* If we are running ethereum.js inside ethereum browser, there are backend based tools responsible for polling, |
||||
* and provider manager polling mechanism is not used |
||||
*/ |
||||
var ProviderManager = function() { |
||||
this.queued = []; |
||||
this.polls = []; |
||||
this.ready = false; |
||||
this.provider = undefined; |
||||
this.id = 1; |
||||
|
||||
var self = this; |
||||
var poll = function () { |
||||
if (self.provider && self.provider.poll) { |
||||
self.polls.forEach(function (data) { |
||||
data.data._id = self.id; |
||||
self.id++; |
||||
self.provider.poll(data.data, data.id); |
||||
}); |
||||
} |
||||
setTimeout(poll, 12000); |
||||
}; |
||||
poll(); |
||||
}; |
||||
|
||||
/// sends outgoing requests, if provider is not available, enqueue the request
|
||||
ProviderManager.prototype.send = function(data, cb) { |
||||
data._id = this.id; |
||||
if (cb) { |
||||
web3._callbacks[data._id] = cb; |
||||
} |
||||
|
||||
data.args = data.args || []; |
||||
this.id++; |
||||
|
||||
if(this.provider !== undefined) { |
||||
this.provider.send(data); |
||||
} else { |
||||
console.warn("provider is not set"); |
||||
this.queued.push(data); |
||||
} |
||||
}; |
||||
|
||||
/// setups provider, which will be used for sending messages
|
||||
ProviderManager.prototype.set = function(provider) { |
||||
if(this.provider !== undefined && this.provider.unload !== undefined) { |
||||
this.provider.unload(); |
||||
} |
||||
|
||||
this.provider = provider; |
||||
this.ready = true; |
||||
}; |
||||
|
||||
/// resends queued messages
|
||||
ProviderManager.prototype.sendQueued = function() { |
||||
for(var i = 0; this.queued.length; i++) { |
||||
// Resend
|
||||
this.send(this.queued[i]); |
||||
} |
||||
}; |
||||
|
||||
/// @returns true if the provider i properly set
|
||||
ProviderManager.prototype.installed = function() { |
||||
return this.provider !== undefined; |
||||
}; |
||||
|
||||
/// this method is only used, when we do not have native qt bindings and have to do polling on our own
|
||||
/// should be callled, on start watching for eth/shh changes
|
||||
ProviderManager.prototype.startPolling = function (data, pollId) { |
||||
if (!this.provider || !this.provider.poll) { |
||||
return; |
||||
} |
||||
this.polls.push({data: data, id: pollId}); |
||||
}; |
||||
|
||||
/// should be called to stop polling for certain watch changes
|
||||
ProviderManager.prototype.stopPolling = function (pollId) { |
||||
for (var i = this.polls.length; i--;) { |
||||
var poll = this.polls[i]; |
||||
if (poll.id === pollId) { |
||||
this.polls.splice(i, 1); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
module.exports = ProviderManager; |
||||
|
@ -1,37 +1,547 @@ |
||||
var assert = require('assert'); |
||||
var abi = require('../lib/abi.js'); |
||||
var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; |
||||
|
||||
var description = [{ |
||||
"name": "test", |
||||
"inputs": [{ |
||||
"name": "a", |
||||
"type": "uint256" |
||||
} |
||||
], |
||||
"outputs": [ |
||||
{ |
||||
"name": "d", |
||||
"type": "uint256" |
||||
} |
||||
] |
||||
}]; |
||||
|
||||
describe('abi', function() { |
||||
describe('inputParser', function() { |
||||
it('should parse ...', function() { |
||||
|
||||
var desc = [{ |
||||
"name": "multiply", |
||||
"inputs": [ |
||||
{ |
||||
"name": "a", |
||||
"type": "uint256" |
||||
} |
||||
], |
||||
"outputs": [ |
||||
{ |
||||
"name": "d", |
||||
"type": "uint256" |
||||
} |
||||
] |
||||
it('should parse input uint', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "uint" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); |
||||
|
||||
}); |
||||
|
||||
it('should parse input uint128', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "uint128" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); |
||||
|
||||
}); |
||||
|
||||
it('should parse input uint256', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "uint256" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); |
||||
|
||||
}); |
||||
|
||||
it('should parse input int', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "int" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); |
||||
assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); |
||||
assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); |
||||
assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); |
||||
|
||||
}); |
||||
|
||||
it('should parse input int128', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "int128" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); |
||||
assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); |
||||
assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); |
||||
assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); |
||||
|
||||
}); |
||||
|
||||
it('should parse input int256', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "int256" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
assert.equal(parser.test(10), "000000000000000000000000000000000000000000000000000000000000000a"); |
||||
assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); |
||||
assert.equal(parser.test(-2), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); |
||||
assert.equal(parser.test(-16), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0"); |
||||
|
||||
}); |
||||
|
||||
it('should parse input bool', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: 'bool' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test(true), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
assert.equal(parser.test(false), "0000000000000000000000000000000000000000000000000000000000000000"); |
||||
|
||||
}); |
||||
|
||||
it('should parse input hash', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "hash" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"); |
||||
|
||||
});
|
||||
|
||||
it('should parse input hash256', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "hash256" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"); |
||||
|
||||
}); |
||||
|
||||
|
||||
it('should parse input hash160', function() { |
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "hash160" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"); |
||||
}); |
||||
|
||||
it('should parse input address', function () { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "address" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d) |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x407d73d8a49eeb85d32cf465507dd71d507100c1"), "000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1"); |
||||
|
||||
}); |
||||
|
||||
it('should parse input string', function () { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].inputs = [ |
||||
{ type: "string" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test('hello'), "68656c6c6f000000000000000000000000000000000000000000000000000000"); |
||||
assert.equal(parser.test('world'), "776f726c64000000000000000000000000000000000000000000000000000000"); |
||||
}); |
||||
|
||||
it('should use proper method name', function () { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
d[0].name = 'helloworld'; |
||||
d[0].inputs = [ |
||||
{ type: "int" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.helloworld(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
|
||||
}); |
||||
|
||||
it('should parse multiple methods', function () { |
||||
|
||||
// given
|
||||
var d = [{ |
||||
name: "test", |
||||
inputs: [{ type: "int" }], |
||||
outputs: [{ type: "int" }] |
||||
},{ |
||||
name: "test2", |
||||
inputs: [{ type: "string" }], |
||||
outputs: [{ type: "string" }] |
||||
}]; |
||||
|
||||
var iParser = abi.inputParser(desc); |
||||
assert.equal(iParser.multiply(1), "0x000000000000000000000000000000000000000000000000000000000000000001"); |
||||
// when
|
||||
var parser = abi.inputParser(d); |
||||
|
||||
//then
|
||||
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
||||
assert.equal(parser.test2('hello'), "68656c6c6f000000000000000000000000000000000000000000000000000000"); |
||||
|
||||
}); |
||||
}); |
||||
|
||||
|
||||
describe('outputParser', function() { |
||||
it('parse ...', function() { |
||||
it('should parse output string', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: "string" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x68656c6c6f000000000000000000000000000000000000000000000000000000")[0], 'hello'); |
||||
assert.equal(parser.test("0x776f726c64000000000000000000000000000000000000000000000000000000")[0], 'world'); |
||||
|
||||
}); |
||||
|
||||
it('should parse output uint', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'uint' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
||||
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
||||
}); |
||||
|
||||
it('should parse output uint256', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'uint256' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
||||
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
||||
}); |
||||
|
||||
it('should parse output uint128', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'uint128' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
||||
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
||||
}); |
||||
|
||||
it('should parse output int', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'int' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
||||
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
||||
}); |
||||
|
||||
it('should parse output int256', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'int256' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
||||
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
||||
}); |
||||
|
||||
it('should parse output int128', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'int128' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
||||
assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
||||
}); |
||||
|
||||
it('should parse output hash', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'hash' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1") |
||||
}); |
||||
|
||||
it('should parse output hash256', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'hash256' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1") |
||||
}); |
||||
|
||||
it('should parse output hash160', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'hash160' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1") |
||||
// TODO shouldnt' the expected hash be shorter?
|
||||
}); |
||||
|
||||
it('should parse output address', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'address' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x407d73d8a49eeb85d32cf465507dd71d507100c1") |
||||
}); |
||||
|
||||
it('should parse output bool', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: 'bool' } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000001")[0], true); |
||||
assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000000")[0], false); |
||||
|
||||
|
||||
}); |
||||
|
||||
it('should parse multiple output strings', function() { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
|
||||
d[0].outputs = [ |
||||
{ type: "string" }, |
||||
{ type: "string" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.test("0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000")[0], 'hello'); |
||||
assert.equal(parser.test("0x68656c6c6f000000000000000000000000000000000000000000000000000000776f726c64000000000000000000000000000000000000000000000000000000")[1], 'world'); |
||||
|
||||
}); |
||||
|
||||
it('should use proper method name', function () { |
||||
|
||||
// given
|
||||
var d = clone(description); |
||||
d[0].name = 'helloworld'; |
||||
d[0].outputs = [ |
||||
{ type: "int" } |
||||
]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
// then
|
||||
assert.equal(parser.helloworld("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
||||
|
||||
}); |
||||
|
||||
|
||||
it('should parse multiple methods', function () { |
||||
|
||||
// given
|
||||
var d = [{ |
||||
name: "test", |
||||
inputs: [{ type: "int" }], |
||||
outputs: [{ type: "int" }] |
||||
},{ |
||||
name: "test2", |
||||
inputs: [{ type: "string" }], |
||||
outputs: [{ type: "string" }] |
||||
}]; |
||||
|
||||
// when
|
||||
var parser = abi.outputParser(d); |
||||
|
||||
//then
|
||||
assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
||||
assert.equal(parser.test2("0x68656c6c6f000000000000000000000000000000000000000000000000000000")[0], "hello"); |
||||
|
||||
}); |
||||
|
||||
}); |
||||
}); |
||||
|
||||
|
@ -1,2 +1,2 @@ |
||||
--reporter Spec |
||||
--reporter spec |
||||
|
||||
|
Loading…
Reference in new issue