Updated sendTransaction, added tests. (#1528)

* Renamed sendTransaction to send, improved API.

* Added send tests.

* Now using promisified web3
This commit is contained in:
Nicolás Venturo
2018-12-01 02:47:32 -03:00
committed by GitHub
parent 88e8c7c94b
commit c0bda4db88
7 changed files with 107 additions and 22 deletions

26
test/helpers/send.js Normal file
View File

@ -0,0 +1,26 @@
const ethjsABI = require('ethjs-abi');
const { ethSendTransaction } = require('./web3');
function findMethod (abi, name, args) {
for (let i = 0; i < abi.length; i++) {
const methodArgs = abi[i].inputs.map(input => input.type).join(',');
if ((abi[i].name === name) && (methodArgs === args)) {
return abi[i];
}
}
}
async function transaction (target, name, argsTypes, argsValues, opts) {
const abiMethod = findMethod(target.abi, name, argsTypes);
const encodedData = ethjsABI.encodeMethod(abiMethod, argsValues);
return target.sendTransaction(Object.assign({ data: encodedData }, opts));
}
function ether (from, to, value) {
return ethSendTransaction({ from, to, value, gasPrice: 0 });
}
module.exports = {
ether,
transaction,
};