Files
openzeppelin-contracts/test/helpers/sendTransaction.js
Aniket c25a1e366f Fix #1358 Test helper to send funds (#1367)
* signing prefix added

* Minor improvement

* Tests changed

* Successfully tested

* Minor improvements

* Minor improvements

* Revert "Dangling commas are now required. (#1359)"

This reverts commit a6889776f4.

* fixes #1358

* linting done

* suggested changes

(cherry picked from commit fa1dfbd113)
2018-10-20 21:29:21 +00:00

31 lines
774 B
JavaScript

const ethjsABI = require('ethjs-abi');
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];
}
}
}
function sendTransaction (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 sendEther (from, to, value) {
web3.eth.sendTransaction({
from: from,
to: to,
value: value,
gasPrice: 0,
});
}
module.exports = {
findMethod,
sendTransaction,
sendEther,
};