fixed failing test

This commit is contained in:
debris 2015-10-15 14:46:47 +08:00
parent 8d3d59df26
commit 31bcdb4496
4 changed files with 54 additions and 48 deletions

View File

@ -54,7 +54,7 @@ var desc = [{
],
}];
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
describe('contract', function () {
describe('event', function () {
@ -72,10 +72,10 @@ describe('contract', function () {
assert.deepEqual(payload.params[0], {
topics: [
'0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000001234567890123456789012345678901234567891',
null
],
address: '0x1234567890123456789012345678901234567890'
address: '0x1234567890123456789012345678901234567891'
});
} else if (step === 1) {
step = 2;
@ -83,7 +83,7 @@ describe('contract', function () {
address: address,
topics: [
'0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000001234567890123456789012345678901234567891',
'0x0000000000000000000000000000000000000000000000000000000000000001'
],
number: 2,
@ -98,7 +98,7 @@ describe('contract', function () {
address: address,
topics: [
'0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000001234567890123456789012345678901234567891',
'0x0000000000000000000000000000000000000000000000000000000000000001'
],
number: 2,
@ -143,10 +143,10 @@ describe('contract', function () {
assert.deepEqual(payload.params[0], {
topics: [
'0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000001234567890123456789012345678901234567891',
null
],
address: '0x1234567890123456789012345678901234567890'
address: '0x1234567890123456789012345678901234567891'
});
} else if (step === 1) {
step = 2;
@ -154,7 +154,7 @@ describe('contract', function () {
address: address,
topics: [
'0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000001234567890123456789012345678901234567891',
'0x0000000000000000000000000000000000000000000000000000000000000001'
],
number: 2,
@ -169,7 +169,7 @@ describe('contract', function () {
address: address,
topics: [
'0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000001234567890123456789012345678901234567891',
'0x0000000000000000000000000000000000000000000000000000000000000001'
],
number: 2,
@ -212,7 +212,7 @@ describe('contract', function () {
assert.equal(payload.method, 'eth_newFilter');
assert.deepEqual(payload.params[0], {
topics: [],
address: '0x1234567890123456789012345678901234567890'
address: '0x1234567890123456789012345678901234567891'
});
} else if (step === 1) {
step = 2;
@ -220,7 +220,7 @@ describe('contract', function () {
address: address,
topics: [
'0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000001234567890123456789012345678901234567891',
'0x0000000000000000000000000000000000000000000000000000000000000001'
],
number: 2,
@ -235,7 +235,7 @@ describe('contract', function () {
address: address,
topics: [
'0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000001234567890123456789012345678901234567891',
'0x0000000000000000000000000000000000000000000000000000000000000001'
],
number: 2,
@ -271,12 +271,12 @@ describe('contract', function () {
var web3 = new Web3(provider);
provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
var signature = 'balance(address)'
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_call');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890',
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567891',
to: address
}, 'latest']);
});
@ -292,12 +292,12 @@ describe('contract', function () {
var web3 = new Web3(provider);
provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
var signature = 'balance(address)'
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_call');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890',
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567891',
to: address
}, '0xb']);
});
@ -312,12 +312,12 @@ describe('contract', function () {
var provider = new FakeHttpProvider();
var web3 = new Web3(provider);
var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_sendTransaction');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000001234567890123456789012345678901234567891' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
from: address,
to: address
@ -334,11 +334,11 @@ describe('contract', function () {
var web3 = new Web3(provider);
provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
var signature = 'balance(address)';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_call');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890',
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567891',
to: address,
from: address,
gas: '0xc350'
@ -357,11 +357,11 @@ describe('contract', function () {
var web3 = new Web3(provider);
provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
var signature = 'balance(address)';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_call');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890',
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567891',
to: address,
from: address,
gas: '0xc350'
@ -380,11 +380,11 @@ describe('contract', function () {
var web3 = new Web3(provider);
provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
var signature = 'balance(address)';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_call');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890',
data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567891',
to: address,
from: address,
gas: '0xc350'
@ -402,12 +402,12 @@ describe('contract', function () {
var provider = new FakeHttpProvider();
var web3 = new Web3(provider);
var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_sendTransaction');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000001234567890123456789012345678901234567891' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
to: address,
from: address,
@ -426,12 +426,12 @@ describe('contract', function () {
var provider = new FakeHttpProvider();
var web3 = new Web3(provider);
var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_sendTransaction');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000001234567890123456789012345678901234567891' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
to: address,
from: address,
@ -449,13 +449,13 @@ describe('contract', function () {
it('should explicitly sendTransaction with optional params and call callback without error', function (done) {
var provider = new FakeHttpProvider();
var web3 = new Web3(provider);
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
var signature = 'send(address,uint256)';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_sendTransaction');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000001234567890123456789012345678901234567891' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
to: address,
from: address,
@ -477,12 +477,12 @@ describe('contract', function () {
var provider = new FakeHttpProvider();
var web3 = new Web3(provider);
var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_estimateGas');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000001234567890123456789012345678901234567891' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
to: address,
from: address,
@ -501,7 +501,7 @@ describe('contract', function () {
var provider = new FakeHttpProvider2();
var web3 = new Web3(provider);
var signature = 'testArr(int[])';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectResultList([{
result: '0x0000000000000000000000000000000000000000000000000000000000000005'
}]);
@ -529,7 +529,7 @@ describe('contract', function () {
var provider = new FakeHttpProvider2();
var web3 = new Web3(provider);
var signature = 'testArr(int[])';
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567891';
provider.injectResultList([{
result: '0x0000000000000000000000000000000000000000000000000000000000000005'
}]);

View File

@ -3,7 +3,6 @@ var assert = chai.assert;
var BigNumber = require('bignumber.js');
var SolidityEvent = require('../lib/web3/event');
var Web3 = require('../index');
var web3 = new Web3();
var name = 'event1';
@ -172,6 +171,7 @@ describe('lib/web3/event', function () {
describe('decode', function () {
tests.forEach(function (test, index) {
it('test no: ' + index, function () {
var web3 = new Web3();
var event = new SolidityEvent(web3, test.abi, address);
var result = event.decode(test.data);

View File

@ -2,7 +2,7 @@ var chai = require('chai');
var assert = chai.assert;
var SolidityEvent = require('../lib/web3/event');
var Web3 = require('../index');
var web3 = new Web3();
var address = '0x1234567890123456789012345678901234567890';
var signature = '0xffff';
@ -222,6 +222,7 @@ describe('lib/web3/event', function () {
describe('encode', function () {
tests.forEach(function (test, index) {
it('test no: ' + index, function () {
var web3 = new Web3();
var event = new SolidityEvent(web3, test.abi, address);
event.signature = function () { // inject signature
return signature.slice(2);

View File

@ -1,7 +1,7 @@
var assert = require('assert');
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var Web3 = require('../index');
var web3 = new Web3();
describe('web3.eth.contract', function() {
it('should create simple contract with one method from abi with explicit type name', function () {
@ -22,9 +22,10 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567892';
// when
var web3 = new Web3();
var myCon = web3.eth.contract(description).at(address);
// then
@ -50,9 +51,10 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567892';
// when
var web3 = new Web3();
var myCon = web3.eth.contract(description).at(address);
// then
@ -92,9 +94,10 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567892';
// when
var web3 = new Web3();
var myCon = web3.eth.contract(description).at(address);
// then
@ -136,9 +139,10 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567892';
// when
var web3 = new Web3();
var myCon = web3.eth.contract(description).at(address);
// then
@ -164,9 +168,10 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567892';
// when
var web3 = new Web3();
var myCon = web3.eth.contract(description).at(address);
// then
@ -192,9 +197,10 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
var address = '0x1234567890123456789012345678901234567892';
// when
var web3 = new Web3();
var myCon = web3.eth.contract(description).at(address);
// then
@ -204,10 +210,9 @@ describe('web3.eth.contract', function() {
});
it('should create contract with nondefault constructor', function (done) {
web3.reset(); // reset different polls
var provider = new FakeHttpProvider();
web3.setProvider(provider);
var address = '0x1234567890123456789012345678901234567890';
var web3 = new Web3(provider);
var address = '0x1234567890123456789012345678901234567894';
var code = '0x31241231231123123123123121cf121212i123123123123123512312412512111111';
var description = [{
"name": "test",
@ -233,12 +238,12 @@ describe('web3.eth.contract', function() {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_newBlockFilter');
steps++;
done();
}
});
web3.eth.contract(description).new(2, {from: address, data: code}, function(e, myCon){
done();
web3.stopWatching();
});
});
});