11import { describe , expect , test } from 'vitest' ;
22import { ContractService } from './contracts.js' ;
33import { loadRegistry } from './registry.js' ;
4+ import EthereumABI from '../protocols/ethereum/abi.js' ;
45
56// An object with some test cases for contract deployment block numbers
67const TEST_CONTRACT_START_BLOCKS = {
@@ -85,6 +86,21 @@ const TEST_CONTRACT_START_BLOCKS = {
8586 // },
8687} ;
8788
89+ const TEST_SOURCIFY_CONTRACT_INFO = {
90+ mainnet : {
91+ '0xc2EdaD668740f1aA35E4D8f227fB8E17dcA888Cd' : {
92+ name : 'MasterChef' ,
93+ startBlock : 10_736_242
94+ }
95+ } ,
96+ optimism : {
97+ '0xc35DADB65012eC5796536bD9864eD8773aBc74C4' : {
98+ name : 'BentoBoxV1' ,
99+ startBlock : 7_019_815 ,
100+ }
101+ }
102+ } ;
103+
88104describe ( 'getStartBlockForContract' , { sequential : true } , async ( ) => {
89105 const registry = await loadRegistry ( ) ;
90106 const contractService = new ContractService ( registry ) ;
@@ -102,3 +118,21 @@ describe('getStartBlockForContract', { sequential: true }, async () => {
102118 }
103119 }
104120} ) ;
121+
122+ describe ( 'getFromSourcifyForContract' , { sequential : true } , async ( ) => {
123+ const registry = await loadRegistry ( ) ;
124+ const contractService = new ContractService ( registry ) ;
125+ for ( const [ networkId , contractInfo ] of Object . entries ( TEST_SOURCIFY_CONTRACT_INFO ) ) {
126+ for ( const [ contract , info ] of Object . entries ( contractInfo ) ) {
127+ test (
128+ `Returns contract information ${ networkId } ${ contract } ${ info . name } ${ info . startBlock } ` ,
129+ async ( ) => {
130+ // Only check name and startBlock, omit API property from Sourcify results
131+ const { name, startBlock } = ( await contractService . getFromSourcify ( EthereumABI , networkId , contract ) ) ! ;
132+ expect ( info ) . toEqual ( { name, startBlock : parseInt ( startBlock ) } ) ;
133+ } ,
134+ { timeout : 10_000 } ,
135+ ) ;
136+ }
137+ }
138+ } ) ;
0 commit comments