t.throws(()=>common.getEffectedVariableName(inlineAssembly),'staticAnalysisCommon.js: not an effect Node or inline assembly','get from inline assembly should throw')
t.ok(common.getEffectedVariableName(assignment)==='c','get right name for assignment')
t.throws(()=>common.getEffectedVariableName({name:'MemberAccess'}),undefined,'should throw on all other nodes')
...
...
@@ -308,56 +176,6 @@ test('staticAnalysisCommon.getEffectedVariableName', function (t) {
t.ok(common.getFullQuallyfiedFuncDefinitionIdent(contract,funDef,['uint256','bool'])==='baz.getY(uint256,bool)','creates right signature')
t.ok(common.getFullQuallyfiedFuncDefinitionIdent(contract,fullyQualifiedFunctionDefinition,['uint256','bool'])==='baz.getY(uint256,bool)','creates right signature')
t.throws(()=>common.getFullQuallyfiedFuncDefinitionIdent(contract,{name:'MemberAccess'},['uint256','bool']),undefined,'throws on wrong nodes')
t.throws(()=>common.getFullQuallyfiedFuncDefinitionIdent({name:'FunctionCall'},funDef,['uint256','bool']),undefined,'throws on wrong nodes')
t.throws(()=>common.getFullQuallyfiedFuncDefinitionIdent({name:'FunctionCall'},fullyQualifiedFunctionDefinition,['uint256','bool']),undefined,'throws on wrong nodes')
t.ok(common.isLowLevelSendInst(sendAst)&&common.isLowLevelCall(sendAst),'send is llc should work')
t.ok(common.isLowLevelCallInst(callAst)&&common.isLowLevelCall(callAst),'call is llc should work')
t.notOk(common.isLowLevelCallInst(callcodeAst),'callcode is not call')
t.ok(common.isLowLevelCallcodeInst(callcodeAst)&&common.isLowLevelCall(callcodeAst),'callcode is llc should work')
t.notOk(common.isLowLevelCallcodeInst(callAst),'call is not callcode')
t.ok(common.isLowLevelDelegatecallInst(delegatecallAst)&&common.isLowLevelCall(delegatecallAst),'delegatecall is llc should work')
t.ok(common.isLowLevelSendInst(lowlevelCall.sendAst)&&common.isLowLevelCall(lowlevelCall.sendAst),'send is llc should work')
t.ok(common.isLowLevelCallInst(lowlevelCall.callAst)&&common.isLowLevelCall(lowlevelCall.callAst),'call is llc should work')
t.notOk(common.isLowLevelCallInst(lowlevelCall.callcodeAst),'callcode is not call')
t.ok(common.isLowLevelCallcodeInst(lowlevelCall.callcodeAst)&&common.isLowLevelCall(lowlevelCall.callcodeAst),'callcode is llc should work')
t.notOk(common.isLowLevelCallcodeInst(lowlevelCall.callAst),'call is not callcode')
t.ok(common.isLowLevelDelegatecallInst(lowlevelCall.delegatecallAst)&&common.isLowLevelCall(lowlevelCall.delegatecallAst),'delegatecall is llc should work')
})
test('staticAnalysisCommon: Call of parameter function',function(t){
t.plan(7)
varnode1={
'attributes':{
'argumentTypes':null,
'isConstant':false,
'isLValue':false,
'isPure':false,
'isStructConstructorCall':false,
'lValueRequested':false,
'names':[
null
],
'type':'uint256',
'type_conversion':false
},
'children':[
{
'attributes':{
'argumentTypes':[
{
'typeIdentifier':'t_uint256',
'typeString':'uint256'
},
{
'typeIdentifier':'t_uint256',
'typeString':'uint256'
}
],
'overloadedDeclarations':[
null
],
'referencedDeclaration':25,
'type':'function (uint256,uint256) pure returns (uint256)',
'value':'f'
},
'id':34,
'name':'Identifier',
'src':'267:1:0'
},
{
'attributes':{
'argumentTypes':null,
'overloadedDeclarations':[
null
],
'referencedDeclaration':27,
'type':'uint256',
'value':'x'
},
'id':35,
'name':'Identifier',
'src':'269:1:0'
},
{
'attributes':{
'argumentTypes':null,
'overloadedDeclarations':[
null
],
'referencedDeclaration':29,
'type':'uint256',
'value':'y'
},
'id':36,
'name':'Identifier',
'src':'272:1:0'
}
],
'id':37,
'name':'FunctionCall',
'src':'267:7:0'
}
t.ok(common.isLocalCall(node1),'is not LocalCall')
t.notOk(common.isThisLocalCall(node1),'is not this local call')
t.notOk(common.isSuperLocalCall(node1),'is not super local call')
t.notOk(common.isExternalDirectCall(node1),'is not ExternalDirectCall')
t.notOk(common.isLibraryCall(node1),'is not LibraryCall')
t.equals(common.getFunctionCallType(node1),'function (uint256,uint256) pure returns (uint256)','Extracts right type')
t.equals(common.getFunctionCallTypeParameterType(node1),'uint256,uint256','Extracts param right type')
t.ok(common.isLocalCall(parameterFunction),'is not LocalCall')
t.notOk(common.isThisLocalCall(parameterFunction),'is not this local call')
t.notOk(common.isSuperLocalCall(parameterFunction),'is not super local call')
t.notOk(common.isExternalDirectCall(parameterFunction),'is not ExternalDirectCall')
t.notOk(common.isLibraryCall(parameterFunction),'is not LibraryCall')
t.equals(common.getFunctionCallType(parameterFunction),'function (uint256,uint256) pure returns (uint256)','Extracts right type')
t.equals(common.getFunctionCallTypeParameterType(parameterFunction),'uint256,uint256','Extracts param right type')
})
test('staticAnalysisCommon: function call with of function with function parameter',function(t){
'typeString':'function (uint256,uint256) pure returns (uint256)'
},
{
'typeIdentifier':'t_uint256',
'typeString':'uint256'
},
{
'typeIdentifier':'t_uint256',
'typeString':'uint256'
}
],
'overloadedDeclarations':[
null
],
'referencedDeclaration':40,
'type':'function (function (uint256,uint256) pure returns (uint256),uint256,uint256) pure returns (uint256)',
'value':'eval'
},
'id':49,
'name':'Identifier',
'src':'361:4:0'
},
{
'attributes':{
'argumentTypes':null,
'overloadedDeclarations':[
null
],
'referencedDeclaration':15,
'type':'function (uint256,uint256) pure returns (uint256)',
'value':'plus'
},
'id':50,
'name':'Identifier',
'src':'366:4:0'
},
{
'attributes':{
'argumentTypes':null,
'overloadedDeclarations':[
null
],
'referencedDeclaration':42,
'type':'uint256',
'value':'x'
},
'id':51,
'name':'Identifier',
'src':'372:1:0'
},
{
'attributes':{
'argumentTypes':null,
'overloadedDeclarations':[
null
],
'referencedDeclaration':44,
'type':'uint256',
'value':'y'
},
'id':52,
'name':'Identifier',
'src':'375:1:0'
}
],
'id':53,
'name':'FunctionCall',
'src':'361:16:0'
}
t.equals(common.getFunctionCallType(node1),'function (function (uint256,uint256) pure returns (uint256),uint256,uint256) pure returns (uint256)','Extracts right type')
t.equals(common.getFunctionCallTypeParameterType(node1),'function (uint256,uint256) pure returns (uint256),uint256,uint256','Extracts param right type')
t.equals(common.getFunctionCallType(parameterFunctionCall),'function (function (uint256,uint256) pure returns (uint256),uint256,uint256) pure returns (uint256)','Extracts right type')
t.equals(common.getFunctionCallTypeParameterType(parameterFunctionCall),'function (uint256,uint256) pure returns (uint256),uint256,uint256','Extracts param right type')