| 
									
										
										
										
											2015-01-28 14:39:10 +01:00
										 |  |  | var assert = require('assert'); | 
					
						
							| 
									
										
										
										
											2015-01-31 15:22:05 +01:00
										 |  |  | var utils = require('../lib/utils.js'); | 
					
						
							| 
									
										
										
										
											2015-01-28 14:39:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-31 15:22:05 +01:00
										 |  |  | describe('utils', function() { | 
					
						
							| 
									
										
										
										
											2015-01-28 14:39:10 +01:00
										 |  |  |     it('should filter functions and events from input array properly', function () { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // given
 | 
					
						
							|  |  |  |         var description = [{ | 
					
						
							|  |  |  |             "name": "test", | 
					
						
							|  |  |  |             "type": "function", | 
					
						
							|  |  |  |             "inputs": [{ | 
					
						
							|  |  |  |                 "name": "a", | 
					
						
							|  |  |  |                 "type": "uint256" | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             "outputs": [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "name": "d", | 
					
						
							|  |  |  |                 "type": "uint256" | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         }, { | 
					
						
							|  |  |  |             "name": "test2", | 
					
						
							|  |  |  |             "type": "event", | 
					
						
							|  |  |  |             "inputs": [{ | 
					
						
							|  |  |  |                 "name": "a", | 
					
						
							|  |  |  |                 "type": "uint256" | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             "outputs": [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "name": "d", | 
					
						
							|  |  |  |                 "type": "uint256" | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         }]; | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         // when
 | 
					
						
							| 
									
										
										
										
											2015-01-31 15:22:05 +01:00
										 |  |  |         var events = utils.filterEvents(description); | 
					
						
							|  |  |  |         var functions = utils.filterFunctions(description); | 
					
						
							| 
									
										
										
										
											2015-01-28 14:39:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // then
 | 
					
						
							|  |  |  |         assert.equal(events.length, 1); | 
					
						
							|  |  |  |         assert.equal(events[0].name, 'test2'); | 
					
						
							|  |  |  |         assert.equal(functions.length, 1); | 
					
						
							|  |  |  |         assert.equal(functions[0].name, 'test'); | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); |