Skip to content

Commit

Permalink
feat(cli): replace deprecated getBytecode() with getCode()
Browse files Browse the repository at this point in the history
  • Loading branch information
saeta-eth committed Jul 12, 2024
1 parent 1b3cfc8 commit 89814a6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/builder/src/create2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const DEFAULT_ARACHNID_ADDRESS = '0x4e59b44847b379578588920cA78FbF26c0B4956C';
describe('util.ts', () => {
describe('ensureArachnidCreate2Exists()', () => {
it('does nothing if create2 exists', async () => {
jest.mocked(fakeRuntime.provider.getBytecode).mockResolvedValue('0x1234');
jest.mocked(fakeRuntime.provider.getCode).mockResolvedValue('0x1234');

// if it tries to do get a signer that function isnt defined so it will fail
expect(await ensureArachnidCreate2Exists(fakeRuntime, ARACHNID_DEFAULT_DEPLOY_ADDR)).toEqual(DEFAULT_ARACHNID_ADDRESS);
});

it('fails if deploy signer is not defined', async () => {
jest.mocked(fakeRuntime.provider.getBytecode).mockResolvedValue('0x');
jest.mocked(fakeRuntime.provider.getCode).mockResolvedValue('0x');
(fakeRuntime.getSigner as any) = async () => {
throw new Error('no signer');
};
Expand All @@ -25,7 +25,7 @@ describe('util.ts', () => {
});

it('calls sendTransaction to create aracnid contract if not deployed', async () => {
jest.mocked(fakeRuntime.provider.getBytecode).mockResolvedValue('0x');
jest.mocked(fakeRuntime.provider.getCode).mockResolvedValue('0x');

const fakeSigner = makeFakeSigner(ARACHNID_DEFAULT_DEPLOY_ADDR);

Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/create2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function ensureArachnidCreate2Exists(
): Promise<viem.Address> {
// if arachnid create2 contract is not deployed
const proxyAddress = viem.getCreateAddress({ from: deployer, nonce: BigInt(0) });
const detectedBytecode = await runtime.provider.getBytecode({ address: proxyAddress });
const detectedBytecode = await runtime.provider.getCode({ address: proxyAddress });
if (!detectedBytecode || detectedBytecode === '0x') {
debug('arachnid create2 contract not found. attempting to deploy...');
// on local testnets the arachnid contract is not deployed,
Expand Down
4 changes: 2 additions & 2 deletions packages/builder/src/steps/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('steps/deploy.ts', () => {
describe('exec()', () => {
describe('when create2 = true', () => {
it('works if contract already deployed', async () => {
jest.mocked(fakeRuntime.provider.getBytecode).mockResolvedValue('0xabcdef');
jest.mocked(fakeRuntime.provider.getCode).mockResolvedValue('0xabcdef');

const result = await action.exec(
fakeRuntime,
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('steps/deploy.ts', () => {
});

it('works if contract needs to be deployed', async () => {
jest.mocked(fakeRuntime.provider.getBytecode).mockImplementation(async ({ address }) => {
jest.mocked(fakeRuntime.provider.getCode).mockImplementation(async ({ address }) => {
if (address === DEFAULT_ARACHNID_ADDRESS) {
return '0xabcd';
}
Expand Down
6 changes: 3 additions & 3 deletions packages/builder/src/steps/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const deploySpec = {

// sanity check that any connected libraries are bytecoded
for (const lib in config.libraries || {}) {
if ((await runtime.provider.getBytecode({ address: config.libraries![lib] as viem.Address })) === '0x') {
if ((await runtime.provider.getCode({ address: config.libraries![lib] as viem.Address })) === '0x') {
throw new Error(`library ${lib} has no bytecode. This is most likely a missing dependency or bad state.`);
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ const deploySpec = {
const [create2Txn, addr] = makeArachnidCreate2Txn(config.salt || '', txn.data!, arachnidDeployerAddress);
debug(`create2: deploy ${addr} by ${arachnidDeployerAddress}`);

const bytecode = await runtime.provider.getBytecode({ address: addr });
const bytecode = await runtime.provider.getCode({ address: addr });

if (bytecode && bytecode !== '0x') {
debug('create2 contract already completed');
Expand Down Expand Up @@ -317,7 +317,7 @@ const deploySpec = {
debug(`contract appears already deployed to address ${contractAddress} (nonce too high)`);

// check that the contract bytecode that was deployed matches the requested
const actualBytecode = await runtime.provider.getBytecode({ address: contractAddress });
const actualBytecode = await runtime.provider.getCode({ address: contractAddress });
// we only check the length because solidity puts non-substantial changes (ex. comments) in bytecode and that
// shouldn't trigger any significant change. And also this is just kind of a sanity check so just verifying the
// length should be sufficient
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/steps/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function runTxn(
// sanity check the contract we are calling has code defined
// we check here because a missing contract will not revert when provided with data, leading to confusing situations
// if invoke calls succeeding when no action was actually performed.
if ((await runtime.provider.getBytecode({ address: contract.address })) === '0x') {
if ((await runtime.provider.getCode({ address: contract.address })) === '0x') {
throw new Error(
`contract ${contract.address} for ${packageState.currentLabel} has no bytecode. This is most likely a missing dependency or bad state.`
);
Expand Down

0 comments on commit 89814a6

Please sign in to comment.