subtly
10 years ago
88 changed files with 1959 additions and 2191 deletions
@ -0,0 +1,13 @@ |
|||
{ |
|||
"title": "Ethereum", |
|||
"icon": "appdmg_icon.icns", |
|||
"background": "appdmg_background.png", |
|||
"icon-size": 80, |
|||
"contents": [ |
|||
{ "x": 600, "y": 170, "type": "link", "path": "/Applications" }, |
|||
{ "x": 150, "y": 90, "type": "file", "path": "${ETH_ALETHZERO_APP}" }, |
|||
{ "x": 150, "y": 260, "type": "file", "path": "${ETH_MIX_APP}" } |
|||
] |
|||
} |
|||
|
|||
|
After Width: | Height: | Size: 171 KiB |
@ -0,0 +1,17 @@ |
|||
|
|||
if (NOT APP_DMG_EXE) |
|||
message(FATAL_ERROR "Please install appdmg! https://github.com/LinusU/node-appdmg") |
|||
endif() |
|||
|
|||
string(REPLACE "/Contents/MacOS" "" ETH_MIX_APP "${ETH_MIX_APP}") |
|||
string(REPLACE "/Contents/MacOS" "" ETH_ALETHZERO_APP "${ETH_ALETHZERO_APP}") |
|||
|
|||
set(OUTFILE "${ETH_BUILD_DIR}/appdmg.json") |
|||
|
|||
configure_file(${APP_DMG_FILE} ${OUTFILE}) |
|||
|
|||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${APP_DMG_ICON}" "${ETH_BUILD_DIR}/appdmg_icon.icns") |
|||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${APP_DMG_BACKGROUND}" "${ETH_BUILD_DIR}/appdmg_background.png") |
|||
execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${ETH_BUILD_DIR}/Ethereum.dmg") |
|||
execute_process(COMMAND ${APP_DMG_EXE} ${OUTFILE} "${ETH_BUILD_DIR}/Ethereum.dmg") |
|||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,3 +1,3 @@ |
|||
{ |
|||
"version": "0.3.3" |
|||
"version": "0.3.6" |
|||
} |
|||
|
@ -1,515 +0,0 @@ |
|||
var chai = require('chai'); |
|||
var assert = chai.assert; |
|||
var BigNumber = require('bignumber.js'); |
|||
var abi = require('../lib/solidity/abi'); |
|||
var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; |
|||
|
|||
var description = [{ |
|||
"name": "test", |
|||
"type": "function", |
|||
"inputs": [{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
} |
|||
], |
|||
"outputs": [ |
|||
{ |
|||
"name": "d", |
|||
"type": "uint256" |
|||
} |
|||
] |
|||
}]; |
|||
|
|||
describe('lib/solidity/abi', function () { |
|||
describe('inputParser', function () { |
|||
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"); |
|||
assert.equal( |
|||
parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal( |
|||
parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
|
|||
}); |
|||
|
|||
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"); |
|||
assert.equal( |
|||
parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal( |
|||
parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
|
|||
}); |
|||
|
|||
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"); |
|||
assert.equal( |
|||
parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal( |
|||
parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
|
|||
}); |
|||
|
|||
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"); |
|||
assert.equal( |
|||
parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal( |
|||
parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
}); |
|||
|
|||
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"); |
|||
assert.equal( |
|||
parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal( |
|||
parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
|
|||
}); |
|||
|
|||
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"); |
|||
assert.equal( |
|||
parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal( |
|||
parser.test(new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)), |
|||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
|||
); |
|||
assert.equal(parser.test(0.1), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test(3.9), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
assert.equal(parser.test('0.1'), "0000000000000000000000000000000000000000000000000000000000000000"); |
|||
assert.equal(parser.test('3.9'), "0000000000000000000000000000000000000000000000000000000000000003"); |
|||
|
|||
}); |
|||
|
|||
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 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 fixed bytes type', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: "bytes" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test('hello'), |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"68656c6c6f000000000000000000000000000000000000000000000000000000" |
|||
); |
|||
assert.equal( |
|||
parser.test('world'), |
|||
"0000000000000000000000000000000000000000000000000000000000000005776f726c64000000000000000000000000000000000000000000000000000000" |
|||
); |
|||
}); |
|||
|
|||
it('should parse input int followed by a fixed bytes type', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: "int" }, |
|||
{ type: "bytes" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test(9, 'hello'), |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000009" + |
|||
"68656c6c6f000000000000000000000000000000000000000000000000000000" |
|||
); |
|||
}); |
|||
|
|||
it('should parse input fixed bytes type followed by an int', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: "bytes" }, |
|||
{ type: "int" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test('hello', 9), |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000009" + |
|||
"68656c6c6f000000000000000000000000000000000000000000000000000000" |
|||
); |
|||
}); |
|||
|
|||
it('should use proper method name', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
d[0].name = 'helloworld(int)'; |
|||
d[0].inputs = [ |
|||
{ type: "int" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.helloworld(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
|||
assert.equal(parser.helloworld['int'](1), "0000000000000000000000000000000000000000000000000000000000000001"); |
|||
|
|||
}); |
|||
|
|||
it('should parse multiple methods', function () { |
|||
|
|||
// given
|
|||
var d = [{ |
|||
name: "test", |
|||
type: "function", |
|||
inputs: [{ type: "int" }], |
|||
outputs: [{ type: "int" }] |
|||
},{ |
|||
name: "test2", |
|||
type: "function", |
|||
inputs: [{ type: "bytes" }], |
|||
outputs: [{ type: "bytes" }] |
|||
}]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
//then
|
|||
assert.equal(parser.test(1), "0000000000000000000000000000000000000000000000000000000000000001"); |
|||
assert.equal( |
|||
parser.test2('hello'), |
|||
"000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000" |
|||
); |
|||
|
|||
}); |
|||
|
|||
it('should parse input array of ints', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: "int[]" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test([5, 6]), |
|||
"0000000000000000000000000000000000000000000000000000000000000002" + |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000006" |
|||
); |
|||
}); |
|||
|
|||
it('should parse an array followed by an int', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: "int[]" }, |
|||
{ type: "int" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test([5, 6], 3), |
|||
"0000000000000000000000000000000000000000000000000000000000000002" + |
|||
"0000000000000000000000000000000000000000000000000000000000000003" + |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000006" |
|||
); |
|||
}); |
|||
|
|||
it('should parse an int followed by an array', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: "int" }, |
|||
{ type: "int[]" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test(3, [5, 6]), |
|||
"0000000000000000000000000000000000000000000000000000000000000002" + |
|||
"0000000000000000000000000000000000000000000000000000000000000003" + |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000006" |
|||
); |
|||
}); |
|||
|
|||
it('should parse mixture of arrays and ints', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: "int" }, |
|||
{ type: "int[]" }, |
|||
{ type: "int" }, |
|||
{ type: "int[]" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test(3, [5, 6, 1, 2], 7, [8, 9]), |
|||
"0000000000000000000000000000000000000000000000000000000000000004" + |
|||
"0000000000000000000000000000000000000000000000000000000000000002" + |
|||
"0000000000000000000000000000000000000000000000000000000000000003" + |
|||
"0000000000000000000000000000000000000000000000000000000000000007" + |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000006" + |
|||
"0000000000000000000000000000000000000000000000000000000000000001" + |
|||
"0000000000000000000000000000000000000000000000000000000000000002" + |
|||
"0000000000000000000000000000000000000000000000000000000000000008" + |
|||
"0000000000000000000000000000000000000000000000000000000000000009" |
|||
); |
|||
}); |
|||
|
|||
it('should parse input real', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: 'real' } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.test(1), "0000000000000000000000000000000100000000000000000000000000000000"); |
|||
assert.equal(parser.test(2.125), "0000000000000000000000000000000220000000000000000000000000000000"); |
|||
assert.equal(parser.test(8.5), "0000000000000000000000000000000880000000000000000000000000000000"); |
|||
assert.equal(parser.test(-1), "ffffffffffffffffffffffffffffffff00000000000000000000000000000000"); |
|||
|
|||
}); |
|||
|
|||
it('should parse input ureal', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].inputs = [ |
|||
{ type: 'ureal' } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.test(1), "0000000000000000000000000000000100000000000000000000000000000000"); |
|||
assert.equal(parser.test(2.125), "0000000000000000000000000000000220000000000000000000000000000000"); |
|||
assert.equal(parser.test(8.5), "0000000000000000000000000000000880000000000000000000000000000000"); |
|||
|
|||
}); |
|||
|
|||
it('should throw an incorrect type error', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
d[0].inputs = [ |
|||
{ type: 'uin' } |
|||
] |
|||
|
|||
// when
|
|||
var parser = abi.inputParser(d); |
|||
|
|||
// then
|
|||
assert.throws(function () {parser.test('0x')}, Error); |
|||
|
|||
}); |
|||
|
|||
}); |
|||
}); |
@ -1,419 +0,0 @@ |
|||
var assert = require('assert'); |
|||
var BigNumber = require('bignumber.js'); |
|||
var abi = require('../lib/solidity/abi.js'); |
|||
var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; |
|||
|
|||
var description = [{ |
|||
"name": "test", |
|||
"type": "function", |
|||
"inputs": [{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
} |
|||
], |
|||
"outputs": [ |
|||
{ |
|||
"name": "d", |
|||
"type": "uint256" |
|||
} |
|||
] |
|||
}]; |
|||
|
|||
describe('lib/solidity/abi', function() { |
|||
describe('outputParser', function() { |
|||
it('should parse output fixed bytes type', function() { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].outputs = [ |
|||
{ type: "bytes" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test( |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"68656c6c6f000000000000000000000000000000000000000000000000000000")[0], |
|||
'hello' |
|||
); |
|||
assert.equal( |
|||
parser.test( |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"776f726c64000000000000000000000000000000000000000000000000000000")[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("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
|||
assert.equal( |
|||
parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), |
|||
new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) |
|||
); |
|||
assert.equal( |
|||
parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), |
|||
new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(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("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
|||
assert.equal( |
|||
parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), |
|||
new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) |
|||
); |
|||
assert.equal( |
|||
parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), |
|||
new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(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("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
|||
assert.equal( |
|||
parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), |
|||
new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) |
|||
); |
|||
assert.equal( |
|||
parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), |
|||
new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(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("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
|||
assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); |
|||
assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); |
|||
}); |
|||
|
|||
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("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
|||
assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); |
|||
assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); |
|||
}); |
|||
|
|||
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("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); |
|||
assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); |
|||
assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); |
|||
}); |
|||
|
|||
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("000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[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("0000000000000000000000000000000000000000000000000000000000000001")[0], true); |
|||
assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000000")[0], false); |
|||
|
|||
|
|||
}); |
|||
|
|||
it('should parse output real', function() { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].outputs = [ |
|||
{ type: 'real' } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.test("0000000000000000000000000000000100000000000000000000000000000000")[0], 1); |
|||
assert.equal(parser.test("0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); |
|||
assert.equal(parser.test("0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); |
|||
assert.equal(parser.test("ffffffffffffffffffffffffffffffff00000000000000000000000000000000")[0], -1); |
|||
|
|||
}); |
|||
|
|||
it('should parse output ureal', function() { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].outputs = [ |
|||
{ type: 'ureal' } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.test("0000000000000000000000000000000100000000000000000000000000000000")[0], 1); |
|||
assert.equal(parser.test("0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); |
|||
assert.equal(parser.test("0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); |
|||
|
|||
}); |
|||
|
|||
|
|||
it('should parse multiple output fixed bytes type', function() { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
|
|||
d[0].outputs = [ |
|||
{ type: "bytes" }, |
|||
{ type: "bytes" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.equal( |
|||
parser.test( |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"68656c6c6f000000000000000000000000000000000000000000000000000000" + |
|||
"776f726c64000000000000000000000000000000000000000000000000000000")[0], |
|||
'hello' |
|||
); |
|||
assert.equal( |
|||
parser.test( |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"68656c6c6f000000000000000000000000000000000000000000000000000000" + |
|||
"776f726c64000000000000000000000000000000000000000000000000000000")[1], |
|||
'world' |
|||
); |
|||
|
|||
}); |
|||
|
|||
it('should use proper method name', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
d[0].name = 'helloworld(int)'; |
|||
d[0].outputs = [ |
|||
{ type: "int" } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.helloworld("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
assert.equal(parser.helloworld['int']("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
|
|||
}); |
|||
|
|||
|
|||
it('should parse multiple methods', function () { |
|||
|
|||
// given
|
|||
var d = [{ |
|||
name: "test", |
|||
type: "function", |
|||
inputs: [{ type: "int" }], |
|||
outputs: [{ type: "int" }] |
|||
},{ |
|||
name: "test2", |
|||
type: "function", |
|||
inputs: [{ type: "bytes" }], |
|||
outputs: [{ type: "bytes" }] |
|||
}]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
//then
|
|||
assert.equal(parser.test("00000000000000000000000000000000000000000000000000000000000001")[0], 1); |
|||
assert.equal(parser.test2( |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"68656c6c6f000000000000000000000000000000000000000000000000000000")[0], |
|||
"hello" |
|||
); |
|||
|
|||
}); |
|||
|
|||
it('should parse output array', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
d[0].outputs = [ |
|||
{ type: 'int[]' } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.test( |
|||
"0000000000000000000000000000000000000000000000000000000000000002" + |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000006")[0][0], |
|||
5 |
|||
); |
|||
assert.equal(parser.test( |
|||
"0000000000000000000000000000000000000000000000000000000000000002" + |
|||
"0000000000000000000000000000000000000000000000000000000000000005" + |
|||
"0000000000000000000000000000000000000000000000000000000000000006")[0][1], |
|||
6 |
|||
); |
|||
|
|||
}); |
|||
|
|||
it('should parse 0x0 value', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
d[0].outputs = [ |
|||
{ type: 'int' } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.test("0x0")[0], 0); |
|||
|
|||
}); |
|||
|
|||
it('should parse 0x0 value', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
d[0].outputs = [ |
|||
{ type: 'uint' } |
|||
]; |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.equal(parser.test("0x0")[0], 0); |
|||
|
|||
}); |
|||
|
|||
it('should throw an incorrect type error', function () { |
|||
|
|||
// given
|
|||
var d = clone(description); |
|||
d[0].outputs = [ |
|||
{ type: 'uin' } |
|||
] |
|||
|
|||
// when
|
|||
var parser = abi.outputParser(d); |
|||
|
|||
// then
|
|||
assert.throws(function () {parser.test('0x')}, Error); |
|||
|
|||
}); |
|||
|
|||
}); |
|||
}); |
|||
|
@ -0,0 +1,38 @@ |
|||
var chai = require('chai'); |
|||
var assert = chai.assert; |
|||
var web3 = require('../index'); |
|||
var FakeHttpProvider = require('./helpers/FakeHttpProvider'); |
|||
|
|||
var method = 'hashrate'; |
|||
|
|||
var tests = [{ |
|||
result: '0x788a8', |
|||
formattedResult: 493736, |
|||
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.strictEqual(test.formattedResult, result); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
Loading…
Reference in new issue