Skip to content

Commit

Permalink
feat: pass target slots to proxy contract
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbate committed Oct 1, 2024
1 parent 5197722 commit 73b69e0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
7 changes: 6 additions & 1 deletion packages/fuels/src/cli/commands/deploy/deployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export async function deployContract(

const targetBytecode = readFileSync(binaryPath);
const targetAbi = JSON.parse(readFileSync(abiPath, 'utf-8'));
const targetStorageSlots = deployConfig.storageSlots;

const proxyBytecode = Src14OwnedProxyFactory.bytecode;
const proxyAbi = Src14OwnedProxy.abi;
const proxyFactory = new Src14OwnedProxyFactory(wallet);
const proxyStorageSlots = Src14OwnedProxy.storageSlots;

const isProxyEnabled = tomlContents?.proxy?.enabled;
const proxyAddress = tomlContents?.proxy?.address;
Expand Down Expand Up @@ -82,15 +84,18 @@ export async function deployContract(
// b. Deploy the SR-C14 Compliant / Proxy Contract
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { storageSlots, stateRoot, ...commonDeployConfig } = deployConfig;
const mergedStorageSlots = [...(targetStorageSlots || []), ...(proxyStorageSlots || [])];

const proxyDeployConfig: DeployContractOptions = {
...commonDeployConfig,
storageSlots: mergedStorageSlots,
configurableConstants: {
INITIAL_TARGET: { bits: targetContract.id.toB256() },
INITIAL_OWNER: { Initialized: { Address: { bits: wallet.address.toB256() } } },
},
};

const proxyFactory = new ContractFactory(proxyBytecode, proxyAbi, wallet);
const { waitForResult: waitForProxy } = await proxyFactory.deploy(proxyDeployConfig);
const { contract: proxyContract } = await waitForProxy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */

/*
Fuels version: 0.94.7
Fuels version: 0.94.8
*/

import { Contract, Interface } from "../../../../..";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */

/*
Fuels version: 0.94.7
Fuels version: 0.94.8
*/

import { Contract, ContractFactory, decompressBytecode } from "../../../../..";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */

/*
Fuels version: 0.94.7
Fuels version: 0.94.8
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */

/*
Fuels version: 0.94.7
Fuels version: 0.94.8
*/

export { Src14OwnedProxy } from './Src14OwnedProxy';
Expand Down
5 changes: 3 additions & 2 deletions packages/fuels/test/features/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ describe('deploy', { timeout: 180000 }, () => {
);

const targetContract = new Contract(upgradableContractId, upgradableAbi, wallet);
const res = await targetContract.functions.test_function().call();
const { value } = await res.waitForResult();

const { value: getCountValue } = await targetContract.functions.get_value().get();
expect(getCountValue).toBe(10);

const res = await targetContract.functions.test_function().call();
const { value } = await res.waitForResult();

return value;
}

Expand Down

0 comments on commit 73b69e0

Please sign in to comment.