add sha3 test

This commit is contained in:
Fabian Vogelsteller 2015-03-24 11:53:21 +01:00
parent afd7e7ba32
commit b247c49511
3 changed files with 30 additions and 10 deletions

View File

@ -43,8 +43,7 @@ var web3Methods = function () {
var sha3 = new Method({
name: 'sha3',
call: 'web3_sha3',
params: 1,
inputFormatter:[utils.toHex]
params: 1
});
return [sha3];

View File

@ -20,8 +20,10 @@ var runTests = function (obj, method, tests) {
assert.deepEqual(payload.params, test.formattedArgs);
});
// when
var result = web3[obj][method].apply(null, test.args.slice(0));
// when
var result = (obj)
? web3[obj][method].apply(null, test.args.slice(0))
: web3[method].apply(null, test.args.slice(0));
// then
assert.deepEqual(test.formattedResult, result);
@ -38,16 +40,19 @@ var runTests = function (obj, method, tests) {
assert.equal(payload.method, test.call);
assert.deepEqual(payload.params, test.formattedArgs);
});
var callback = function (err, result) {
assert.deepEqual(test.formattedResult, result);
done();
};
var args = test.args.slice(0);
args.push(callback);
// add callback
args.push(function (err, result) {
assert.deepEqual(test.formattedResult, result);
done();
});
// when
web3[obj][method].apply(null, args);
if(obj)
web3[obj][method].apply(null, args);
else
web3[method].apply(null, args);
});
});
});

16
test/web3.sha3.js Normal file
View File

@ -0,0 +1,16 @@
var BigNumber = require('bignumber.js');
var web3 = require('../index');
var testMethod = require('./helpers/test.method.js');
var method = 'sha3';
var tests = [{
args: ['myString'],
formattedArgs: ['myString'],
result: '0x319319f831983198319881',
formattedResult: '0x319319f831983198319881',
call: 'web3_'+ method
}];
testMethod.runTests(null, method, tests);