Commit 381b0e3b authored by aniket-engg's avatar aniket-engg Committed by Aniket

dependency on constant field of ABI removed

parent 10fd7a32
...@@ -44,7 +44,7 @@ var basicRegex = { ...@@ -44,7 +44,7 @@ var basicRegex = {
CONTRACTTYPE: '^contract ', CONTRACTTYPE: '^contract ',
FUNCTIONTYPE: '^function \\(', FUNCTIONTYPE: '^function \\(',
EXTERNALFUNCTIONTYPE: '^function \\(.*\\).* external', EXTERNALFUNCTIONTYPE: '^function \\(.*\\).* external',
CONSTANTFUNCTIONTYPE: '^function \\(.*\\).* (constant|view|pure)', CONSTANTFUNCTIONTYPE: '^function \\(.*\\).* (view|pure)',
REFTYPE: '( storage )|(mapping\\()|(\\[\\])', REFTYPE: '( storage )|(mapping\\()|(\\[\\])',
FUNCTIONSIGNATURE: '^function \\(([^\\(]*)\\)', FUNCTIONSIGNATURE: '^function \\(([^\\(]*)\\)',
LIBRARYTYPE: '^type\\(library (.*)\\)' LIBRARYTYPE: '^type\\(library (.*)\\)'
...@@ -664,7 +664,6 @@ function isStateVariable (name, stateVariables) { ...@@ -664,7 +664,6 @@ function isStateVariable (name, stateVariables) {
*/ */
function isConstantFunction (node) { function isConstantFunction (node) {
return isFunctionDefinition(node) && ( return isFunctionDefinition(node) && (
node.attributes.constant === true ||
node.attributes.stateMutability === 'view' || node.attributes.stateMutability === 'view' ||
node.attributes.stateMutability === 'pure' node.attributes.stateMutability === 'pure'
) )
......
...@@ -43,7 +43,8 @@ module.exports = { ...@@ -43,7 +43,8 @@ module.exports = {
* @param {Function} finalCallback - last callback. * @param {Function} finalCallback - last callback.
*/ */
callFunction: function (from, to, data, value, gasLimit, funAbi, txRunner, callbacks, finalCallback) { callFunction: function (from, to, data, value, gasLimit, funAbi, txRunner, callbacks, finalCallback) {
var tx = { from: from, to: to, data: data, useCall: funAbi.constant, value: value, gasLimit: gasLimit } const isCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure'
var tx = { from: from, to: to, data: data, useCall: isCall, value: value, gasLimit: gasLimit }
txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => { txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case) // see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
finalCallback(error, txResult) finalCallback(error, txResult)
......
...@@ -44,10 +44,15 @@ module.exports = { ...@@ -44,10 +44,15 @@ module.exports = {
// Sorts the list of ABI entries. Constant functions will appear first, // Sorts the list of ABI entries. Constant functions will appear first,
// followed by non-constant functions. Within those t wo groupings, functions // followed by non-constant functions. Within those t wo groupings, functions
// will be sorted by their names. // will be sorted by their names.
function isConstant (funcABI) {
return (funcABI.stateMutability === 'view' || funcABI.stateMutability === 'pure')
}
return contractabi.sort(function (a, b) { return contractabi.sort(function (a, b) {
if (a.constant === true && b.constant !== true) { if (isConstant(a) && !isConstant(b)) {
return 1 return 1
} else if (b.constant === true && a.constant !== true) { } else if (isConstant(b) && !isConstant(a)) {
return -1 return -1
} }
// If we reach here, either a and b are both constant or both not; sort by name then // If we reach here, either a and b are both constant or both not; sort by name then
......
...@@ -232,7 +232,8 @@ module.exports = class UniversalDApp { ...@@ -232,7 +232,8 @@ module.exports = class UniversalDApp {
* @param {Function} callback - callback. * @param {Function} callback - callback.
*/ */
callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) { callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) {
this.runTx({to: to, data: data, useCall: funAbi.constant}, confirmationCb, continueCb, promptCb, (error, txResult) => { const isCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure'
this.runTx({to: to, data: data, useCall: isCall}, confirmationCb, continueCb, promptCb, (error, txResult) => {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case) // see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
callback(error, txResult) callback(error, txResult)
}) })
......
...@@ -13,6 +13,10 @@ function getFunctionFullName (signature: string, methodIdentifiers: Record <stri ...@@ -13,6 +13,10 @@ function getFunctionFullName (signature: string, methodIdentifiers: Record <stri
return null return null
} }
function isConstant(funcABI: FunctionDescription): boolean {
return (funcABI.stateMutability === 'view' || funcABI.stateMutability === 'pure')
}
function getOverridedSender (userdoc: UserDocumentation, signature: string, methodIdentifiers: Record <string, string>) { function getOverridedSender (userdoc: UserDocumentation, signature: string, methodIdentifiers: Record <string, string>) {
let fullName: any = getFunctionFullName(signature, methodIdentifiers) let fullName: any = getFunctionFullName(signature, methodIdentifiers)
let match: RegExp = /sender: account-+(\d)/g let match: RegExp = /sender: account-+(\d)/g
...@@ -77,7 +81,7 @@ function createRunList (jsonInterface: FunctionDescription[], fileAST: AstNode, ...@@ -77,7 +81,7 @@ function createRunList (jsonInterface: FunctionDescription[], fileAST: AstNode,
if (availableFunctions.indexOf('beforeEach') >= 0) { if (availableFunctions.indexOf('beforeEach') >= 0) {
runList.push({ name: 'beforeEach', type: 'internal', constant: false }) runList.push({ name: 'beforeEach', type: 'internal', constant: false })
} }
runList.push({ name: func.name, signature: func.signature, type: 'test', constant: func.constant }) runList.push({ name: func.name, signature: func.signature, type: 'test', constant: isConstant(func) })
if (availableFunctions.indexOf('afterEach') >= 0) { if (availableFunctions.indexOf('afterEach') >= 0) {
runList.push({ name: 'afterEach', type: 'internal', constant: false }) runList.push({ name: 'afterEach', type: 'internal', constant: false })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment