mirror of
				https://github.com/Instadapp/Forta-Agents.git
				synced 2024-07-29 21:47:22 +00:00 
			
		
		
		
	added-test
This commit is contained in:
		
							parent
							
								
									0192090d09
								
							
						
					
					
						commit
						0ab105a9ab
					
				|  | @ -112,7 +112,7 @@ describe('Detect Instadapp Connector Contract Event', () => { | ||||||
|           description: `Instadapp ADDED Connector Event is detected.`, |           description: `Instadapp ADDED Connector Event is detected.`, | ||||||
|           alertId: 'INSTADAPP-16', |           alertId: 'INSTADAPP-16', | ||||||
|           protocol: 'INSTADAPP', |           protocol: 'INSTADAPP', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  | @ -137,7 +137,7 @@ describe('Detect Instadapp Connector Contract Event', () => { | ||||||
|           description: `Instadapp UPDATED Connector Event is detected.`, |           description: `Instadapp UPDATED Connector Event is detected.`, | ||||||
|           alertId: 'INSTADAPP-16', |           alertId: 'INSTADAPP-16', | ||||||
|           protocol: 'INSTADAPP', |           protocol: 'INSTADAPP', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  | @ -162,7 +162,7 @@ describe('Detect Instadapp Connector Contract Event', () => { | ||||||
|           description: `Instadapp REMOVED Connector Event is detected.`, |           description: `Instadapp REMOVED Connector Event is detected.`, | ||||||
|           alertId: 'INSTADAPP-16', |           alertId: 'INSTADAPP-16', | ||||||
|           protocol: 'INSTADAPP', |           protocol: 'INSTADAPP', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  |  | ||||||
|  | @ -44,7 +44,7 @@ const handleTransaction: HandleTransaction = async ( | ||||||
|           description: `Instadapp ${sig} Connector Event is detected.`, |           description: `Instadapp ${sig} Connector Event is detected.`, | ||||||
|           alertId: 'INSTADAPP-16', |           alertId: 'INSTADAPP-16', | ||||||
|           protocol: 'INSTADAPP', |           protocol: 'INSTADAPP', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }) |         }) | ||||||
|       ) |       ) | ||||||
|  |  | ||||||
|  | @ -110,7 +110,7 @@ describe('Detect Instadapp Governance Event', () => { | ||||||
|           description: `Instadapp QUEUE Proposal Event is detected.`, |           description: `Instadapp QUEUE Proposal Event is detected.`, | ||||||
|           alertId: 'Instadapp-12', |           alertId: 'Instadapp-12', | ||||||
|           protocol: 'Instadapp', |           protocol: 'Instadapp', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  | @ -135,7 +135,7 @@ describe('Detect Instadapp Governance Event', () => { | ||||||
|           description: `Instadapp EXECUTE Proposal Event is detected.`, |           description: `Instadapp EXECUTE Proposal Event is detected.`, | ||||||
|           alertId: 'Instadapp-12', |           alertId: 'Instadapp-12', | ||||||
|           protocol: 'Instadapp', |           protocol: 'Instadapp', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  | @ -160,7 +160,7 @@ describe('Detect Instadapp Governance Event', () => { | ||||||
|           description: `Instadapp CANCEL Proposal Event is detected.`, |           description: `Instadapp CANCEL Proposal Event is detected.`, | ||||||
|           alertId: 'Instadapp-12', |           alertId: 'Instadapp-12', | ||||||
|           protocol: 'Instadapp', |           protocol: 'Instadapp', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ const handleTransaction: HandleTransaction = async ( | ||||||
|           description: `Instadapp ${sig} Proposal Event is detected.`, |           description: `Instadapp ${sig} Proposal Event is detected.`, | ||||||
|           alertId: 'Instadapp-12', |           alertId: 'Instadapp-12', | ||||||
|           protocol: 'Instadapp', |           protocol: 'Instadapp', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }) |         }) | ||||||
|       ) |       ) | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ function provideHandleTransaction(amountThreshold) { | ||||||
|         InstTransfer.args.value.toString() |         InstTransfer.args.value.toString() | ||||||
|       ).dividedBy(10 ** INST_DECIMALS) |       ).dividedBy(10 ** INST_DECIMALS) | ||||||
| 
 | 
 | ||||||
|       if (amount.isLessThan(amountThreshold)) return; |       if (amount.isLessThan(amountThreshold)) return findings; | ||||||
| 
 | 
 | ||||||
|       const formattedAmount = amount.toFixed(2); |       const formattedAmount = amount.toFixed(2); | ||||||
|       findings.push( |       findings.push( | ||||||
|  |  | ||||||
|  | @ -110,7 +110,7 @@ describe('Detect Instadapp Implementation Contract Event', () => { | ||||||
|           description: `Instadapp SETDEFAULT Implementation Event is detected.`, |           description: `Instadapp SETDEFAULT Implementation Event is detected.`, | ||||||
|           alertId: 'Instadapp-14', |           alertId: 'Instadapp-14', | ||||||
|           protocol: 'Instadapp', |           protocol: 'Instadapp', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  | @ -135,7 +135,7 @@ describe('Detect Instadapp Implementation Contract Event', () => { | ||||||
|           description: `Instadapp ADD Implementation Event is detected.`, |           description: `Instadapp ADD Implementation Event is detected.`, | ||||||
|           alertId: 'Instadapp-14', |           alertId: 'Instadapp-14', | ||||||
|           protocol: 'Instadapp', |           protocol: 'Instadapp', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  | @ -160,7 +160,7 @@ describe('Detect Instadapp Implementation Contract Event', () => { | ||||||
|           description: `Instadapp REMOVE Implementation Event is detected.`, |           description: `Instadapp REMOVE Implementation Event is detected.`, | ||||||
|           alertId: 'Instadapp-14', |           alertId: 'Instadapp-14', | ||||||
|           protocol: 'Instadapp', |           protocol: 'Instadapp', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }), |         }), | ||||||
|       ]) |       ]) | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ const handleTransaction: HandleTransaction = async ( | ||||||
|           description: `Instadapp ${sig} Implementation Event is detected.`, |           description: `Instadapp ${sig} Implementation Event is detected.`, | ||||||
|           alertId: 'Instadapp-14', |           alertId: 'Instadapp-14', | ||||||
|           protocol: 'Instadapp', |           protocol: 'Instadapp', | ||||||
|           type: FindingType.Unknown, |           type: FindingType.Info, | ||||||
|           severity: FindingSeverity.Info, |           severity: FindingSeverity.Info, | ||||||
|         }) |         }) | ||||||
|       ) |       ) | ||||||
|  |  | ||||||
							
								
								
									
										92
									
								
								Token_Tracking_agent/src/agent.spec.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								Token_Tracking_agent/src/agent.spec.js
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,92 @@ | ||||||
|  | 
 | ||||||
|  | const BigNumber = require("bignumber.js"); | ||||||
|  | const { Finding, FindingSeverity, FindingType } = require("forta-agent"); | ||||||
|  | const { provideHandleTransaction } = require("./agent"); | ||||||
|  | 
 | ||||||
|  | const { | ||||||
|  |     DAI_ADDRESS, | ||||||
|  |     TRANSFER_EVENT, | ||||||
|  |     DAI_DECIMALS, | ||||||
|  |     USDC_ADDRESS, | ||||||
|  |     USDC_DECIMALS | ||||||
|  | } = require("./constants"); | ||||||
|  | 
 | ||||||
|  | describe("large transfer event agent", () => { | ||||||
|  |     let handleTransaction; | ||||||
|  |     const mockAmountThreshold = "1000"; | ||||||
|  |     const mockTxEvent = { | ||||||
|  |         filterLog: jest.fn(), | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     beforeAll(() => { | ||||||
|  |         handleTransaction = provideHandleTransaction(mockAmountThreshold); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     beforeEach(() => { | ||||||
|  |         mockTxEvent.filterLog.mockReset(); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     it("returns empty findings if there are no transfer events", async () => { | ||||||
|  | 
 | ||||||
|  |         mockTxEvent.filterLog.mockReturnValue([]); | ||||||
|  |         const findings = await handleTransaction(mockTxEvent); | ||||||
|  |         // console.log("findings", findings)
 | ||||||
|  |         expect(findings).toStrictEqual([]); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it("returns empty findings if there are large token transfer events but no dsa address is involved", async () => { | ||||||
|  |         const amount = new BigNumber("1001"); | ||||||
|  |         const formattedAmount = amount.toFixed(2); | ||||||
|  |         const mockDaiTransferEvent = { | ||||||
|  |             args: { | ||||||
|  |                 from: "0x80f36f504c63b7663cebcdecb2ae7620a1fcb6e1", | ||||||
|  |                 to: "0x6b175474e89094c44da98b954eedeac495271d0f", | ||||||
|  |                 value: amount.multipliedBy(10 ** DAI_DECIMALS), | ||||||
|  |             }, | ||||||
|  |         }; | ||||||
|  |         mockTxEvent.filterLog.mockReturnValueOnce([mockDaiTransferEvent]); | ||||||
|  |         mockTxEvent.filterLog.mockReturnValueOnce([]); | ||||||
|  | 
 | ||||||
|  |         const findings = await handleTransaction(mockTxEvent); | ||||||
|  | 
 | ||||||
|  |         expect(findings).toStrictEqual([]); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it("returns findings if there are large token transfer events involving dsa address", async () => { | ||||||
|  | 
 | ||||||
|  |         const amount = new BigNumber("1001"); | ||||||
|  |         const formattedAmount = amount.toFixed(2); | ||||||
|  |         const mockDaiTransferEvent = { | ||||||
|  |             args: { | ||||||
|  |                 from: "0xf151ed2caedbda83c17ae39d6990d92909fcf529", // dsa
 | ||||||
|  |                 to: "0x4f58985b75eec8f14c536878a19eadf4a1960d6c", | ||||||
|  |                 value: amount.multipliedBy(10 ** DAI_DECIMALS), | ||||||
|  |             }, | ||||||
|  |         }; | ||||||
|  |         mockTxEvent.filterLog.mockReturnValueOnce([mockDaiTransferEvent]); | ||||||
|  |         mockTxEvent.filterLog.mockReturnValueOnce([]); | ||||||
|  | 
 | ||||||
|  |         const findings = await handleTransaction(mockTxEvent); | ||||||
|  | 
 | ||||||
|  |         expect(findings).toStrictEqual([ | ||||||
|  |             Finding.fromObject({ | ||||||
|  |                 name: "Large DAI Transfer", | ||||||
|  |                 description: `${formattedAmount} DAI Transferred`, | ||||||
|  |                 alertId: "INST-41", | ||||||
|  |                 severity: FindingSeverity.Info, | ||||||
|  |                 type: FindingType.Info, | ||||||
|  |                 metadata: { | ||||||
|  |                     from: mockDaiTransferEvent.args.from, | ||||||
|  |                     to: mockDaiTransferEvent.args.to, | ||||||
|  |                     amount: formattedAmount, | ||||||
|  |                 }, | ||||||
|  |             }), | ||||||
|  |         ]); | ||||||
|  | 
 | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | }); | ||||||
|  | @ -19,8 +19,8 @@ function token(name, address, decimals) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var tokens = [ | var tokens = [ | ||||||
|   new token("USDC", USDC_ADDRESS, USDC_DECIMALS), |   new token("DAI", DAI_ADDRESS, DAI_DECIMALS), | ||||||
|   new token("DAI", DAI_ADDRESS, DAI_DECIMALS) |   new token("USDC", USDC_ADDRESS, USDC_DECIMALS) | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 bhavik
						bhavik