Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reverting changes to create2 deploy #1332

Merged
merged 11 commits into from
Sep 3, 2024
3 changes: 3 additions & 0 deletions packages/builder/src/steps/__snapshots__/deploy.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`steps/deploy.ts exec() when create2 = true fails if contract already deployed 1`] = `"The CREATE2 contract seems to be failing in the constructor. However, we were not able to get a stack trace."`;
50 changes: 14 additions & 36 deletions packages/builder/src/steps/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,45 +177,23 @@ describe('steps/deploy.ts', () => {

describe('exec()', () => {
describe('when create2 = true', () => {
it('works if contract already deployed', async () => {
it('fails if contract already deployed', async () => {
jest.mocked(fakeRuntime.provider.getCode).mockResolvedValue('0xabcdef');

const result = await action.exec(
fakeRuntime,
fakeCtx,
{
artifact: 'hello',
create2: true,
args: [viem.stringToHex('one', { size: 32 }), viem.stringToHex('two', { size: 32 }), { three: 'four' }],
salt: 'wohoo',
value: '1234',
},
{ ref: new PackageReference('hello:1.0.0'), currentLabel: 'contract.Woot' }
);

expect(result).toStrictEqual({
contracts: {
Woot: {
abi: fakeAbi,
address: '0x3F9270CE7b8704E7BE0BfcA0EA8836f2B135a4ef',
constructorArgs: [
viem.stringToHex('one', { size: 32 }),
viem.stringToHex('two', { size: 32 }),
{ three: 'four' },
],
contractName: undefined,
deployTxnHash: '',
deployTxnBlockNumber: '',
deployTimestamp: '',
deployedOn: 'contract.Woot',
gasCost: '0',
gasUsed: 0,
linkedLibraries: {},
sourceName: undefined,
highlight: undefined,
expect(
action.exec(
fakeRuntime,
fakeCtx,
{
artifact: 'hello',
create2: true,
args: [viem.stringToHex('one', { size: 32 }), viem.stringToHex('two', { size: 32 }), { three: 'four' }],
salt: 'wohoo',
value: '1234',
},
},
});
{ ref: new PackageReference('hello:1.0.0'), currentLabel: 'contract.Woot' }
)
).rejects.toThrowErrorMatchingSnapshot();
});

it('works if contract needs to be deployed', async () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/builder/src/steps/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ const deploySpec = {

if (bytecode && bytecode !== '0x') {
debug('create2 contract already completed');
// our work is done for us. unfortunately, its not easy to figure out what the transaction hash was

// the cannon state does not think a contract should be deployed, but the on-chain state says a contract
// is deployed. this could be a mistake. alert the user and explain how to override
throw new Error(
`The contract at the create2 destination ${addr} is already deployed, but the Cannon state does not recognize that this contract has already been deployed. This typically indicates incorrect upgrade configuration. Please confirm if this contract should already be deployed or not, and if you want to continue the build as-is, run 'cannon alter ${packageState.ref} set-contract-address ${packageState.currentLabel} ${addr}'`
);
} else {
const signer = config.from
? await runtime.getSigner(config.from as viem.Address)
Expand Down
Loading