empty data is allowed
This commit is contained in:
		
							parent
							
								
									c312f4fb92
								
							
						
					
					
						commit
						8a60ed1315
					
				| @ -42,15 +42,15 @@ export function decodeCallData (data) { | |||||||
| export function decodeMethodInput (methodAbi, paramdata) { | export function decodeMethodInput (methodAbi, paramdata) { | ||||||
|   if (!methodAbi) { |   if (!methodAbi) { | ||||||
|     throw new Error('decodeMethodInput should receive valid method-specific ABI'); |     throw new Error('decodeMethodInput should receive valid method-specific ABI'); | ||||||
|   } else if (!paramdata) { |   } else if (paramdata && paramdata.length) { | ||||||
|     throw new Error('decodeMethodInput should receive valid parameter input data'); |     if (!isHex(paramdata)) { | ||||||
|   } else if (!isHex(paramdata)) { |  | ||||||
|       throw new Error('Input to decodeMethodInput should be a hex value'); |       throw new Error('Input to decodeMethodInput should be a hex value'); | ||||||
|     } else if (paramdata.substr(0, 2) === '0x') { |     } else if (paramdata.substr(0, 2) === '0x') { | ||||||
|       return decodeMethodInput(methodAbi, paramdata.slice(2)); |       return decodeMethodInput(methodAbi, paramdata.slice(2)); | ||||||
|     } else if (paramdata.length % 64 !== 0) { |     } else if (paramdata.length % 64 !== 0) { | ||||||
|       throw new Error('Parameter length in decodeMethodInput not a multiple of 64 characters'); |       throw new Error('Parameter length in decodeMethodInput not a multiple of 64 characters'); | ||||||
|     } |     } | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   return new Func(methodAbi).decodeInput(paramdata).map((decoded) => decoded.value); |   return new Func(methodAbi).decodeInput(paramdata).map((decoded) => decoded.value); | ||||||
| } | } | ||||||
|  | |||||||
| @ -44,10 +44,6 @@ describe('api/util/decode', () => { | |||||||
|       expect(() => decodeMethodInput(null, null)).to.throw(/should receive valid method/); |       expect(() => decodeMethodInput(null, null)).to.throw(/should receive valid method/); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('expects valid parameter data', () => { |  | ||||||
|       expect(() => decodeMethodInput({}, null)).to.throw(/should receive valid parameter/); |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     it('expect valid hex parameter data', () => { |     it('expect valid hex parameter data', () => { | ||||||
|       expect(() => decodeMethodInput({}, 'invalid')).to.throw(/should be a hex value/); |       expect(() => decodeMethodInput({}, 'invalid')).to.throw(/should be a hex value/); | ||||||
|     }); |     }); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user