Skip to content

Commit 7aa683f

Browse files
committed
Add tests for contract name and startBlock info
1 parent 84b3d9e commit 7aa683f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/cli/src/command-helpers/contracts.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, test } from 'vitest';
2+
import EthereumABI from '../protocols/ethereum/abi.js';
23
import { ContractService } from './contracts.js';
34
import { loadRegistry } from './registry.js';
45

@@ -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+
88104
describe('getStartBlockForContract', { sequential: true }, async () => {
89105
const registry = await loadRegistry();
90106
const contractService = new ContractService(registry);
@@ -102,3 +118,25 @@ 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(
132+
EthereumABI,
133+
networkId,
134+
contract,
135+
))!;
136+
expect(info).toEqual({ name, startBlock: parseInt(startBlock) });
137+
},
138+
{ timeout: 10_000 },
139+
);
140+
}
141+
}
142+
});

0 commit comments

Comments
 (0)