Browse Source
3b799d1 fixed typos c5f6379 version 0.3.3 d795d36 fixed trimming call output prefix a2f561f fixed calling contract only with array param 4912ec6 tests for decoding solidity params 2b4fd21 solidity param encoding tests git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: 3b799d128452639463424c657956ee90a28daec6cl-refactor
Marek Kotewicz
10 years ago
16 changed files with 247 additions and 48 deletions
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.2" |
|||
"version": "0.3.3" |
|||
} |
|||
|
@ -1,23 +1,68 @@ |
|||
var chai = require('chai'); |
|||
var assert = chai.assert; |
|||
var coder = require('../lib/solidity/coder'); |
|||
var BigNumber = require('bignumber.js'); |
|||
var bn = BigNumber; |
|||
|
|||
var tests = [ |
|||
{ type: 'int', value: '0000000000000000000000000000000000000000000000000000000000000001', expected: 1}, |
|||
{ type: 'int', value: '0000000000000000000000000000000000000000000000000000000000000010', expected: 16}, |
|||
{ type: 'int', value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: -1}, |
|||
{ type: 'bytes32', value: '6761766f66796f726b0000000000000000000000000000000000000000000000', expected: 'gavofyork'}, |
|||
{ type: 'bytes', value: '0000000000000000000000000000000000000000000000000000000000000009' + |
|||
'6761766f66796f726b0000000000000000000000000000000000000000000000', expected: 'gavofyork'} |
|||
]; |
|||
|
|||
describe('lib/solidity/coder', function () { |
|||
describe('decodeParam', function () { |
|||
tests.forEach(function (test) { |
|||
it('should turn ' + test.value + ' to ' + test.expected, function () { |
|||
assert.equal(coder.decodeParam(test.type, test.value), test.expected); |
|||
var test = function (t) { |
|||
it('should turn ' + t.value + ' to ' + t.expected, function () { |
|||
assert.deepEqual(coder.decodeParam(t.type, t.value), t.expected); |
|||
}); |
|||
}); |
|||
}; |
|||
|
|||
|
|||
test({ type: 'int', expected: new bn(1), value: '0000000000000000000000000000000000000000000000000000000000000001'}); |
|||
test({ type: 'int', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'}); |
|||
test({ type: 'int', expected: new bn(-1), value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}); |
|||
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: '0000000000000000000000000000000000000000000000000000000000000009' + |
|||
'6761766f66796f726b0000000000000000000000000000000000000000000000'}); |
|||
test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000001' + |
|||
'0000000000000000000000000000000000000000000000000000000000000003'}); |
|||
test({ type: 'int256[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000001' + |
|||
'0000000000000000000000000000000000000000000000000000000000000003'}); |
|||
test({ type: 'int[]', expected: [new bn(1), new bn(2), new bn(3)], |
|||
value: '0000000000000000000000000000000000000000000000000000000000000003' + |
|||
'0000000000000000000000000000000000000000000000000000000000000001' + |
|||
'0000000000000000000000000000000000000000000000000000000000000002' + |
|||
'0000000000000000000000000000000000000000000000000000000000000003'}); |
|||
}); |
|||
}); |
|||
|
|||
describe('lib/solidity/coder', function () { |
|||
describe('decodeParams', function () { |
|||
var test = function (t) { |
|||
it('should turn ' + t.values + ' to ' + t.expected, function () { |
|||
assert.deepEqual(coder.decodeParams(t.types, t.values), t.expected); |
|||
}); |
|||
}; |
|||
|
|||
|
|||
test({ types: ['int'], expected: [new bn(1)], values: '0000000000000000000000000000000000000000000000000000000000000001'}); |
|||
test({ types: ['bytes32', 'int'], expected: ['gavofyork', new bn(5)], |
|||
values: '6761766f66796f726b0000000000000000000000000000000000000000000000' + |
|||
'0000000000000000000000000000000000000000000000000000000000000005'}); |
|||
test({ types: ['int', 'bytes32'], expected: [new bn(5), 'gavofyork'], |
|||
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), |
|||
[new bn(5), new bn(6), new bn(7)]], |
|||
values: '0000000000000000000000000000000000000000000000000000000000000009' + |
|||
'0000000000000000000000000000000000000000000000000000000000000003' + |
|||
'0000000000000000000000000000000000000000000000000000000000000001' + |
|||
'0000000000000000000000000000000000000000000000000000000000000002' + |
|||
'0000000000000000000000000000000000000000000000000000000000000003' + |
|||
'0000000000000000000000000000000000000000000000000000000000000004' + |
|||
'6761766f66796f726b0000000000000000000000000000000000000000000000' + |
|||
'0000000000000000000000000000000000000000000000000000000000000005' + |
|||
'0000000000000000000000000000000000000000000000000000000000000006' + |
|||
'0000000000000000000000000000000000000000000000000000000000000007'}); |
|||
}); |
|||
}); |
|||
|
|||
|
@ -0,0 +1,27 @@ |
|||
var FakeHttpProvider = require('./FakeHttpProvider'); |
|||
|
|||
var FakeHttpProvider2 = function () { |
|||
this.counter = 0; |
|||
this.resultList = []; |
|||
}; |
|||
|
|||
FakeHttpProvider2.prototype = new FakeHttpProvider(); |
|||
FakeHttpProvider2.prototype.constructor = FakeHttpProvider2; |
|||
|
|||
FakeHttpProvider2.prototype.injectResultList = function (list) { |
|||
this.resultList = list; |
|||
}; |
|||
|
|||
FakeHttpProvider2.prototype.getResponse = function () { |
|||
var result = this.resultList[this.counter]; |
|||
this.counter++; |
|||
if (result.type === 'batch') { |
|||
this.injectBatchResults(result.result); |
|||
} else { |
|||
this.injectResult(result.result); |
|||
} |
|||
return this.response; |
|||
}; |
|||
|
|||
module.exports = FakeHttpProvider2; |
|||
|
Loading…
Reference in new issue