Skip to content

Commit 25fd23e

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

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, test } from 'vitest';
22
import { ContractService } from './contracts.js';
33
import { 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
67
const 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+
88104
describe('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

Comments
 (0)