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: proxy deployments for contracts with storage #6591

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ async fn deploy_chunked(
async fn deploy_new_proxy(
command: &cmd::Deploy,
pkg_name: &str,
pkg_storage_slots: &[StorageSlot],
impl_contract: &fuel_tx::ContractId,
provider: &Provider,
account: &ForcClientAccount,
Expand All @@ -208,9 +209,11 @@ async fn deploy_new_proxy(
let proxy_dir_output = create_proxy_contract(pkg_name)?;
let address = account.address();

let storage_path = proxy_dir_output.join("proxy-storage_slots.json");
let storage_configuration =
StorageConfiguration::default().add_slot_overrides_from_file(storage_path)?;
// Add the combined storage slots from the original contract and the proxy contract.
let proxy_storage_path = proxy_dir_output.join("proxy-storage_slots.json");
let storage_configuration = StorageConfiguration::default()
.add_slot_overrides(pkg_storage_slots.iter().cloned())
.add_slot_overrides_from_file(proxy_storage_path)?;

let configurables = ProxyContractConfigurables::default()
.with_INITIAL_TARGET(Some(*impl_contract))?
Expand Down Expand Up @@ -391,10 +394,12 @@ pub async fn deploy(command: cmd::Deploy) -> Result<Vec<DeployedContract>> {
address: None,
}) => {
let pkg_name = &pkg.descriptor.name;
let pkg_storage_slots = &pkg.storage_slots;
// Deploy a new proxy contract.
let deployed_proxy_contract = deploy_new_proxy(
&command,
pkg_name,
pkg_storage_slots,
&deployed_contract_id,
&provider,
&account,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
contract;

storage {
value: u8 = 5,
}

abi MyContract {
fn test_function() -> bool;

#[storage(read)]
fn test_function_read() -> u8;

#[storage(read, write)]
fn test_function_write(value: u8) -> u8;
}

impl MyContract for Contract {
fn test_function() -> bool {
true
}

#[storage(read)]
fn test_function_read() -> u8 {
storage.value.read()
}

#[storage(read, write)]
fn test_function_write(value: u8) -> u8 {
storage.value.write(value);
storage.value.read()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
{
"type": "bool",
"concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903"
},
{
"type": "u8",
"concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b"
}
],
"metadataTypes": [],
Expand All @@ -15,6 +19,38 @@
"name": "test_function",
"output": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903",
"attributes": null
},
{
"inputs": [],
"name": "test_function_read",
"output": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b",
"attributes": [
{
"name": "storage",
"arguments": [
"read"
]
}
]
},
{
"inputs": [
{
"name": "value",
"concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b"
}
],
"name": "test_function_write",
"output": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b",
"attributes": [
{
"name": "storage",
"arguments": [
"read",
"write"
]
}
]
}
],
"loggedTypes": [],
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

43 changes: 41 additions & 2 deletions forc-plugins/forc-client/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,12 @@ async fn test_deploy_fresh_proxy() {
node.kill().unwrap();
let impl_contract = DeployedContract {
id: ContractId::from_str(
"50fe882cbef5f3da6da82509a66b7e5e0a64a40d70164861c01c908a332198ae",
"4ea5fa100cd7c8972bc8925ed6f8ccfb6bf1e16f79c3642c3a503c73b7d18de2",
)
.unwrap(),
proxy: Some(
ContractId::from_str(
"8eae70214f55d25a65608bd288a5863e7187fcf65705143ee1a45fd228dacc19",
"deb633128bceadcd4eb4fe546089f6653727348b60228638a7f9d55d0b6da1ae",
)
.unwrap(),
),
Expand Down Expand Up @@ -491,6 +491,25 @@ async fn test_proxy_contract_re_routes_call() {
));

let impl_contract_a = ImplementationContract::new(proxy_contract_id, wallet_unlocked.clone());

// Test storage functions
let res = impl_contract_a
.methods()
.test_function_read()
.with_contract_ids(&[impl_contract_id.into()])
.call()
.await
.unwrap();
assert_eq!(res.value, 5);
let res = impl_contract_a
.methods()
.test_function_write(8)
.with_contract_ids(&[impl_contract_id.into()])
.call()
.await
.unwrap();
assert_eq!(res.value, 8);

let res = impl_contract_a
.methods()
.test_function()
Expand Down Expand Up @@ -525,6 +544,26 @@ async fn test_proxy_contract_re_routes_call() {
let impl_contract_id_after_update = contract_ids[0].id;
assert!(impl_contract_id != impl_contract_id_after_update);
let impl_contract_a = ImplementationContract::new(proxy_contract_after_update, wallet_unlocked);

// Test storage functions
let res = impl_contract_a
.methods()
.test_function_read()
.with_contract_ids(&[impl_contract_id_after_update.into()])
.call()
.await
.unwrap();
// Storage should be preserved from the previous target contract.
assert_eq!(res.value, 8);
let res = impl_contract_a
.methods()
.test_function_write(9)
.with_contract_ids(&[impl_contract_id_after_update.into()])
.call()
.await
.unwrap();
assert_eq!(res.value, 9);

let res = impl_contract_a
.methods()
.test_function()
Expand Down
Loading