Updated sendTransaction, added tests. (#1528)
* Renamed sendTransaction to send, improved API. * Added send tests. * Now using promisified web3
This commit is contained in:
26
test/helpers/send.js
Normal file
26
test/helpers/send.js
Normal 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,
|
||||
};
|
||||
Reference in New Issue
Block a user