Browse Source
Conflicts: libjsqrc/ethereumjs/dist/ethereum.js.map libjsqrc/ethereumjs/dist/ethereum.min.jscl-refactor
Marek Kotewicz
10 years ago
13 changed files with 555 additions and 247 deletions
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,66 @@ |
|||
<!doctype> |
|||
<html> |
|||
<head> |
|||
<script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script> |
|||
<script type="text/javascript" src="../dist/ethereum.js"></script> |
|||
<script type="text/javascript"> |
|||
var web3 = require('web3'); |
|||
web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080')); |
|||
|
|||
var source = "" + |
|||
"contract Contract { " + |
|||
" event Incremented(bool indexed odd, uint x); " + |
|||
" function Contract() { " + |
|||
" x = 69; " + |
|||
" } " + |
|||
" function inc() { " + |
|||
" ++x; " + |
|||
" Incremented(x % 2 == 1, x); " + |
|||
" } " + |
|||
" uint x; " + |
|||
"}"; |
|||
|
|||
var desc = [{ |
|||
"type":"event", |
|||
"name":"Incremented", |
|||
"inputs": [{"name":"odd","type":"bool","indexed":true},{"name":"x","type":"uint","indexed":false}], |
|||
}, { |
|||
"type":"function", |
|||
"name":"inc", |
|||
"inputs": [], |
|||
"outputs": [] |
|||
}]; |
|||
|
|||
var address; |
|||
var contract; |
|||
|
|||
var update = function (x) { |
|||
document.getElementById('result').innerText = JSON.stringify(x); |
|||
}; |
|||
|
|||
var createContract = function () { |
|||
address = web3.eth.transact({code: web3.eth.solidity(source)}); |
|||
contract = web3.eth.contract(address, desc); |
|||
contract.Incremented({odd: true}).changed(update); |
|||
|
|||
}; |
|||
|
|||
var callContract = function () { |
|||
contract.call().inc(); |
|||
}; |
|||
|
|||
|
|||
</script> |
|||
</head> |
|||
|
|||
<body> |
|||
<div> |
|||
<button type="button" onClick="createContract();">create contract</button> |
|||
</div> |
|||
<div> |
|||
<button type="button" onClick="callContract();">test1</button> |
|||
</div> |
|||
<div id="result"> |
|||
</div> |
|||
</body> |
|||
</html> |
@ -0,0 +1,125 @@ |
|||
var assert = require('assert'); |
|||
var event = require('../lib/event.js'); |
|||
var f = require('../lib/formatters.js'); |
|||
|
|||
describe('event', function () { |
|||
describe('inputParser', function () { |
|||
it('should create basic filter input object', function () { |
|||
|
|||
// given
|
|||
var address = '0x012345'; |
|||
var signature = '0x987654'; |
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event.inputParser(address, signature, e); |
|||
var result = impl(); |
|||
|
|||
// then
|
|||
assert.equal(result.address, address); |
|||
assert.equal(result.topic.length, 1); |
|||
assert.equal(result.topic[0], signature); |
|||
|
|||
}); |
|||
|
|||
it('should create filter input object with options', function () { |
|||
|
|||
// given
|
|||
var address = '0x012345'; |
|||
var signature = '0x987654'; |
|||
var options = { |
|||
earliest: 1, |
|||
latest: 2, |
|||
offset: 3, |
|||
max: 4 |
|||
}; |
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event.inputParser(address, signature, e); |
|||
var result = impl({}, options); |
|||
|
|||
// then
|
|||
assert.equal(result.address, address); |
|||
assert.equal(result.topic.length, 1); |
|||
assert.equal(result.topic[0], signature); |
|||
assert.equal(result.earliest, options.earliest); |
|||
assert.equal(result.latest, options.latest); |
|||
assert.equal(result.offset, options.offset); |
|||
assert.equal(result.max, options.max); |
|||
|
|||
}); |
|||
|
|||
it('should create filter input object with indexed params', function () { |
|||
|
|||
// given
|
|||
var address = '0x012345'; |
|||
var signature = '0x987654'; |
|||
var options = { |
|||
earliest: 1, |
|||
latest: 2, |
|||
offset: 3, |
|||
max: 4 |
|||
}; |
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event.inputParser(address, signature, e); |
|||
var result = impl({a: 4}, options); |
|||
|
|||
// then
|
|||
assert.equal(result.address, address); |
|||
assert.equal(result.topic.length, 2); |
|||
assert.equal(result.topic[0], signature); |
|||
assert.equal(result.topic[1], f.formatInputInt(4)); |
|||
assert.equal(result.earliest, options.earliest); |
|||
assert.equal(result.latest, options.latest); |
|||
assert.equal(result.offset, options.offset); |
|||
assert.equal(result.max, options.max); |
|||
|
|||
}); |
|||
|
|||
it('should create filter input object with an array of indexed params', function () { |
|||
|
|||
// given
|
|||
var address = '0x012345'; |
|||
var signature = '0x987654'; |
|||
var options = { |
|||
earliest: 1, |
|||
latest: 2, |
|||
offset: 3, |
|||
max: 4 |
|||
}; |
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event.inputParser(address, signature, e); |
|||
var result = impl({a: [4, 69]}, options); |
|||
|
|||
// then
|
|||
assert.equal(result.address, address); |
|||
assert.equal(result.topic.length, 2); |
|||
assert.equal(result.topic[0], signature); |
|||
assert.equal(result.topic[1][0], f.formatInputInt(4)); |
|||
assert.equal(result.topic[1][1], f.formatInputInt(69)); |
|||
assert.equal(result.earliest, options.earliest); |
|||
assert.equal(result.latest, options.latest); |
|||
assert.equal(result.offset, options.offset); |
|||
assert.equal(result.max, options.max); |
|||
|
|||
}); |
|||
}); |
|||
}); |
|||
|
@ -1,124 +0,0 @@ |
|||
var assert = require('assert'); |
|||
var event = require('../lib/event.js'); |
|||
var f = require('../lib/formatters.js'); |
|||
|
|||
describe('event', function () { |
|||
it('should create basic filter input object', function () { |
|||
|
|||
// given
|
|||
var address = '0x012345'; |
|||
var signature = '0x987654'; |
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event(address, signature, e); |
|||
var result = impl(); |
|||
|
|||
// then
|
|||
assert.equal(result.address, address); |
|||
assert.equal(result.topic.length, 1); |
|||
assert.equal(result.topic[0], signature); |
|||
|
|||
}); |
|||
|
|||
it('should create filter input object with options', function () { |
|||
|
|||
// given
|
|||
var address = '0x012345'; |
|||
var signature = '0x987654'; |
|||
var options = { |
|||
earliest: 1, |
|||
latest: 2, |
|||
offset: 3, |
|||
max: 4 |
|||
}; |
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event(address, signature, e); |
|||
var result = impl({}, options); |
|||
|
|||
// then
|
|||
assert.equal(result.address, address); |
|||
assert.equal(result.topic.length, 1); |
|||
assert.equal(result.topic[0], signature); |
|||
assert.equal(result.earliest, options.earliest); |
|||
assert.equal(result.latest, options.latest); |
|||
assert.equal(result.offset, options.offset); |
|||
assert.equal(result.max, options.max); |
|||
|
|||
}); |
|||
|
|||
it('should create filter input object with indexed params', function () { |
|||
|
|||
// given
|
|||
var address = '0x012345'; |
|||
var signature = '0x987654'; |
|||
var options = { |
|||
earliest: 1, |
|||
latest: 2, |
|||
offset: 3, |
|||
max: 4 |
|||
}; |
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event(address, signature, e); |
|||
var result = impl({a: 4}, options); |
|||
|
|||
// then
|
|||
assert.equal(result.address, address); |
|||
assert.equal(result.topic.length, 2); |
|||
assert.equal(result.topic[0], signature); |
|||
assert.equal(result.topic[1], f.formatInputInt(4)); |
|||
assert.equal(result.earliest, options.earliest); |
|||
assert.equal(result.latest, options.latest); |
|||
assert.equal(result.offset, options.offset); |
|||
assert.equal(result.max, options.max); |
|||
|
|||
}); |
|||
|
|||
it('should create filter input object with an array of indexed params', function () { |
|||
|
|||
// given
|
|||
var address = '0x012345'; |
|||
var signature = '0x987654'; |
|||
var options = { |
|||
earliest: 1, |
|||
latest: 2, |
|||
offset: 3, |
|||
max: 4 |
|||
}; |
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event(address, signature, e); |
|||
var result = impl({a: [4, 69]}, options); |
|||
|
|||
// then
|
|||
assert.equal(result.address, address); |
|||
assert.equal(result.topic.length, 2); |
|||
assert.equal(result.topic[0], signature); |
|||
assert.equal(result.topic[1][0], f.formatInputInt(4)); |
|||
assert.equal(result.topic[1][1], f.formatInputInt(69)); |
|||
assert.equal(result.earliest, options.earliest); |
|||
assert.equal(result.latest, options.latest); |
|||
assert.equal(result.offset, options.offset); |
|||
assert.equal(result.max, options.max); |
|||
|
|||
}); |
|||
|
|||
}); |
|||
|
@ -0,0 +1,81 @@ |
|||
var assert = require('assert'); |
|||
var event = require('../lib/event.js'); |
|||
|
|||
describe('event', function () { |
|||
describe('outputParser', function () { |
|||
it('should parse basic event output object', function () { |
|||
|
|||
// given
|
|||
var output = { |
|||
"address":"0x78dfc5983baecf65f73e3de3a96cee24e6b7981e", |
|||
"data":"0x000000000000000000000000000000000000000000000000000000000000004b", |
|||
"number":2, |
|||
"topic":[ |
|||
"0x6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad", |
|||
"0x0000000000000000000000000000000000000000000000000000000000000001" |
|||
] |
|||
}; |
|||
|
|||
var e = { |
|||
name: 'Event', |
|||
inputs: [{"name":"a","type":"bool","indexed":true},{"name":"b","type":"uint256","indexed":false}] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event.outputParser(e); |
|||
var result = impl(output); |
|||
|
|||
// then
|
|||
assert.equal(result.event, 'Event'); |
|||
assert.equal(result.number, 2); |
|||
assert.equal(Object.keys(result.args).length, 2); |
|||
assert.equal(result.args.a, true); |
|||
assert.equal(result.args.b, 75); |
|||
}); |
|||
|
|||
it('should parse event output object arguments in correct order', function () { |
|||
|
|||
// given
|
|||
var output = { |
|||
"address":"0x78dfc5983baecf65f73e3de3a96cee24e6b7981e", |
|||
"data": "0x" + |
|||
"000000000000000000000000000000000000000000000000000000000000004b" + |
|||
"000000000000000000000000000000000000000000000000000000000000004c" + |
|||
"0000000000000000000000000000000000000000000000000000000000000001", |
|||
"number":3, |
|||
"topic":[ |
|||
"0x6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad", |
|||
"0x0000000000000000000000000000000000000000000000000000000000000001", |
|||
"0x0000000000000000000000000000000000000000000000000000000000000005" |
|||
] |
|||
}; |
|||
|
|||
var e = { |
|||
name: 'Event2', |
|||
inputs: [ |
|||
{"name":"a","type":"bool","indexed":true}, |
|||
{"name":"b","type":"int","indexed":false}, |
|||
{"name":"c","type":"int","indexed":false}, |
|||
{"name":"d","type":"int","indexed":true}, |
|||
{"name":"e","type":"bool","indexed":false} |
|||
] |
|||
}; |
|||
|
|||
// when
|
|||
var impl = event.outputParser(e); |
|||
var result = impl(output); |
|||
|
|||
// then
|
|||
assert.equal(result.event, 'Event2'); |
|||
assert.equal(result.number, 3); |
|||
assert.equal(Object.keys(result.args).length, 5); |
|||
assert.equal(result.args.a, true); |
|||
assert.equal(result.args.b, 75); |
|||
assert.equal(result.args.c, 76); |
|||
assert.equal(result.args.d, 5); |
|||
assert.equal(result.args.e, true); |
|||
|
|||
}); |
|||
}); |
|||
}); |
|||
|
Loading…
Reference in new issue