unit test for bytes array and no params

pull/5370/head
aniket-engg 5 years ago
parent d865f00404
commit 219a83bf06
  1. 4
      remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts
  2. 8
      remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
  3. 1
      remix-analyzer/src/types.ts
  4. 88
      remix-analyzer/test/analysis/astBlocks/funcDefForComplexParams.json
  5. 6
      remix-analyzer/test/analysis/staticAnalysisCommon-test.ts

@ -1,6 +1,6 @@
import { default as category } from './categories'
import { default as algorithm } from './algorithmCategories'
import { getFunctionDefinitionName, helpers, isVariableTurnedIntoGetter, getSplittedTypeDesc } from './staticAnalysisCommon'
import { getFunctionDefinitionName, helpers, isVariableTurnedIntoGetter, getMethodParamsSplittedTypeDesc } from './staticAnalysisCommon'
import { ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, CompiledContract, AnalyzerModule,
FunctionDefinitionAstNode, VariableDeclarationAstNode } from './../../types'
@ -23,7 +23,7 @@ export default class gasCosts implements AnalyzerModule {
let signature: string;
if(node.nodeType === 'FunctionDefinition'){
const functionName: string = getFunctionDefinitionName(node)
signature = helpers.buildAbiSignature(functionName, getSplittedTypeDesc(node, compilationResults.contracts))
signature = helpers.buildAbiSignature(functionName, getMethodParamsSplittedTypeDesc(node, compilationResults.contracts))
}
else
signature = node.name + '()'

@ -3,7 +3,7 @@
import { FunctionDefinitionAstNode, ModifierDefinitionAstNode, ParameterListAstNode, ForStatementAstNode,
WhileStatementAstNode, VariableDeclarationAstNode, ContractDefinitionAstNode, InheritanceSpecifierAstNode,
MemberAccessAstNode, BinaryOperationAstNode, FunctionCallAstNode, ExpressionStatementAstNode, UnaryOperationAstNode,
IdentifierAstNode, IndexAccessAstNode, BlockAstNode, AssignmentAstNode, InlineAssemblyAstNode, IfStatementAstNode, CompiledContractObj } from "types"
IdentifierAstNode, IndexAccessAstNode, BlockAstNode, AssignmentAstNode, InlineAssemblyAstNode, IfStatementAstNode, CompiledContractObj, ABIParameter } from "types"
import { util } from 'remix-lib'
type SpecialObjDetail = {
@ -1079,7 +1079,7 @@ function buildAbiSignature (funName: string, paramTypes: any[]): string {
// To create the method signature similar to contract.evm.gasEstimates.external object
// For address payable, return address
function getSplittedTypeDesc(node: FunctionDefinitionAstNode, contracts: CompiledContractObj): string[] {
function getMethodParamsSplittedTypeDesc(node: FunctionDefinitionAstNode, contracts: CompiledContractObj): string[] {
return node.parameters.parameters.map((varNode, varIndex) => {
let finalTypeString;
const typeString = varNode.typeDescriptions.typeString
@ -1104,7 +1104,7 @@ function buildAbiSignature (funName: string, paramTypes: any[]): string {
})
}
function getTypeStringFromComponents(components: any[]) {
function getTypeStringFromComponents(components: ABIParameter[]) {
let typeString = '('
for(var i=0; i < components.length; i++) {
const param = components[i]
@ -1157,7 +1157,7 @@ export {
getFunctionOrModifierDefinitionParameterPart,
getFunctionDefinitionReturnParameterPart,
getUnAssignedTopLevelBinOps,
getSplittedTypeDesc,
getMethodParamsSplittedTypeDesc,
// #################### Complex Node Identification
isDeleteOfDynamicArray,

@ -837,6 +837,7 @@ export interface CommonYulAstNode {
}
export interface ABIParameter {
internalType: string
/** The name of the parameter */
name: string
/** The canonical type of the parameter */

@ -79,5 +79,93 @@
"stateMutability": "nonpayable",
"superFunction": null,
"visibility": "public"
},
"bytesArray": {
"body":
{
"id": 287,
"nodeType": "Block",
"src": "4988:2:0",
"statements": []
},
"documentation": null,
"id": 288,
"implemented": true,
"kind": "function",
"modifiers": [],
"name": "testWithArray",
"nodeType": "FunctionDefinition",
"parameters":
{ "id": 285,
"nodeType": "ParameterList",
"parameters": [
{
"constant": false,
"id": 284,
"name": "param",
"nodeType": "VariableDeclaration",
"scope": 288,
"src": "4957:22:0",
"stateVariable": false,
"storageLocation": "memory",
"typeDescriptions":
{ "typeIdentifier": "t_array$_t_bytes32_$dyn_memory_ptr",
"typeString": "bytes32[]" },
"typeName":
{ "baseType": "[Object]",
"id": 283,
"length": null,
"nodeType": "ArrayTypeName",
"src": "4957:9:0",
"typeDescriptions": "[Object]"
},
"value": null,
"visibility": "internal"
}
],
"src": "4956:24:0"
},
"returnParameters":
{ "id": 286,
"nodeType": "ParameterList",
"parameters": [],
"src": "4988:0:0" },
"scope": 289,
"src": "4933:57:0",
"stateMutability": "nonpayable",
"superFunction": null,
"visibility": "public"
},
"withoutParams" : {
"body":
{
"id": 280,
"nodeType": "Block",
"src": "4864:63:0",
"statements": "[ [Object] ]"
},
"documentation": null,
"id": 281,
"implemented": true,
"kind": "function",
"modifiers": [],
"name": "winnerName",
"nodeType": "FunctionDefinition",
"parameters":
{ "id": 268,
"nodeType": "ParameterList",
"parameters": [],
"src": "4804:2:0"
},
"returnParameters":
{ "id": 271,
"nodeType": "ParameterList",
"parameters": "[ [Object] ]",
"src": "4839:20:0"
},
"scope": 289,
"src": "4785:142:0",
"stateMutability": "view",
"superFunction": null,
"visibility": "public" }
}

@ -292,8 +292,10 @@ test('staticAnalysisCommon.getFullQuallyfiedFuncDefinitionIdent', function (t) {
})
test('staticAnalysisCommon.getSplittedTypeDesc', function (t) {
t.plan(1)
t.ok(common.getSplittedTypeDesc(funcDefForComplexParams.nestedStruct, compiledContractObj)[0] === '(bytes32,uint256,uint256[],address,(bytes32,uint256)[])[][]', 'creates right params type signature')
t.plan(3)
t.ok(common.getMethodParamsSplittedTypeDesc(funcDefForComplexParams.withoutParams, compiledContractObj).length === 0, 'no params, no params type signature')
t.ok(common.getMethodParamsSplittedTypeDesc(funcDefForComplexParams.bytesArray, compiledContractObj)[0] === 'bytes32[]', 'creates right params type signature')
t.ok(common.getMethodParamsSplittedTypeDesc(funcDefForComplexParams.nestedStruct, compiledContractObj)[0] === '(bytes32,uint256,uint256[],address,(bytes32,uint256)[])[][]', 'creates right params type signature')
})
// #################### Complex Node Identification

Loading…
Cancel
Save