solidity/web3.eth.contract.js
Marek Kotewicz 710a1463c1 Squashed 'libjsqrc/ethereumjs/' changes from e908439..16861fc
16861fc version 0.4.2
e4f7dde fixed failing lint
69e7d9d fixed #133
55553d7 add async error test
d02a375 Merge branch 'develop' of github.com:ethereum/web3.js into develop
ff48da1 fixed callback error issue
471bce1 #133 in progress
dc69085 version 0.4.1
2ae0afa critical bugfix
09f2a92 updated examples
a0a36e5 Merge branch 'develop' of https://github.com/ethereum/ethereum.js into develop
2b179a8 updated node install test
8f63640 Merge pull request #203 from frozeman/develop
22ef4a1 added estimateGas method
cd2e462 version 0.4.0
ae7762a Merge pull request #198 from ethereum/minerMethods
d1e1206 removed byte formatter methods
6fd17d9 merged develop
373fd1b Merge pull request #201 from debris/batch
274fc29 Merge pull request #200 from debris/contract_overhaul
b2ff2ff Merge branch 'contract_overhaul' into batch
99a3bda removed redundant lines
7cafac9 Merge branch 'develop' into contract_overhaul
fa8db32 Merge pull request #202 from debris/async_properties
5f9272c asyncGet -> getAsync
cd0df61 gulp
80c0792 async getting properties, remove property setters
744bb9e batch for requests with calls/transacts
8636077 initial support for batch requests
a0b9cfb contract async call && transact
1272780 sendTransaction && call async
6afb1f9 Merge branch 'async-contract-calls' of https://github.com/niran/web3.js into contract_overhaul
611f640 asynchronous contract creation, breaking changes
e3796bf merged develop
edf808a add getWork and submitWork functions and toXBytes utils
9812b01 Merge branch 'blockFilterProposal' of https://github.com/ethereum/ethereum.js into develop
6f466f6 add miner functions
3af8e27 add newblockfilter Proposal
e86552f Use async contract calls when a callback is passed

git-subtree-dir: libjsqrc/ethereumjs
git-subtree-split: 16861fc1944cca721672bb8faa81909d69be2b99
2015-05-14 14:05:30 +02:00

234 lines
6.3 KiB
JavaScript

var assert = require('assert');
var contract = require('../lib/web3/contract.js');
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var web3 = require('../index');
describe('web3.eth.contract', function() {
it('should create simple contract with one method from abi with explicit type name', function () {
// given
var description = [{
"name": "test(uint256)",
"type": "function",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var myCon = contract(description).at(address);
// then
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
});
it('should create simple contract with one method from abi with implicit type name', function () {
// given
var description = [{
"name": "test",
"type": "function",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var myCon = contract(description).at(address);
// then
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
});
it('should create contract with multiple methods', function () {
// given
var description = [{
"name": "test",
"type": "function",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
],
}, {
"name": "test2",
"type": "function",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var myCon = contract(description).at(address);
// then
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
assert.equal('function', typeof myCon.test2);
assert.equal('function', typeof myCon.test2['uint256']);
});
it('should create contract with overloaded methods', function () {
// given
var description = [{
"name": "test",
"type": "function",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
],
}, {
"name": "test",
"type": "function",
"inputs": [{
"name": "a",
"type": "string"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var myCon = contract(description).at(address);
// then
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
assert.equal('function', typeof myCon.test['string']);
});
it('should create contract with no methods', function () {
// given
var description = [{
"name": "test(uint256)",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var myCon = contract(description).at(address);
// then
assert.equal('undefined', typeof myCon.test);
});
it('should create contract with one event', function () {
// given
var description = [{
"name": "test",
"type": "event",
"inputs": [{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var myCon = contract(description).at(address);
// then
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
});
it('should create contract with nondefault constructor', function (done) {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset(); // reset different polls
var address = '0x1234567890123456789012345678901234567890';
var code = '0x31241231231123123123123121cf121212i123123123123123512312412512111111';
var description = [{
"name": "test",
"type": "constructor",
"inputs": [{
"name": "a",
"type": "uint256"
}
]
}];
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();
});
var myCon = contract(description).new(2, {data: code});
});
});